On Friday, 21 October 2016 at 10:24:40 UTC, Chris wrote:
On Thursday, 20 October 2016 at 21:52:09 UTC, Andrei
Alexandrescu wrote:
On 10/20/2016 04:16 PM, Karabuta wrote:
We can't assume all beginners come from imperative languages.
D beginners may come from languages where the idiomatic way of
doing things is by means of pipelines. Generally it's not
worth debating this because there's so little evidence to
dwell on - please let's keep both and move with our lives.
Thanks! -- Andrei
Today many people don't even want to see a for-loop. What we
could do, though, is to give an example of each common or
"expected" feature (OOP, functional, concurrency, memory model
etc.), so that people see immediately that they can do A, B
_and_ C in D :-)
I second that.
Also, it may be a good idea to simply use classical algorithms
(binary search, quicksort, etc.), written in "D style", as
examples. The typical visitor is probably familiar with these
algorithms and thus the foreign syntax won't be as scary. It also
puts the syntax in a context that the visitor is already familiar
with, so there is a good chance that he'll deduce its meaning
even without supplementary comments.
For instance, TDPL has the following implementation of binary
search in its introductory chapter:
bool binarySearch(T)(T[] input, T value) {
while (!input.empty) {
auto i = input.length / 2;
auto mid = input[i];
if (mid > value) input = input[0 .. i];
else if (mid < value) input = input[i + 1 .. $];
else return true;
}
return false;
}
Nothing too fancy, but it's a good example of how array slicing
in D helps make the code cleaner, shorter and easier to
understand.