From 29cbff176857653422555650c983afef4a28ae1f Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Tue, 6 Oct 2015 18:16:33 -0400 Subject: [java/en] Edits and additions Included an example of printf Discussed final variable initialization Gave a floating point division example Discussed boolean operators Defined the abstract and final class and compared them. Added some clarifying remarks to comments. --- java.html.markdown | 90 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 19 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 928eb39f..5e580f33 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Jakukyo Friel", "http://weakish.github.io"] - ["Madison Dickson", "http://github.com/mix3d"] - ["Simon Morgan", "http://sjm.io/"] + - ["Zachary Ferguson", "http://github.com/zfergus2"] filename: LearnJava.java --- @@ -31,7 +32,7 @@ import java.security.*; // the file. public class LearnJava { - // A program must have a main method as an entry point. + // In order to run a java program, it must have a main method as an entry point. public static void main (String[] args) { // Use System.out.println() to print lines. @@ -45,6 +46,8 @@ public class LearnJava { System.out.print("Hello "); System.out.print("World"); + // Use System.out.printf() for easy formatted printing. + System.out.printf("pi = %.5f", Math.PI); // => pi = 3.14159 /////////////////////////////////////// // Types & Variables @@ -73,7 +76,7 @@ public class LearnJava { // Float - Single-precision 32-bit IEEE 754 Floating Point float fooFloat = 234.5f; - // f is used to denote that this variable value is of type float; + // f or F is used to denote that this variable value is of type float; // otherwise it is treated as double. // Double - Double-precision 64-bit IEEE 754 Floating Point @@ -86,9 +89,12 @@ public class LearnJava { // Char - A single 16-bit Unicode character char fooChar = 'A'; - // final variables can't be reassigned to another object. + // final variables can't be reassigned to another object, final int HOURS_I_WORK_PER_WEEK = 9001; - + // but they can be initialized later. + final double E; + E = 2.71828; + // Strings String fooString = "My String Is Here!"; @@ -146,6 +152,7 @@ public class LearnJava { System.out.println("2-1 = " + (i2 - i1)); // => 1 System.out.println("2*1 = " + (i2 * i1)); // => 2 System.out.println("1/2 = " + (i1 / i2)); // => 0 (0.5 truncated down) + System.out.println("1/2 = " + (i1 / (i2*1.0))); // => 0.5 // Modulo System.out.println("11%3 = "+(11 % 3)); // => 2 @@ -158,12 +165,17 @@ public class LearnJava { System.out.println("2 <= 2? " + (2 <= 2)); // => true System.out.println("2 >= 2? " + (2 >= 2)); // => true + // Boolean operators + System.out.println("3 > 2 && 2 > 3? " + ((3 > 2) && (2 > 3))); // => false + System.out.println("3 > 2 || 2 > 3? " + ((3 > 2) || (2 > 3))); // => true + System.out.println("!(3 == 2)? " + (!(3 == 2))); // => true + // Bitwise operators! /* ~ Unary bitwise complement << Signed left shift - >> Signed right shift - >>> Unsigned right shift + >> Signed/Arithmetic right shift + >>> Unsigned/Logical right shift & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR @@ -216,9 +228,8 @@ public class LearnJava { System.out.println("fooDoWhile Value: " + fooDoWhile); // For Loop - int fooFor; // for loop structure => for(; ; ) - for (fooFor = 0; fooFor < 10; fooFor++) { + for (int fooFor = 0; fooFor < 10; fooFor++) { System.out.println(fooFor); // Iterated 10 times, fooFor 0->9 } @@ -310,7 +321,8 @@ public class LearnJava { } // End LearnJava class -// You can include other, non-public outer-level classes in a .java file +// You can include other, non-public outer-level classes in a .java file, +// but it is good practice. Instead split classes into separate files. // Class Declaration Syntax: @@ -330,6 +342,8 @@ class Bicycle { // Constructors are a way of creating classes // This is a constructor public Bicycle() { + // You can also call another constructor: + // this(1, 50, 5, "Bontrager"); gear = 1; cadence = 50; speed = 5; @@ -351,7 +365,7 @@ class Bicycle { // Java classes often implement getters and setters for their fields // Method declaration syntax: - // () + // () public int getCadence() { return cadence; } @@ -382,7 +396,7 @@ class Bicycle { } //Method to display the attribute values of this Object. - @Override + @Override // Inherited from the Object class. public String toString() { return "gear: " + gear + " cadence: " + cadence + " speed: " + speed + " name: " + name; @@ -417,26 +431,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 @@ -451,6 +465,44 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, public void InterfaceTwoMethod() { } } + +// There are also two special types of classes, abstract and final. + +// Marking a class as abstract means that it contains abstract methods that must +// be defined in a child class. Similar to interfaces, abstract classes cannot +// be instantiated, but instead must be extended and the abstract methods +// defined. Different from interfaces, abstract classes can contain a mixture of +// concrete and abstract methods. +public abstract class Mammal() +{ + // Abstract classes can contain concrete methods. + public boolean hasHair() + { + return true; + } + + // Final methods, like, final classes cannot be overridden by a child class. + public final boolean isWarmBlooded() + { + return true; + } + + // Abstract methods are methods required to be overridden in a child class. + public abstract String getBinomialNomenclature(); +} + +// Final classes are classes that cannot be inherited from and are therefore a +// final child. In a way, final classes are the opposite of abstract classes +// because abstract classes must be extended, but final classes cannot be +// extended. +public final class SaberToothedCat extends Mammal +{ + public String getBinomialNomenclature() + { + return "Smilodon fatalis"; + } +} + ``` ## Further Reading -- cgit v1.2.3 From 93d7d801d8cd40417d88e67a248dd232d75cdd34 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Tue, 6 Oct 2015 18:28:57 -0400 Subject: [java/en] Merged definitions of abstract and added final Merged definitions of abstract and added a definition of final classes. --- java.html.markdown | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 34da903a..39878c8f 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -513,14 +513,9 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, } } -<<<<<<< HEAD // There are also two special types of classes, abstract and final. -// Marking a class as abstract means that it contains abstract methods that must -// be defined in a child class. Similar to interfaces, abstract classes cannot -// be instantiated, but instead must be extended and the abstract methods -// defined. Different from interfaces, abstract classes can contain a mixture of -// concrete and abstract methods. + public abstract class Mammal() { // Abstract classes can contain concrete methods. @@ -539,17 +534,6 @@ public abstract class Mammal() public abstract String getBinomialNomenclature(); } -// Final classes are classes that cannot be inherited from and are therefore a -// final child. In a way, final classes are the opposite of abstract classes -// because abstract classes must be extended, but final classes cannot be -// extended. -public final class SaberToothedCat extends Mammal -{ - public String getBinomialNomenclature() - { - return "Smilodon fatalis"; - } -======= // Abstract Classes // Abstract Class declaration syntax @@ -558,10 +542,13 @@ public final class SaberToothedCat extends Mammal // // 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. +// Marking a class as abstract means that it contains abstract methods that must +// be defined in a child class. Similar to interfaces, abstract classes cannot +// be instantiated, but instead must be extended and the abstract methods +// defined. Different from interfaces, abstract classes can contain a mixture of +// concrete and abstract methods. Methods in an interface cannot have a body, +// unless the method is static, and variables are final by default, unlike an +// abstract class. Also abstract classes CAN have the "main" method. public abstract class Animal { @@ -578,7 +565,7 @@ public abstract class Animal // No need to initialize, however in an interface // a variable is implicitly final and hence has // to be initialized. - private int age; + protected int age; public void printAge() { @@ -615,7 +602,28 @@ class Dog extends Animal pluto.eat(); pluto.printAge(); } ->>>>>>> adambard/master +} + +// Final Classes +// Final Class declaration syntax +// final { +// // Constants and variables +// // Method declarations +// } + +// Final classes are classes that cannot be inherited from and are therefore a +// final child. In a way, final classes are the opposite of abstract classes +// because abstract classes must be extended, but final classes cannot be +// extended. +public final class SaberToothedCat extends Animal +{ + // Note still have to override the abstract methods in the + // abstract class. + @Override + public void makeSound() + { + System.out.println("Roar"); + } } ``` -- cgit v1.2.3 From 01685afb8429f1b9756e97d6116ab7cbf24ce6c0 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Tue, 6 Oct 2015 18:31:11 -0400 Subject: [java/en] removed excess abstract class removed excess abstract class --- java.html.markdown | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 39878c8f..6bfa6633 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -513,28 +513,6 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, } } -// There are also two special types of classes, abstract and final. - - -public abstract class Mammal() -{ - // Abstract classes can contain concrete methods. - public boolean hasHair() - { - return true; - } - - // Final methods, like, final classes cannot be overridden by a child class. - public final boolean isWarmBlooded() - { - return true; - } - - // Abstract methods are methods required to be overridden in a child class. - public abstract String getBinomialNomenclature(); -} - - // Abstract Classes // Abstract Class declaration syntax // abstract extends { -- cgit v1.2.3 From 420e04a5909ae309683201c9fb272ed3dc142283 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Tue, 6 Oct 2015 19:07:24 -0400 Subject: [java/en] Final Methods Explained Final Methods --- java.html.markdown | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/java.html.markdown b/java.html.markdown index 6bfa6633..9ab257a4 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -406,7 +406,7 @@ class Bicycle { this.name = name; } - // Function Syntax: + // Method Syntax: // () // Java classes often implement getters and setters for their fields @@ -604,6 +604,19 @@ public final class SaberToothedCat extends Animal } } +// Final Methods +public abstract class Mammal() +{ + // Final Method Syntax: + // final () + + // Final methods, like, final classes cannot be overridden by a child class, + // and are therefore the final implementation of the method. + public final boolean isWarmBlooded() + { + return true; + } +} ``` ## Further Reading -- cgit v1.2.3 From cea7db46eb1365c42d2e56a84af0ee2e3a750569 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Tue, 6 Oct 2015 19:09:13 -0400 Subject: [java/en] Fixed Whitespace Converted tabs to 4 spaces for consistency. --- java.html.markdown | 126 ++++++++++++++++++++++++++--------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 9ab257a4..5c230501 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -343,9 +343,9 @@ public class LearnJava { private static final Set COUNTRIES = new HashSet(); static { - validCodes.add("DENMARK"); - validCodes.add("SWEDEN"); - validCodes.add("FINLAND"); + validCodes.add("DENMARK"); + validCodes.add("SWEDEN"); + validCodes.add("FINLAND"); } // But there's a nifty way to achive the same thing in an @@ -505,12 +505,12 @@ 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() { + } } // Abstract Classes @@ -530,56 +530,56 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, 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 initialize, however in an interface - // a variable is implicitly final and hence has - // to be initialized. - protected 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"); - } + 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 initialize, however in an interface + // a variable is implicitly final and hence has + // to be initialized. + protected 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(); - } + // 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(); + } } // Final Classes @@ -595,23 +595,23 @@ class Dog extends Animal // extended. public final class SaberToothedCat extends Animal { - // Note still have to override the abstract methods in the - // abstract class. - @Override - public void makeSound() - { - System.out.println("Roar"); - } + // Note still have to override the abstract methods in the + // abstract class. + @Override + public void makeSound() + { + System.out.println("Roar"); + } } // Final Methods public abstract class Mammal() { - // Final Method Syntax: + // Final Method Syntax: // final () - + // Final methods, like, final classes cannot be overridden by a child class, - // and are therefore the final implementation of the method. + // and are therefore the final implementation of the method. public final boolean isWarmBlooded() { return true; -- cgit v1.2.3 From fe525731183779ef5b76cc714c47bd9033953e46 Mon Sep 17 00:00:00 2001 From: Raphael Nascimento Date: Tue, 6 Oct 2015 20:51:47 -0300 Subject: Update javascript.html.markdown For/In loop JavaScript --- javascript.html.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/javascript.html.markdown b/javascript.html.markdown index ba2e8ce4..3308b08d 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -218,6 +218,13 @@ for (var i = 0; i < 5; i++){ // will run 5 times } +//The For/In statement loops through the properties of an object: +var description = ""; +var person = {fname:"Paul", lname:"Ken", age:18}; +for (var x in person) { + description += person[x] + " "; +} + // && is logical and, || is logical or if (house.size == "big" && house.colour == "blue"){ house.contains = "bear"; -- cgit v1.2.3 From f165e721cedf80edf560304b7d83b0687045f8b1 Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Tue, 6 Oct 2015 20:55:51 -0400 Subject: Update ruby.html.markdown --- ruby.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ruby.html.markdown b/ruby.html.markdown index 8f23b2e6..3e85a038 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -106,8 +106,14 @@ placeholder = 'use string interpolation' 'hello ' + 3 #=> TypeError: can't convert Fixnum into String 'hello ' + 3.to_s #=> "hello 3" -# print to the output +# print to the output with a newline at the end puts "I'm printing!" +#=> I'm printing! +#=> nil + +# print to the output without a newline +print "I'm printing!" +#=> I'm printing! => nill # Variables x = 25 #=> 25 -- cgit v1.2.3 From d73584cc9a7eefbcede32d64fa0fc6177e1640bf Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Tue, 6 Oct 2015 21:06:44 -0400 Subject: Add information about mapping arrays --- ruby.html.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ruby.html.markdown b/ruby.html.markdown index 8f23b2e6..cf6bf2ce 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -269,6 +269,19 @@ end #=> iteration 4 #=> iteration 5 +# There are a bunch of other helpful looping functions in Ruby, +# for example "map", "reduce", "inject", the list goes on. Map, +# for instance, takes the array it's looping over, does something +# to it as defined in your block, and returns an entirely new array. +array = [1,2,3,4,5] +doubled = array.map do |element| + element * 2 +end +puts doubled +#=> [2,4,6,8,10] +puts array +#=> [1,2,3,4,5] + grade = 'B' case grade -- cgit v1.2.3 From f30200b31c60f082cf4f192245a4a2c058f76fa4 Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Tue, 6 Oct 2015 21:22:09 -0400 Subject: Add examples to show how printing works --- scala.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scala.html.markdown b/scala.html.markdown index c482752d..7189be10 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -43,9 +43,13 @@ Scala - the scalable language // Printing, and forcing a new line on the next print println("Hello world!") println(10) +// Hello world! +// 10 // Printing, without forcing a new line on next print print("Hello world") +print(10) +// Hello world!10 // Declaring values is done using either var or val. // val declarations are immutable, whereas vars are mutable. Immutability is -- cgit v1.2.3 From 7afadb01811e1fb97a928a0e2d8b1a3b7a3a42f6 Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Tue, 6 Oct 2015 21:31:07 -0400 Subject: Fix indentation to make compiled JS more readable --- coffeescript.html.markdown | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown index 4c080bc6..a198f40d 100644 --- a/coffeescript.html.markdown +++ b/coffeescript.html.markdown @@ -54,19 +54,19 @@ math = square: square cube: (x) -> x * square x #=> var math = { -# "root": Math.sqrt, -# "square": square, -# "cube": function(x) { return x * square(x); } -#} +# "root": Math.sqrt, +# "square": square, +# "cube": function(x) { return x * square(x); } +# }; # Splats: race = (winner, runners...) -> print winner, runners #=>race = function() { -# var runners, winner; -# winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : []; -# return print(winner, runners); -#}; +# var runners, winner; +# winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : []; +# return print(winner, runners); +# }; # Existence: alert "I knew it!" if elvis? @@ -75,14 +75,14 @@ alert "I knew it!" if elvis? # Array comprehensions: cubes = (math.cube num for num in list) #=>cubes = (function() { -# var _i, _len, _results; -# _results = []; +# var _i, _len, _results; +# _results = []; # for (_i = 0, _len = list.length; _i < _len; _i++) { -# num = list[_i]; -# _results.push(math.cube(num)); -# } -# return _results; -# })(); +# num = list[_i]; +# _results.push(math.cube(num)); +# } +# return _results; +# })(); foods = ['broccoli', 'spinach', 'chocolate'] eat food for food in foods when food isnt 'chocolate' -- cgit v1.2.3 From f1711ddd4c98633f059558b8d13e2532afbb5ba7 Mon Sep 17 00:00:00 2001 From: Raphael Nascimento Date: Tue, 6 Oct 2015 23:44:30 -0300 Subject: [javascript/en] Added for/in loop JavaScript more explanation about for/in java script. --- javascript.html.markdown | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/javascript.html.markdown b/javascript.html.markdown index 3308b08d..f7a662a4 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -218,13 +218,26 @@ for (var i = 0; i < 5; i++){ // will run 5 times } -//The For/In statement loops through the properties of an object: +//The For/In statement loops iterates over every property across the entire prototype chain var description = ""; var person = {fname:"Paul", lname:"Ken", age:18}; for (var x in person) { description += person[x] + " "; } +//If only want to consider properties attached to the object itself, +//and not its prototypes use hasOwnProperty() check +var description = ""; +var person = {fname:"Paul", lname:"Ken", age:18}; +for (var x in person) { + if( person.hasOwnProperty( x ) ) { + description += person[x] + " "; + } +} + +//for/in should not be used to iterate over an Array where the index order is important. +//There is no guarantee that for/in will return the indexes in any particular order + // && is logical and, || is logical or if (house.size == "big" && house.colour == "blue"){ house.contains = "bear"; -- cgit v1.2.3 From 5dac348b72000dedc2e8a35f1ccaea55a7f408f7 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Tue, 6 Oct 2015 23:00:11 -0400 Subject: Forgot to add myself as a contributor from swift-1 pull request. --- swift.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/swift.html.markdown b/swift.html.markdown index 509c9d2f..23ebcfc5 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Christopher Bess", "http://github.com/cbess"] - ["Joey Huang", "http://github.com/kamidox"] - ["Anthony Nguyen", "http://github.com/anthonyn60"] + - ["Clayton Walker", "https://github.com/cwalk"] filename: learnswift.swift --- -- cgit v1.2.3 From ad16a31c0751f244a46cadbfb3540943af73349d Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Tue, 6 Oct 2015 23:36:32 -0400 Subject: Added clearer description of Optionals and Unwrapping. Minor typo changes as well. --- swift.html.markdown | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/swift.html.markdown b/swift.html.markdown index 23ebcfc5..46e5e6d4 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -58,8 +58,9 @@ let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation print("Build value: \(buildValue)") // Build value: 7 /* - Optionals are a Swift language feature that allows you to store a `Some` or - `None` value. + Optionals are a Swift language feature that either contains a value, + or contains nil (no value) to indicate that a value is missing. + A question mark (?) after the type marks the value as optional. Because Swift requires every property to have a value, even nil must be explicitly stored as an Optional value. @@ -75,11 +76,17 @@ if someOptionalString != nil { if someOptionalString!.hasPrefix("opt") { print("has the prefix") } - + let empty = someOptionalString?.isEmpty } someOptionalString = nil +/* + To get the underlying type from an optional, you unwrap it using the + force unwrap operator (!). Only use the unwrap operator if you're sure + the underlying value isn't nil. +*/ + // implicitly unwrapped optional var unwrappedString: String! = "Value is expected." // same as above, but ! is a postfix operator (more syntax candy) @@ -94,13 +101,13 @@ if let someOptionalStringConstant = someOptionalString { // Swift has support for storing a value of any type. // AnyObject == id -// Unlike Objective-C `id`, AnyObject works with any value (Class, Int, struct, etc) +// Unlike Objective-C `id`, AnyObject works with any value (Class, Int, struct, etc.) var anyObjectVar: AnyObject = 7 anyObjectVar = "Changed value to a string, not good practice, but possible." /* Comment here - + /* Nested comments are also supported */ @@ -296,10 +303,10 @@ print(numbers) // [3, 6, 18] // MARK: Structures // -// Structures and classes have very similar capabilites +// Structures and classes have very similar capabilities struct NamesTable { let names = [String]() - + // Custom subscript subscript(index: Int) -> String { return names[index] @@ -330,7 +337,7 @@ public class Shape { internal class Rect: Shape { var sideLength: Int = 1 - + // Custom getter and setter property private var perimeter: Int { get { @@ -341,11 +348,11 @@ internal class Rect: Shape { sideLength = newValue / 4 } } - + // Lazily load a property // subShape remains nil (uninitialized) until getter called lazy var subShape = Rect(sideLength: 4) - + // If you don't need a custom getter and setter, // but still want to run code before and after getting or setting // a property, you can use `willSet` and `didSet` @@ -355,19 +362,19 @@ internal class Rect: Shape { print(someIdentifier) } } - + init(sideLength: Int) { self.sideLength = sideLength // always super.init last when init custom properties super.init() } - + func shrink() { if sideLength > 0 { --sideLength } } - + override func getArea() -> Int { return sideLength * sideLength } @@ -399,13 +406,13 @@ class Circle: Shape { override func getArea() -> Int { return 3 * radius * radius } - + // Place a question mark postfix after `init` is an optional init // which can return nil init?(radius: Int) { self.radius = radius super.init() - + if radius <= 0 { return nil } @@ -459,7 +466,7 @@ enum Furniture { case Desk(height: Int) // Associate with String and Int case Chair(String, Int) - + func description() -> String { switch self { case .Desk(let height): @@ -498,7 +505,7 @@ protocol ShapeGenerator { class MyShape: Rect { var delegate: TransformShape? - + func grow() { sideLength += 2 @@ -533,7 +540,7 @@ extension Int { var customProperty: String { return "This is \(self)" } - + func multiplyBy(num: Int) -> Int { return num * self } -- cgit v1.2.3 From 6a2fe434b837cbc52895511138b86287d738bc46 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Tue, 6 Oct 2015 23:56:55 -0400 Subject: Minor Typos, increased readability --- go.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/go.html.markdown b/go.html.markdown index 34b855e3..61ba9c42 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -10,6 +10,7 @@ contributors: - ["Quint Guvernator", "https://github.com/qguv"] - ["Jose Donizetti", "https://github.com/josedonizetti"] - ["Alexej Friesen", "https://github.com/heyalexej"] + - ["Clayton Walker", "https://github.com/cwalk"] --- Go was created out of the need to get work done. It's not the latest trend @@ -115,7 +116,7 @@ can include line breaks.` // Same string type. fmt.Println(s) // Updated slice is now [1 2 3 4 5 6] // To append another slice, instead of list of atomic elements we can // pass a reference to a slice or a slice literal like this, with a - // trailing elipsis, meaning take a slice and unpack its elements, + // trailing ellipsis, meaning take a slice and unpack its elements, // appending them to slice s. s = append(s, []int{7, 8, 9}...) // Second argument is a slice literal. fmt.Println(s) // Updated slice is now [1 2 3 4 5 6 7 8 9] @@ -129,7 +130,7 @@ can include line breaks.` // Same string type. m["one"] = 1 // Unused variables are an error in Go. - // The underbar lets you "use" a variable but discard its value. + // The underscore lets you "use" a variable but discard its value. _, _, _, _, _, _, _, _, _, _ = str, s2, g, f, u, pi, n, a3, s4, bs // Output of course counts as using a variable. fmt.Println(s, c, a4, s3, d2, m) @@ -164,7 +165,7 @@ func expensiveComputation() float64 { } func learnFlowControl() { - // If statements require brace brackets, and do not require parens. + // If statements require brace brackets, and do not require parentheses. if true { fmt.Println("told ya") } -- cgit v1.2.3 From 56ec0882a4e9c1e13dfbff20b4d15470c130c1f3 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 7 Oct 2015 00:07:00 -0400 Subject: Added more to further reading --- go.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.html.markdown b/go.html.markdown index 61ba9c42..f9821a0c 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -408,6 +408,8 @@ func requestServer() { The root of all things Go is the [official Go web site](http://golang.org/). There you can follow the tutorial, play interactively, and read lots. +Aside from a tour, [the docs](https://golang.org/doc/) contain how to write +clean and effective Go code, package and command docs, and release history. The language definition itself is highly recommended. It's easy to read and amazingly short (as language definitions go these days.) -- cgit v1.2.3 From 777423dcc519b2f25bbcf5238c12ee3a0d4c67c9 Mon Sep 17 00:00:00 2001 From: Cadel Watson Date: Wed, 7 Oct 2015 17:01:28 +1100 Subject: Add examples of higher-order functions taking multiple arguments --- python.html.markdown | 3 +++ python3.html.markdown | 3 +++ 2 files changed, 6 insertions(+) diff --git a/python.html.markdown b/python.html.markdown index 5572e38e..6cfb5dca 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -473,9 +473,12 @@ add_10(3) # => 13 # There are also anonymous functions (lambda x: x > 2)(3) # => True +(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5 # There are built-in higher order functions map(add_10, [1, 2, 3]) # => [11, 12, 13] +map(max, [1, 2, 3], [4, 2, 1]) # => [4, 2, 3] + filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7] # We can use list comprehensions for nice maps and filters diff --git a/python3.html.markdown b/python3.html.markdown index 971ca0a4..b8fa529c 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -550,10 +550,13 @@ add_10(3) # => 13 # There are also anonymous functions (lambda x: x > 2)(3) # => True +(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5 # TODO - Fix for iterables # There are built-in higher order functions map(add_10, [1, 2, 3]) # => [11, 12, 13] +map(max, [1, 2, 3], [4, 2, 1]) # => [4, 2, 3] + filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7] # We can use list comprehensions for nice maps and filters -- cgit v1.2.3 From 0904a24f30de1f0311aff17116c0c9e45a5f2772 Mon Sep 17 00:00:00 2001 From: Gayan Date: Wed, 7 Oct 2015 15:12:31 +0800 Subject: Adding exceptions and error handling --- php.html.markdown | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/php.html.markdown b/php.html.markdown index 93066284..80e689b7 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -693,7 +693,37 @@ use My\Namespace as SomeOtherNamespace; $cls = new SomeOtherNamespace\MyClass(); -*/ +// Simple error handling can be done with try catch block + +try { + // Do something +catch ( Exception $e) { + // Handle exception +} + +// When using try catch blocks in a namespaced enviroment use the following + +try { + // Do something +catch (\Exception $e) { + // Handle exception +} + +// Custom exceptions + +class MyException extends Exception {} + +try { + + $condition = true; + + if ($condition) { + throw new MyException('Something just happend'); + } + +} catch (MyException $e) { + // Handle my exception +} ``` @@ -709,4 +739,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). \ No newline at end of file +[PSR standards](https://github.com/php-fig/fig-standards). -- cgit v1.2.3 From a03b4003907e54da8c47c6aabe93c95f958b4f4d Mon Sep 17 00:00:00 2001 From: Gayan Date: Wed, 7 Oct 2015 15:13:17 +0800 Subject: Update php.html.markdown --- php.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php.html.markdown b/php.html.markdown index 80e689b7..2de0d3fa 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -697,7 +697,7 @@ $cls = new SomeOtherNamespace\MyClass(); try { // Do something -catch ( Exception $e) { +} catch ( Exception $e) { // Handle exception } @@ -705,7 +705,7 @@ catch ( Exception $e) { try { // Do something -catch (\Exception $e) { +} catch (\Exception $e) { // Handle exception } -- cgit v1.2.3 From ddb3c9eab5f12a0942c9aab61a679d58043a483b Mon Sep 17 00:00:00 2001 From: Gayan Date: Wed, 7 Oct 2015 16:01:09 +0800 Subject: Update php.html.markdown --- php.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/php.html.markdown b/php.html.markdown index 2de0d3fa..7c796652 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -693,6 +693,11 @@ use My\Namespace as SomeOtherNamespace; $cls = new SomeOtherNamespace\MyClass(); +/********************** +* Error Handling +* +*/ + // Simple error handling can be done with try catch block try { -- cgit v1.2.3 From 07c12337055746ad0958869d1bbed40a79e38b98 Mon Sep 17 00:00:00 2001 From: Iandenh Date: Wed, 7 Oct 2015 11:36:24 +0200 Subject: Fix dutch notation for large numbers The Dutch notation for large numbers is with a `.` instead of a `,` --- nl-nl/brainfuck-nl.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nl-nl/brainfuck-nl.html.markdown b/nl-nl/brainfuck-nl.html.markdown index cd12b1d0..6062b24c 100644 --- a/nl-nl/brainfuck-nl.html.markdown +++ b/nl-nl/brainfuck-nl.html.markdown @@ -15,7 +15,7 @@ minimalistische Turing-complete programmeertaal met maar acht commando's. ``` Elk karakter behalve "><+-.,[]" (en de quotes) wordt genegeerd. -Brainfuck wordt gerepresenteerd door een array met 30,000 cellen die initieel +Brainfuck wordt gerepresenteerd door een array met 30.000 cellen die initieel gevuld is met nullen en een pointer die wijst naar de huidige cel. Dit zijn de acht commando's: -- cgit v1.2.3 From 83a229e3f5f7932fa3e152793913799646661faf Mon Sep 17 00:00:00 2001 From: Aayush Ranaut Date: Wed, 7 Oct 2015 20:50:30 -0400 Subject: Fixes typos --- perl6.html.markdown | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/perl6.html.markdown b/perl6.html.markdown index 8d425f7d..3e9b3b25 100644 --- a/perl6.html.markdown +++ b/perl6.html.markdown @@ -7,11 +7,11 @@ contributors: - ["Nami-Doc", "http://github.com/Nami-Doc"] --- -Perl 6 is a highly capable, feature-rich programming language made for at +Perl 6 is a highly capable, feature-rich programming language made for at least the next hundred years. The primary Perl 6 compiler is called [Rakudo](http://rakudo.org), which runs on -the JVM and [the MoarVM](http://moarvm.com) and +the JVM and [the MoarVM](http://moarvm.com) and [prior to March 2015](http://pmthium.com/2015/02/suspending-rakudo-parrot/), [the Parrot VM](http://parrot.org/). @@ -132,7 +132,7 @@ sub with-named($normal-arg, :$named) { with-named(1, named => 6); #=> 7 # There's one gotcha to be aware of, here: # If you quote your key, Perl 6 won't be able to see it at compile time, -# and you'll have a single Pair object as a positional paramater, +# and you'll have a single Pair object as a positional parameter, # which means this fails: with-named(1, 'named' => 6); @@ -143,7 +143,7 @@ sub with-mandatory-named(:$str!) { say "$str !"; } with-mandatory-named(str => "My String"); #=> My String ! -with-mandatory-named; # run time error: "Required named parameter not passed" +with-mandatory-named; # run time error: "Required named parameter not passed" with-mandatory-named(3); # run time error: "Too many positional parameters passed" ## If a sub takes a named boolean argument ... @@ -197,7 +197,7 @@ sub mutate($n is rw) { say "\$n is now $n !"; } -# If what you want is a copy instead, use `is copy`. +# If what you want a copy instead, use `is copy`. # A sub itself returns a container, which means it can be marked as rw: my $x = 42; @@ -234,7 +234,7 @@ say "Quite truthy" if True; # - Ternary conditional, "?? !!" (like `x ? y : z` in some other languages) my $a = $condition ?? $value-if-true !! $value-if-false; -# - `given`-`when` looks like other languages `switch`, but much more +# - `given`-`when` looks like other languages' `switch`, but much more # powerful thanks to smart matching and thanks to Perl 6's "topic variable", $_. # # This variable contains the default argument of a block, @@ -290,7 +290,7 @@ for @array -> $variable { # That means you can use `when` in a `for` just like you were in a `given`. for @array { say "I've got $_"; - + .say; # This is also allowed. # A dot call with no "topic" (receiver) is sent to `$_` by default $_.say; # the above and this are equivalent. @@ -634,14 +634,14 @@ class A { method get-value { $.field + $!private-field; } - + method set-value($n) { # $.field = $n; # As stated before, you can't use the `$.` immutable version. $!field = $n; # This works, because `$!` is always mutable. - + $.other-field = 5; # This works, because `$.other-field` is `rw`. } - + method !private-method { say "This method is private to the class !"; } @@ -660,19 +660,19 @@ $a.other-field = 10; # This, however, works, because the public field class A { has $.val; - + submethod not-inherited { say "This method won't be available on B."; say "This is most useful for BUILD, which we'll see later"; } - + method bar { $.val * 5 } } class B is A { # inheritance uses `is` method foo { say $.val; } - + method bar { $.val * 10 } # this shadows A's `bar` } @@ -699,20 +699,20 @@ role PrintableVal { # you "import" a mixin (a "role") with "does": class Item does PrintableVal { has $.val; - + # When `does`-ed, a `role` literally "mixes in" the class: # the methods and fields are put together, which means a class can access # the private fields/methods of its roles (but not the inverse !): method access { say $!counter++; } - + # However, this: # method print {} # is ONLY valid when `print` isn't a `multi` with the same dispatch. # (this means a parent class can shadow a child class's `multi print() {}`, # but it's an error if a role does) - + # NOTE: You can use a role as a class (with `is ROLE`). In this case, methods # will be shadowed, since the compiler will consider `ROLE` to be a class. } @@ -812,7 +812,7 @@ module Foo::Bar { say "Can't access me from outside, I'm my !"; } } - + say ++$n; # lexically-scoped variables are still available } say $Foo::Bar::n; #=> 1 @@ -1075,8 +1075,8 @@ say [//] Nil, Any, False, 1, 5; #=> False # Default value examples: -say [*] (); #=> 1 -say [+] (); #=> 0 +say [*] (); #=> 1 +say [+] (); #=> 0 # meaningless values, since N*1=N and N+0=N. say [//]; #=> (Any) # There's no "default value" for `//`. @@ -1335,7 +1335,7 @@ sub MAIN($name) { say "Hello, $name !" } # This produces: # $ perl6 cli.pl # Usage: -# t.pl +# t.pl # And since it's a regular Perl 6 sub, you can haz multi-dispatch: # (using a "Bool" for the named argument so that we can do `--replace` @@ -1348,7 +1348,7 @@ multi MAIN('import', File, Str :$as) { ... } # omitting parameter name # This produces: # $ perl 6 cli.pl # Usage: -# t.pl [--replace] add +# t.pl [--replace] add # t.pl remove # t.pl [--as=] import (File) # As you can see, this is *very* powerful. @@ -1400,7 +1400,7 @@ for { # (explained in details below). .say } - + if rand == 0 ff rand == 1 { # compare variables other than `$_` say "This ... probably will never run ..."; } @@ -1461,4 +1461,3 @@ If you want to go further, you can: - Come along on `#perl6` at `irc.freenode.net`. The folks here are always helpful. - Check the [source of Perl 6's functions and classes](https://github.com/rakudo/rakudo/tree/nom/src/core). Rakudo is mainly written in Perl 6 (with a lot of NQP, "Not Quite Perl", a Perl 6 subset easier to implement and optimize). - Read [the language design documents](http://design.perl6.org). They explain P6 from an implementor point-of-view, but it's still very interesting. - -- cgit v1.2.3 From 087bc761d527857455e19664f4af99ae972754a5 Mon Sep 17 00:00:00 2001 From: Aayush Ranaut Date: Wed, 7 Oct 2015 21:19:50 -0400 Subject: Sugar Assert fix --- nim.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nim.html.markdown b/nim.html.markdown index c9548a1c..79271732 100644 --- a/nim.html.markdown +++ b/nim.html.markdown @@ -235,7 +235,7 @@ proc ask(question: string): Answer = else: echo("Please be clear: yes or no") proc addSugar(amount: int = 2) = # Default amount is 2, returns nothing - assert(amount > 0 or amount < 9000, "Crazy Sugar") + assert(amount > 0 and amount < 9000, "Crazy Sugar") for a in 1..amount: echo(a, " sugar...") -- cgit v1.2.3 From e1ac6209a8d3f43e7a018d79454fb1095b3314c0 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Wed, 7 Oct 2015 23:45:01 -0400 Subject: [c/en] Added a section for header files. Added a section for header files. Included a discussion of what belongs in a header file and what does not. --- c.html.markdown | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/c.html.markdown b/c.html.markdown index db2ac930..f1201eac 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -6,7 +6,7 @@ contributors: - ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"] - ["Jakub Trzebiatowski", "http://cbs.stgn.pl"] - ["Marco Scannadinari", "https://marcoms.github.io"] - + - ["Zachary Ferguson", "https://github.io/zfergus2"] --- Ah, C. Still **the** language of modern high-performance computing. @@ -630,6 +630,54 @@ typedef void (*my_fnp_type)(char *); ``` +Header files are an important part of c as they allow for the connection of c +source files and can simplify code and definitions by seperating them into +seperate files. + +Header files are syntaxtically similar to c source files but reside in ".h" +files. They can be included in your c source file by using the precompiler +command #include "example.h", given that example.h exists in the same directory +as the c file. + +```c +/* A safe guard to prevent the header from being defined too many times. This */ +/* happens in the case of circle dependency, the contents of the header is */ +/* already defined. */ +#ifndef EXAMPLE_H /* if EXAMPLE_H is not yet defined. */ +#define EXAMPLE_H /* Define the macro EXAMPLE_H. */ + +/* Other headers can be included in headers and therefore transitively */ +/* included into files that include this header. */ +#include + +/* Like c source files macros can be defined in headers and used in files */ +/* that include this header file. */ +#define EXAMPLE_NAME "Dennis Ritchie" +/* Function macros can also be defined. */ +#define ADD(a, b) (a + b) + +/* Structs and typedefs can be used for consistency between files. */ +typedef struct node +{ + int val; + struct node *next; +} Node; + +/* So can enumerations. */ +enum traffic_light_state {GREEN, YELLOW, RED}; + +/* Function prototypes can also be defined here for use in multiple files, */ +/* but it is bad practice to define the function in the header. Definitions */ +/* should instead be put in a c file. */ +Node createLinkedList(int *vals, int len); + +/* Beyond the above elements, other definitions should be left to a c source */ +/* file. Excessive includeds or definitions should, also not be contained in */ +/* a header file but instead put into separate headers or a c file. */ + +#endif /* End of the if precompiler directive. */ + +``` ## Further Reading Best to find yourself a copy of [K&R, aka "The C Programming Language"](https://en.wikipedia.org/wiki/The_C_Programming_Language) -- cgit v1.2.3 From 3c02fdb8e496816b0fd615e029fad4a8ed9f4585 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Wed, 7 Oct 2015 23:49:46 -0400 Subject: Revert "[c/en] Added a section for header files." This reverts commit e1ac6209a8d3f43e7a018d79454fb1095b3314c0. --- c.html.markdown | 50 +------------------------------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/c.html.markdown b/c.html.markdown index f1201eac..db2ac930 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -6,7 +6,7 @@ contributors: - ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"] - ["Jakub Trzebiatowski", "http://cbs.stgn.pl"] - ["Marco Scannadinari", "https://marcoms.github.io"] - - ["Zachary Ferguson", "https://github.io/zfergus2"] + --- Ah, C. Still **the** language of modern high-performance computing. @@ -630,54 +630,6 @@ typedef void (*my_fnp_type)(char *); ``` -Header files are an important part of c as they allow for the connection of c -source files and can simplify code and definitions by seperating them into -seperate files. - -Header files are syntaxtically similar to c source files but reside in ".h" -files. They can be included in your c source file by using the precompiler -command #include "example.h", given that example.h exists in the same directory -as the c file. - -```c -/* A safe guard to prevent the header from being defined too many times. This */ -/* happens in the case of circle dependency, the contents of the header is */ -/* already defined. */ -#ifndef EXAMPLE_H /* if EXAMPLE_H is not yet defined. */ -#define EXAMPLE_H /* Define the macro EXAMPLE_H. */ - -/* Other headers can be included in headers and therefore transitively */ -/* included into files that include this header. */ -#include - -/* Like c source files macros can be defined in headers and used in files */ -/* that include this header file. */ -#define EXAMPLE_NAME "Dennis Ritchie" -/* Function macros can also be defined. */ -#define ADD(a, b) (a + b) - -/* Structs and typedefs can be used for consistency between files. */ -typedef struct node -{ - int val; - struct node *next; -} Node; - -/* So can enumerations. */ -enum traffic_light_state {GREEN, YELLOW, RED}; - -/* Function prototypes can also be defined here for use in multiple files, */ -/* but it is bad practice to define the function in the header. Definitions */ -/* should instead be put in a c file. */ -Node createLinkedList(int *vals, int len); - -/* Beyond the above elements, other definitions should be left to a c source */ -/* file. Excessive includeds or definitions should, also not be contained in */ -/* a header file but instead put into separate headers or a c file. */ - -#endif /* End of the if precompiler directive. */ - -``` ## Further Reading Best to find yourself a copy of [K&R, aka "The C Programming Language"](https://en.wikipedia.org/wiki/The_C_Programming_Language) -- cgit v1.2.3 From 7aca9100a042f3813d383f979f8c32a95ecc4bbb Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Thu, 8 Oct 2015 00:00:37 -0400 Subject: [java/en] Fixed repitions --- java.html.markdown | 59 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 61478968..ba602d2e 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -513,12 +513,8 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, } } -<<<<<<< HEAD -// Abstract Classes -======= - // Abstract Classes ->>>>>>> adambard/master + // Abstract Class declaration syntax // abstract extends { // // Constants and variables @@ -535,7 +531,6 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, public abstract class Animal { -<<<<<<< HEAD public abstract void makeSound(); // Method can have a body @@ -561,38 +556,10 @@ public abstract class Animal { System.out.println("I am abstract"); } -======= - 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 initialize, however in an interface - // a variable is implicitly final and hence has - // to be initialized. - 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"); - } ->>>>>>> adambard/master } class Dog extends Animal { -<<<<<<< HEAD // Note still have to override the abstract methods in the // abstract class. @Override @@ -614,32 +581,10 @@ class Dog extends Animal pluto.eat(); pluto.printAge(); } -======= - // 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(); - } ->>>>>>> adambard/master } // Final Classes + // Final Class declaration syntax // final { // // Constants and variables -- cgit v1.2.3 From 707c8db171cb5239682332f14fd2098901741c63 Mon Sep 17 00:00:00 2001 From: Valentine Silvansky Date: Thu, 8 Oct 2015 10:00:13 +0300 Subject: Add generics operator in Swift --- swift.html.markdown | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/swift.html.markdown b/swift.html.markdown index a40e86c8..75535e43 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -574,4 +574,18 @@ print(mySquare.sideLength) // 4 // change side length using custom !!! operator, increases size by 3 !!!mySquare print(mySquare.sideLength) // 12 + +// Operators can also be generics +infix operator <-> {} +func <-> (inout a: T, inout b: T) { + let c = a + a = b + b = c +} + +var foo: Float = 10 +var bar: Float = 20 + +foo <-> bar +print("foo is \(foo), bar is \(bar)") // "foo is 20.0, bar is 10.0" ``` -- cgit v1.2.3 From 6f2d38155930911159bfb4e169b4a4430fed2e72 Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Thu, 8 Oct 2015 07:14:24 -0400 Subject: Typo: "thought of" not "though of" --- chapel.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapel.html.markdown b/chapel.html.markdown index e20be998..7252a3e4 100644 --- a/chapel.html.markdown +++ b/chapel.html.markdown @@ -633,7 +633,7 @@ writeln( toThisArray ); // var iterArray : [1..10] int = [ i in 1..10 ] if ( i % 2 == 1 ) then j; // exhibits a runtime error. // Even though the domain of the array and the loop-expression are -// the same size, the body of the expression can be though of as an iterator. +// the same size, the body of the expression can be thought of as an iterator. // Because iterators can yield nothing, that iterator yields a different number // of things than the domain of the array or loop, which is not allowed. -- cgit v1.2.3 From c39264fd881d9a7e39dbba1f37ec9de15cf11eea Mon Sep 17 00:00:00 2001 From: Tim Heaney Date: Thu, 8 Oct 2015 09:00:59 -0400 Subject: Typo: "easily" rather than "easy" --- fsharp.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsharp.html.markdown b/fsharp.html.markdown index 62118006..76318d7d 100644 --- a/fsharp.html.markdown +++ b/fsharp.html.markdown @@ -119,7 +119,7 @@ printfn "A string %s, and something generic %A" "hello" [1;2;3;4] // ================================================ // F# is a true functional language -- functions are first -// class entities and can be combined easy to make powerful +// class entities and can be combined easily to make powerful // constructs // Modules are used to group functions together -- cgit v1.2.3 From 4b74a7a76d5840cee8f713605347a6cad245d4bb Mon Sep 17 00:00:00 2001 From: Tom Samstag Date: Thu, 8 Oct 2015 08:46:54 -0700 Subject: fix the output of ff example --- perl6.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perl6.html.markdown b/perl6.html.markdown index 63c0830a..26373c28 100644 --- a/perl6.html.markdown +++ b/perl6.html.markdown @@ -1429,7 +1429,7 @@ for { # A flip-flop can change state as many times as needed: for { .say if $_ eq 'start' ^ff^ $_ eq 'stop'; # exclude both "start" and "stop", - #=> "print this printing again" + #=> "print it print again" } # you might also use a Whatever Star, -- cgit v1.2.3 From c3914e277bafb320a37617c4a41984462be1a20d Mon Sep 17 00:00:00 2001 From: Raphael Nascimento Date: Thu, 8 Oct 2015 18:34:03 -0300 Subject: Added for/in loop JavaScript Fixing code style --- javascript.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/javascript.html.markdown b/javascript.html.markdown index f7a662a4..0e38be8f 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -221,7 +221,7 @@ for (var i = 0; i < 5; i++){ //The For/In statement loops iterates over every property across the entire prototype chain var description = ""; var person = {fname:"Paul", lname:"Ken", age:18}; -for (var x in person) { +for (var x in person){ description += person[x] + " "; } @@ -229,8 +229,8 @@ for (var x in person) { //and not its prototypes use hasOwnProperty() check var description = ""; var person = {fname:"Paul", lname:"Ken", age:18}; -for (var x in person) { - if( person.hasOwnProperty( x ) ) { +for (var x in person){ + if (person.hasOwnProperty(x)){ description += person[x] + " "; } } -- cgit v1.2.3 From bc065831ce25467ba06d3cf6e6ad159eed16a525 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Thu, 8 Oct 2015 23:24:25 -0400 Subject: Added suggested changes --- go.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.html.markdown b/go.html.markdown index f9821a0c..646a5650 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -408,8 +408,8 @@ func requestServer() { The root of all things Go is the [official Go web site](http://golang.org/). There you can follow the tutorial, play interactively, and read lots. -Aside from a tour, [the docs](https://golang.org/doc/) contain how to write -clean and effective Go code, package and command docs, and release history. +Aside from a tour, [the docs](https://golang.org/doc/) contain information on +how to write clean and effective Go code, package and command docs, and release history. The language definition itself is highly recommended. It's easy to read and amazingly short (as language definitions go these days.) -- cgit v1.2.3 From b4860de42f2bbf0ab97ef28085eb40accb030657 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Thu, 8 Oct 2015 23:27:19 -0400 Subject: Suggested changes --- swift.html.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/swift.html.markdown b/swift.html.markdown index 46e5e6d4..9f0019d8 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -58,8 +58,8 @@ let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation print("Build value: \(buildValue)") // Build value: 7 /* - Optionals are a Swift language feature that either contains a value, - or contains nil (no value) to indicate that a value is missing. + Optionals are a Swift language feature that either contains a value, + or contains nil (no value) to indicate that a value is missing. A question mark (?) after the type marks the value as optional. Because Swift requires every property to have a value, even nil must be @@ -82,9 +82,9 @@ if someOptionalString != nil { someOptionalString = nil /* - To get the underlying type from an optional, you unwrap it using the - force unwrap operator (!). Only use the unwrap operator if you're sure - the underlying value isn't nil. + Trying to use ! to access a non-existent optional value triggers a runtime + error. Always make sure that an optional contains a non-nil value before + using ! to force-unwrap its value. */ // implicitly unwrapped optional -- cgit v1.2.3 From 7fd149485e0cbef6fc57206cb1377f261ed70278 Mon Sep 17 00:00:00 2001 From: Martin N Date: Fri, 9 Oct 2015 07:39:22 +0000 Subject: Mention of trailing commas in JSON and that they should be avoided --- json.html.markdown | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/json.html.markdown b/json.html.markdown index 6aff2ce2..a85cecc4 100644 --- a/json.html.markdown +++ b/json.html.markdown @@ -10,8 +10,11 @@ As JSON is an extremely simple data-interchange format, this is most likely goin to be the simplest Learn X in Y Minutes ever. JSON in its purest form has no actual comments, but most parsers will accept -C-style (`//`, `/* */`) comments. For the purposes of this, however, everything is -going to be 100% valid JSON. Luckily, it kind of speaks for itself. +C-style (`//`, `/* */`) comments. Some parsers also tolerate a trailing comma +(i.e. a comma after the last element of an array or the after the last property of an object), +but they should be avoided for better compatibility. + +For the purposes of this, however, everything is going to be 100% valid JSON. Luckily, it kind of speaks for itself. ```json { -- cgit v1.2.3 From ab8267f4273d6fa2c3027775e353d95e7d5f1493 Mon Sep 17 00:00:00 2001 From: payet-s Date: Thu, 8 Oct 2015 16:48:50 +0200 Subject: [yaml/fr] Fix typos --- fr-fr/yaml-fr.html.markdown | 92 +++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/fr-fr/yaml-fr.html.markdown b/fr-fr/yaml-fr.html.markdown index 43b1df54..1e8296d3 100644 --- a/fr-fr/yaml-fr.html.markdown +++ b/fr-fr/yaml-fr.html.markdown @@ -8,113 +8,117 @@ lang: fr-fr Proposé à l'origine par Clark Evans en Mai 2001, YAML est un un format de représentation de données par sérialisation, conçu pour être aisément -éditable et lisible par nous même, les humains. +modifiable et lisible par nous-mêmes, les humains. -YAML est plus concis que le XML auquel il est parfois comparé par ceux qui le découvre, plus lisible et clair que le CSV, et emprunte beaucoup au JSON dont il est un parent naturel. Toutefois, YAML emprunte également des idées et concepts de chez Python, et s'intègre bien avec bon nombre de langages. +YAML est plus concis que le XML auquel il est parfois comparé par ceux qui le +découvre, plus lisible et clair que le CSV, et emprunte beaucoup au JSON dont +il est un parent naturel. Toutefois, YAML emprunte également des idées et +concepts de Python, et s'intègre bien avec bon nombre de langages. +Contrairement à ce dernier, YAML interdit l'utilisation des tabulations. ```yaml -# les Commentaires sont précédés d'un signe "#", comme cette ligne. +# Les commentaires sont précédés d'un signe "#", comme cette ligne. ############# # SCALAIRES # ############# -# Les scalaires sont l'ensemble des types YAML qui ne sont pas des collections -# ( listes ou tableaux associatifs ). +# Les scalaires sont l'ensemble des types YAML qui ne sont pas des collections +# (listes ou tableaux associatifs). -# Notre objet root ( racine ), sera une map ( carte ) et englobera -# l'intégralité du document. Cette map est l'équivalent d'un dictionnaire, +# Notre objet root (racine), sera une map (carte) et englobera +# l'intégralité du document. Cette map est l'équivalent d'un dictionnaire, # hash ou objet dans d'autres langages. clé: valeur -aurtre_clé: une autre valeur +autre_clé: une autre valeur valeur_numérique: 100 notation_scientifique: 1e+12 -boolean: true +booléen: true valeur_null: null clé avec espaces: valeur -# Bien qu'il ne soit pas nécessaire d'enfermer les chaînes de caractères +# Bien qu'il ne soit pas nécessaire de mettre les chaînes de caractères # entre guillemets, cela reste possible, et parfois utile. toutefois: "Une chaîne, peut être contenue entre guillemets." -"Une clé entre guillemets.": "Utile si on veut utiliser ':' dans la clé." +"Une clé entre guillemets.": "Utile si l'on veut utiliser ':' dans la clé." -# Les chaînes couvrant plusieurs lignes, peuvent être écrites au choix, -# comme un 'bloc littéral' ( avec | ) ou bien 'bloc replié' avec ( > ). +# Les chaînes couvrant plusieurs lignes, peuvent être écrites au choix, +# comme un "bloc littéral" (avec '|') ou bien un "bloc replié" (avec '>'). bloc_littéral: | - Tout ce bloc de texte sera la valeur de la clé 'bloc_littéral', - avec préservation des retours à la ligne. ( chaque ligne vide à - l'intérieur du même bloc, sera remplacée par "\n\n" ) + Tout ce bloc de texte sera la valeur de la clé "bloc_littéral", + avec préservation des retours à la ligne. Le littéral continue jusqu'à ce que l'indentation soit annulée. - Toutes lignes qui serait "d'avantage indentées" conservent leur + Toutes lignes qui seraient "davantage indentées" conservent leur indentation, constituée de 4 espaces. bloc_replié: > - Tout ce bloc de texte sera la valeur de la clé 'bloc_replié', mais - cette fois ci, toutes les nouvelles lignes deviendront un simple espace. + Tout ce bloc de texte sera la valeur de la clé "bloc_replié", mais + cette fois-ci, toutes les nouvelles lignes deviendront un simple espace. - Les lignes vides, comme ci-dessus, seront converties en caractère "\n". + Les lignes vides, comme ci-dessus, seront converties en caractère de + nouvelle ligne. - Les lignes 'plus-indentées' gardent leurs retours à la ligne - + Les lignes "plus-indentées" gardent leurs retours à la ligne - ce texte apparaîtra sur deux lignes. ############### # COLLECTIONS # ############### -# l'Imbrication est créée par indentation. +# L'imbrication est créée par indentation. une_map_imbriquée: clé: valeur autre_clé: autre valeur autre_map_imbriquée: bonjour: bonjour -# les Clés des Maps ne sont pas nécessairement des chaînes de caractères. -0.25: une clé de type float +# Les clés des maps ne sont pas nécessairement des chaînes de caractères. +0.25: une clé de type flottant -# les Clés peuvent également être des objets s'étendant sur plusieurs lignes, +# Les clés peuvent également être des objets s'étendant sur plusieurs lignes, # en utilisant le signe "?" pour indiquer le début de la clé. ? | - ceci est une Clé + ceci est une clé sur de multiples lignes -: et ceci est sa Valeur +: et ceci est sa valeur # YAML autorise aussi l'usage des collections à l'intérieur des clés, # mais certains langages de programmation ne le tolère pas si bien. -# les Séquences (équivalent des listes ou tableaux) ressemblent à cela: +# Les séquences (équivalent des listes ou tableaux) ressemblent à cela : une_séquence: - - Item 1 - - Item 2 + - Objet 1 + - Objet 2 - 0.5 # les séquences peuvent contenir des types variés. - - Item 4 + - Objet 4 - clé: valeur autre_clé: autre_valeur - - Ceci est une séquence - dans une autre séquence -# YAML étant un proche parent de JSON, vous pouvez écrire directement +# YAML étant un proche parent de JSON, vous pouvez écrire directement # des maps et séquences façon JSON json_map: {"clé": "valeur"} json_seq: [1, 2, 3, "soleil"] -################################# +################################ # AUTRES FONCTIONNALITÉES YAML # -################################# +################################ -# YAML possède une fonctionnalité fort utile nommée 'ancres'. Celle-ci +# YAML possède une fonctionnalité fort utile nommée "ancres". Celle-ci # vous permet de dupliquer aisément du contenu au sein de votre document. -# Les deux clés suivantes auront la même valeur: +# Les deux clés suivantes auront la même valeur : contenu_ancré: &nom_ancre Cette chaîne sera la valeur des deux clés. autre_ancre: *nom_ancre -# Avec les Tags YAML, vous pouvez explicitement déclarer des types de données. +# Avec les tags YAML, vous pouvez explicitement déclarer des types de données. chaine_explicite: !!str 0.5 -# Certains parsers implémentent des tags spécifiques à d'autres langages, -# comme par exemple le "complex number" de Python. +# Certains analyseurs syntaxiques (parsers) implémentent des tags spécifiques à +# d'autres langages, comme par exemple celui des nombres complexes de Python. python_complex_number: !!python/complex 1+2j ##################### @@ -122,7 +126,7 @@ python_complex_number: !!python/complex 1+2j ##################### # YAML interprète également les données formatées ISO de type date et datetime, -# pas seulement les chaînes et nombres. +# pas seulement les chaînes et nombres. datetime: 2001-12-15T02:59:43.1Z datetime_avec_espaces: 2001-12-14 21:59:43.10 -5 date: 2002-12-14 @@ -135,14 +139,14 @@ fichier_gif: !!binary | +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs= -# YAML a de même un type "set", qui ressemble à cela: +# YAML a de même un type "set", semblable à ceci : set: ? item1 ? item2 ? item3 # Comme dans Python, les sets ne sont que des maps contenant des valeurs null ; -# le set précédent est l'équivalent du suivant: +# le set précédent est l'équivalent du suivant : set2: item1: null item2: null @@ -152,6 +156,6 @@ set2: Quelques références et outils : -- Doc officielle [YAML 1.2](http://www.yaml.org/spec/1.2/spec.html) *anglais*, +- Documentation officielle [YAML 1.2](http://www.yaml.org/spec/1.2/spec.html) *anglais*, - Une [Introduction à YAML](http://sweetohm.net/html/introduction-yaml.html) très bien construite et claire, -- Un outil pour tester [live](http://yaml-online-parser.appspot.com/) la syntaxe YAML, avec des exemples. +- Un outil pour tester [en ligne](http://yaml-online-parser.appspot.com/) la syntaxe YAML, avec des exemples. -- cgit v1.2.3