From 510eeb7684748afc83eb14e27d95a6b6c65deff4 Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Wed, 30 Sep 2015 22:40:46 -0300 Subject: [PATCH 01/55] [javascript pt-br] : first part --- pt-br/javascript-pt.html.markdown | 533 ++++++++++++++++++++++++++++++ 1 file changed, 533 insertions(+) create mode 100644 pt-br/javascript-pt.html.markdown diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown new file mode 100644 index 00000000..c4115b3e --- /dev/null +++ b/pt-br/javascript-pt.html.markdown @@ -0,0 +1,533 @@ +--- +language: javascript +contributors: + - ["Adam Brenecki", "http://adam.brenecki.id.au"] + - ["Ariel Krakowski", "http://www.learneroo.com"] +filename: javascript.js +--- + +JavaScript foi criada por Brendan Eich, funcionário da Netscape, em 1995. Ela +foi originalmente criada para ser uma linguagem de script para websites, +complementando o uso de Java para aplicações web mais complexas, mas a sua +integração com páginas web e seu suporte nativo nos browsers fez com que +ela se tornasse mais comum que Java no frontend web. + +Javascript não é somente limitado a browsers web, no entanto: existe o Node.js, +que é um projeto que fornece um interpretador baseado no motor V8 do Google +Chrome e está se tornando cada vez mais famoso. + + +Feedback são muito apreciados! Você me encontrar em +[@adambrenecki](https://twitter.com/adambrenecki), ou +[adam@brenecki.id.au](mailto:adam@brenecki.id.au). + +```js +// Comentários são como em C. Comentários de uma linha começam com duas barras, +/* e comentários de múltplas linhas começam com barra-asterisco + e fecham com asterisco-barra */ + +// comandos podem ser terminados com ; +facaAlgo(); + +// ... mas eles não precisam ser, assim como o ponto-e-vírgula é automaticamente +// inserido quando há uma nova linha, exceto alguns casos. +facaAlgo() + +// Porque esses casos podem causar resultados inesperados, vamos continuar +// a usar ponto-e-vírgula neste guia. + +/////////////////////////////////// +// 1. Numbers, Strings and Operators + +// JavaScript has one number type (which is a 64-bit IEEE 754 double). +// Doubles have a 52-bit mantissa, which is enough to store integers +// up to about 9✕10¹⁵ precisely. +3; // = 3 +1.5; // = 1.5 + +// Some basic arithmetic works as you'd expect. +1 + 1; // = 2 +0.1 + 0.2; // = 0.30000000000000004 +8 - 1; // = 7 +10 * 2; // = 20 +35 / 5; // = 7 + +// Including uneven division. +5 / 2; // = 2.5 + +// Bitwise operations also work; when you perform a bitwise operation your float +// is converted to a signed int *up to* 32 bits. +1 << 2; // = 4 + +// Precedence is enforced with parentheses. +(1 + 3) * 2; // = 8 + +// There are three special not-a-real-number values: +Infinity; // result of e.g. 1/0 +-Infinity; // result of e.g. -1/0 +NaN; // result of e.g. 0/0 + +// There's also a boolean type. +true; +false; + +// Strings are created with ' or ". +'abc'; +"Hello, world"; + +// Negation uses the ! symbol +!true; // = false +!false; // = true + +// Equality is === +1 === 1; // = true +2 === 1; // = false + +// Inequality is !== +1 !== 1; // = false +2 !== 1; // = true + +// More comparisons +1 < 10; // = true +1 > 10; // = false +2 <= 2; // = true +2 >= 2; // = true + +// Strings are concatenated with + +"Hello " + "world!"; // = "Hello world!" + +// and are compared with < and > +"a" < "b"; // = true + +// Type coercion is performed for comparisons with double equals... +"5" == 5; // = true +null == undefined; // = true + +// ...unless you use === +"5" === 5; // = false +null === undefined; // = false + +// ...which can result in some weird behaviour... +13 + !0; // 14 +"13" + !0; // '13true' + +// You can access characters in a string with `charAt` +"This is a string".charAt(0); // = 'T' + +// ...or use `substring` to get larger pieces. +"Hello world".substring(0, 5); // = "Hello" + +// `length` is a property, so don't use (). +"Hello".length; // = 5 + +// There's also `null` and `undefined`. +null; // used to indicate a deliberate non-value +undefined; // used to indicate a value is not currently present (although + // `undefined` is actually a value itself) + +// false, null, undefined, NaN, 0 and "" are falsy; everything else is truthy. +// Note that 0 is falsy and "0" is truthy, even though 0 == "0". + +/////////////////////////////////// +// 2. Variables, Arrays and Objects + +// Variables are declared with the `var` keyword. JavaScript is dynamically +// typed, so you don't need to specify type. Assignment uses a single `=` +// character. +var someVar = 5; + +// if you leave the var keyword off, you won't get an error... +someOtherVar = 10; + +// ...but your variable will be created in the global scope, not in the scope +// you defined it in. + +// Variables declared without being assigned to are set to undefined. +var someThirdVar; // = undefined + +// There's shorthand for performing math operations on variables: +someVar += 5; // equivalent to someVar = someVar + 5; someVar is 10 now +someVar *= 10; // now someVar is 100 + +// and an even-shorter-hand for adding or subtracting 1 +someVar++; // now someVar is 101 +someVar--; // back to 100 + +// Arrays are ordered lists of values, of any type. +var myArray = ["Hello", 45, true]; + +// Their members can be accessed using the square-brackets subscript syntax. +// Array indices start at zero. +myArray[1]; // = 45 + +// Arrays are mutable and of variable length. +myArray.push("World"); +myArray.length; // = 4 + +// Add/Modify at specific index +myArray[3] = "Hello"; + +// JavaScript's objects are equivalent to "dictionaries" or "maps" in other +// languages: an unordered collection of key-value pairs. +var myObj = {key1: "Hello", key2: "World"}; + +// Keys are strings, but quotes aren't required if they're a valid +// JavaScript identifier. Values can be any type. +var myObj = {myKey: "myValue", "my other key": 4}; + +// Object attributes can also be accessed using the subscript syntax, +myObj["my other key"]; // = 4 + +// ... or using the dot syntax, provided the key is a valid identifier. +myObj.myKey; // = "myValue" + +// Objects are mutable; values can be changed and new keys added. +myObj.myThirdKey = true; + +// If you try to access a value that's not yet set, you'll get undefined. +myObj.myFourthKey; // = undefined + +/////////////////////////////////// +// 3. Logic and Control Structures + +// The syntax for this section is almost identical to Java's. + +// The `if` structure works as you'd expect. +var count = 1; +if (count == 3){ + // evaluated if count is 3 +} else if (count == 4){ + // evaluated if count is 4 +} else { + // evaluated if it's not either 3 or 4 +} + +// As does `while`. +while (true){ + // An infinite loop! +} + +// Do-while loops are like while loops, except they always run at least once. +var input; +do { + input = getInput(); +} while (!isValid(input)) + +// The `for` loop is the same as C and Java: +// initialisation; continue condition; iteration. +for (var i = 0; i < 5; i++){ + // will run 5 times +} + +// && is logical and, || is logical or +if (house.size == "big" && house.colour == "blue"){ + house.contains = "bear"; +} +if (colour == "red" || colour == "blue"){ + // colour is either red or blue +} + +// && and || "short circuit", which is useful for setting default values. +var name = otherName || "default"; + + +// The `switch` statement checks for equality with `===`. +// use 'break' after each case +// or the cases after the correct one will be executed too. +grade = 'B'; +switch (grade) { + case 'A': + console.log("Great job"); + break; + case 'B': + console.log("OK job"); + break; + case 'C': + console.log("You can do better"); + break; + default: + console.log("Oy vey"); + break; +} + + +/////////////////////////////////// +// 4. Functions, Scope and Closures + +// JavaScript functions are declared with the `function` keyword. +function myFunction(thing){ + return thing.toUpperCase(); +} +myFunction("foo"); // = "FOO" + +// Note that the value to be returned must start on the same line as the +// `return` keyword, otherwise you'll always return `undefined` due to +// automatic semicolon insertion. Watch out for this when using Allman style. +function myFunction() +{ + return // <- semicolon automatically inserted here + { + thisIsAn: 'object literal' + } +} +myFunction(); // = undefined + +// JavaScript functions are first class objects, so they can be reassigned to +// different variable names and passed to other functions as arguments - for +// example, when supplying an event handler: +function myFunction(){ + // this code will be called in 5 seconds' time +} +setTimeout(myFunction, 5000); +// Note: setTimeout isn't part of the JS language, but is provided by browsers +// and Node.js. + +// Function objects don't even have to be declared with a name - you can write +// an anonymous function definition directly into the arguments of another. +setTimeout(function(){ + // this code will be called in 5 seconds' time +}, 5000); + +// JavaScript has function scope; functions get their own scope but other blocks +// do not. +if (true){ + var i = 5; +} +i; // = 5 - not undefined as you'd expect in a block-scoped language + +// This has led to a common pattern of "immediately-executing anonymous +// functions", which prevent temporary variables from leaking into the global +// scope. +(function(){ + var temporary = 5; + // We can access the global scope by assiging to the "global object", which + // in a web browser is always `window`. The global object may have a + // different name in non-browser environments such as Node.js. + window.permanent = 10; +})(); +temporary; // raises ReferenceError +permanent; // = 10 + +// One of JavaScript's most powerful features is closures. If a function is +// defined inside another function, the inner function has access to all the +// outer function's variables, even after the outer function exits. +function sayHelloInFiveSeconds(name){ + var prompt = "Hello, " + name + "!"; + // Inner functions are put in the local scope by default, as if they were + // declared with `var`. + function inner(){ + alert(prompt); + } + setTimeout(inner, 5000); + // setTimeout is asynchronous, so the sayHelloInFiveSeconds function will + // exit immediately, and setTimeout will call inner afterwards. However, + // because inner is "closed over" sayHelloInFiveSeconds, inner still has + // access to the `prompt` variable when it is finally called. +} +sayHelloInFiveSeconds("Adam"); // will open a popup with "Hello, Adam!" in 5s + +/////////////////////////////////// +// 5. More about Objects; Constructors and Prototypes + +// Objects can contain functions. +var myObj = { + myFunc: function(){ + return "Hello world!"; + } +}; +myObj.myFunc(); // = "Hello world!" + +// When functions attached to an object are called, they can access the object +// they're attached to using the `this` keyword. +myObj = { + myString: "Hello world!", + myFunc: function(){ + return this.myString; + } +}; +myObj.myFunc(); // = "Hello world!" + +// What this is set to has to do with how the function is called, not where +// it's defined. So, our function doesn't work if it isn't called in the +// context of the object. +var myFunc = myObj.myFunc; +myFunc(); // = undefined + +// Inversely, a function can be assigned to the object and gain access to it +// through `this`, even if it wasn't attached when it was defined. +var myOtherFunc = function(){ + return this.myString.toUpperCase(); +} +myObj.myOtherFunc = myOtherFunc; +myObj.myOtherFunc(); // = "HELLO WORLD!" + +// We can also specify a context for a function to execute in when we invoke it +// using `call` or `apply`. + +var anotherFunc = function(s){ + return this.myString + s; +} +anotherFunc.call(myObj, " And Hello Moon!"); // = "Hello World! And Hello Moon!" + +// The `apply` function is nearly identical, but takes an array for an argument +// list. + +anotherFunc.apply(myObj, [" And Hello Sun!"]); // = "Hello World! And Hello Sun!" + +// This is useful when working with a function that accepts a sequence of +// arguments and you want to pass an array. + +Math.min(42, 6, 27); // = 6 +Math.min([42, 6, 27]); // = NaN (uh-oh!) +Math.min.apply(Math, [42, 6, 27]); // = 6 + +// But, `call` and `apply` are only temporary. When we want it to stick, we can +// use `bind`. + +var boundFunc = anotherFunc.bind(myObj); +boundFunc(" And Hello Saturn!"); // = "Hello World! And Hello Saturn!" + +// `bind` can also be used to partially apply (curry) a function. + +var product = function(a, b){ return a * b; } +var doubler = product.bind(this, 2); +doubler(8); // = 16 + +// When you call a function with the `new` keyword, a new object is created, and +// made available to the function via the this keyword. Functions designed to be +// called like that are called constructors. + +var MyConstructor = function(){ + this.myNumber = 5; +} +myNewObj = new MyConstructor(); // = {myNumber: 5} +myNewObj.myNumber; // = 5 + +// Every JavaScript object has a 'prototype'. When you go to access a property +// on an object that doesn't exist on the actual object, the interpreter will +// look at its prototype. + +// Some JS implementations let you access an object's prototype on the magic +// property `__proto__`. While this is useful for explaining prototypes it's not +// part of the standard; we'll get to standard ways of using prototypes later. +var myObj = { + myString: "Hello world!" +}; +var myPrototype = { + meaningOfLife: 42, + myFunc: function(){ + return this.myString.toLowerCase() + } +}; + +myObj.__proto__ = myPrototype; +myObj.meaningOfLife; // = 42 + +// This works for functions, too. +myObj.myFunc(); // = "hello world!" + +// Of course, if your property isn't on your prototype, the prototype's +// prototype is searched, and so on. +myPrototype.__proto__ = { + myBoolean: true +}; +myObj.myBoolean; // = true + +// There's no copying involved here; each object stores a reference to its +// prototype. This means we can alter the prototype and our changes will be +// reflected everywhere. +myPrototype.meaningOfLife = 43; +myObj.meaningOfLife; // = 43 + +// We mentioned that `__proto__` was non-standard, and there's no standard way to +// change the prototype of an existing object. However, there are two ways to +// create a new object with a given prototype. + +// The first is Object.create, which is a recent addition to JS, and therefore +// not available in all implementations yet. +var myObj = Object.create(myPrototype); +myObj.meaningOfLife; // = 43 + +// The second way, which works anywhere, has to do with constructors. +// Constructors have a property called prototype. This is *not* the prototype of +// the constructor function itself; instead, it's the prototype that new objects +// are given when they're created with that constructor and the new keyword. +MyConstructor.prototype = { + myNumber: 5, + getMyNumber: function(){ + return this.myNumber; + } +}; +var myNewObj2 = new MyConstructor(); +myNewObj2.getMyNumber(); // = 5 +myNewObj2.myNumber = 6 +myNewObj2.getMyNumber(); // = 6 + +// Built-in types like strings and numbers also have constructors that create +// equivalent wrapper objects. +var myNumber = 12; +var myNumberObj = new Number(12); +myNumber == myNumberObj; // = true + +// Except, they aren't exactly equivalent. +typeof myNumber; // = 'number' +typeof myNumberObj; // = 'object' +myNumber === myNumberObj; // = false +if (0){ + // This code won't execute, because 0 is falsy. +} +if (Number(0)){ + // This code *will* execute, because Number(0) is truthy. +} + +// However, the wrapper objects and the regular builtins share a prototype, so +// you can actually add functionality to a string, for instance. +String.prototype.firstCharacter = function(){ + return this.charAt(0); +} +"abc".firstCharacter(); // = "a" + +// This fact is often used in "polyfilling", which is implementing newer +// features of JavaScript in an older subset of JavaScript, so that they can be +// used in older environments such as outdated browsers. + +// For instance, we mentioned that Object.create isn't yet available in all +// implementations, but we can still use it with this polyfill: +if (Object.create === undefined){ // don't overwrite it if it exists + Object.create = function(proto){ + // make a temporary constructor with the right prototype + var Constructor = function(){}; + Constructor.prototype = proto; + // then use it to create a new, appropriately-prototyped object + return new Constructor(); + } +} +``` + +## Further Reading + +The [Mozilla Developer +Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript) provides +excellent documentation for JavaScript as it's used in browsers. Plus, it's a +wiki, so as you learn more you can help others out by sharing your own +knowledge. + +MDN's [A re-introduction to +JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) +covers much of the concepts covered here in more detail. This guide has quite +deliberately only covered the JavaScript language itself; if you want to learn +more about how to use JavaScript in web pages, start by learning about the +[Document Object +Model](https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core) + +[Learn Javascript by Example and with Challenges](http://www.learneroo.com/modules/64/nodes/350) is a variant of this reference with built-in challenges. + +[JavaScript Garden](http://bonsaiden.github.io/JavaScript-Garden/) is an in-depth +guide of all the counter-intuitive parts of the language. + +[JavaScript: The Definitive Guide](http://www.amazon.com/gp/product/0596805527/) is a classic guide / reference book. + +In addition to direct contributors to this article, some content is adapted +from Louie Dinh's Python tutorial on this site, and the [JS +Tutorial](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) +on the Mozilla Developer Network. From e4a33446a9c910f13bc0224c745c51baf62c1778 Mon Sep 17 00:00:00 2001 From: Jesus Tinoco <JesusTinoco@users.noreply.github.com> Date: Thu, 1 Oct 2015 21:34:02 +0200 Subject: [PATCH 02/55] Typos fixed in julia-es.html.markdown --- es-es/julia-es.html.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/es-es/julia-es.html.markdown b/es-es/julia-es.html.markdown index 95a16412..bf035edf 100644 --- a/es-es/julia-es.html.markdown +++ b/es-es/julia-es.html.markdown @@ -45,7 +45,7 @@ Esto se basa en la versión `0.3.11`. # Los comentarios de una línea comienzan con una almohadilla (o signo de gato). #= - Los commentarios multilínea pueden escribirse + Los comentarios multilínea pueden escribirse usando '#=' antes de el texto y '=#' después del texto. También se pueden anidar. =# @@ -174,7 +174,7 @@ otraVariable_123! = 6 # => 6 otra_variable * Los nombres de los tipos comienzan con una letra mayúscula y separación de - palabras se muestra con CamelCase en vez de guion bajo: + palabras se muestra con CamelCase en vez de guión bajo: OtroTipo @@ -214,7 +214,7 @@ matrix = [1 2; 3 4] 3 4 =# -# Añadir cosas a la final de un arreglo con push! y append!. +# Añadir cosas al final de un arreglo con push! y append!. push!(a, 1) # => [1] push!(a, 2) # => [1,2] push!(a, 4) # => [1,2,4] @@ -237,7 +237,7 @@ a[end] # => 6 shift!(a) # => 1 y a es ahora: [2,4,3,4,5,6] unshift!(a, 7) # => [7,2,4,3,4,5,6] -# Los nombres de funciónes que terminan en exclamaciones indican que modifican +# Los nombres de funciones que terminan en exclamaciones indican que modifican # su o sus argumentos de entrada. arr = [5, 4, 6] # => 3-element Array{Int64,1}: [5,4,6] sort(arr) # => [4,5,6] y arr es todavía: [5,4,6] @@ -710,7 +710,7 @@ end # Sólo define una función del mismo nombre que el tipo y llama al constructor # existente para obtener un valor del tipo correcto. -# Este es un constructor externo porque es fuera de la definición del tipo. +# Este es un constructor externo porque está fuera de la definición del tipo. Leon(rugido::String) = Leon("verde", rugido) type Pantera <: Gato # Pantera también es un a subtipo de Gato @@ -730,7 +730,7 @@ end ######################## # En Julia, todas las funciones nombradas son funciones genéricas. -# Esto significa que se construyen a partir de muchos métodosmás pequeños. +# Esto significa que se construyen a partir de muchos métodos más pequeños. # Cada constructor de Leon es un método de la función genérica Leon. # Por ejemplo, vamos a hacer métodos para para Leon, Pantera, y Tigre de una From ed2bc5a84c4dfc1af45c05ea8b1a20122ac72620 Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Thu, 1 Oct 2015 22:23:18 -0300 Subject: [PATCH 03/55] =?UTF-8?q?[javascript=20pt-br]=20:=201.=20N=C3=BAme?= =?UTF-8?q?ros,=20Strings=20e=20Operadores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt-br/javascript-pt.html.markdown | 75 ++++++++++++++++--------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown index c4115b3e..72f4cf0f 100644 --- a/pt-br/javascript-pt.html.markdown +++ b/pt-br/javascript-pt.html.markdown @@ -37,96 +37,99 @@ facaAlgo() // a usar ponto-e-vírgula neste guia. /////////////////////////////////// -// 1. Numbers, Strings and Operators +// 1. Números, Strings e Operadores -// JavaScript has one number type (which is a 64-bit IEEE 754 double). -// Doubles have a 52-bit mantissa, which is enough to store integers -// up to about 9✕10¹⁵ precisely. +// Javascript tem um tipo de número (que é o 64-bit IEEE 754 double). +// Doublas tem uma mantissa 52-bit, que é suficiente para guardar inteiros +// acima de 9✕10¹⁵ precisamente. 3; // = 3 1.5; // = 1.5 -// Some basic arithmetic works as you'd expect. +// A aritmética básica funciona seria de esperar. 1 + 1; // = 2 0.1 + 0.2; // = 0.30000000000000004 8 - 1; // = 7 10 * 2; // = 20 35 / 5; // = 7 -// Including uneven division. +// Inclusive divisão desigual. 5 / 2; // = 2.5 -// Bitwise operations also work; when you perform a bitwise operation your float -// is converted to a signed int *up to* 32 bits. +// Operadores Bitwise também funcionam; quando você faz uma operação bitwise +// seu float é convertido para um int de até 32 bits. 1 << 2; // = 4 -// Precedence is enforced with parentheses. +// A precedência é aplicada com parênteses. (1 + 3) * 2; // = 8 // There are three special not-a-real-number values: -Infinity; // result of e.g. 1/0 --Infinity; // result of e.g. -1/0 -NaN; // result of e.g. 0/0 +// Existem três especiais valores não-é-número-real: +Infinity; // resultado de 1/0 +-Infinity; // resultado de -1/0 +NaN; // resultado de 0/0 -// There's also a boolean type. +// Existe também o tipo booleano. true; false; -// Strings are created with ' or ". +// Strings são criados com ' ou ". 'abc'; -"Hello, world"; +"Olá, mundo"; // Negation uses the ! symbol +// Negação usa o símbolo ! !true; // = false !false; // = true -// Equality is === +// Igualdade é === 1 === 1; // = true 2 === 1; // = false -// Inequality is !== +// Desigualdade é !== 1 !== 1; // = false 2 !== 1; // = true -// More comparisons +// Mais comparações 1 < 10; // = true 1 > 10; // = false 2 <= 2; // = true 2 >= 2; // = true -// Strings are concatenated with + -"Hello " + "world!"; // = "Hello world!" +// Strings são concatenadas com + +"Olá " + "mundo!"; // = "Olá mundo!" -// and are compared with < and > +// e comparadas com < e > "a" < "b"; // = true -// Type coercion is performed for comparisons with double equals... +// A coerção de tipos é feita para comparações com dois iguais... "5" == 5; // = true null == undefined; // = true -// ...unless you use === +// ...a menos que use === "5" === 5; // = false null === undefined; // = false -// ...which can result in some weird behaviour... +// ...que irá resultar num comportamento estranho... 13 + !0; // 14 "13" + !0; // '13true' -// You can access characters in a string with `charAt` -"This is a string".charAt(0); // = 'T' +// Você pode acessar caracteres de uma String usando o `charAt` +"Isto é uma String".charAt(0); // = 'I' -// ...or use `substring` to get larger pieces. -"Hello world".substring(0, 5); // = "Hello" +// ...ou usar `substring` para pegar pedaços maiores. +"Olá mundo".substring(0, 3); // = "Olá" -// `length` is a property, so don't use (). -"Hello".length; // = 5 +// `length` é uma propriedade, portanto não use (). +"Olá".length; // = 3 -// There's also `null` and `undefined`. -null; // used to indicate a deliberate non-value -undefined; // used to indicate a value is not currently present (although - // `undefined` is actually a value itself) +// Existe também o `null` e o `undefined`. +null; // usado para indicar um valor não considerado +undefined; // usado para indicar um valor que não é a atualmente definido + // (entretando `undefined` é usado como um próprio valor -// false, null, undefined, NaN, 0 and "" are falsy; everything else is truthy. -// Note that 0 is falsy and "0" is truthy, even though 0 == "0". +// false, null, undefined, NaN, 0 and "" são valores falsy; +// qualquer outro valor é truthy +// Note que 0 é falsy e "0" é truthy, até mesmo 0 == "0". /////////////////////////////////// // 2. Variables, Arrays and Objects From 716e0ced466ef98f7fb9d78d15a5ab606b6b755c Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Thu, 1 Oct 2015 23:48:05 -0300 Subject: [PATCH 04/55] =?UTF-8?q?[javascript=20pt-br]=20:=202.=20Vari?= =?UTF-8?q?=C3=A1veis,=20Arrays=20e=20Objetos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt-br/javascript-pt.html.markdown | 57 ++++++++++++++++--------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown index 72f4cf0f..6667a77d 100644 --- a/pt-br/javascript-pt.html.markdown +++ b/pt-br/javascript-pt.html.markdown @@ -132,62 +132,65 @@ undefined; // usado para indicar um valor que não é a atualmente definido // Note que 0 é falsy e "0" é truthy, até mesmo 0 == "0". /////////////////////////////////// -// 2. Variables, Arrays and Objects +// 2. Variáveis, Arrays e Objetos -// Variables are declared with the `var` keyword. JavaScript is dynamically -// typed, so you don't need to specify type. Assignment uses a single `=` -// character. +// Variáveis são declarados com a palavra-chave `var`. O Javascript é +// dinâmicamente tipado, portanto você não precisa especificar o tipo. +// Atribuições usam um simples caracter de `=`. var someVar = 5; -// if you leave the var keyword off, you won't get an error... +// se você deixar de colocar a palavra-chave var, você não receber um erro... someOtherVar = 10; -// ...but your variable will be created in the global scope, not in the scope -// you defined it in. +// ...mas sua variável será criada no escopo global, não no escopo em que você +// definiu ela. -// Variables declared without being assigned to are set to undefined. +// Variáveis declaradas sem receberem um valor são definidas como `undefined`. var someThirdVar; // = undefined -// There's shorthand for performing math operations on variables: -someVar += 5; // equivalent to someVar = someVar + 5; someVar is 10 now -someVar *= 10; // now someVar is 100 +// Existe um shorthad para operações matemáticas em variáveis: +someVar += 5; // equivalente a someVar = someVar + 5; someVar é 10 agora +someVar *= 10; // agora someVar é 100 -// and an even-shorter-hand for adding or subtracting 1 +// e um para adição e subtração de 1 someVar++; // now someVar is 101 someVar--; // back to 100 -// Arrays are ordered lists of values, of any type. -var myArray = ["Hello", 45, true]; +// Arrays são listas ordenadas de valores, de qualquer tipo. +var myArray = ["Olá", 45, true]; -// Their members can be accessed using the square-brackets subscript syntax. -// Array indices start at zero. +// Seus membros podem ser acessados usando a sintaxe de colchetes. +// O indíce de um Array começa pelo 0. myArray[1]; // = 45 -// Arrays are mutable and of variable length. +// Arrays são mutáveis e de tamanho variável. myArray.push("World"); myArray.length; // = 4 -// Add/Modify at specific index +// Adicionar/modificar em um índice específico myArray[3] = "Hello"; -// JavaScript's objects are equivalent to "dictionaries" or "maps" in other -// languages: an unordered collection of key-value pairs. -var myObj = {key1: "Hello", key2: "World"}; +// Objetos de Javascript são equivalentes aos dicionários ou maps de outras +// linguagens: uma coleção não ordenada de pares chave-valor. +var myObj = {chave1: "Olá", chave2: "Mundo"}; -// Keys are strings, but quotes aren't required if they're a valid -// JavaScript identifier. Values can be any type. +// Chaves são strings, mas as aspas não são necessárias se elas são +// identificadores válidos no Javascript. Valores podem ser de qualquer tipo. var myObj = {myKey: "myValue", "my other key": 4}; -// Object attributes can also be accessed using the subscript syntax, +// Atributos de objetos também podem ser acessados com a sintaxe de colchetes. myObj["my other key"]; // = 4 -// ... or using the dot syntax, provided the key is a valid identifier. +// ... ou usando a sintaxe de ponto, passando a chave que é um identificador +// válido. myObj.myKey; // = "myValue" -// Objects are mutable; values can be changed and new keys added. +// Objetos são mutáveis, valores podem ser modificados e novas chaves +// adicionadas. myObj.myThirdKey = true; -// If you try to access a value that's not yet set, you'll get undefined. +// Se você tentar acessar um valor que não foi determinado ainda, você irá +// receber `undefined`. myObj.myFourthKey; // = undefined /////////////////////////////////// From 32caaabe05e2d920c4be42c278e2e6d51ddea6ed Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Fri, 2 Oct 2015 01:05:31 -0300 Subject: [PATCH 05/55] =?UTF-8?q?[javascript=20pt-br]=20:=203.=20L=C3=B3gi?= =?UTF-8?q?ca=20e=20Estruturas=20de=20Controle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt-br/javascript-pt.html.markdown | 42 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown index 6667a77d..14d82146 100644 --- a/pt-br/javascript-pt.html.markdown +++ b/pt-br/javascript-pt.html.markdown @@ -194,52 +194,54 @@ myObj.myThirdKey = true; myObj.myFourthKey; // = undefined /////////////////////////////////// -// 3. Logic and Control Structures +// 3. Lógica e Estruturas de Controle -// The syntax for this section is almost identical to Java's. +// A sintaxe para essa seção é quase idêntica a maioria das linguagens. // The `if` structure works as you'd expect. -var count = 1; +// A estrutura `if` funciona como deveria ser. +var count = 1 if (count == 3){ - // evaluated if count is 3 + // executa se count é 3 } else if (count == 4){ - // evaluated if count is 4 + // executa se count é 4 } else { - // evaluated if it's not either 3 or 4 + // executa se count não é 3 nem 4 } -// As does `while`. +// Como se faz `while`. while (true){ - // An infinite loop! + // Um loop infinito! } -// Do-while loops are like while loops, except they always run at least once. -var input; +// Os loops do-while são como os loops de while, exceto quando eles sempre +// executam pelo menos uma vez. do { input = getInput(); } while (!isValid(input)) // The `for` loop is the same as C and Java: // initialisation; continue condition; iteration. + +// O loop `for` é o mesmo de C e Java: +// inicialização, condição de continuar; iteração for (var i = 0; i < 5; i++){ - // will run 5 times + // vai rodar cinco vezes } -// && is logical and, || is logical or +// && é o `e` lógico , || é o `ou` lógico if (house.size == "big" && house.colour == "blue"){ house.contains = "bear"; } -if (colour == "red" || colour == "blue"){ - // colour is either red or blue +if (cor == "red" || cor == "blue"){ + // cor é vermelha OU azul } -// && and || "short circuit", which is useful for setting default values. -var name = otherName || "default"; +// && e || "pequeno circuito", é útil para determinar valores padrões. +var name = otherName || "padrão"; - -// The `switch` statement checks for equality with `===`. -// use 'break' after each case -// or the cases after the correct one will be executed too. +// O `switch` checa pela igualdade com `===`. +// Use `break` após cada `case` grade = 'B'; switch (grade) { case 'A': From 2534c71c4f5cc8f6b806914857da11b8ae89f45d Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Fri, 2 Oct 2015 01:23:46 -0300 Subject: [PATCH 06/55] =?UTF-8?q?[javascript=20pt-br]=20:=20Fun=C3=A7?= =?UTF-8?q?=C3=B5es,=20Escopos=20e=20Closures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt-br/javascript-pt.html.markdown | 79 ++++++++++++++++--------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown index 14d82146..08448d0b 100644 --- a/pt-br/javascript-pt.html.markdown +++ b/pt-br/javascript-pt.html.markdown @@ -209,7 +209,7 @@ if (count == 3){ // executa se count não é 3 nem 4 } -// Como se faz `while`. +// Como se faz um `while`. while (true){ // Um loop infinito! } @@ -224,7 +224,7 @@ do { // initialisation; continue condition; iteration. // O loop `for` é o mesmo de C e Java: -// inicialização, condição de continuar; iteração +// inicialização, condição para continuar; iteração for (var i = 0; i < 5; i++){ // vai rodar cinco vezes } @@ -260,79 +260,84 @@ switch (grade) { /////////////////////////////////// -// 4. Functions, Scope and Closures +// 4. Funções, Escopos e Closures -// JavaScript functions are declared with the `function` keyword. +// Funções Javascript são declaradas com a palavra-chave `function`. function myFunction(thing){ return thing.toUpperCase(); } myFunction("foo"); // = "FOO" -// Note that the value to be returned must start on the same line as the -// `return` keyword, otherwise you'll always return `undefined` due to -// automatic semicolon insertion. Watch out for this when using Allman style. +// Repare que o valor a ser retornado deve começar na mesma linha que +// a palavra-chave `return`, senão você sempre irá retornar `undefined` +// visto que o ponto-e-vírgula é inserido automáticamente nas quebras de +// linha. Preste atenção quando usar o estilo Allman. function myFunction() { - return // <- semicolon automatically inserted here + return // <- ponto-e-vírgula adicionado automaticamente aqui { thisIsAn: 'object literal' } } myFunction(); // = undefined -// JavaScript functions are first class objects, so they can be reassigned to -// different variable names and passed to other functions as arguments - for -// example, when supplying an event handler: +// Funções Javascript são objetos de primeira classe, portanto elas podem +// ser atribuídas a nomes de variáveis e serem passadas para outras funções +// como argumentos - por exemplo, quando criamos um manipulador de eventos: function myFunction(){ - // this code will be called in 5 seconds' time + // este código será chamado em 5 segundos } setTimeout(myFunction, 5000); -// Note: setTimeout isn't part of the JS language, but is provided by browsers -// and Node.js. +// Nota: `setTimeout` não é parte da linguagem Javascript, mas é provido pelos +// browsers e o Node.js. -// Function objects don't even have to be declared with a name - you can write -// an anonymous function definition directly into the arguments of another. +// Objetos de funções não precisam nem serem declarados com nome - você pode +// escrever a definição de uma função anônima diretamente nos argumentos de +// outra função. setTimeout(function(){ - // this code will be called in 5 seconds' time + // este código será chamado em 5 segundos }, 5000); -// JavaScript has function scope; functions get their own scope but other blocks -// do not. +// O Javascript tem escopo de função; as funções tem seu próprio escopo, +// mas outros blocos não. if (true){ var i = 5; } -i; // = 5 - not undefined as you'd expect in a block-scoped language +i; // = 5 - não `undefined` como você esperaria numa linguagem de blogo-escopo -// This has led to a common pattern of "immediately-executing anonymous -// functions", which prevent temporary variables from leaking into the global -// scope. +// Isso levou a padrão comum chamado de IIFE (Imediately Invoked Function +// Expression) ou (Expressão de Função Invocada Imediatamente), que previne +// que variáveis temporárias vazem para o escopo global. (function(){ var temporary = 5; - // We can access the global scope by assiging to the "global object", which - // in a web browser is always `window`. The global object may have a - // different name in non-browser environments such as Node.js. + // Nós podemos acessar o escopo global definindo o "objeto global", que + // no browser vai ser sempre `window`. O objeto global pode ter um nome + // diferente para ambiente não-browser como o Node.js. window.permanent = 10; })(); -temporary; // raises ReferenceError +temporary; // levanta um erro de referência inexiste permanent; // = 10 -// One of JavaScript's most powerful features is closures. If a function is -// defined inside another function, the inner function has access to all the -// outer function's variables, even after the outer function exits. +// Uma das principais características do Javascript é a closure. Que é +// uma função definida dentro de outra função, a função interna pode acessar +// todas as variáveis da função externa, mesmo depois da função de fora +// finalizar sua execução. function sayHelloInFiveSeconds(name){ var prompt = "Hello, " + name + "!"; - // Inner functions are put in the local scope by default, as if they were - // declared with `var`. + + // Funções internas são colocadas no escopo local por padrão, assim como + // se fossem declaradas com `var`. function inner(){ alert(prompt); } setTimeout(inner, 5000); - // setTimeout is asynchronous, so the sayHelloInFiveSeconds function will - // exit immediately, and setTimeout will call inner afterwards. However, - // because inner is "closed over" sayHelloInFiveSeconds, inner still has - // access to the `prompt` variable when it is finally called. + // `setTimeout` é assíncrono, portanto a função `sayHelloInFiveSeconds` + // vai sair imediatamente, e o `setTimeout` irá chamar a interna depois. + // Entretanto. como a interna é fechada dentro de "sayHelloInFiveSeconds", + // a interna permanece podendo acessar a variável `prompt` quando depois + // de chamada. } -sayHelloInFiveSeconds("Adam"); // will open a popup with "Hello, Adam!" in 5s +sayHelloInFiveSeconds("Adam"); // Vai abrir um popup com "Hello, Adam!" em 5s /////////////////////////////////// // 5. More about Objects; Constructors and Prototypes From acc9a73c018a28a9c8ead7b108dd1fdfee7a797b Mon Sep 17 00:00:00 2001 From: ksami <ksami.ihide@gmail.com> Date: Fri, 2 Oct 2015 22:08:27 +0800 Subject: [PATCH 07/55] [bash/en] Improved descriptions --- bash.html.markdown | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bash.html.markdown b/bash.html.markdown index 08182c2c..d4f3d424 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -51,7 +51,7 @@ echo $Variable echo "$Variable" echo '$Variable' # When you use the variable itself — assign it, export it, or else — you write -# its name without $. If you want to use variable's value, you should use $. +# its name without $. If you want to use the variable's value, you should use $. # Note that ' (single quote) won't expand the variables! # String substitution in variables @@ -70,11 +70,11 @@ echo ${Foo:-"DefaultValueIfFooIsMissingOrEmpty"} # Builtin variables: # There are some useful builtin variables, like -echo "Last program return value: $?" +echo "Last program's return value: $?" echo "Script's PID: $$" -echo "Number of arguments: $#" -echo "Scripts arguments: $@" -echo "Scripts arguments separated in different variables: $1 $2..." +echo "Number of arguments passed to script: $#" +echo "All arguments passed to script: $@" +echo "Script's arguments separated into different variables: $1 $2..." # Reading a value from input: echo "What's your name?" @@ -108,8 +108,8 @@ fi # Expressions are denoted with the following format: echo $(( 10 + 5 )) -# Unlike other programming languages, bash is a shell — so it works in a context -# of current directory. You can list files and directories in the current +# Unlike other programming languages, bash is a shell so it works in the context +# of a current directory. You can list files and directories in the current # directory with the ls command: ls From c0b09da46f93bc1b59231c9ebd2832198bc85fcb Mon Sep 17 00:00:00 2001 From: Jesus Tinoco <JesusTinoco@users.noreply.github.com> Date: Fri, 2 Oct 2015 16:11:23 +0200 Subject: [PATCH 08/55] Fixing typo in julia-es.html.markdown --- es-es/julia-es.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es-es/julia-es.html.markdown b/es-es/julia-es.html.markdown index bf035edf..e4181609 100644 --- a/es-es/julia-es.html.markdown +++ b/es-es/julia-es.html.markdown @@ -733,7 +733,7 @@ end # Esto significa que se construyen a partir de muchos métodos más pequeños. # Cada constructor de Leon es un método de la función genérica Leon. -# Por ejemplo, vamos a hacer métodos para para Leon, Pantera, y Tigre de una +# Por ejemplo, vamos a hacer métodos para Leon, Pantera, y Tigre de una # función genérica maullar: # acceso utilizando notación de puntos From ae86e4ebabb0c78c1bd8052e6ab5916446ef39c2 Mon Sep 17 00:00:00 2001 From: Alva Connor Waters <connor_waters@hotmail.com> Date: Fri, 2 Oct 2015 15:19:38 +0000 Subject: [PATCH 09/55] Clarify character literals --- c++.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/c++.html.markdown b/c++.html.markdown index 8a7f5a59..1cf5508a 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -53,11 +53,11 @@ int main(int argc, char** argv) // However, C++ varies in some of the following ways: -// In C++, character literals are one byte. -sizeof('c') == 1 +// In C++, character literals are chars +sizeof('c') == sizeof(char) == 1 -// In C, character literals are the same size as ints. -sizeof('c') == sizeof(10) +// In C, character literals are ints +sizeof('c') == sizeof(int) // C++ has strict prototyping From 455afa3a7bf59fc272f3439825da55659765eec0 Mon Sep 17 00:00:00 2001 From: Alva Connor Waters <connor_waters@hotmail.com> Date: Fri, 2 Oct 2015 15:55:05 +0000 Subject: [PATCH 10/55] More explanation on virtual destructors --- c++.html.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/c++.html.markdown b/c++.html.markdown index 1cf5508a..b59635f5 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -349,7 +349,10 @@ public: // These are called when an object is deleted or falls out of scope. // This enables powerful paradigms such as RAII // (see below) - // Destructors must be virtual to allow classes to be derived from this one. + // Destructors should be virtual if a class is to be derived from; + // if they are not virtual, then any resources allocated using RAII in + // the derived class will not be released if it destroyed through a + // base-class reference or pointer. virtual ~Dog(); }; // A semicolon must follow the class definition. From 12286a4b78f82bde3907d4bf348e20c12dd6d46f Mon Sep 17 00:00:00 2001 From: Alva Connor Waters <connor_waters@hotmail.com> Date: Fri, 2 Oct 2015 16:00:13 +0000 Subject: [PATCH 11/55] Misc. typos and formatting --- c++.html.markdown | 72 +++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/c++.html.markdown b/c++.html.markdown index b59635f5..e5eceac1 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -159,9 +159,9 @@ void foo() int main() { - // Includes all symbols from `namesapce Second` into the current scope. Note - // that simply `foo()` no longer works, since it is now ambiguous whether - // we're calling the `foo` in `namespace Second` or the top level. + // Includes all symbols from namespace Second into the current scope. Note + // that simply foo() no longer works, since it is now ambiguous whether + // we're calling the foo in namespace Second or the top level. using namespace Second; Second::foo(); // prints "This is Second::foo" @@ -256,7 +256,7 @@ string tempObjectFun() { ... } string retVal = tempObjectFun(); // What happens in the second line is actually: -// - a string object is returned from `tempObjectFun` +// - a string object is returned from tempObjectFun // - a new string is constructed with the returned object as arugment to the // constructor // - the returned object is destroyed @@ -268,15 +268,15 @@ string retVal = tempObjectFun(); // code: foo(bar(tempObjectFun())) -// assuming `foo` and `bar` exist, the object returned from `tempObjectFun` is -// passed to `bar`, and it is destroyed before `foo` is called. +// assuming foo and bar exist, the object returned from tempObjectFun is +// passed to bar, and it is destroyed before foo is called. // Now back to references. The exception to the "at the end of the enclosing // expression" rule is if a temporary object is bound to a const reference, in // which case its life gets extended to the current scope: void constReferenceTempObjectFun() { - // `constRef` gets the temporary object, and it is valid until the end of this + // constRef gets the temporary object, and it is valid until the end of this // function. const string& constRef = tempObjectFun(); ... @@ -301,7 +301,7 @@ basic_string(basic_string&& other); // Idea being if we are constructing a new string from a temporary object (which // is going to be destroyed soon anyway), we can have a more efficient // constructor that "salvages" parts of that temporary string. You will see this -// concept referred to as the move semantic. +// concept referred to as "move semantics". ////////////////////////////////////////// // Classes and object-oriented programming @@ -349,10 +349,10 @@ public: // These are called when an object is deleted or falls out of scope. // This enables powerful paradigms such as RAII // (see below) - // Destructors should be virtual if a class is to be derived from; - // if they are not virtual, then any resources allocated using RAII in - // the derived class will not be released if it destroyed through a - // base-class reference or pointer. + // The destructor should be virtual if a class is to be derived from; + // if it is not virtual, then the derived class' destructor will + // not be called if the object is destroyed through a base-class reference + // or pointer. virtual ~Dog(); }; // A semicolon must follow the class definition. @@ -495,9 +495,10 @@ int main () { ///////////////////// // Templates in C++ are mostly used for generic programming, though they are -// much more powerful than generics constructs in other languages. It also -// supports explicit and partial specialization, functional-style type classes, -// and also it's Turing-complete. +// much more powerful than generic constructs in other languages. They also +// support explicit and partial specialization and functional-style type +// classes; in fact, they are a Turing-complete functional language embedded +// in C++! // We start with the kind of generic programming you might be familiar with. To // define a class or function that takes a type parameter: @@ -509,7 +510,7 @@ public: }; // During compilation, the compiler actually generates copies of each template -// with parameters substituted, and so the full definition of the class must be +// with parameters substituted, so the full definition of the class must be // present at each invocation. This is why you will see template classes defined // entirely in header files. @@ -523,13 +524,13 @@ intBox.insert(123); Box<Box<int> > boxOfBox; boxOfBox.insert(intBox); -// Up until C++11, you must place a space between the two '>'s, otherwise '>>' -// will be parsed as the right shift operator. +// Until C++11, you had to place a space between the two '>'s, otherwise '>>' +// would be parsed as the right shift operator. // You will sometimes see // template<typename T> -// instead. The 'class' keyword and 'typename' keyword are _mostly_ -// interchangeable in this case. For full explanation, see +// instead. The 'class' keyword and 'typename' keywords are _mostly_ +// interchangeable in this case. For the full explanation, see // http://en.wikipedia.org/wiki/Typename // (yes, that keyword has its own Wikipedia page). @@ -585,12 +586,15 @@ try { // Do not allocate exceptions on the heap using _new_. throw std::runtime_error("A problem occurred"); } + // Catch exceptions by const reference if they are objects catch (const std::exception& ex) { - std::cout << ex.what(); + std::cout << ex.what(); +} + // Catches any exception not caught by previous _catch_ blocks -} catch (...) +catch (...) { std::cout << "Unknown exception caught"; throw; // Re-throws the exception @@ -600,8 +604,8 @@ catch (const std::exception& ex) // RAII /////// -// RAII stands for Resource Allocation Is Initialization. -// It is often considered the most powerful paradigm in C++, +// RAII stands for "Resource Acquisition Is Initialization". +// It is often considered the most powerful paradigm in C++ // and is the simple concept that a constructor for an object // acquires that object's resources and the destructor releases them. @@ -622,9 +626,9 @@ void doSomethingWithAFile(const char* filename) // Unfortunately, things are quickly complicated by error handling. // Suppose fopen can fail, and that doSomethingWithTheFile and // doSomethingElseWithIt return error codes if they fail. -// (Exceptions are the preferred way of handling failure, -// but some programmers, especially those with a C background, -// disagree on the utility of exceptions). +// (Exceptions are the preferred way of handling failure, +// but some programmers, especially those with a C background, +// disagree on the utility of exceptions). // We now have to check each call for failure and close the file handle // if a problem occurred. bool doSomethingWithAFile(const char* filename) @@ -744,15 +748,17 @@ class FooSub : public Foo { // 0 == false == NULL (most of the time)! bool* pt = new bool; -*pt = 0; // Sets the value points by 'pt' to false. +*pt = 0; // Sets the value points by 'pt' to false. pt = 0; // Sets 'pt' to the null pointer. Both lines compile without warnings. // nullptr is supposed to fix some of that issue: int* pt2 = new int; -*pt2 = nullptr; // Doesn't compile +*pt2 = nullptr; // Doesn't compile pt2 = nullptr; // Sets pt2 to null. -// But somehow 'bool' type is an exception (this is to make `if (ptr)` compile). +// There is an exception made for bools. +// This is to allow you to test for null pointers with if(!ptr), +// but as a consequence you can assign nullptr to a bool directly! *pt = nullptr; // This still compiles, even though '*pt' is a bool! @@ -779,12 +785,12 @@ vector<Foo> v; for (int i = 0; i < 10; ++i) v.push_back(Foo()); -// Following line sets size of v to 0, but destructors don't get called, +// Following line sets size of v to 0, but destructors don't get called // and resources aren't released! v.empty(); -v.push_back(Foo()); // New value is copied into the first Foo we inserted in the loop. +v.push_back(Foo()); // New value is copied into the first Foo we inserted -// Truly destroys all values in v. See section about temporary object for +// Truly destroys all values in v. See section about temporary objects for // explanation of why this works. v.swap(vector<Foo>()); From c4b8281ceeed59ddfa003cc95e40944735d1c910 Mon Sep 17 00:00:00 2001 From: Alva Connor Waters <connor_waters@hotmail.com> Date: Fri, 2 Oct 2015 16:19:29 +0000 Subject: [PATCH 12/55] Add to contributors --- c++.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/c++.html.markdown b/c++.html.markdown index e5eceac1..4acc1b9d 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Steven Basart", "http://github.com/xksteven"] - ["Matt Kline", "https://github.com/mrkline"] - ["Geoff Liu", "http://geoffliu.me"] + - ["Connor Waters", "http://github.com/connorwaters"] lang: en --- From 0ad95b119d1f0135bf3a9fd55cebf24d63692c11 Mon Sep 17 00:00:00 2001 From: Michele Orselli <mo@ideato.it> Date: Fri, 2 Oct 2015 18:24:45 +0200 Subject: [PATCH 13/55] adds some new php operators --- php.html.markdown | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/php.html.markdown b/php.html.markdown index 52ea2a95..53be5391 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -215,6 +215,14 @@ assert($a !== $d); assert(1 === '1'); assert(1 !== '1'); +// spaceship operator since PHP 7 +$a = 100; +$b = 1000; + +echo $a <=> $a; // 0 since they are equal +echo $a <=> $b; // -1 since $a < $b +echo $b <=> $a; // 1 since $b > $a + // Variables can be converted between types, depending on their usage. $integer = 1; @@ -264,6 +272,18 @@ if (false) { // ternary operator print (false ? 'Does not get printed' : 'Does'); +// ternary shortcut operator since PHP 5.3 +// equivalent of "$x ? $x : 'Does'"" +$x = false; +print($x ?: 'Does'); + +// null coalesce operator since php 7 +$a = null; +$b = 'Does print'; +echo $a ?? 'a is not set'; // prints 'a is not set' +echo $b ?? 'b is not set'; // prints 'Does print' + + $x = 0; if ($x === '0') { print 'Does not print'; From f35472d8d268f3e07dbbcccf953882d425a53240 Mon Sep 17 00:00:00 2001 From: Jesse Huang <jh3141@gmail.com> Date: Fri, 2 Oct 2015 14:00:54 -0400 Subject: [PATCH 14/55] Removed random "r" --- python.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python.html.markdown b/python.html.markdown index 352f7349..5572e38e 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -198,7 +198,7 @@ li[::-1] # => [3, 4, 2, 1] # Remove arbitrary elements from a list with "del" del li[2] # li is now [1, 2, 3] -r + # You can add lists li + other_li # => [1, 2, 3, 4, 5, 6] # Note: values for li and for other_li are not modified. From 795583521a81868ac96db53533fab4dd0c6a7285 Mon Sep 17 00:00:00 2001 From: Eric McCormick <edm00se@users.noreply.github.com> Date: Fri, 2 Oct 2015 13:50:07 -0500 Subject: [PATCH 15/55] fixed missing ! to create an actual comment ... which was causing everything subsequently to be rendered as code block, as the triple back tick (which should be inside a comment) wasn't being escaped as part of a comment --- markdown.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown.html.markdown b/markdown.html.markdown index 6d19710f..acb808ea 100644 --- a/markdown.html.markdown +++ b/markdown.html.markdown @@ -160,7 +160,7 @@ def foobar end \`\`\` <!-- here too, no backslashes, just ``` --> -<-- The above text doesn't require indenting, plus Github will use syntax +<!-- The above text doesn't require indenting, plus Github will use syntax highlighting of the language you specify after the ``` --> <!-- Horizontal rule (<hr />) --> From fb43ef2942f29ece285be3e8944c91bde6306095 Mon Sep 17 00:00:00 2001 From: Dhwani Shah <dshah202@gmail.com> Date: Fri, 2 Oct 2015 14:12:15 -0500 Subject: [PATCH 16/55] Added example of when string concatenation can also be helpful with combination of strings with html tags as this is important to understand when templating say output code from a database transaction. --- php.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/php.html.markdown b/php.html.markdown index 3fcce264..86fb14e5 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -102,6 +102,8 @@ END; // String concatenation is done with . echo 'This string ' . 'is concatenated'; +// Strings concatenation can also be combined with html elements +echo 'This string is' . '<strong>' . 'bold with strong tags ' . '</strong>.' /******************************** From 8e388cd3344b90cfdc02741359850a2352a8f9b7 Mon Sep 17 00:00:00 2001 From: Dhwani Shah <dshah202@gmail.com> Date: Fri, 2 Oct 2015 14:30:45 -0500 Subject: [PATCH 17/55] Added section on how to declare and initialize both single varible and multiple varibles with the same value. Important concept for large structured programs. Seperated this a little bit. --- java.html.markdown | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 928eb39f..0f5b39af 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -47,10 +47,30 @@ public class LearnJava { /////////////////////////////////////// - // Types & Variables + // Variables /////////////////////////////////////// - + + /* + * Variable Declaration + */ // Declare a variable using <type> <name> + int fooInt; + // Declare multiple variables of same type <type> <name1>, <name2>, <name3> + int fooInt1, fooInt2, fooInt3; + + /* + * Variable Initialization + */ + + // Initialize a variable using <type> <name> = <val> + int fooInt = 1; + // Initialize multiple variables of same type with same value <type> <name1>, <name2>, <name3> = <val> + int fooInt1, fooInt2, fooInt3; + fooInt1 = fooInt2 = fooInt3 = 1; + + /* + * Variable types + */ // Byte - 8-bit signed two's complement integer // (-128 <= byte <= 127) byte fooByte = 100; From 231cd629cab3553d126f8cca04a034c995c4668f Mon Sep 17 00:00:00 2001 From: Dhwani Shah <dhwanishah@users.noreply.github.com> Date: Fri, 2 Oct 2015 14:45:25 -0500 Subject: [PATCH 18/55] Update java.html.markdown --- java.html.markdown | 104 ++++++--------------------------------------- 1 file changed, 14 insertions(+), 90 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 0f5b39af..745741f8 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -1,18 +1,3 @@ ---- -language: java -contributors: - - ["Jake Prather", "http://github.com/JakeHP"] - - ["Jakukyo Friel", "http://weakish.github.io"] - - ["Madison Dickson", "http://github.com/mix3d"] - - ["Simon Morgan", "http://sjm.io/"] -filename: LearnJava.java ---- - -Java is a general-purpose, concurrent, class-based, object-oriented computer -programming language. -[Read more here.](http://docs.oracle.com/javase/tutorial/java/) - -```java // Single-line comments start with // /* Multi-line comments look like this. @@ -47,30 +32,10 @@ public class LearnJava { /////////////////////////////////////// - // Variables + // Types & Variables /////////////////////////////////////// - - /* - * Variable Declaration - */ + // Declare a variable using <type> <name> - int fooInt; - // Declare multiple variables of same type <type> <name1>, <name2>, <name3> - int fooInt1, fooInt2, fooInt3; - - /* - * Variable Initialization - */ - - // Initialize a variable using <type> <name> = <val> - int fooInt = 1; - // Initialize multiple variables of same type with same value <type> <name1>, <name2>, <name3> = <val> - int fooInt1, fooInt2, fooInt3; - fooInt1 = fooInt2 = fooInt3 = 1; - - /* - * Variable types - */ // Byte - 8-bit signed two's complement integer // (-128 <= byte <= 127) byte fooByte = 100; @@ -437,26 +402,26 @@ class PennyFarthing extends Bicycle { // Example - Food: public interface Edible { - public void eat(); // Any class that implements this interface, must + public void eat(); // Any class that implements this interface, must // implement this method. } public interface Digestible { - public void digest(); + public void digest(); } // We can now create a class that implements both of these interfaces. public class Fruit implements Edible, Digestible { @Override - public void eat() { - // ... - } + public void eat() { + // ... + } @Override - public void digest() { - // ... - } + public void digest() { + // ... + } } // In Java, you can extend only one class, but you can implement many @@ -464,51 +429,10 @@ public class Fruit implements Edible, Digestible { public class ExampleClass extends ExampleClassParent implements InterfaceOne, InterfaceTwo { @Override - public void InterfaceOneMethod() { - } + public void InterfaceOneMethod() { + } @Override - public void InterfaceTwoMethod() { - } + public void InterfaceTwoMethod() { + } } -``` - -## Further Reading - -The links provided here below are just to get an understanding of the topic, feel free to Google and find specific examples. - -**Official Oracle Guides**: - -* [Java Tutorial Trail from Sun / Oracle](http://docs.oracle.com/javase/tutorial/index.html) - -* [Java Access level modifiers](http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html) - -* [Object-Oriented Programming Concepts](http://docs.oracle.com/javase/tutorial/java/concepts/index.html): - * [Inheritance](http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html) - * [Polymorphism](http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html) - * [Abstraction](http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html) - -* [Exceptions](http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html) - -* [Interfaces](http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html) - -* [Generics](http://docs.oracle.com/javase/tutorial/java/generics/index.html) - -* [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html) - -**Online Practice and Tutorials** - -* [Learneroo.com - Learn Java](http://www.learneroo.com) - -* [Codingbat.com](http://codingbat.com/java) - - -**Books**: - -* [Head First Java](http://www.headfirstlabs.com/books/hfjava/) - -* [Thinking in Java](http://www.mindview.net/Books/TIJ/) - -* [Objects First with Java](http://www.amazon.com/Objects-First-Java-Practical-Introduction/dp/0132492660) - -* [Java The Complete Reference](http://www.amazon.com/gp/product/0071606300) From c7240369b6465f2a736cb61d1bff89c971e76929 Mon Sep 17 00:00:00 2001 From: Dhwani Shah <dhwanishah@users.noreply.github.com> Date: Fri, 2 Oct 2015 14:47:17 -0500 Subject: [PATCH 19/55] Update java.html.markdown --- java.html.markdown | 80 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 12 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 745741f8..928eb39f 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -1,3 +1,18 @@ +--- +language: java +contributors: + - ["Jake Prather", "http://github.com/JakeHP"] + - ["Jakukyo Friel", "http://weakish.github.io"] + - ["Madison Dickson", "http://github.com/mix3d"] + - ["Simon Morgan", "http://sjm.io/"] +filename: LearnJava.java +--- + +Java is a general-purpose, concurrent, class-based, object-oriented computer +programming language. +[Read more here.](http://docs.oracle.com/javase/tutorial/java/) + +```java // Single-line comments start with // /* Multi-line comments look like this. @@ -402,26 +417,26 @@ class PennyFarthing extends Bicycle { // Example - Food: public interface Edible { - public void eat(); // Any class that implements this interface, must + public void eat(); // Any class that implements this interface, must // implement this method. } public interface Digestible { - public void digest(); + public void digest(); } // We can now create a class that implements both of these interfaces. public class Fruit implements Edible, Digestible { @Override - public void eat() { - // ... - } + public void eat() { + // ... + } @Override - public void digest() { - // ... - } + public void digest() { + // ... + } } // In Java, you can extend only one class, but you can implement many @@ -429,10 +444,51 @@ public class Fruit implements Edible, Digestible { public class ExampleClass extends ExampleClassParent implements InterfaceOne, InterfaceTwo { @Override - public void InterfaceOneMethod() { - } + public void InterfaceOneMethod() { + } @Override - public void InterfaceTwoMethod() { - } + public void InterfaceTwoMethod() { + } } +``` + +## Further Reading + +The links provided here below are just to get an understanding of the topic, feel free to Google and find specific examples. + +**Official Oracle Guides**: + +* [Java Tutorial Trail from Sun / Oracle](http://docs.oracle.com/javase/tutorial/index.html) + +* [Java Access level modifiers](http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html) + +* [Object-Oriented Programming Concepts](http://docs.oracle.com/javase/tutorial/java/concepts/index.html): + * [Inheritance](http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html) + * [Polymorphism](http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html) + * [Abstraction](http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html) + +* [Exceptions](http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html) + +* [Interfaces](http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html) + +* [Generics](http://docs.oracle.com/javase/tutorial/java/generics/index.html) + +* [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html) + +**Online Practice and Tutorials** + +* [Learneroo.com - Learn Java](http://www.learneroo.com) + +* [Codingbat.com](http://codingbat.com/java) + + +**Books**: + +* [Head First Java](http://www.headfirstlabs.com/books/hfjava/) + +* [Thinking in Java](http://www.mindview.net/Books/TIJ/) + +* [Objects First with Java](http://www.amazon.com/Objects-First-Java-Practical-Introduction/dp/0132492660) + +* [Java The Complete Reference](http://www.amazon.com/gp/product/0071606300) From 63793af2e955f8a8abe698c4a70809cfbff63452 Mon Sep 17 00:00:00 2001 From: Dhwani Shah <dshah202@gmail.com> Date: Fri, 2 Oct 2015 14:54:09 -0500 Subject: [PATCH 20/55] Added section on how to declare and initialize both single varible and multiple varibles with the same value. Important concept for large structured programs. Seperated this a little bit. --- java.html.markdown | 24 ++++++++++++++++++++++-- php.html.markdown | 4 +--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 928eb39f..1aa06570 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -47,10 +47,30 @@ public class LearnJava { /////////////////////////////////////// - // Types & Variables + // Variables /////////////////////////////////////// - + + /* + * Variable Declaration + */ // Declare a variable using <type> <name> + int fooInt; + // Declare multiple variables of the same type <type> <name1>, <name2>, <name3> + int fooInt1, fooInt2, fooInt3; + + /* + * Variable Initialization + */ + + // Initialize a variable using <type> <name> = <val> + int fooInt = 1; + // Initialize multiple variables of same type with same value <type> <name1>, <name2>, <name3> = <val> + int fooInt1, fooInt2, fooInt3; + fooInt1 = fooInt2 = fooInt3 = 1; + + /* + * Variable types + */ // Byte - 8-bit signed two's complement integer // (-128 <= byte <= 127) byte fooByte = 100; diff --git a/php.html.markdown b/php.html.markdown index 86fb14e5..1c2204fd 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -101,9 +101,7 @@ $sgl_quotes END; // String concatenation is done with . -echo 'This string ' . 'is concatenated'; -// Strings concatenation can also be combined with html elements -echo 'This string is' . '<strong>' . 'bold with strong tags ' . '</strong>.' +echo 'This string ' . 'is concatenated'; /******************************** From 4e139ae2f528a08eb47427ea790bd176092e1bf0 Mon Sep 17 00:00:00 2001 From: Dhwani Shah <dshah202@gmail.com> Date: Fri, 2 Oct 2015 14:57:39 -0500 Subject: [PATCH 21/55] unneeded change fixed --- php.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php.html.markdown b/php.html.markdown index 1c2204fd..d4131992 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -101,7 +101,7 @@ $sgl_quotes END; // String concatenation is done with . -echo 'This string ' . 'is concatenated'; +echo 'This string ' . 'is concatenated'; /******************************** @@ -689,4 +689,4 @@ If you're coming from a language with good package management, check out [Composer](http://getcomposer.org/). For common standards, visit the PHP Framework Interoperability Group's -[PSR standards](https://github.com/php-fig/fig-standards). +[PSR standards](https://github.com/php-fig/fig-standards). \ No newline at end of file From 2e05ec8d955b62fef844bd460f5bb455e351d1d0 Mon Sep 17 00:00:00 2001 From: edholland <edjholland@gmail.com> Date: Fri, 2 Oct 2015 02:26:04 +0200 Subject: [PATCH 22/55] Add clarification on bind / match with = op in erlang. Fixes #1139 --- erlang.html.markdown | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erlang.html.markdown b/erlang.html.markdown index 8b67a76a..d0af7f05 100644 --- a/erlang.html.markdown +++ b/erlang.html.markdown @@ -25,6 +25,7 @@ filename: learnerlang.erl %% 1. Variables and pattern matching. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% In Erlang new variables are bound with an `=` statement. Num = 42. % All variable names must start with an uppercase letter. % Erlang has single-assignment variables; if you try to assign a different @@ -32,9 +33,11 @@ Num = 42. % All variable names must start with an uppercase letter. Num = 43. % ** exception error: no match of right hand side value 43 % In most languages, `=` denotes an assignment statement. In Erlang, however, -% `=` denotes a pattern-matching operation. `Lhs = Rhs` really means this: -% evaluate the right side (`Rhs`), and then match the result against the -% pattern on the left side (`Lhs`). +% `=` denotes a pattern-matching operation. When an empty variable is used on the +% left hand side of the `=` operator to is bound (assigned), but when a bound +% varaible is used on the left hand side the following behaviour is observed. +% `Lhs = Rhs` really means this: evaluate the right side (`Rhs`), and then +% match the result against the pattern on the left side (`Lhs`). Num = 7 * 6. % Floating-point number. From 61597e603f78dc0645517a13b0b258236e5a3563 Mon Sep 17 00:00:00 2001 From: Ed Holland <edjholland@gmail.com> Date: Fri, 2 Oct 2015 01:11:10 +0100 Subject: [PATCH 23/55] Add section on eunit in erlang doc --- erlang.html.markdown | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/erlang.html.markdown b/erlang.html.markdown index 8b67a76a..31cdcdab 100644 --- a/erlang.html.markdown +++ b/erlang.html.markdown @@ -299,6 +299,39 @@ CalculateArea ! {circle, 2}. % 12.56000000000000049738 % The shell is also a process; you can use `self` to get the current pid. self(). % <0.41.0> +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% 5. Testing with EUnit +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% Unit tests can be written using EUnits's test generators and assert macros +-module(fib). + -export([fib/1]). + -include_lib("eunit/include/eunit.hrl"). + + fib(0) -> 1; + fib(1) -> 1; + fib(N) when N > 1 -> fib(N-1) + fib(N-2). + + fib_test_() -> + [?_assert(fib(0) =:= 1), + ?_assert(fib(1) =:= 1), + ?_assert(fib(2) =:= 2), + ?_assert(fib(3) =:= 3), + ?_assert(fib(4) =:= 5), + ?_assert(fib(5) =:= 8), + ?_assertException(error, function_clause, fib(-1)), + ?_assert(fib(31) =:= 2178309) + ]. + +% EUnit will automatically export to a test() fucntion to allo running the tests +% in the erlang shell +fib:test() + +% The popular erlang build tool Rebar is also compatible with EUnit +% ``` +% rebar eunit +% ``` + ``` ## References From 466b51d9fa4a223014b0d1d79d3d55709c32373d Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Sat, 3 Oct 2015 13:49:07 -0300 Subject: [PATCH 24/55] [javascript pt-br] : 5. More about Objects; Constructors and Prototypes --- pt-br/javascript-pt.html.markdown | 134 +++++++++++++++--------------- 1 file changed, 69 insertions(+), 65 deletions(-) diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown index 08448d0b..097a1a8e 100644 --- a/pt-br/javascript-pt.html.markdown +++ b/pt-br/javascript-pt.html.markdown @@ -340,75 +340,74 @@ function sayHelloInFiveSeconds(name){ sayHelloInFiveSeconds("Adam"); // Vai abrir um popup com "Hello, Adam!" em 5s /////////////////////////////////// -// 5. More about Objects; Constructors and Prototypes +// 5. Mais sobre Objetos; Construtores e Prototypes -// Objects can contain functions. +// Objetos podem conter funções. var myObj = { myFunc: function(){ - return "Hello world!"; + return "Olá mundo!"; } }; -myObj.myFunc(); // = "Hello world!" +myObj.myFunc(); // = "Olá mundo!" -// When functions attached to an object are called, they can access the object -// they're attached to using the `this` keyword. +// Quando uma função ligada a um objeto é chamada, ela pode acessar o objeto +// da qual foi ligada usando a palavra-chave `this`. myObj = { - myString: "Hello world!", + myString: "Olá mundo!", myFunc: function(){ return this.myString; } }; -myObj.myFunc(); // = "Hello world!" +myObj.myFunc(); // = "Olá mundo!" -// What this is set to has to do with how the function is called, not where -// it's defined. So, our function doesn't work if it isn't called in the -// context of the object. +// O `this` só funciona para dentro do escopo do objeto, portanto, se chamarmos +// um método do objeto fora de seu escopo, este não irá funcionar. var myFunc = myObj.myFunc; myFunc(); // = undefined -// Inversely, a function can be assigned to the object and gain access to it -// through `this`, even if it wasn't attached when it was defined. +// Inversamente, uma função pode ser atribuída a um objeto e ganhar a acesso +// através do `this`, até mesmo se ela não for chamada quando foi definida. var myOtherFunc = function(){ return this.myString.toUpperCase(); } myObj.myOtherFunc = myOtherFunc; -myObj.myOtherFunc(); // = "HELLO WORLD!" +myObj.myOtherFunc(); // = "OLÁ MUNDO!" -// We can also specify a context for a function to execute in when we invoke it -// using `call` or `apply`. +// Nós podemos também especificar um contexto onde a função irá executar, +// usando o `call` ou `apply`. var anotherFunc = function(s){ return this.myString + s; } -anotherFunc.call(myObj, " And Hello Moon!"); // = "Hello World! And Hello Moon!" +anotherFunc.call(myObj, " E Olá Lua!"); // = "Olá mundo! E Olá Lua!" -// The `apply` function is nearly identical, but takes an array for an argument -// list. +// A função `apply` é praticamente a mesma coisa, mas ela pega um array +// como lista de argumentos. -anotherFunc.apply(myObj, [" And Hello Sun!"]); // = "Hello World! And Hello Sun!" +anotherFunc.apply(myObj, [" E Olá Sol!"]); // = "Olá mundo! E Olá Sol!" -// This is useful when working with a function that accepts a sequence of -// arguments and you want to pass an array. +// Isto é util quando trabalhamos com uma função que aceita uma sequência de +// argumentos e você quer passar um array. Math.min(42, 6, 27); // = 6 Math.min([42, 6, 27]); // = NaN (uh-oh!) Math.min.apply(Math, [42, 6, 27]); // = 6 -// But, `call` and `apply` are only temporary. When we want it to stick, we can -// use `bind`. +// Mas, o `call` e `apply` são somente temporários. Quando você quiser que +// permaneça sempre no escopo, use `bind`. var boundFunc = anotherFunc.bind(myObj); -boundFunc(" And Hello Saturn!"); // = "Hello World! And Hello Saturn!" +boundFunc(" E Olá Saturno!"); // = "Olá mundo! E Olá Saturno!" -// `bind` can also be used to partially apply (curry) a function. +// `bind` também pode ser usado para parcialmente aplicar (curry) uma função. var product = function(a, b){ return a * b; } var doubler = product.bind(this, 2); doubler(8); // = 16 -// When you call a function with the `new` keyword, a new object is created, and -// made available to the function via the this keyword. Functions designed to be -// called like that are called constructors. +// Quando você invoca uma função com a palavra-chave `new`, um novo objeto +// é criado, e fica disponível para a função pela palavra-chave `this`. +// Funções são desenhadas para serem invocadas como se invocam os construtores. var MyConstructor = function(){ this.myNumber = 5; @@ -416,15 +415,17 @@ var MyConstructor = function(){ myNewObj = new MyConstructor(); // = {myNumber: 5} myNewObj.myNumber; // = 5 -// Every JavaScript object has a 'prototype'. When you go to access a property -// on an object that doesn't exist on the actual object, the interpreter will -// look at its prototype. +// Todo objeto JavaScript possui um `prototype`. Quando você tenta acessar +// uma propriedade de um objeto que não existe no objeto atual, o interpretador +// vai olhar imediatamente para o seu prototype. + +// Algumas implementações em JS deixam você acessar o objeto prototype com a +// propriedade mágica `__proto__`. Enquanto isso é util para explicar +// prototypes, não é parte de um padrão; nós vamos falar de algumas formas de +// usar prototypes depois. -// Some JS implementations let you access an object's prototype on the magic -// property `__proto__`. While this is useful for explaining prototypes it's not -// part of the standard; we'll get to standard ways of using prototypes later. var myObj = { - myString: "Hello world!" + myString: "Olá Mundo!" }; var myPrototype = { meaningOfLife: 42, @@ -437,34 +438,36 @@ myObj.__proto__ = myPrototype; myObj.meaningOfLife; // = 42 // This works for functions, too. -myObj.myFunc(); // = "hello world!" +// Isto funciona para funções, também. +myObj.myFunc(); // = "olá mundo!" -// Of course, if your property isn't on your prototype, the prototype's -// prototype is searched, and so on. +// É claro, se sua propriedade não está em seu prototype, +// o prototype do prototype será procurado e por aí vai. myPrototype.__proto__ = { myBoolean: true }; myObj.myBoolean; // = true -// There's no copying involved here; each object stores a reference to its -// prototype. This means we can alter the prototype and our changes will be -// reflected everywhere. +// Não há cópia envolvida aqui; cada objeto guarda uma referência do +// prototype. Isso significa que podemos alterar o prototype e nossas mudanças +// serão refletidas em qualquer lugar. myPrototype.meaningOfLife = 43; myObj.meaningOfLife; // = 43 -// We mentioned that `__proto__` was non-standard, and there's no standard way to -// change the prototype of an existing object. However, there are two ways to -// create a new object with a given prototype. -// The first is Object.create, which is a recent addition to JS, and therefore -// not available in all implementations yet. +// Nós mencionamos que o `__proto__` não é uma forma padrão, e não há uma +// forma padrão de mudar o prototype de um objeto já existente. Entretanto, +// existem duas formas de se criar um objeto com um dado prototype. + +// A primeira forma é `Object.create`, que é uma adição recente do JS, +// e ainda não está disponível em todas as implementações. var myObj = Object.create(myPrototype); myObj.meaningOfLife; // = 43 -// The second way, which works anywhere, has to do with constructors. -// Constructors have a property called prototype. This is *not* the prototype of -// the constructor function itself; instead, it's the prototype that new objects -// are given when they're created with that constructor and the new keyword. +// A segunda forma, que funciona em qualquer lugar, é feita com construtores. +// Construtores tem uma propriedade chamada prototype. Este *não* é o prototype +// do construtor em si; ao invés disso, ele é o prototype dos novos objetos +// criados pelo construtor. MyConstructor.prototype = { myNumber: 5, getMyNumber: function(){ @@ -476,42 +479,43 @@ myNewObj2.getMyNumber(); // = 5 myNewObj2.myNumber = 6 myNewObj2.getMyNumber(); // = 6 -// Built-in types like strings and numbers also have constructors that create -// equivalent wrapper objects. +// Tipos originais da linguagem como strings e números também possuem +// construtores equivalentes. var myNumber = 12; var myNumberObj = new Number(12); myNumber == myNumberObj; // = true -// Except, they aren't exactly equivalent. +// Exceto, que eles não são totalmente equivalentes. typeof myNumber; // = 'number' typeof myNumberObj; // = 'object' myNumber === myNumberObj; // = false if (0){ - // This code won't execute, because 0 is falsy. + // O código não vai executar, porque 0 é um valor falso. } if (Number(0)){ - // This code *will* execute, because Number(0) is truthy. + // O código *vai* executar, porque `Number(0)` é um valor verdadeiro. } -// However, the wrapper objects and the regular builtins share a prototype, so -// you can actually add functionality to a string, for instance. +// Entretanto, esses objetos encapsulados e as funções originais compartilham +// um mesmo prototype, portanto você pode adicionar funcionalidades a uma string, +// por exemplo. String.prototype.firstCharacter = function(){ return this.charAt(0); } "abc".firstCharacter(); // = "a" -// This fact is often used in "polyfilling", which is implementing newer -// features of JavaScript in an older subset of JavaScript, so that they can be -// used in older environments such as outdated browsers. +// Esse fato é usado para criar os chamados `polyfills`, que implementam +// uma nova característica do Javascript em uma versão mais velha, para que +// assim funcionem em ambientes mais velhos como browsers ultrapassados. -// For instance, we mentioned that Object.create isn't yet available in all -// implementations, but we can still use it with this polyfill: +// Havíamos mencionado que `Object.create` não estava ainda disponível em +// todos as implementações, mas nós podemos usá-lo com esse polyfill: if (Object.create === undefined){ // don't overwrite it if it exists Object.create = function(proto){ - // make a temporary constructor with the right prototype + // faz um construtor temporário com o prototype certo var Constructor = function(){}; Constructor.prototype = proto; - // then use it to create a new, appropriately-prototyped object + // então utiliza o new para criar um objeto prototype apropriado return new Constructor(); } } From 46d509077f10fc9b04aaf69829526d4b8297798d Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Sat, 3 Oct 2015 14:03:54 -0300 Subject: [PATCH 25/55] [javascript pt-br] : Leitura Adicional --- pt-br/javascript-pt.html.markdown | 39 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown index 097a1a8e..f4b5ed2c 100644 --- a/pt-br/javascript-pt.html.markdown +++ b/pt-br/javascript-pt.html.markdown @@ -521,30 +521,31 @@ if (Object.create === undefined){ // don't overwrite it if it exists } ``` -## Further Reading +## Leitura Adicional -The [Mozilla Developer -Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript) provides -excellent documentation for JavaScript as it's used in browsers. Plus, it's a -wiki, so as you learn more you can help others out by sharing your own -knowledge. +O [Mozilla Developer +Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript) dispõe de uma +excelente documentação sobre Javascript e seu uso nos browsers. E mais, +é uma wiki, portanto conforme você vai aprendendo, mais você pode ir ajudando +os outros compartilhando do seu conhecimento. -MDN's [A re-introduction to -JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) -covers much of the concepts covered here in more detail. This guide has quite -deliberately only covered the JavaScript language itself; if you want to learn -more about how to use JavaScript in web pages, start by learning about the +[Uma re-introdução do JavaScript pela MDN] +(https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) +cobre muito dos conceitos abordados aqui em mais detalhes. Este guia fala +somente sobre a linguagem JavaScript em si; se você quiser aprender mais +sobre e como usar o JavaScript em páginas na web, comece aprendendo sobre [Document Object Model](https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core) -[Learn Javascript by Example and with Challenges](http://www.learneroo.com/modules/64/nodes/350) is a variant of this reference with built-in challenges. +[Aprenda Javascript por Exemplos e com Desafios](http://www.learneroo.com/modules/64/nodes/350) é uma +variação desse guia com desafios. -[JavaScript Garden](http://bonsaiden.github.io/JavaScript-Garden/) is an in-depth -guide of all the counter-intuitive parts of the language. +[JavaScript Garden](http://bonsaiden.github.io/JavaScript-Garden/) é um guia +profundo de todas as partes do JavaScript. -[JavaScript: The Definitive Guide](http://www.amazon.com/gp/product/0596805527/) is a classic guide / reference book. +[JavaScript: The Definitive Guide](http://www.amazon.com/gp/product/0596805527/) é o guia clássico +/ livro de referência. -In addition to direct contributors to this article, some content is adapted -from Louie Dinh's Python tutorial on this site, and the [JS -Tutorial](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) -on the Mozilla Developer Network. +Parte desse artigo foi adaptado do tutorial de Python do Louie Dinh que está +nesse site e do [Tutorial de JS](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) +da Mozilla Developer Network. From 261f7a249f13f3f13f5619f2a3202d0273010df2 Mon Sep 17 00:00:00 2001 From: DPS <DennisPS@users.noreply.github.com> Date: Sat, 3 Oct 2015 20:00:47 +0200 Subject: [PATCH 26/55] [git/de] fixed typo --- de-de/git-de.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de-de/git-de.html.markdown b/de-de/git-de.html.markdown index c7b6ad86..43939129 100644 --- a/de-de/git-de.html.markdown +++ b/de-de/git-de.html.markdown @@ -48,7 +48,7 @@ Ein Repository besteht in Git aus dem .git-Verzeichnis und dem Arbeitsverzeichni ### .git-Verzeichnis (Teil des Repositorys) -Das .git-Verzeichnis enth? alle Einstellung, Logs, Branches, den HEAD und mehr. +Das .git-Verzeichnis enthält alle Einstellung, Logs, Branches, den HEAD und mehr. [Ausführliche Übersicht](http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html) ### Arbeitsverzeichnis (Teil des Repositorys) From 4719d4707cbda05daab4e05e1c85655ff7abf2fd Mon Sep 17 00:00:00 2001 From: DPS <DennisPS@users.noreply.github.com> Date: Sat, 3 Oct 2015 20:20:03 +0200 Subject: [PATCH 27/55] [go/de] fixed typo --- de-de/go-de.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de-de/go-de.html.markdown b/de-de/go-de.html.markdown index 83d59c8b..765372e0 100644 --- a/de-de/go-de.html.markdown +++ b/de-de/go-de.html.markdown @@ -312,7 +312,7 @@ Dokumentation lesen. Auch zu empfehlen ist die Spezifikation von Go, die nach heutigen Standards sehr kurz und auch gut verständlich formuliert ist. Auf der Leseliste von Go-Neulingen ist außerdem der Quelltext der [Go standard Bibliothek](http://golang.org/src/pkg/). -Gut documentiert, demonstriert sie leicht zu verstehendes und im idiomatischen Stil +Gut dokumentiert, demonstriert sie leicht zu verstehendes und im idiomatischen Stil verfasstes Go. Erreichbar ist der Quelltext auch durch das Klicken der Funktionsnamen in der [offiziellen Dokumentation von Go](http://golang.org/pkg/). From 6f29bcc20175a348f3b1dd606d8a0ace5d48fe54 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier <bussonniermatthias@gmail.com> Date: Sat, 3 Oct 2015 15:39:37 -0700 Subject: [PATCH 28/55] Update Python-fr.html.markdown Add Link to Python3 English article. --- fr-fr/python-fr.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fr-fr/python-fr.html.markdown b/fr-fr/python-fr.html.markdown index 58a036ba..26cab55f 100644 --- a/fr-fr/python-fr.html.markdown +++ b/fr-fr/python-fr.html.markdown @@ -15,7 +15,7 @@ Je suis tombé amoureux de Python de par la clarté de sa syntaxe. C'est pratiqu Vos retours sont grandement appréciés. Vous pouvez me contacter sur Twitter [@louiedinh](http://twitter.com/louiedinh) ou par e-mail: louiedinh [at] [google's email service] NB: Cet artice s'applique spécifiquement à Python 2.7, mais devrait s'appliquer pour toute version Python 2.x -Vous pourrez bientôt trouver un article pour Python 3! +Vous pourrez bientôt trouver un article pour Python 3 an Français. Pour le moment vous pouvez jettez un coup d'oeil à l'article [Python 3 en Anglais](http://learnxinyminutes.com/docs/python3/). ```python # Une ligne simple de commentaire commence par un dièse From 998fdfdfcdff05cb0721841215addbcdd94d30b0 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier <bussonniermatthias@gmail.com> Date: Sat, 3 Oct 2015 15:40:41 -0700 Subject: [PATCH 29/55] typo --- fr-fr/python-fr.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fr-fr/python-fr.html.markdown b/fr-fr/python-fr.html.markdown index 26cab55f..5a03ecfc 100644 --- a/fr-fr/python-fr.html.markdown +++ b/fr-fr/python-fr.html.markdown @@ -15,7 +15,7 @@ Je suis tombé amoureux de Python de par la clarté de sa syntaxe. C'est pratiqu Vos retours sont grandement appréciés. Vous pouvez me contacter sur Twitter [@louiedinh](http://twitter.com/louiedinh) ou par e-mail: louiedinh [at] [google's email service] NB: Cet artice s'applique spécifiquement à Python 2.7, mais devrait s'appliquer pour toute version Python 2.x -Vous pourrez bientôt trouver un article pour Python 3 an Français. Pour le moment vous pouvez jettez un coup d'oeil à l'article [Python 3 en Anglais](http://learnxinyminutes.com/docs/python3/). +Vous pourrez bientôt trouver un article pour Python 3 en Français. Pour le moment vous pouvez jettez un coup d'oeil à l'article [Python 3 en Anglais](http://learnxinyminutes.com/docs/python3/). ```python # Une ligne simple de commentaire commence par un dièse From 0d2863186231324b14e8d3a1d25aa8e44078aa68 Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Sat, 3 Oct 2015 21:03:58 -0300 Subject: [PATCH 30/55] Sync pt with original js --- pt-br/javascript-pt.html.markdown | 3 --- 1 file changed, 3 deletions(-) diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown index f4b5ed2c..e39c6c8e 100644 --- a/pt-br/javascript-pt.html.markdown +++ b/pt-br/javascript-pt.html.markdown @@ -492,9 +492,6 @@ myNumber === myNumberObj; // = false if (0){ // O código não vai executar, porque 0 é um valor falso. } -if (Number(0)){ - // O código *vai* executar, porque `Number(0)` é um valor verdadeiro. -} // Entretanto, esses objetos encapsulados e as funções originais compartilham // um mesmo prototype, portanto você pode adicionar funcionalidades a uma string, From 4206b4ccd04c8343e6becd58a2c9549e9593cbd6 Mon Sep 17 00:00:00 2001 From: David Stockton <dave@davidstockton.com> Date: Sat, 3 Oct 2015 19:35:42 -0600 Subject: [PATCH 31/55] Correct usage of "it's" in javascript doc --- json.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json.html.markdown b/json.html.markdown index f57b82b8..47a8cb21 100644 --- a/json.html.markdown +++ b/json.html.markdown @@ -49,7 +49,7 @@ going to be 100% valid JSON. Luckily, it kind of speaks for itself. "alternative style": { "comment": "check this out!" - , "comma position": "doesn't matter - as long as its before the value, then its valid" + , "comma position": "doesn't matter - as long as it's before the value, then it's valid" , "another comment": "how nice" }, From eb35f7748a11e04f15cb9901a86702f881155b14 Mon Sep 17 00:00:00 2001 From: David Stockton <dave@davidstockton.com> Date: Sat, 3 Oct 2015 19:40:02 -0600 Subject: [PATCH 32/55] Fix usage of "it's" in example comment for chapel --- chapel.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapel.html.markdown b/chapel.html.markdown index c8489371..05e5b867 100644 --- a/chapel.html.markdown +++ b/chapel.html.markdown @@ -1074,14 +1074,14 @@ Installing the Compiler Chapel can be built and installed on your average 'nix machine (and cygwin). [Download the latest release version](https://github.com/chapel-lang/chapel/releases/) -and its as easy as +and it's as easy as 1. `tar -xvf chapel-1.11.0.tar.gz` 2. `cd chapel-1.11.0` 3. `make` 4. `source util/setchplenv.bash # or .sh or .csh or .fish` -You will need to `source util/setchplenv.EXT` from within the Chapel directory (`$CHPL_HOME`) every time your terminal starts so its suggested that you drop that command in a script that will get executed on startup (like .bashrc). +You will need to `source util/setchplenv.EXT` from within the Chapel directory (`$CHPL_HOME`) every time your terminal starts so it's suggested that you drop that command in a script that will get executed on startup (like .bashrc). Chapel is easily installed with Brew for OS X @@ -1100,4 +1100,4 @@ Notable arguments: * `--fast`: enables a number of optimizations and disables array bounds checks. Should only enable when application is stable. * `--set <Symbol Name>=<Value>`: set config param `<Symbol Name>` to `<Value>` at compile-time. * `--main-module <Module Name>`: use the main() procedure found in the module `<Module Name>` as the executable's main. - * `--module-dir <Directory>`: includes `<Directory>` in the module search path. \ No newline at end of file + * `--module-dir <Directory>`: includes `<Directory>` in the module search path. From 2ede63f54cb59b99c0d3da712814f5556a979660 Mon Sep 17 00:00:00 2001 From: David Stockton <dave@davidstockton.com> Date: Sat, 3 Oct 2015 19:41:52 -0600 Subject: [PATCH 33/55] Fix incorrect "its" to "it is" in visual basic doc --- visualbasic.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visualbasic.html.markdown b/visualbasic.html.markdown index 00d61843..f9906e96 100644 --- a/visualbasic.html.markdown +++ b/visualbasic.html.markdown @@ -236,7 +236,7 @@ Module Module1 'Nine Private Sub IfElseStatement() Console.Title = "If / Else Statement | Learn X in Y Minutes" - 'Sometimes its important to consider more than two alternatives. + 'Sometimes it is important to consider more than two alternatives. 'Sometimes there are a good few others. 'When this is the case, more than one if statement would be required. 'An if statement is great for vending machines. Where the user enters a code. From 9bc553c46ce9b7154ec7c82451d71608f4beda82 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma <thepsguy@icloud.com> Date: Sun, 4 Oct 2015 10:12:55 +0530 Subject: [PATCH 34/55] Update c++.html.markdown Regarding issue #1216, Better explaining the Reference 'fooRef'. --- c++.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/c++.html.markdown b/c++.html.markdown index 4acc1b9d..bbd2f9a9 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -245,7 +245,13 @@ cout << fooRef; // Prints "I am foo. Hi!" // Doesn't reassign "fooRef". This is the same as "foo = bar", and // foo == "I am bar" // after this line. +cout << &fooRef << endl; //Prints address of fooRef fooRef = bar; +cout << &fooRef << endl; //Prints address of fooRef, AGAIN +cout << fooRef; // Prints "I am bar" + +//The address of fooRef remains the same, i.e. it is still referring to foo. + const string& barRef = bar; // Create a const reference to bar. // Like C, const values (and pointers and references) cannot be modified. From c7e552c448c5a562a3ff5f442a7ed834aec04d9e Mon Sep 17 00:00:00 2001 From: Pushkar Sharma <thepsguy@icloud.com> Date: Sun, 4 Oct 2015 10:34:31 +0530 Subject: [PATCH 35/55] Variable size array, user size input added. #1170 Fixed Issue #1170 Variable size array, user size input added. --- c.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/c.html.markdown b/c.html.markdown index 8e631de4..36621a9e 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -130,7 +130,9 @@ int main(void) { // can be declared as well. The size of such an array need not be a compile // time constant: printf("Enter the array size: "); // ask the user for an array size - char buf[0x100]; + int size; + scanf("%d", &size); + char buf[size]; fgets(buf, sizeof buf, stdin); // strtoul parses a string to an unsigned integer From 9b00510c452a24197f7b8d30dee1a5f170e3cdee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerson=20L=C3=A1zaro?= <gersonlazaro@gersonlazaro.com> Date: Sun, 4 Oct 2015 00:09:26 -0500 Subject: [PATCH 36/55] =?UTF-8?q?[c++/es]=20a=C3=B1adido?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es-es/c++-es.html.markdown | 829 +++++++++++++++++++++++++++++++++++++ 1 file changed, 829 insertions(+) create mode 100644 es-es/c++-es.html.markdown diff --git a/es-es/c++-es.html.markdown b/es-es/c++-es.html.markdown new file mode 100644 index 00000000..bcc775e5 --- /dev/null +++ b/es-es/c++-es.html.markdown @@ -0,0 +1,829 @@ +--- +language: c++ +filename: learncpp.cpp +contributors: + - ["Steven Basart", "http://github.com/xksteven"] + - ["Matt Kline", "https://github.com/mrkline"] + - ["Geoff Liu", "http://geoffliu.me"] + - ["Connor Waters", "http://github.com/connorwaters"] +translators: + - ["Gerson Lázaro", "https://gersonlazaro.com"] +lang: es-es +--- + +C++ es un lenguaje de programación de sistemas que, +[de acuerdo a su inventor Bjarne Stroustrup](http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/Keynote), +fue diseñado para + +- ser un "mejor C" +- soportar abstracción de datos +- soportar programación orientada a objetos +- soportar programación genérica + +Aunque su sintaxis puede ser más difícil o compleja que los nuevos lenguajes, +es ampliamente utilizado, ya que compila instrucciones nativas que pueden ser +directamente ejecutadas por el procesador y ofrece un estricto control sobre +el hardware (como C), mientras ofrece características de alto nivel como +genericidad, excepciones, y clases. Esta combinación de velocidad y +funcionalidad hace de C ++ uno de los lenguajes de programación más utilizados. + +```c++ +//////////////////// +// Comparación con C +//////////////////// + +// C ++ es _casi_ un superconjunto de C y comparte su sintaxis básica para las +// declaraciones de variables, tipos primitivos y funciones. + +// Al igual que en C, el punto de entrada de tu programa es una función llamada +// main con un retorno de tipo entero. +// Este valor sirve como código de salida del programa. +// Mira http://en.wikipedia.org/wiki/Exit_status para mayor información. +int main(int argc, char** argv) +{ + // Los argumentos de la línea de comandos se pasan por argc y argv de la + // misma manera que en C. + // argc indica el número de argumentos, + // y argv es un arreglo de strings de estilo C (char*) + // representando los argumentos. + // El primer argumento es el nombre con el que el programa es llamado. + // argc y argv pueden omitirse si no te preocupan los argumentos, + // dejando la definición de la función como int main () + + // Un estado de salida 0 indica éxito. + return 0; +} + +// Sin embargo, C ++ varía en algunas de las siguientes maneras: + +// En C++, los caracteres literales son caracteres +sizeof('c') == sizeof(char) == 1 + +// En C, los caracteres literales son enteros +sizeof('c') == sizeof(int) + + +// C++ tiene prototipado estricto +void func(); // función que no acepta argumentos + +// En C +void func(); // función que puede aceptar cualquier número de argumentos + +// Use nullptr en lugar de NULL en C++ +int* ip = nullptr; + +// Las cabeceras (headers) estándar de C están disponibles en C ++, +// pero tienen el prefijo "c" y no tienen sufijo .h. +#include <cstdio> + +int main() +{ + printf("Hola mundo!\n"); + return 0; +} + +////////////////////////// +// Sobrecarga de funciones +////////////////////////// + +// C++ soporta sobrecarga de funciones +// siempre que cada función tenga diferentes parámetros. + +void print(char const* myString) +{ + printf("String %s\n", myString); +} + +void print(int myInt) +{ + printf("Mi entero es %d", myInt); +} + +int main() +{ + print("Hello"); // Resolves to void print(const char*) + print(15); // Resolves to void print(int) +} + +//////////////////////////////////// +// Argumentos de función por defecto +//////////////////////////////////// + +// Puedes proporcionar argumentos por defecto para una función si no son +// proporcionados por quien la llama. + +void doSomethingWithInts(int a = 1, int b = 4) +{ + // Hacer algo con los enteros aqui +} + +int main() +{ + doSomethingWithInts(); // a = 1, b = 4 + doSomethingWithInts(20); // a = 20, b = 4 + doSomethingWithInts(20, 5); // a = 20, b = 5 +} + +// Los argumentos predeterminados deben estar al final de la lista de argumentos. + +void invalidDeclaration(int a = 1, int b) // Error! +{ +} + +///////////////////// +// Espacios de nombre +///////////////////// + +// Espacios de nombres proporcionan ámbitos separados para variable, función y +// otras declaraciones. +// Los espacios de nombres se pueden anidar. + +namespace First { + namespace Nested { + void foo() + { + printf("Esto es First::Nested::foo\n"); + } + } // fin del nombre de espacio Nested +} // fin del nombre de espacio First + +namespace Second { + void foo() + { + printf("Esto es Second::foo\n") + } +} + +void foo() +{ + printf("Este es global: foo\n"); +} + +int main() +{ + + // Incluye todos los símbolos del espacio de nombre Second en el ámbito + // actual. Tenga en cuenta que simplemente foo() no funciona, ya que ahora + // es ambigua si estamos llamando a foo en espacio de nombres Second o en + // el nivel superior. + using namespace Second; + + Second::foo(); // imprime "Esto es Second::foo" + First::Nested::foo(); // imprime "Esto es First::Nested::foo" + ::foo(); // imprime "Este es global: foo" +} + +///////////////// +// Entrada/Salida +///////////////// + +// La entrada y salida de C++ utiliza flujos (streams) +// cin, cout, y cerr representan a stdin, stdout, y stderr. +// << es el operador de inserción >> es el operador de extracción. + + +#include <iostream> // Incluir para el flujo de entrada/salida + +using namespace std; // Los streams estan en std namespace (libreria estandar) + +int main() +{ + int myInt; + + // Imprime a la stdout (o terminal/pantalla) + cout << "Ingresa tu número favorito:\n"; + // Toma una entrada + cin >> myInt; + + // cout puede también ser formateado + cout << "Tu número favorito es " << myInt << "\n"; + // imprime "Tu número favorito es <myInt>" + + cerr << "Usado para mensajes de error"; +} +//////////////////// +// Cadenas (Strings) +//////////////////// + +// Las cadenas en C++ son objetos y tienen muchas funciones +#include <string> + +using namespace std; // Strings también estan en namespace std + +string myString = "Hola"; +string myOtherString = " Mundo"; + +// + es usado para concatenar. +cout << myString + myOtherString; // "Hola Mundo" + +cout << myString + " Tu"; // "Hola Tu" + +// Las cadenas en C++ son mutables y tienen valor semántico. +myString.append(" Perro"); +cout << myString; // "Hola Perro" + + +////////////// +// Referencias +////////////// + +// Además de punteros como los de C, +// C++ tiene _references_. +// Estos tipos de puntero no pueden ser reasignados una vez establecidos +// Y no pueden ser nulos. +// También tienen la misma sintaxis que la propia variable: +// No es necesaria * para eliminar la referencia y +// & (dirección) no se utiliza para la asignación. + +using namespace std; + +string foo = "Yo soy foo"; +string bar = "Yo soy bar"; + +string& fooRef = foo; // Crea una referencia a foo. +fooRef += ". Hola!"; // Modifica foo través de la referencia +cout << fooRef; // Imprime "Yo soy foo. Hola!" + +// No trate de reasignar "fooRef". Esto es lo mismo que "foo = bar", y +// foo == "Yo soy bar" +// después de esta linea. +fooRef = bar; + +const string& barRef = bar; // Crea una referencia constante a bar. +// Como en C, los valores constantes (y punteros y referencias) no pueden ser +// modificados. +barRef += ". Hola!"; // Error, referencia constante no puede ser modificada. + +// Sidetrack: Antes de hablar más sobre referencias, hay que introducir un +// concepto llamado objeto temporal. Supongamos que tenemos el siguiente código: +string tempObjectFun() { ... } +string retVal = tempObjectFun(); + +// Lo que pasa en la segunda línea es en realidad: +// - Un objeto de cadena es retornado desde tempObjectFun +// - Una nueva cadena se construye con el objeto devuelto como argumento al +// constructor +// - El objeto devuelto es destruido +// El objeto devuelto se llama objeto temporal. Objetos temporales son +// creados cada vez que una función devuelve un objeto, y es destruido en el +// fin de la evaluación de la expresión que encierra (Bueno, esto es lo que la +// norma dice, pero los compiladores están autorizados a cambiar este +// comportamiento. Busca "return value optimization" para ver mas detalles). +// Así que en este código: +foo(bar(tempObjectFun())) + +// Suponiendo que foo y bar existen, el objeto retornado de tempObjectFun es +// pasado al bar, y se destruye antes de llamar foo. + +// Ahora, de vuelta a las referencias. La excepción a la regla "en el extremo +// de la expresión encerrada" es si un objeto temporal se une a una +// referencia constante, en cuyo caso su vida se extiende al ámbito actual: + +void constReferenceTempObjectFun() { + // ConstRef obtiene el objeto temporal, y es válido hasta el final de esta + // función. + const string& constRef = tempObjectFun(); + ... +} + +// Otro tipo de referencia introducida en C ++ 11 es específicamente para +// objetos temporales. No se puede tener una variable de este tipo, pero tiene +// prioridad en resolución de sobrecarga: + +void someFun(string& s) { ... } // Referencia regular +void someFun(string&& s) { ... } // Referencia a objeto temporal + +string foo; +someFun(foo); // Llama la función con referencia regular +someFun(tempObjectFun()); // Llama la versión con referencia temporal + +// Por ejemplo, puedes ver estas dos versiones de constructores para +// std::basic_string: +basic_string(const basic_string& other); +basic_string(basic_string&& other); + +// La idea es que si estamos construyendo una nueva cadena de un objeto temporal +// (que va a ser destruido pronto de todos modos), podemos tener un constructor +// mas eficiente que "rescata" partes de esa cadena temporal. Usted verá este +// Concepto denominado "movimiento semántico". + +//////////////////////////////////////////// +// Clases y programación orientada a objetos +//////////////////////////////////////////// + +// Primer ejemplo de clases +#include <iostream> + +// Declara una clase. +// Las clases son usualmente declaradas en archivos de cabeceras (.h o .hpp) +class Dog { + // Variables y funciones de la clase son privados por defecto. + std::string name; + int weight; + +// Todos los miembros siguientes de este son públicos +// Hasta que se encuentre "private" o "protected". +// All members following this are public +// until "private:" or "protected:" is found. +public: + + // Constructor por defecto + Dog(); + + // Declaraciones de funciones de la clase (implementaciones a seguir) + // Nota que usamos std::string aquí en lugar de colocar + // using namespace std; + // arriba. + // Nunca ponga una declaración "using namespace" en un encabezado. + void setName(const std::string& dogsName); + + void setWeight(int dogsWeight); + // Funciones que no modifican el estado del objeto + // Deben marcarse como const. + // Esto le permite llamarlas si se envia una referencia constante al objeto. + // También tenga en cuenta que las funciones deben ser declaradas + // explícitamente como _virtual_ para que sea reemplazada en las clases + // derivadas. + // Las funciones no son virtuales por defecto por razones de rendimiento. + virtual void print() const; + + // Las funciones también se pueden definir en el interior + // del cuerpo de la clase. + // Funciones definidas como tales están entre líneas automáticamente. + void bark() const { std::cout << name << " barks!\n"; } + + // Junto a los constructores, C++ proporciona destructores. + // Estos son llamados cuando un objeto se elimina o está fuera del ámbito. + // Esto permite paradigmas potentes como RAII + // (mira abajo) + // El destructor debe ser virtual si una clase es dervada desde el; + // Si no es virtual, entonces la clase derivada destructor + // No será llamada si el objeto se destruye a través de una referencia de + // la clase base o puntero. + virtual ~Dog(); + + + +}; // Un punto y coma debe seguir la definición de clase. + +// Las funciones de una clase son normalmente implementados en archivos .cpp. +Dog::Dog() +{ + std::cout << "Un perro ha sido construido\n"; +} + +// Objetos (tales como cadenas) deben ser pasados por referencia +// Si los estas modificando o referencia constante en caso contrario. +void Dog::setName(const std::string& dogsName) +{ + name = dogsName; +} + +void Dog::setWeight(int dogsWeight) +{ + weight = dogsWeight; +} + +// Nota que "virtual" sólo se necesita en la declaración, no en la definición. +void Dog::print() const +{ + std::cout << "El perro es " << name << " y pesa " << weight << "kg\n"; +} + +Dog::~Dog() +{ + cout << "Adiós " << name << "\n"; +} + +int main() { + Dog myDog; // imprime "Un perro ha sido construido" + myDog.setName("Barkley"); + myDog.setWeight(10); + myDog.print(); // imprime "El perro es Barkley y pesa 10 kg" + return 0; +} // imprime "Adiós Barkley" + +// Herencia: + +// Esta clase hereda todo lo público y protegido de la clase Dog +class OwnedDog : public Dog { + + void setOwner(const std::string& dogsOwner); + + // Reemplaza el comportamiento de la función de impresión + // de todos los OwnedDogs. Mira + // http://en.wikipedia.org/wiki/Polymorphism_(computer_science)#Subtyping + // Para una introducción más general si no está familiarizado con el + // polimorfismo de subtipo. + // La palabra clave override es opcional, pero asegura que estás + // reemplazando el método de una clase base. + void print() const override; + +private: + std::string owner; +}; + +// Mientras tanto, en el archivo .cpp correspondiente: + +void OwnedDog::setOwner(const std::string& dogsOwner) +{ + owner = dogsOwner; +} + +void OwnedDog::print() const +{ + Dog::print(); // Llama a la función de impresión en la clase base Dog + std::cout << "El perro es de " << owner << "\n"; + // Imprime "El perro es <name> y pesa <weight>" + // "El perro es de <owner>" +} + +//////////////////////////////////////////// +// Inicialización y sobrecarga de operadores +//////////////////////////////////////////// + +// En C ++ se puede sobrecargar el comportamiento +// de los operadores como +, -, *, /, etc. +// Esto se hace mediante la definición de una función que es llamada +// cada vez que se utiliza el operador. + +#include <iostream> +using namespace std; + +class Point { +public: + // Las variables de la clase pueden dar valores por defecto de esta manera. + double x = 0; + double y = 0; + + // Define un constructor por defecto que no hace nada + // pero inicializa el punto al valor por defecto (0, 0) + Point() { }; + + // The following syntax is known as an initialization list + // and is the proper way to initialize class member values + Point (double a, double b) : + x(a), + y(b) + { /* No hace nada excepto inicializar los valores */ } + + // Sobrecarga el operador + + Point operator+(const Point& rhs) const; + + // Sobrecarga el operador += + Point& operator+=(const Point& rhs); + + // También tendría sentido añadir los operadores - y -=, + // Pero vamos a omitirlos por razones de brevedad. +}; + +Point Point::operator+(const Point& rhs) const +{ + // Crea un nuevo punto que es la suma de este y rhs. + return Point(x + rhs.x, y + rhs.y); +} + +Point& Point::operator+=(const Point& rhs) +{ + x += rhs.x; + y += rhs.y; + return *this; +} + +int main () { + Point up (0,1); + Point right (1,0); + // Llama al operador + de Point + // Point llama la función + con right como parámetro + Point result = up + right; + // Prints "Result is upright (1,1)" + cout << "Result is upright (" << result.x << ',' << result.y << ")\n"; + return 0; +} + +///////////////////////// +// Plantillas (Templates) +///////////////////////// + +// Las plantillas en C++ se utilizan sobre todo en la programación genérica, +// a pesar de que son mucho más poderoso que los constructores genéricos +// en otros lenguajes. Ellos también soportan especialización explícita y +// parcial y clases de tipo estilo funcional; de hecho, son un lenguaje +// funcional Turing-completo incrustado en C ++! + +// Empezamos con el tipo de programación genérica que podría estar +// familiarizado. +// Para definir una clase o función que toma un parámetro de tipo: +template<class T> +class Box { +public: + // En este caso, T puede ser usado como cualquier otro tipo. + void insert(const T&) { ... } +}; + +// Durante la compilación, el compilador realmente genera copias de cada +// plantilla con parámetros sustituidos, por lo que la definición completa +// de la clase debe estar presente en cada invocación. +// Es por esto que usted verá clases de plantilla definidas +// Enteramente en archivos de cabecera. + +//Para crear una instancia de una clase de plantilla en la pila: +Box<int> intBox; + +y puedes utilizarlo como era de esperar: +intBox.insert(123); + +// Puedes, por supuesto, anidar plantillas: +Box<Box<int> > boxOfBox; +boxOfBox.insert(intBox); + +// Hasta C++11, había que colocar un espacio entre los dos '>'s, +// de lo contrario '>>' serían analizados como el operador de desplazamiento +// a la derecha. + + +// A veces verás +// template<typename T> +// en su lugar. La palabra clave "class" y las palabras clave "typename" son +// mayormente intercambiables en este caso. Para la explicación completa, mira +// http://en.wikipedia.org/wiki/Typename +// (sí, esa palabra clave tiene su propia página de Wikipedia). + +// Del mismo modo, una plantilla de función: +template<class T> +void barkThreeTimes(const T& input) +{ + input.bark(); + input.bark(); + input.bark(); +} + +// Observe que no se especifica nada acerca de los tipos de parámetros aquí. +// El compilador generará y comprobará cada invocación de la plantilla, +// por lo que la función anterior funciona con cualquier tipo "T" +// que tenga un método 'bark' constante! + + +Dog fluffy; +fluffy.setName("Fluffy") +barkThreeTimes(fluffy); // Imprime "Fluffy barks" 3 veces. + +Los parámetros de la plantilla no tienen que ser las clases: +template<int Y> +void printMessage() { + cout << "Aprende C++ en " << Y << " minutos!" << endl; +} + +// Y usted puede especializar explícitamente plantillas +// para código más eficiente. +// Por supuesto, la mayor parte del mundo real que utiliza una especialización +// no son tan triviales como esta. +// Tenga en cuenta que usted todavía tiene que declarar la función (o clase) +// como plantilla incluso si ha especificado de forma explícita todos +// los parámetros. + +template<> +void printMessage<10>() { + cout << "Aprende C++ rapido en solo 10 minutos!" << endl; +} + +printMessage<20>(); // Prints "Aprende C++ en 20 minutos!" +printMessage<10>(); // Prints "Aprende C++ rapido en solo 10 minutos!" + + +///////////////////// +// Manejador de excepciones +///////////////////// + +// La biblioteca estándar proporciona algunos tipos de excepción +// (mira http://en.cppreference.com/w/cpp/error/exception) +// pero cualquier tipo puede ser lanzado como una excepción +#include <exception> +#include <stdexcept> + +//Todas las excepciones lanzadas dentro del bloque _try_ pueden ser +// capturados por los siguientes manejadores _catch_. +try { + // No asignar excepciones en el heap usando _new_. + throw std::runtime_error("Ocurrió un problema"); +} + +// Captura excepciones por referencia const si son objetos +catch (const std::exception& ex) +{ + std::cout << ex.what(); +} +******************************************************************************** +// Captura cualquier excepción no capturada por bloques _catch_ anteriores +catch (...) +{ + std::cout << "Excepción desconocida capturada"; + throw; // Re-lanza la excepción +} + +/////// +// RAII +/////// + +// RAII significa "Resource Acquisition Is Initialization" +// (Adquisición de recursos es inicialización). +// A menudo se considera el paradigma más poderoso en C++ +// Y el concepto es simple: un constructor de un objeto +// Adquiere recursos de ese objeto y el destructor les libera. + +// Para entender cómo esto es útil, +// Considere una función que utiliza un identificador de archivo C: +void doSomethingWithAFile(const char* filename) +{ + // Para empezar, asuma que nada puede fallar. + + FILE* fh = fopen(filename, "r"); // Abre el archivo en modo lectura + + doSomethingWithTheFile(fh); + doSomethingElseWithIt(fh); + + fclose(fh); // Cierra el manejador de archivos +} + +// Por desgracia, las cosas se complican rápidamente por el control de errores. +// Supongamos que fopen puede fallar, y que doSomethingWithTheFile y +// DoSomethingElseWithIt retornan códigos de error si fallan. +// (Excepciones son la mejor forma de manejar los fallos, +// pero algunos programadores, especialmente los que tienen un fondo C, +// estan en desacuerdo sobre la utilidad de las excepciones). +// Ahora tenemos que comprobar cada llamado por fallos y cerrar el manejador +// del archivo si se ha producido un problema. +bool doSomethingWithAFile(const char* filename) +{ + FILE* fh = fopen(filename, "r"); // Abre el archivo en modo lectura + if (fh == nullptr) // El puntero retornado es nulo o falla. + return false; // Reporta el fallo a quien hizo el llamado. + + // Asume que cada función retorna falso si falla + if (!doSomethingWithTheFile(fh)) { + fclose(fh); // Cierre el manejador de archivo para que no se filtre. + return false; // Propaga el error. + } + if (!doSomethingElseWithIt(fh)) { + fclose(fh); // Cierre el manejador de archivo para que no se filtre. + return false; // Propaga el error. + } + + fclose(fh); // Cierre el archivo. + return true; // Indica que todo funcionó correctamente. +} + +// Programadores C suelen limpiar esto un poco usando goto: +bool doSomethingWithAFile(const char* filename) +{ + FILE* fh = fopen(filename, "r"); + if (fh == nullptr) + return false; + + if (!doSomethingWithTheFile(fh)) + goto failure; + + if (!doSomethingElseWithIt(fh)) + goto failure; + + fclose(fh); // Cierre el archivo. + return true; // Indica que todo funcionó correctamente. + +failure: + fclose(fh); + return false; // Propagate el error +} + +// Si las funciones indican errores mediante excepciones, +// Las cosas son un poco más claras, pero pueden optimizarse mas. +void doSomethingWithAFile(const char* filename) +{ + FILE* fh = fopen(filename, "r"); // Abrir el archivo en modo lectura + if (fh == nullptr) + throw std::runtime_error("No puede abrirse el archivo."); + + try { + doSomethingWithTheFile(fh); + doSomethingElseWithIt(fh); + } + catch (...) { + fclose(fh); // Asegúrese de cerrar el archivo si se produce un error. + throw; // Luego vuelve a lanzar la excepción. + } + + fclose(fh); // Cierra el archivo +} + +// Compare esto con el uso de la clase de flujo de archivos de C++ (fstream) +// fstream utiliza su destructor para cerrar el archivo. +// Los destructores son llamados automáticamente +// cuando un objeto queda fuera del ámbito. +void doSomethingWithAFile(const std::string& filename) +{ + // ifstream es la abreviatura de el input file stream + std::ifstream fh(filename); // Abre el archivo + + // Hacer algo con el archivo + doSomethingWithTheFile(fh); + doSomethingElseWithIt(fh); + +} // El archivo se cierra automáticamente aquí por el destructor + + +// Esto tiene ventajas _enormes_: +// 1. No importa lo que pase, +// El recurso (en este caso el manejador de archivo) será limpiado. +// Una vez que escribes el destructor correctamente, +// Es _imposible_ olvidar cerrar el identificador y permitir +// fugas del recurso. +// 2. Tenga en cuenta que el código es mucho más limpio. +// El destructor se encarga de cerrar el archivo detrás de cámaras +// Sin que tenga que preocuparse por ello. +// 3. El código es seguro. +// Una excepción puede ser lanzado en cualquier lugar de la función +// y la limpieza ocurrirá. + +// Todo el código idiomático C++ utiliza RAII ampliamente para todos los +// recursos. +// Otros ejemplos incluyen +// - Memoria usando unique_ptr y shared_ptr +// - Contenedores (Containers) - la biblioteca estándar linked list, +// vector (es decir, array con auto-cambio de tamaño), hash maps, etc. +// Destruimos todos sus contenidos de forma automática +// cuando quedan fuera del ámbito. +// - Mutex utilizando lock_guard y unique_lock + + +///////////////////// +// Cosas divertidas +///////////////////// + +// Aspectos de C ++ que pueden sorprender a los recién llegados +// (e incluso algunos veteranos). +// Esta sección es, por desgracia, salvajemente incompleta; +// C++ es uno de los lenguajes con los que mas facil te disparas en el pie. + +// Tu puedes sobreescribir métodos privados! +class Foo { + virtual void bar(); +}; +class FooSub : public Foo { + virtual void bar(); // Sobreescribe Foo::bar! +}; + + +// 0 == false == NULL (La mayoria de las veces)! +bool* pt = new bool; +*pt = 0; // Establece los puntos de valor de 'pt' en falso. +pt = 0; // Establece 'pt' al apuntador nulo. Ambas lineas compilan sin error. + +// nullptr se supone que arregla un poco de ese tema: +int* pt2 = new int; +*pt2 = nullptr; // No compila +pt2 = nullptr; // Establece pt2 como null. + +// Hay una excepción para los valores bool. +// Esto es para permitir poner a prueba punteros nulos con if (!ptr), +// pero como consecuencia se puede asignar nullptr a un bool directamente! +*pt = nullptr; // Esto todavía compila, a pesar de que '*pt' es un bool! + +// '=' != '=' != '='! +// Llama Foo::Foo(const Foo&) o alguna variante (mira movimientos semanticos) +// copia del constructor. +Foo f2; +Foo f1 = f2; + +// Llama Foo::Foo(const Foo&) o variante, pero solo copia el 'Foo' parte de +// 'fooSub'. Cualquier miembro extra de 'fooSub' se descarta. Este +// comportamiento horrible se llama "Corte de objetos." +FooSub fooSub; +Foo f1 = fooSub; + +// Llama a Foo::operator=(Foo&) o variantes. +Foo f1; +f1 = f2; + + +// Cómo borrar realmente un contenedor: +class Foo { ... }; +vector<Foo> v; +for (int i = 0; i < 10; ++i) + v.push_back(Foo()); +// La siguiente línea establece el tamaño de v en 0, +// pero los destructores no son llamados y los recursos no se liberan! + +v.empty(); +v.push_back(Foo()); // Nuevo valor se copia en el primer Foo que insertamos + +// En verdad destruye todos los valores en v. +// Consulta la sección acerca de los objetos temporales para la +// explicación de por qué esto funciona. +v.swap(vector<Foo>()); + +``` +Otras lecturas: + +Una referencia del lenguaje hasta a la fecha se puede encontrar en +<http://cppreference.com/w/cpp> + +Recursos adicionales se pueden encontrar en <http://cplusplus.com> From 224d4e9c7f8b13da852662edcf57f83d7f78c278 Mon Sep 17 00:00:00 2001 From: Jesus Tinoco <JesusTinoco@users.noreply.github.com> Date: Sun, 4 Oct 2015 13:17:50 +0200 Subject: [PATCH 37/55] Fixing typo in git-es.html.markdown --- es-es/git-es.html.markdown | 64 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/es-es/git-es.html.markdown b/es-es/git-es.html.markdown index 73853a9d..f370aa4d 100644 --- a/es-es/git-es.html.markdown +++ b/es-es/git-es.html.markdown @@ -11,15 +11,15 @@ lang: es-es --- Git es un sistema de control de versiones distribuido diseñado para manejar -cualquier tipo de proyecto ya sea largos o pequeños, con velocidad y eficiencia. +cualquier tipo de proyect,o ya sea largo o pequeño, con velocidad y eficiencia. Git realiza esto haciendo "snapshots" del proyecto, con ello permite versionar y administrar nuestro código fuente. ## Versionamiento, conceptos. -### Que es el control de versiones? -El control de versiones es un sistema que guarda todos los cambios realizados a +### Qué es el control de versiones? +El control de versiones es un sistema que guarda todos los cambios realizados en uno o varios archivos, a lo largo del tiempo. ### Versionamiento centralizado vs Versionamiento Distribuido. @@ -31,15 +31,15 @@ uno o varios archivos, a lo largo del tiempo. + El versionamiento distribuido no tiene una estructura definida, incluso se puede mantener el estilo de los repositorios SVN con git. -[Informacion adicional](http://git-scm.com/book/es/Empezando-Acerca-del-control-de-versiones) +[Información adicional](http://git-scm.com/book/es/Empezando-Acerca-del-control-de-versiones) -### Por que usar Git? +### Por qué usar Git? * Se puede trabajar sin conexion. * Colaborar con otros es sencillo!. -* Derivar, Crear ramas del proyecto (aka: Branching) es facil!. +* Derivar, Crear ramas del proyecto (aka: Branching) es fácil!. * Combinar (aka: Merging) -* Git es rapido. +* Git es rápido. * Git es flexible. ## Arquitectura de Git. @@ -48,10 +48,10 @@ uno o varios archivos, a lo largo del tiempo. Un repositorio es un conjunto de archivos, directorios, registros, cambios (aka: comits), y encabezados (aka: heads). Imagina que un repositorio es una clase, -y que sus atributos otorgan acceso al historial del elemento, ademas de otras +y que sus atributos otorgan acceso al historial del elemento, además de otras cosas. -Un repositorio esta compuesto por la carpeta .git y un "arbol de trabajo". +Un repositorio esta compuesto por la carpeta .git y un "árbol de trabajo". ### Directorio .git (componentes del repositorio) @@ -62,38 +62,38 @@ y mas. ### Directorio de trabajo (componentes del repositorio) -Es basicamente los directorios y archivos dentro del repositorio. La mayorioa de +Es basicamente los directorios y archivos dentro del repositorio. La mayoría de las veces se le llama "directorio de trabajo". -### Inidice (componentes del directorio .git) +### Índice (componentes del directorio .git) -El inidice es la area de inicio en git. Es basicamente la capa que separa el +El índice es el área de inicio en git. Es basicamente la capa que separa el directorio de trabajo, del repositorio en git. Esto otorga a los desarrolladores -mas poder sobre lo que envia y recibe en el repositorio. +mas poder sobre lo que envía y recibe en el repositorio. ### Commit (aka: cambios) Un commit es una captura de un conjunto de cambios, o modificaciones hechas en el directorio de trabajo. Por ejemplo, si se añaden 5 archivos, se remueven 2, -estos cambios se almacenaran en un commit (aka: captura). Este commit puede ser o +estos cambios se almacenarán en un commit (aka: captura). Este commit puede ser o no ser enviado (aka: "pusheado") hacia un repositorio. ### Branch (rama) -Un "branch", es escencialmente un apuntador hacia el ultimo commit (cambio -registrado) que se ha realizado. A medida que se realizan mas commits, este -apuntador se actualizara automaticamente hacia el ultimo commit. +Un "branch", es escencialmente un apuntador hacia el último commit (cambio +registrado) que se ha realizado. A medida que se realizan más commits, este +apuntador se actualizará automaticamente hacia el ultimo commit. ### "HEAD" y "head" (component of .git dir) "HEAD" es un apuntador hacia la rama (branch) que se esta utilizando. Un repositorio solo puede tener un HEAD activo. En cambio "head", es un apuntador a -cualquier commit realizado, un repositorio puede tener cualquier numero de +cualquier commit realizado, un repositorio puede tener cualquier número de "heads". ### conceptos - recursos. -* [Git para informaticos](http://eagain.net/articles/git-for-computer-scientists/) +* [Git para informáticos](http://eagain.net/articles/git-for-computer-scientists/) * [Git para diseñadores](http://hoth.entp.com/output/git_for_designers.html) @@ -102,8 +102,8 @@ cualquier commit realizado, un repositorio puede tener cualquier numero de ### init -Crear un repositorio de git vacio. Las configuraciones, informacion almacenada y -demas son almacenadas en el directorio ".git". +Crear un repositorio de git vacio. Las configuraciones, información almacenada y +demás son almacenadas en el directorio ".git". ```bash $ git init @@ -127,7 +127,7 @@ $ git config --global user.name "nombre" ### help -Otorga un accceso rapido a una guia extremadamente detallada de cada comando en +Otorga un accceso rápido a una guía extremadamente detallada de cada comando en git. O puede ser usada simplemente como un recordatorio de estos. ```bash @@ -146,7 +146,7 @@ $ git help init ### status -Muestra las diferencias entre el archivo indice y el commit al cual apunta el +Muestra las diferencias entre el archivo índice y el commit al cual apunta el HEAD actualmente. @@ -163,7 +163,7 @@ $ git help status Para añadir archivos al arbol (directorio, repositorio) de trabajo. Si no se utiliza `git add`, los nuevos archivos no se añadiran al arbol de trabajo, por -lo que no se incluiran en los commits (cambios). +lo que no se incluirán en los commits (cambios). ```bash # Añade un archivo en el directorio de trabajo actual. @@ -202,7 +202,7 @@ $ git branch master --edit-description ### checkout Actualiza todos los archivos en el directorio de trabajo para que sean igual que -las versiones almacenadas en el indice, o en un arbol de trabajo especificado. +las versiones almacenadas en el índice, o en un árbol de trabajo especificado. ```bash # Despachar un repositorio. - Por defecto la master branch. (la rama principal llamada 'master') @@ -215,8 +215,8 @@ $ git checkout -b jdei ### clone -Clona, o copia, una repo existente en un nuevo directorio. Tambien añada el -seguimiento hacia las ramas existentes del repo que ha sido clonada, lo que +Clona, o copia, un repositorio existente en un nuevo directorio. También añade el +seguimiento hacia las ramas existentes del repositorio que ha sido clonado, lo que permite subir (push) los archivos hacia una rama remota. ```bash @@ -226,8 +226,8 @@ $ git clone https://github.com/jquery/jquery.git ### commit -Almacena los cambios que almacenados en el indice en un nuevo "commit". Este -commit contiene los cambios hechos mas un resumen hecho por el desarrollador. +Almacena el contenido actual del índice en un nuevo "commit". Este +commit contiene los cambios hechos más un resumen proporcionado por el desarrollador. ```bash # commit with a message @@ -237,8 +237,8 @@ $ git commit -m "jedi anakin wil be - jedis.list" ### diff -Muestra las diferencias entre un archivo en el directorio de trabajo, el indice -y commits. +Muestra las diferencias entre un archivo en el directorio de trabajo, el índice +y los commits. ```bash # Muestra la diferencia entre un directorio de trabajo y el indice. @@ -253,7 +253,7 @@ $ git diff HEAD ### grep -Permite realizar una busqueda rapida en un repositorio. +Permite realizar una busqueda rápida en un repositorio. Configuracion opcionales: From f7cfb3b194ff4fb590173cb7e790c4effc1656c0 Mon Sep 17 00:00:00 2001 From: edholland <edjholland@gmail.com> Date: Sun, 4 Oct 2015 13:18:06 +0200 Subject: [PATCH 38/55] Fix poor formatting and typos --- erlang.html.markdown | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/erlang.html.markdown b/erlang.html.markdown index 64330867..48cee6ec 100644 --- a/erlang.html.markdown +++ b/erlang.html.markdown @@ -308,25 +308,25 @@ self(). % <0.41.0> % Unit tests can be written using EUnits's test generators and assert macros -module(fib). - -export([fib/1]). - -include_lib("eunit/include/eunit.hrl"). +-export([fib/1]). +-include_lib("eunit/include/eunit.hrl"). - fib(0) -> 1; - fib(1) -> 1; - fib(N) when N > 1 -> fib(N-1) + fib(N-2). +fib(0) -> 1; +fib(1) -> 1; +fib(N) when N > 1 -> fib(N-1) + fib(N-2). - fib_test_() -> - [?_assert(fib(0) =:= 1), - ?_assert(fib(1) =:= 1), - ?_assert(fib(2) =:= 2), - ?_assert(fib(3) =:= 3), - ?_assert(fib(4) =:= 5), - ?_assert(fib(5) =:= 8), - ?_assertException(error, function_clause, fib(-1)), - ?_assert(fib(31) =:= 2178309) - ]. +fib_test_() -> + [?_assert(fib(0) =:= 1), + ?_assert(fib(1) =:= 1), + ?_assert(fib(2) =:= 2), + ?_assert(fib(3) =:= 3), + ?_assert(fib(4) =:= 5), + ?_assert(fib(5) =:= 8), + ?_assertException(error, function_clause, fib(-1)), + ?_assert(fib(31) =:= 2178309) + ]. -% EUnit will automatically export to a test() fucntion to allo running the tests +% EUnit will automatically export to a test() function to allow running the tests % in the erlang shell fib:test() From 8aec122beaffc6d7d8e108aa4bbe4a2218062a46 Mon Sep 17 00:00:00 2001 From: Jesus Tinoco <JesusTinoco@users.noreply.github.com> Date: Sun, 4 Oct 2015 13:19:34 +0200 Subject: [PATCH 39/55] Typos fixed in git-es.html.markdown --- es-es/git-es.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es-es/git-es.html.markdown b/es-es/git-es.html.markdown index f370aa4d..51812447 100644 --- a/es-es/git-es.html.markdown +++ b/es-es/git-es.html.markdown @@ -11,7 +11,7 @@ lang: es-es --- Git es un sistema de control de versiones distribuido diseñado para manejar -cualquier tipo de proyect,o ya sea largo o pequeño, con velocidad y eficiencia. +cualquier tipo de proyecto, ya sea largo o pequeño, con velocidad y eficiencia. Git realiza esto haciendo "snapshots" del proyecto, con ello permite versionar y administrar nuestro código fuente. From 6b6f88c64d9a4b2d26de5725dee24f3c459fb93c Mon Sep 17 00:00:00 2001 From: bk2dcradle <ankitsultana@gmail.com> Date: Sun, 4 Oct 2015 01:47:09 +0530 Subject: [PATCH 40/55] Added abstract classes --- java.html.markdown | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/java.html.markdown b/java.html.markdown index 928eb39f..2f41be81 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -451,6 +451,74 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, public void InterfaceTwoMethod() { } } + + +// Abstract Classes +// Abstract Class declaration syntax +// <access-level> abstract <abstract-class-name> extends <super-abstract-classes> { +// // Constants and variables +// // Method declarations +// } + +// Methods can't have bodies in an interface, unless the method is +// static. Also variables are NOT final by default, unlike an interface. +// Also abstract classes CAN have the "main" method. +// Abstract classes solve these problems. + +public abstract class Animal +{ + public abstract void makeSound(); + + // Method can have a body + public void eat() + { + System.out.println("I am an animal and I am Eating."); + // Note: We can access private variable here. + age = 30; + } + + // No need to initialise, however in an interface + // a variable is implicitly final and hence has + // to be initialised. + private int age; + + public void printAge() + { + System.out.println(age); + } + + // Abstract classes can have main function. + public static void main(String[] args) + { + System.out.println("I am abstract"); + } +} + +class Dog extends Animal +{ + // Note still have to override the abstract methods in the + // abstract class. + @Override + public void makeSound() + { + System.out.println("Bark"); + // age = 30; ==> ERROR! age is private to Animal + } + + // NOTE: You will get an error if you used the + // @Override annotation here, since java doesn't allow + // overriding of static methods. + // What is happening here is called METHOD HIDING. + // Check out this awesome SO post: (http://stackoverflow.com/questions/16313649/) + public static void main(String[] args) + { + Dog pluto = new Dog(); + pluto.makeSound(); + pluto.eat(); + pluto.printAge(); + } +} + ``` ## Further Reading From f1a90a4e636616ce91a271504eee3f374bfd7094 Mon Sep 17 00:00:00 2001 From: Guntbert Reiter <guntbert@gmx.at> Date: Sun, 4 Oct 2015 16:44:24 +0200 Subject: [PATCH 41/55] Put demonstrative condition into ternary expression It should be made clear that the part before the ternary operator is indeed a condition, most often created as some comparison expression. --- csharp.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/csharp.html.markdown b/csharp.html.markdown index 479b7f01..222ba0d2 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -236,7 +236,8 @@ on a new line! ""Wow!"", the masses cried"; // Ternary operators // A simple if/else can be written as follows // <condition> ? <true> : <false> - string isTrue = (true) ? "True" : "False"; + int toCompare = 17; + string isTrue = toCompare == 17 ? "True" : "False"; // While loop int fooWhile = 0; From ff1b91d463938a0809f4115c20c6f9fc89e24cfc Mon Sep 17 00:00:00 2001 From: David Lima <dave@blogdodave.com.br> Date: Sun, 4 Oct 2015 11:55:16 -0300 Subject: [PATCH 42/55] [hack/en] Fixed some typos --- hack.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hack.html.markdown b/hack.html.markdown index 632fc705..b9730dc0 100644 --- a/hack.html.markdown +++ b/hack.html.markdown @@ -2,6 +2,7 @@ language: Hack contributors: - ["Stephen Holdaway", "https://github.com/stecman"] + - ["David Lima", "https://github.com/davelima"] filename: learnhack.hh --- @@ -152,7 +153,7 @@ class ArgumentPromotion private bool $isAwesome) {} } -class WithoutArugmentPromotion +class WithoutArgumentPromotion { public string $name; @@ -169,9 +170,9 @@ class WithoutArugmentPromotion } -// Co-oprerative multi-tasking +// Co-operative multi-tasking // -// Two new keywords "async" and "await" can be used to perform mutli-tasking +// Two new keywords "async" and "await" can be used to perform multi-tasking // Note that this does not involve threads - it just allows transfer of control async function cooperativePrint(int $start, int $end) : Awaitable<void> { From 29ea66dbef66944f59b5a7abe68b7113e1679791 Mon Sep 17 00:00:00 2001 From: David Lima <dave@blogdodave.com.br> Date: Sun, 4 Oct 2015 12:02:20 -0300 Subject: [PATCH 43/55] [hack/pt-br] Add pt-br translation --- pt-br/hack-pt.html.markdown | 316 ++++++++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 pt-br/hack-pt.html.markdown diff --git a/pt-br/hack-pt.html.markdown b/pt-br/hack-pt.html.markdown new file mode 100644 index 00000000..3efa5f0a --- /dev/null +++ b/pt-br/hack-pt.html.markdown @@ -0,0 +1,316 @@ +--- +language: Hack +contributors: + - ["Stephen Holdaway", "https://github.com/stecman"] + - ["David Lima", "https://github.com/davelima"] +translators: + - ["David Lima", "https://github.com/davelima"] +lang: pt-br +filename: learnhack.hh +--- + +Hack é uma linguagem baseada no PHP e roda numa máquina virtual chamada HHVM. +Hack é quase completamente interoperável com códigos PHP existentes e adiciona +alguns recursos úteis de linguagens estaticamente tipadas. + +Somente recursos específicos da linguagem Hack serão abordados aqui. Detalhes +sobre a sintaxe do PHP estão disponíveis no +[artigo PHP](http://learnxinyminutes.com/docs/php/) neste site. + +```php +<?hh + +// A sintaxe do Hack é ativada apenas em arquivos que comecem com <?hh +// Marcadores <?hh não podem ser incluídos em páginas HTML, diferente de <?php. +// Usar o marcador "<?hh //strict" coloca o verificador de tipo no modo estrito. + + +// Indução de tipo de parâmetros escalares +function repeat(string $palavra, int $contagem) +{ + $palavra = trim($palavra); + return str_repeat($palavra . ' ', $contagem); +} + +// Indução de tipo para valores de retorno +function add(...$numeros) : int +{ + return array_sum($numeros); +} + +// Funções que não retornam nada são induzidas com "void" +function truncate(resource $recurso) : void +{ + // ... +} + +// Induções de tipo devem permitir nulos de forma explícita +function identity(?string $stringOuNulo) : ?string +{ + return $stringOuNulo; +} + +// Induções de tipo podem ser especificadas em propriedades de classes +class PropriedadesComTipos +{ + public ?string $nome; + + protected int $id; + + private float $pontuacao = 100.0; + + // O verificador de tipos do Hack reforça que propriedades tipadas devem + // ter um valor padrão ou devem ser definidos no construtor + public function __construct(int $id) + { + $this->id = $id; + } +} + + +// Funções anônimas (lambdas) +$multiplicador = 5; +array_map($y ==> $y * $multiplicador, [1, 2, 3]); + + +// Genéricos +class Caixa<T> +{ + protected T $dados; + + public function __construct(T $dados) { + $this->dados = $dados; + } + + public function pegaDados(): T { + return $this->dados; + } +} + +function abreCaixa(Caixa<int> $caixa) : int +{ + return $caixa->pegaDados(); +} + + +// Formas +// +// Hack adiciona o conceito de formas para definir arrays com uma estrutura +// e tipos de dados garantidos +type Point2D = shape('x' => int, 'y' => int); + +function distancia(Point2D $a, Point2D $b) : float +{ + return sqrt(pow($b['x'] - $a['x'], 2) + pow($b['y'] - $a['y'], 2)); +} + +distancia( + shape('x' => -1, 'y' => 5), + shape('x' => 2, 'y' => 50) +); + + +// Pseudônimos de tipos +// +// Hack adiciona vários recursos para criação de pseudônimos, tornando tipos complexos +// mais fáceis de entender +newtype VectorArray = array<int, Vector<int>>; + +// Um tuple contendo dois inteiros +newtype Point = (int, int); + +function adicionaPontos(Point $p1, Point $p2) : Point +{ + return tuple($p1[0] + $p2[0], $p1[1] + $p2[1]); +} + +adicionaPontos( + tuple(1, 2), + tuple(5, 6) +); + + +// enums em classes +enum TipoDePista : int +{ + Estrada = 0; + Rua = 1; + Alameda = 2; + Avenida = 3; +} + +function getTipoDePista() : TipoDePista +{ + return TipoDePista::Alameda; +} + + +// Especificação de argumentos no construtor (Argument Promotion) +// +// Para evitar que propriedades sejam definidas em mais de um lugar, e +// construtores que só definem propriedades, o Hack adiciona uma sintaxe para +// definir as propriedades e o construtor ao mesmo tempo. +class ArgumentPromotion +{ + public function __construct(public string $nome, + protected int $idade, + private bool $legal) {} +} + +class SemArgumentPromotion +{ + public string $nome; + + protected int $idade; + + private bool $legal; + + public function __construct(string $nome, int $idade, bool $legal) + { + $this->nome = $nome; + $this->idade = $idade; + $this->legal = $legal; + } +} + + +// Multi-tarefas cooperativo +// +// Duas novas palavras-chave ("async" e "await") podem ser usadas para +// trabalhar com multi-tarefas. +// Obs. Isto não envolve threads - apenas permite a transferência de controle +async function printCooperativo(int $inicio, int $fim) : Awaitable<void> +{ + for ($i = $inicio; $i <= $fim; $i++) { + echo "$i "; + + // Permite que outras tarefas façam algo + await RescheduleWaitHandle::create(RescheduleWaitHandle::QUEUE_DEFAULT, 0); + } +} + +// Imprime "1 4 7 2 5 8 3 6 9" +AwaitAllWaitHandle::fromArray([ + printCooperativo(1, 3), + printCooperativo(4, 6), + printCooperativo(7, 9) +])->getWaitHandle()->join(); + + +// Atributos +// +// Atributos são uma forma de definir metadados para funções. +// Hack tem alguns atributos especiais que possuem comportamentos úteis. + +// O atributo especial __Memoize faz com que o resultado da função fique em cache +<<__Memoize>> +function tarefaDemorada() : ?string +{ + return file_get_contents('http://exemplo.com'); +} + +// O corpo da função só é executado uma vez aqui: +tarefaDemorada(); +tarefaDemorada(); + + +// O atributo especial __ConsistentConstruct faz com que o Hack certifique-se +// de que a assinatura do construtor seja a mesma em todas as subclasses +<<__ConsistentConstruct>> +class FooConsistente +{ + public function __construct(int $x, float $y) + { + // ... + } + + public function algumMetodo() + { + // ... + } +} + +class BarConsistente extends FooConsistente +{ + public function __construct(int $x, float $y) + { + // O verificador de tipos do Hack exige que os construtores pai + // sejam chamados + parent::__construct($x, $y); + + // ... + } + + // A anotação __Override é uma anotação opcional que faz com que o + // verificador de tipos do Hack sobrescreva um método em uma classe pai + // ou um trait. Sem __Override, definir este método causará um erro, + // pois ele já foi definido na classe pai (FooConsistente): + <<__Override>> + public function algumMetodo() + { + // ... + } +} + +class SubclasseFooInvalida extends FooConsistente +{ + // Caso o construtor não combine com o construtor da classe pai, o + // verificador de tipos acusará um erro: + // + // "Este objeto é incompatível com o objeto FooConsistente porque algum(ns) + // dos seus métodos são incompatíveis" + // + public function __construct(float $x) + { + // ... + } + + // Usar a anotação __Override em um método que não existe na classe pai + // causará um erro do verificador de tipos: + // "SubclasseFooInvalida::outroMetodo() está marcada para sobrescrever; + // nenhuma definição não-privada foi encontrada ou a classe pai foi + // definida em código não-<?hh" + // + <<__Override>> + public function outroMetodo() + { + // ... + } +} + + +// Traits podem implementar interfaces (não suportado pelo PHP) +interface InterfaceGatinho +{ + public function brinca() : void; +} + +trait TraitGato implements GatinhoInterface +{ + public function brinca() : void + { + // ... + } +} + +class Samuel +{ + use TraitGato; +} + + +$gato = new Samuel(); +$gato instanceof GatinhoInterface === true; // True + +``` + +## Mais informações + +Visite a [documentação do Hack](http://docs.hhvm.com/manual/en/hacklangref.php) +para ver explicações detalhadas dos recursos que Hack adiciona ao PHP, ou o [site oficial do Hack](http://hanlang.org/) +para outras informações. + +Visite o [site oficial do HHVM](http://hhvm.com/) para aprender a instalar o HHVM. + +Visite [este artigo](http://docs.hhvm.com/manual/en/hack.unsupported.php) para ver +os recursos do PHP que o Hack não suporta e ver incompatibilidades entre Hack e PHP. From 09f8a34244af976f7ca29efc620a6bd51ad4ffa7 Mon Sep 17 00:00:00 2001 From: David Lima <dave@blogdodave.com.br> Date: Sun, 4 Oct 2015 12:05:07 -0300 Subject: [PATCH 44/55] [hack/pt-br] Fixed some typos --- pt-br/hack-pt.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pt-br/hack-pt.html.markdown b/pt-br/hack-pt.html.markdown index 3efa5f0a..2f9d3c1b 100644 --- a/pt-br/hack-pt.html.markdown +++ b/pt-br/hack-pt.html.markdown @@ -285,7 +285,7 @@ interface InterfaceGatinho public function brinca() : void; } -trait TraitGato implements GatinhoInterface +trait TraitGato implements InterfaceGatinho { public function brinca() : void { @@ -300,7 +300,7 @@ class Samuel $gato = new Samuel(); -$gato instanceof GatinhoInterface === true; // True +$gato instanceof InterfaceGatinho === true; // True ``` From fbd07f268cd6e64c65912ccc27f2ec9e222ec536 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma <thepsguy@icloud.com> Date: Sun, 4 Oct 2015 21:24:57 +0530 Subject: [PATCH 45/55] Issue #1157 Comment explaining '-p', in line 178. --- common-lisp.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common-lisp.html.markdown b/common-lisp.html.markdown index f9f64d68..e3bb61cf 100644 --- a/common-lisp.html.markdown +++ b/common-lisp.html.markdown @@ -175,7 +175,8 @@ nil ; for false - and the empty list :age 5)) *rover* ; => #S(DOG :NAME "rover" :BREED "collie" :AGE 5) -(dog-p *rover*) ; => t ;; ewww) +(dog-p *rover*) ; => true #| -p signifies "predicate". It's used to + check if *rover* is an instance of dog.|# (dog-name *rover*) ; => "rover" ;; Dog-p, make-dog, and dog-name are all created by defstruct! From 87e8e77e5fd8d84a252dbb6d6697202118378774 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma <thepsguy@icloud.com> Date: Mon, 5 Oct 2015 00:13:54 +0530 Subject: [PATCH 46/55] Fixed a mistake from previous commit. Better explained reference address. --- c++.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c++.html.markdown b/c++.html.markdown index bbd2f9a9..bd86e9e5 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -245,9 +245,9 @@ cout << fooRef; // Prints "I am foo. Hi!" // Doesn't reassign "fooRef". This is the same as "foo = bar", and // foo == "I am bar" // after this line. -cout << &fooRef << endl; //Prints address of fooRef +cout << &fooRef << endl; //Prints address of foo fooRef = bar; -cout << &fooRef << endl; //Prints address of fooRef, AGAIN +cout << &fooRef << endl; //Still prints address of foo cout << fooRef; // Prints "I am bar" //The address of fooRef remains the same, i.e. it is still referring to foo. From f72588075d0cd200d53893ad51129844df17aea7 Mon Sep 17 00:00:00 2001 From: ozgur sahin <ozgursahin555@gmail.com> Date: Sun, 4 Oct 2015 22:01:10 +0300 Subject: [PATCH 47/55] swift-tr.html.markdown Translated some English sentences. --- tr-tr/swift-tr.html.markdown | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tr-tr/swift-tr.html.markdown b/tr-tr/swift-tr.html.markdown index 41835e13..c13f5ecf 100644 --- a/tr-tr/swift-tr.html.markdown +++ b/tr-tr/swift-tr.html.markdown @@ -3,16 +3,14 @@ language: swift contributors: - ["Özgür Şahin", "https://github.com/ozgurshn/"] filename: learnswift.swift +lang: tr-tr --- Swift iOS ve OSX platformlarında geliştirme yapmak için Apple tarafından oluşturulan yeni bir programlama dilidir. Objective - C ile beraber kullanılabilecek ve de hatalı kodlara karşı daha esnek bir yapı sunacak bir şekilde tasarlanmıştır. Swift 2014 yılında Apple'ın geliştirici konferansı WWDC de tanıtıldı. Xcode 6+'a dahil edilen LLVM derleyici ile geliştirildi. - -The official [Swift Programming Language](https://itunes.apple.com/us/book/swift-programming-language/id881256329) book from Apple is now available via iBooks. + Apple'ın resmi [Swift Programlama Dili](https://itunes.apple.com/us/book/swift-programming-language/id881256329) kitabı iBooks'ta yerini aldı. -See also Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/RoadMapiOS/index.html), which has a complete tutorial on Swift. - Ayrıca Swift ile gelen tüm özellikleri görmek için Apple'ın [başlangıç kılavuzu](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/RoadMapiOS/index.html)na bakmanızda yarar var. @@ -243,7 +241,7 @@ print("Benzin fiyatı: \(fiyat)") // Çeşitli Argümanlar func ayarla(sayilar: Int...) { - // its an array + // bu bir dizidir let sayi = sayilar[0] let argumanSAyisi = sayilar.count } From 3b246fd869564b0a7f7c847f44aecac82d318c78 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma <thepsguy@icloud.com> Date: Mon, 5 Oct 2015 00:32:34 +0530 Subject: [PATCH 48/55] Grammar the address --- c++.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c++.html.markdown b/c++.html.markdown index bd86e9e5..8ee964ca 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -245,9 +245,9 @@ cout << fooRef; // Prints "I am foo. Hi!" // Doesn't reassign "fooRef". This is the same as "foo = bar", and // foo == "I am bar" // after this line. -cout << &fooRef << endl; //Prints address of foo +cout << &fooRef << endl; //Prints the address of foo fooRef = bar; -cout << &fooRef << endl; //Still prints address of foo +cout << &fooRef << endl; //Still prints the address of foo cout << fooRef; // Prints "I am bar" //The address of fooRef remains the same, i.e. it is still referring to foo. From 68fc9b5c1f71adcbbbd53711e9a5692a8372b8cf Mon Sep 17 00:00:00 2001 From: Pushkar Sharma <thepsguy@icloud.com> Date: Mon, 5 Oct 2015 00:35:49 +0530 Subject: [PATCH 49/55] fixed the comment format --- common-lisp.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-lisp.html.markdown b/common-lisp.html.markdown index e3bb61cf..e0597e94 100644 --- a/common-lisp.html.markdown +++ b/common-lisp.html.markdown @@ -176,7 +176,7 @@ nil ; for false - and the empty list *rover* ; => #S(DOG :NAME "rover" :BREED "collie" :AGE 5) (dog-p *rover*) ; => true #| -p signifies "predicate". It's used to - check if *rover* is an instance of dog.|# + check if *rover* is an instance of dog. |# (dog-name *rover*) ; => "rover" ;; Dog-p, make-dog, and dog-name are all created by defstruct! From 1194e9456f2f1302614f8086349c01f4797d34c0 Mon Sep 17 00:00:00 2001 From: willianjusten <willianjustenqui@gmail.com> Date: Sun, 4 Oct 2015 16:13:11 -0300 Subject: [PATCH 50/55] Fixing some typos --- pt-br/javascript-pt.html.markdown | 45 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/pt-br/javascript-pt.html.markdown b/pt-br/javascript-pt.html.markdown index e39c6c8e..406042fa 100644 --- a/pt-br/javascript-pt.html.markdown +++ b/pt-br/javascript-pt.html.markdown @@ -3,20 +3,21 @@ language: javascript contributors: - ["Adam Brenecki", "http://adam.brenecki.id.au"] - ["Ariel Krakowski", "http://www.learneroo.com"] -filename: javascript.js +translators: + - ["Willian Justen", "http://willianjusten.com.br"] +lang: pt-br --- -JavaScript foi criada por Brendan Eich, funcionário da Netscape, em 1995. Ela +JavaScript foi criada por Brendan Eich, funcionário da Netscape na época, em 1995. Ela foi originalmente criada para ser uma linguagem de script para websites, complementando o uso de Java para aplicações web mais complexas, mas a sua integração com páginas web e seu suporte nativo nos browsers fez com que ela se tornasse mais comum que Java no frontend web. -Javascript não é somente limitado a browsers web, no entanto: existe o Node.js, +Javascript não é somente limitada a browsers web, existindo o Node.js, que é um projeto que fornece um interpretador baseado no motor V8 do Google Chrome e está se tornando cada vez mais famoso. - Feedback são muito apreciados! Você me encontrar em [@adambrenecki](https://twitter.com/adambrenecki), ou [adam@brenecki.id.au](mailto:adam@brenecki.id.au). @@ -29,23 +30,23 @@ Feedback são muito apreciados! Você me encontrar em // comandos podem ser terminados com ; facaAlgo(); -// ... mas eles não precisam ser, assim como o ponto-e-vírgula é automaticamente +// ... mas eles não precisam ser, o ponto-e-vírgula é automaticamente // inserido quando há uma nova linha, exceto alguns casos. facaAlgo() -// Porque esses casos podem causar resultados inesperados, vamos continuar +// Como esses casos podem causar resultados inesperados, vamos continuar // a usar ponto-e-vírgula neste guia. /////////////////////////////////// // 1. Números, Strings e Operadores // Javascript tem um tipo de número (que é o 64-bit IEEE 754 double). -// Doublas tem uma mantissa 52-bit, que é suficiente para guardar inteiros +// Doubles tem uma mantissa 52-bit, que é suficiente para guardar inteiros // acima de 9✕10¹⁵ precisamente. 3; // = 3 1.5; // = 1.5 -// A aritmética básica funciona seria de esperar. +// A aritmética básica funciona como seria de se esperar. 1 + 1; // = 2 0.1 + 0.2; // = 0.30000000000000004 8 - 1; // = 7 @@ -62,7 +63,6 @@ facaAlgo() // A precedência é aplicada com parênteses. (1 + 3) * 2; // = 8 -// There are three special not-a-real-number values: // Existem três especiais valores não-é-número-real: Infinity; // resultado de 1/0 -Infinity; // resultado de -1/0 @@ -76,16 +76,15 @@ false; 'abc'; "Olá, mundo"; -// Negation uses the ! symbol // Negação usa o símbolo ! !true; // = false !false; // = true -// Igualdade é === +// Igualdade é o sinal de === 1 === 1; // = true 2 === 1; // = false -// Desigualdade é !== +// Desigualdade é o sinal de !== 1 !== 1; // = false 2 !== 1; // = true @@ -101,7 +100,7 @@ false; // e comparadas com < e > "a" < "b"; // = true -// A coerção de tipos é feita para comparações com dois iguais... +// A comparação de tipos não é feita com o uso de ==... "5" == 5; // = true null == undefined; // = true @@ -109,7 +108,7 @@ null == undefined; // = true "5" === 5; // = false null === undefined; // = false -// ...que irá resultar num comportamento estranho... +// ...isso pode resultar em comportamentos estranhos... 13 + !0; // 14 "13" + !0; // '13true' @@ -125,21 +124,21 @@ null === undefined; // = false // Existe também o `null` e o `undefined`. null; // usado para indicar um valor não considerado undefined; // usado para indicar um valor que não é a atualmente definido - // (entretando `undefined` é usado como um próprio valor + // (entretando `undefined` é considerado de fato um valor -// false, null, undefined, NaN, 0 and "" são valores falsy; -// qualquer outro valor é truthy -// Note que 0 é falsy e "0" é truthy, até mesmo 0 == "0". +// false, null, undefined, NaN, 0 and "" são valores falsos; +// qualquer outro valor é verdadeiro +// Note que 0 é falso e "0" é verdadeiro, até mesmo 0 == "0". /////////////////////////////////// // 2. Variáveis, Arrays e Objetos -// Variáveis são declarados com a palavra-chave `var`. O Javascript é +// Variáveis são declaradas com a palavra-chave `var`. O Javascript é // dinâmicamente tipado, portanto você não precisa especificar o tipo. // Atribuições usam um simples caracter de `=`. var someVar = 5; -// se você deixar de colocar a palavra-chave var, você não receber um erro... +// se você deixar de colocar a palavra-chave var, você não irá receber um erro... someOtherVar = 10; // ...mas sua variável será criada no escopo global, não no escopo em que você @@ -148,13 +147,13 @@ someOtherVar = 10; // Variáveis declaradas sem receberem um valor são definidas como `undefined`. var someThirdVar; // = undefined -// Existe um shorthad para operações matemáticas em variáveis: +// Existe um shorthand para operações matemáticas em variáveis: someVar += 5; // equivalente a someVar = someVar + 5; someVar é 10 agora someVar *= 10; // agora someVar é 100 // e um para adição e subtração de 1 -someVar++; // now someVar is 101 -someVar--; // back to 100 +someVar++; // agora someVar é 101 +someVar--; // volta para 100 // Arrays são listas ordenadas de valores, de qualquer tipo. var myArray = ["Olá", 45, true]; From 2e987df42225e6bdf824584058467aaffc73fb49 Mon Sep 17 00:00:00 2001 From: Pushkar Sharma <thepsguy@icloud.com> Date: Mon, 5 Oct 2015 00:52:47 +0530 Subject: [PATCH 51/55] replaced scanf with fscanf. --- c.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c.html.markdown b/c.html.markdown index 36621a9e..db2ac930 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -131,7 +131,7 @@ int main(void) { // time constant: printf("Enter the array size: "); // ask the user for an array size int size; - scanf("%d", &size); + fscanf(stdin, "%d", &size); char buf[size]; fgets(buf, sizeof buf, stdin); From d2fde6512424b754e0d45ac484d86472a99da3ef Mon Sep 17 00:00:00 2001 From: David Lima <dave@blogdodave.com.br> Date: Sun, 4 Oct 2015 16:30:42 -0300 Subject: [PATCH 52/55] Including '-pt' suffix on filename --- pt-br/hack-pt.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pt-br/hack-pt.html.markdown b/pt-br/hack-pt.html.markdown index 2f9d3c1b..7c938149 100644 --- a/pt-br/hack-pt.html.markdown +++ b/pt-br/hack-pt.html.markdown @@ -6,7 +6,7 @@ contributors: translators: - ["David Lima", "https://github.com/davelima"] lang: pt-br -filename: learnhack.hh +filename: learnhack-pt.hh --- Hack é uma linguagem baseada no PHP e roda numa máquina virtual chamada HHVM. From b1984042c845a73333972715e88a3d7a2e8cfdd7 Mon Sep 17 00:00:00 2001 From: Guntbert Reiter <guntbert@gmx.at> Date: Sun, 4 Oct 2015 16:44:24 +0200 Subject: [PATCH 53/55] Put demonstrative condition into ternary expression It should be made clear that the part before the ternary operator is indeed a condition, most often created as some comparison expression. --- de-de/csharp-de.html.markdown | 5 +++-- fr-fr/csharp-fr.html.markdown | 3 ++- tr-tr/csharp-tr.html.markdown | 3 ++- zh-cn/csharp-cn.html.markdown | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/de-de/csharp-de.html.markdown b/de-de/csharp-de.html.markdown index dc77dda0..8ad7d71f 100644 --- a/de-de/csharp-de.html.markdown +++ b/de-de/csharp-de.html.markdown @@ -248,7 +248,8 @@ zur nächsten Zeile, ""Wahnsinn!"", die Massen waren kaum zu bändigen"; // Ternärer Operator // Anstatt eines einfachen if/else lässt sich auch folgendes schreiben: // <condition> ? <true> : <false> - string isTrue = true ? "Ja" : "Nein"; + int zumVergleich = 17; + string isTrue = zumVergleich == 17 ? "Ja" : "Nein"; // while-Schleife int fooWhile = 0; @@ -886,4 +887,4 @@ zur nächsten Zeile, ""Wahnsinn!"", die Massen waren kaum zu bändigen"; * [ASP.NET Web Forms Tutorials](http://www.asp.net/web-forms/tutorials) * [Windows Forms Programming in C#](http://www.amazon.com/Windows-Forms-Programming-Chris-Sells/dp/0321116208) -[C# Coding Conventions](http://msdn.microsoft.com/de-de/library/vstudio/ff926074.aspx) \ No newline at end of file +[C# Coding Conventions](http://msdn.microsoft.com/de-de/library/vstudio/ff926074.aspx) diff --git a/fr-fr/csharp-fr.html.markdown b/fr-fr/csharp-fr.html.markdown index e51eacc8..58b3f386 100644 --- a/fr-fr/csharp-fr.html.markdown +++ b/fr-fr/csharp-fr.html.markdown @@ -239,7 +239,8 @@ sur une nouvelle ligne! ""Wow!"", quel style"; // Opérateur ternaire // Un simple if/else peut s'écrire : // <condition> ? <valeur si true> : <valeur si false> - string isTrue = (true) ? "True" : "False"; + int toCompare = 17; + string isTrue = toCompare == 17 ? "True" : "False"; // Boucle while int fooWhile = 0; diff --git a/tr-tr/csharp-tr.html.markdown b/tr-tr/csharp-tr.html.markdown index a68026a5..91c7c269 100644 --- a/tr-tr/csharp-tr.html.markdown +++ b/tr-tr/csharp-tr.html.markdown @@ -234,7 +234,8 @@ on a new line! ""Wow!"", the masses cried"; // Üçlü operatörler // Basit bir if/else ifadesi şöyle yazılabilir // <koşul> ? <true> : <false> - string isTrue = (true) ? "True" : "False"; + int toCompare = 17; + string isTrue = toCompare == 17 ? "True" : "False"; // While döngüsü int fooWhile = 0; diff --git a/zh-cn/csharp-cn.html.markdown b/zh-cn/csharp-cn.html.markdown index a3cda5b3..971c1be9 100644 --- a/zh-cn/csharp-cn.html.markdown +++ b/zh-cn/csharp-cn.html.markdown @@ -232,7 +232,8 @@ on a new line! ""Wow!"", the masses cried"; // 三元表达式 // 简单的 if/else 语句可以写成: // <条件> ? <真> : <假> - string isTrue = (true) ? "True" : "False"; + int toCompare = 17; + string isTrue = toCompare == 17 ? "True" : "False"; // While 循环 int fooWhile = 0; From d8efd3ba3416669177683887b2822eb5d56c157b Mon Sep 17 00:00:00 2001 From: bk2dcradle <ankitsultana@gmail.com> Date: Mon, 5 Oct 2015 01:38:02 +0530 Subject: [PATCH 54/55] Modified as said to by a Collaborator --- java.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 2f41be81..89a710ee 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -477,9 +477,9 @@ public abstract class Animal age = 30; } - // No need to initialise, however in an interface + // No need to initialize, however in an interface // a variable is implicitly final and hence has - // to be initialised. + // to be initialized. private int age; public void printAge() @@ -509,7 +509,7 @@ class Dog extends Animal // @Override annotation here, since java doesn't allow // overriding of static methods. // What is happening here is called METHOD HIDING. - // Check out this awesome SO post: (http://stackoverflow.com/questions/16313649/) + // Check out this awesome SO post: http://stackoverflow.com/questions/16313649/ public static void main(String[] args) { Dog pluto = new Dog(); From e7a50adb78d4babdf77039ee58c59f5bc7d241c4 Mon Sep 17 00:00:00 2001 From: ven <vendethiel@hotmail.fr> Date: Sun, 4 Oct 2015 22:44:34 +0200 Subject: [PATCH 55/55] Fix #1289 --- id-id/xml-id.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/id-id/xml-id.html.markdown b/id-id/xml-id.html.markdown index 8e8cdf4e..c1e985aa 100644 --- a/id-id/xml-id.html.markdown +++ b/id-id/xml-id.html.markdown @@ -5,6 +5,7 @@ contributors: - ["João Farias", "https://github.com/JoaoGFarias"] translators: - ["Rizky Luthfianto", "https://github.com/rilut"] +lang: id-id --- XML adalah bahasa markup yang dirancang untuk menyimpan dan mengirim data.