From 960ee4a1856db8eadb96277bb2422edfa8f2a81c Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 23:11:24 -0400 Subject: removing whitespace all over --- d.html.markdown | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index daba8020..ba24b60f 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -1,6 +1,6 @@ --- -language: D -filename: learnd.d +language: D +filename: learnd.d contributors: - ["Nick Papanastasiou", "www.nickpapanastasiou.github.io"] lang: en @@ -18,9 +18,9 @@ void main(string[] args) { } ``` -If you're like me and spend way too much time on the internet, odds are you've heard +If you're like me and spend way too much time on the internet, odds are you've heard about [D](http://dlang.org/). The D programming language is a modern, general-purpose, -multi-paradigm language with support for everything from low-level features to +multi-paradigm language with support for everything from low-level features to expressive high-level abstractions. D is actively developed by Walter Bright and Andrei Alexandrescu, two super smart, really cool @@ -37,7 +37,7 @@ void main() { } auto n = 1; // use auto for type inferred variables - + // Numeric literals can use _ as a digit seperator for clarity while(n < 10_000) { n += n; @@ -49,7 +49,7 @@ void main() { // For and while are nice, but in D-land we prefer foreach // The .. creates a continuous range, excluding the end - foreach(i; 1..1_000_000) { + foreach(i; 1..1_000_000) { if(n % 2 == 0) writeln(i); } @@ -72,12 +72,12 @@ we can use templates to parameterize all of these on both types and values! // Here, T is a type parameter. Think from C++/C#/Java struct LinkedList(T) { T data = null; - LinkedList!(T)* next; // The ! is used to instaniate a parameterized type. Again, think + LinkedList!(T)* next; // The ! is used to instaniate a parameterized type. Again, think } class BinTree(T) { T data = null; - + // If there is only one template parameter, we can omit parens BinTree!T left; BinTree!T right; @@ -101,7 +101,7 @@ alias NumTree = BinTree!double; // We can create function templates as well! T max(T)(T a, T b) { - if(a < b) + if(a < b) return b; return a; @@ -114,7 +114,7 @@ void swap(T)(ref T a, ref T b) { auto temp = a; a = b; - b = temp; + b = temp; } // With templates, we can also parameterize on values, not just types @@ -145,13 +145,13 @@ class MyClass(T, U) { class MyClass(T, U) { T _data; U _other; - + // Constructors are always named `this` this(T t, U u) { data = t; other = u; } - + // getters @property T data() { return _data; @@ -161,7 +161,7 @@ class MyClass(T, U) { return _other; } - // setters + // setters @property void data(T t) { _data = t; } @@ -177,7 +177,7 @@ void main() { mc.data = 7; mc.other = "seven"; - + writeln(mc.data); writeln(mc.other); } @@ -193,7 +193,7 @@ and `override`ing methods. D does inheritance just like Java: Extend one class, implement as many interfaces as you please. We've seen D's OOP facilities, but let's switch gears. D offers -functional programming with first-class functions, `pure` +functional programming with first-class functions, `pure` functions, and immutable data. In addition, all of your favorite functional algorithms (map, filter, reduce and friends) can be found in the wonderful `std.algorithm` module! @@ -205,7 +205,7 @@ import std.range : iota; // builds an end-exclusive range void main() { // We want to print the sum of a list of squares of even ints // from 1 to 100. Easy! - + // Just pass lambda expressions as template parameters! // You can pass any old function you like, but lambdas are convenient here. auto num = iota(1, 101).filter!(x => x % 2 == 0) @@ -216,12 +216,12 @@ void main() { } ``` -Notice how we got to build a nice Haskellian pipeline to compute num? +Notice how we got to build a nice Haskellian pipeline to compute num? That's thanks to a D innovation know as Uniform Function Call Syntax. With UFCS, we can choose whether to write a function call as a method or free function call! Walter wrote a nice article on this -[here.](http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394) -In short, you can call functions whose first parameter +[here.](http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394) +In short, you can call functions whose first parameter is of some type A on any expression of type A as a method. I like parallelism. Anyone else like parallelism? Sure you do. Let's do some! -- cgit v1.2.3 From a4d9115decdfaa0346c66994df372e529d343d37 Mon Sep 17 00:00:00 2001 From: Gautam Kotian Date: Tue, 13 Oct 2015 18:15:49 +0200 Subject: Clarify that not just two people develop D The present construction seems to imply that only Walter and Andrei and involved in the development of D. This is nowhere close to being true! --- d.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index ba24b60f..7c23f2dd 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -23,8 +23,8 @@ about [D](http://dlang.org/). The D programming language is a modern, general-pu multi-paradigm language with support for everything from low-level features to expressive high-level abstractions. -D is actively developed by Walter Bright and Andrei Alexandrescu, two super smart, really cool -dudes. With all that out of the way, let's look at some examples! +D is actively developed by a large group of super-smart people and is spearheaded by Walter Bright +and Andrei Alexandrescu. With all that out of the way, let's look at some examples! ```c import std.stdio; -- cgit v1.2.3 From 064b82eab443fa1bc8c1dd0b061bedbc04b60e66 Mon Sep 17 00:00:00 2001 From: Gautam Kotian Date: Tue, 13 Oct 2015 18:16:30 +0200 Subject: Add wikipedia page links Link to the wikipedia pages of Walter Bright and Andrei Alexandrescu in an attempt to at least partially establish their credibility. --- d.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index 7c23f2dd..d56e08a6 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -23,8 +23,10 @@ about [D](http://dlang.org/). The D programming language is a modern, general-pu multi-paradigm language with support for everything from low-level features to expressive high-level abstractions. -D is actively developed by a large group of super-smart people and is spearheaded by Walter Bright -and Andrei Alexandrescu. With all that out of the way, let's look at some examples! +D is actively developed by a large group of super-smart people and is spearheaded by +[Walter Bright](https://en.wikipedia.org/wiki/Walter_Bright) and +[Andrei Alexandrescu](https://en.wikipedia.org/wiki/Andrei_Alexandrescu). +With all that out of the way, let's look at some examples! ```c import std.stdio; -- cgit v1.2.3 From 4be1044a64e7ac1000a458087ee9131a9999d05f Mon Sep 17 00:00:00 2001 From: Gautam Kotian Date: Tue, 13 Oct 2015 18:17:11 +0200 Subject: Improve code comments --- d.html.markdown | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index d56e08a6..88a83e41 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -38,9 +38,10 @@ void main() { writeln(i); } - auto n = 1; // use auto for type inferred variables + // 'auto' can be used for inferring types. + auto n = 1; - // Numeric literals can use _ as a digit seperator for clarity + // Numeric literals can use '_' as a digit separator for clarity. while(n < 10_000) { n += n; } @@ -49,13 +50,15 @@ void main() { n -= (n / 2); } while(n > 0); - // For and while are nice, but in D-land we prefer foreach - // The .. creates a continuous range, excluding the end + // For and while are nice, but in D-land we prefer 'foreach' loops. + // The '..' creates a continuous range, including the first value + // but excluding the last. foreach(i; 1..1_000_000) { if(n % 2 == 0) writeln(i); } + // There's also 'foreach_reverse' when you want to loop backwards. foreach_reverse(i; 1..int.max) { if(n % 2 == 1) { writeln(i); @@ -80,7 +83,7 @@ struct LinkedList(T) { class BinTree(T) { T data = null; - // If there is only one template parameter, we can omit parens + // If there is only one template parameter, we can omit the parentheses BinTree!T left; BinTree!T right; } -- cgit v1.2.3