October 20, 2016
On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
> I think this example is a bit awkward for D newbies to decipher. I think here we are showing D's ctRegex; dropping the functional map and lambdas would make this more universally understood.

https://github.com/dlang/dlang.org/pull/1500
October 20, 2016
On Thursday, 20 October 2016 at 11:38:04 UTC, Nick Treleaven wrote:
> On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
>> I think this example is a bit awkward for D newbies to decipher. I think here we are showing D's ctRegex; dropping the functional map and lambdas would make this more universally understood.
>
> https://github.com/dlang/dlang.org/pull/1500

Sounds reasonable. What about adding code for hardcore systems programmers too? Some flashy low-level stuff.
October 20, 2016
On 10/20/2016 07:38 AM, Nick Treleaven wrote:
> On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
>> I think this example is a bit awkward for D newbies to decipher. I
>> think here we are showing D's ctRegex; dropping the functional map and
>> lambdas would make this more universally understood.
>
> https://github.com/dlang/dlang.org/pull/1500

I think it would be best if we kept both. -- Andrei
October 20, 2016
On Thursday, 20 October 2016 at 14:04:06 UTC, Andrei Alexandrescu wrote:
> On 10/20/2016 07:38 AM, Nick Treleaven wrote:
>> On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
>>> I think this example is a bit awkward for D newbies to decipher. I
>>> think here we are showing D's ctRegex; dropping the functional map and
>>> lambdas would make this more universally understood.
>>
>> https://github.com/dlang/dlang.org/pull/1500
>
> I think it would be best if we kept both. -- Andrei

Actually, the whole example would be easier to understand, if there were more comments. I.e. explain what `pipe!` does and what `ctRegex` is.

It's much clearer in the Docs[1]:

// Read an entire text file, split the resulting string in
// whitespace-separated tokens, and then convert each token into an
// integer
int[] a = pipe!(readText, split, map!(to!(int)))("file.txt");

In general I find it helpful, when there are comments in example snippets. Some examples from the Docs would actually be quite good for newbies. Maybe we can harvest snippets there.


[1] http://dlang.org/phobos/std_functional.html#.pipe
October 20, 2016
On Thursday, 20 October 2016 at 14:04:06 UTC, Andrei Alexandrescu wrote:
> On 10/20/2016 07:38 AM, Nick Treleaven wrote:
>> On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
>>> I think this example is a bit awkward for D newbies to decipher. I
>>> think here we are showing D's ctRegex; dropping the functional map and
>>> lambdas would make this more universally understood.
>>
>> https://github.com/dlang/dlang.org/pull/1500
>
> I think it would be best if we kept both. -- Andrei

Test using bottom- up approach. Test on a newbie.
October 20, 2016
On 10/20/2016 03:48 PM, Karabuta wrote:
> On Thursday, 20 October 2016 at 14:04:06 UTC, Andrei Alexandrescu wrote:
>> On 10/20/2016 07:38 AM, Nick Treleaven wrote:
>>> On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
>>>> I think this example is a bit awkward for D newbies to decipher. I
>>>> think here we are showing D's ctRegex; dropping the functional map and
>>>> lambdas would make this more universally understood.
>>>
>>> https://github.com/dlang/dlang.org/pull/1500
>>
>> I think it would be best if we kept both. -- Andrei
>
> Test using bottom- up approach. Test on a newbie.

We ought to test on different newbies with different sensibilities. The PR replaces one style of doing things with another. For some the first style may be more pleasant than the second ("you mean I need to go back to for loops now?") etc. -- Andrei

October 20, 2016
On Thursday, 20 October 2016 at 19:52:32 UTC, Andrei Alexandrescu wrote:
> On 10/20/2016 03:48 PM, Karabuta wrote:
>> On Thursday, 20 October 2016 at 14:04:06 UTC, Andrei Alexandrescu wrote:
>>> On 10/20/2016 07:38 AM, Nick Treleaven wrote:
>>>> On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
>>>>> [...]
>>>>
>>>> https://github.com/dlang/dlang.org/pull/1500
>>>
>>> I think it would be best if we kept both. -- Andrei
>>
>> Test using bottom- up approach. Test on a newbie.
>
> We ought to test on different newbies with different sensibilities. The PR replaces one style of doing things with another. For some the first style may be more pleasant than the second ("you mean I need to go back to for loops now?") etc. -- Andrei

Generally. All examples you assume will be effective for beginners.
October 20, 2016
On 10/20/2016 04:16 PM, Karabuta wrote:
> On Thursday, 20 October 2016 at 19:52:32 UTC, Andrei Alexandrescu wrote:
>> On 10/20/2016 03:48 PM, Karabuta wrote:
>>> On Thursday, 20 October 2016 at 14:04:06 UTC, Andrei Alexandrescu wrote:
>>>> On 10/20/2016 07:38 AM, Nick Treleaven wrote:
>>>>> On Sunday, 16 October 2016 at 16:07:19 UTC, Nick Treleaven wrote:
>>>>>> [...]
>>>>>
>>>>> https://github.com/dlang/dlang.org/pull/1500
>>>>
>>>> I think it would be best if we kept both. -- Andrei
>>>
>>> Test using bottom- up approach. Test on a newbie.
>>
>> We ought to test on different newbies with different sensibilities.
>> The PR replaces one style of doing things with another. For some the
>> first style may be more pleasant than the second ("you mean I need to
>> go back to for loops now?") etc. -- Andrei
>
> Generally. All examples you assume will be effective for beginners.

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
October 21, 2016
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 :-)
October 21, 2016
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.