www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Code example on www.d-programming-language.org?

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
We have a rather aged code example on www.d-programming-language.org. 
What would you think would be a good replacement? The ideal snippet 
would make a compelling tour of the language's and stdlib's most 
important features while at the same time being simple and concise.

Andrei
Apr 04 2011
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Andrei:

 We have a rather aged code example on www.d-programming-language.org. 
 What would you think would be a good replacement? The ideal snippet 
 would make a compelling tour of the language's and stdlib's most 
 important features while at the same time being simple and concise.
If you try to cram most features in a simple small program you end with something that looks like a little Christmas tree. I don't think this is a good advertisement for D. On the rosettacode.org site there are many ways to implement the D solutions. The C solutions are often not much general, and too much low level. The C++ solutions are often over-engineered, over-generalized, and sometimes not easy to understand. The Go solutions are sometimes too much simple. A good D solution is quite short and to the point, simple, at the level required to solve the task, not too much slow, not too much optimized, very easy to read, easy to understand, not too much specific but not even too much generalized. Sometimes solutions in other languages are tagged as derived from the Python and D solutions, this means the D code was readable enough, this is how very publicly visible D code has to be. Readability first, generality but not too much of it, low level when necessary, high level when possible. It's a matter of style. People run away from C++ because sometimes it has an image of a messy and over-engineered language. I suggest to avoid this trap in D code that everyone sees. Bye, bearophile
Apr 04 2011
next sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 4/4/11 4:02 PM, bearophile wrote:
 Andrei:

 We have a rather aged code example on www.d-programming-language.org.
 What would you think would be a good replacement? The ideal snippet
 would make a compelling tour of the language's and stdlib's most
 important features while at the same time being simple and concise.
If you try to cram most features in a simple small program you end with something that looks like a little Christmas tree. I don't think this is a good advertisement for D.
Keywords: "ideal" "compelling" "most important" "simple" "concise". Clearly finding a good example with such conflicting requirements is not easy and there's no need to restate that. If it were easy I would've done it. What is needed is an example that successfully finds the sweet spot. Thanks, Andrei
Apr 04 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
Andrei:

 Clearly finding a good example with such conflicting requirements is not 
 easy and there's no need to restate that. If it were easy I would've 
 done it. What is needed is an example that successfully finds the sweet 
 spot.
In my opinion what I have explained in my answer is not obvious stuff, seeing how many solutions/programmers on Rosettacode fail. My point was that in my opinion there is no such single example that satisfies your requests, and that your requests are bad. If you put too much stuff in a single example, the result is not what I will call a good example for very public D code. So you have to put only a limited amount of stuff in the example, or you have to show more than one example. If you want a single example, the second on Wikipedia is the one I like: http://en.wikipedia.org/wiki/D_language#Example_2 Bye, bearophile
Apr 04 2011
parent reply Emil Madsen <sovende gmail.com> writes:
On 5 April 2011 00:02, bearophile <bearophileHUGS lycos.com> wrote:

 Andrei:

 Clearly finding a good example with such conflicting requirements is not
 easy and there's no need to restate that. If it were easy I would've
 done it. What is needed is an example that successfully finds the sweet
 spot.
In my opinion what I have explained in my answer is not obvious stuff, seeing how many solutions/programmers on Rosettacode fail. My point was that in my opinion there is no such single example that satisfies your requests, and that your requests are bad. If you put too much stuff in a single example, the result is not what I will call a good example for very public D code. So you have to put only a limited amount of stuff in the example, or you have to show more than one example. If you want a single example, the second on Wikipedia is the one I like: http://en.wikipedia.org/wiki/D_language#Example_2 Bye, bearophile
Honestly I would rather meet a site that has several simple examples illustrating the capabilities of a language, instead of a single one, thats messy. -- // Yours sincerely // Emil 'Skeen' Madsen
Apr 04 2011
next sibling parent David Gileadi <gileadis NSPMgmail.com> writes:
On 4/4/11 3:18 PM, Emil Madsen wrote:
 On 5 April 2011 00:02, bearophile <bearophileHUGS lycos.com
 <mailto:bearophileHUGS lycos.com>> wrote:

     Andrei:

      > Clearly finding a good example with such conflicting requirements
     is not
      > easy and there's no need to restate that. If it were easy I would've
      > done it. What is needed is an example that successfully finds the
     sweet
      > spot.

     In my opinion what I have explained in my answer is not obvious
     stuff, seeing how many solutions/programmers on Rosettacode fail.

     My point was that in my opinion there is no such single example that
     satisfies your requests, and that your requests are bad. If you put
     too much stuff in a single example, the result is not what I will
     call a good example for very public D code. So you have to put only
     a limited amount of stuff in the example, or you have to show more
     than one example.

     If you want a single example, the second on Wikipedia is the one I like:
     http://en.wikipedia.org/wiki/D_language#Example_2

     Bye,
     bearophile



 Honestly I would rather meet a site that has several simple examples
 illustrating the capabilities of a language, instead of a single one,
 thats messy.

 --
 // Yours sincerely
 // Emil 'Skeen' Madsen
It might be a good idea to offer a very simple code example near the top of the page to give the flavor of the language, together with a link to a page with further code examples. That page might live somewhere under the Overview navigation section, and might merge with the "Example: wc" page.
Apr 04 2011
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 4/4/11 5:18 PM, Emil Madsen wrote:
 On 5 April 2011 00:02, bearophile <bearophileHUGS lycos.com
 <mailto:bearophileHUGS lycos.com>> wrote:

     Andrei:

      > Clearly finding a good example with such conflicting requirements
     is not
      > easy and there's no need to restate that. If it were easy I would've
      > done it. What is needed is an example that successfully finds the
     sweet
      > spot.

     In my opinion what I have explained in my answer is not obvious
     stuff, seeing how many solutions/programmers on Rosettacode fail.

     My point was that in my opinion there is no such single example that
     satisfies your requests, and that your requests are bad. If you put
     too much stuff in a single example, the result is not what I will
     call a good example for very public D code. So you have to put only
     a limited amount of stuff in the example, or you have to show more
     than one example.

     If you want a single example, the second on Wikipedia is the one I like:
     http://en.wikipedia.org/wiki/D_language#Example_2

     Bye,
     bearophile



 Honestly I would rather meet a site that has several simple examples
 illustrating the capabilities of a language, instead of a single one,
 thats messy.
Of course. I'm just talking about the greeter example here. Andrei
Apr 04 2011
prev sibling next sibling parent reply spir <denis.spir gmail.com> writes:
On 04/04/2011 11:02 PM, bearophile wrote:
 Andrei:

 We have a rather aged code example on www.d-programming-language.org.
 What would you think would be a good replacement? The ideal snippet
 would make a compelling tour of the language's and stdlib's most
 important features while at the same time being simple and concise.
If you try to cram most features in a simple small program you end with something that looks like a little Christmas tree. I don't think this is a good advertisement for D. On the rosettacode.org site there are many ways to implement the D solutions. The C solutions are often not much general, and too much low level. The C++ solutions are often over-engineered, over-generalized, and sometimes not easy to understand. The Go solutions are sometimes too much simple. A good D solution is quite short and to the point, simple, at the level required to solve the task, not too much slow, not too much optimized, very easy to read, easy to understand, not too much specific but not even too much generalized. Sometimes solutions in other languages are tagged as derived from the Python and D solutions, this means the D code was readable enough, this is how very publicly visible D code has to be. Readability first, generality but not too much of it, low level when necessary, high level when possible. It's a matter of style. People run away from C++ because sometimes it has an image of a messy and over-engineered language. I suggest to avoid this trap in D c
ode that everyone sees. Very well stated. The one example to find (one only, for the home page) is thus one piece of code shows clearly shows the *differential* advantage(s) of D over well known programming languages. Else, it's useless. Denis -- _________________ vita es estrany spir.wikidot.com
Apr 04 2011
parent Daniel Gibson <metalcaedes gmail.com> writes:
Am 05.04.2011 02:52, schrieb spir:
 On 04/04/2011 11:02 PM, bearophile wrote:
 Andrei:

 We have a rather aged code example on www.d-programming-language.org.
 What would you think would be a good replacement? The ideal snippet
 would make a compelling tour of the language's and stdlib's most
 important features while at the same time being simple and concise.
If you try to cram most features in a simple small program you end with something that looks like a little Christmas tree. I don't think this is a good advertisement for D. On the rosettacode.org site there are many ways to implement the D solutions. The C solutions are often not much general, and too much low level. The C++ solutions are often over-engineered, over-generalized, and sometimes not easy to understand. The Go solutions are sometimes too much simple. A good D solution is quite short and to the point, simple, at the level required to solve the task, not too much slow, not too much optimized, very easy to read, easy to understand, not too much specific but not even too much generalized. Sometimes solutions in other languages are tagged as derived from the Python and D solutions, this means the D code was readable enough, this is how very publicly visible D code has to be. Readability first, generality but not too much of it, low level when necessary, high level when possible. It's a matter of style. People run away from C++ because sometimes it has an image of a messy and over-engineered language. I suggest to avoid this trap in D c
ode that everyone sees. Very well stated. The one example to find (one only, for the home page) is thus one piece of code shows clearly shows the *differential* advantage(s) of D over well known programming languages. Else, it's useless. Denis
Maybe it's sufficient to show just *some* cool features/differences in the greeter example. I'd suggest: * slicing (could also show that arrays have a length) * some easy template-stuff - we allow types as parameters (of course), but also values - static if * scope guards * maybe closures (delegates)? * /what else?/ Cheers, - Daniel
Apr 04 2011
prev sibling next sibling parent Jose Armando Garcia <jsancio gmail.com> writes:
Maybe we should start by identifying which small set of "simple"
features best identify D. With a minimal list of features we want to
showcase we can talk about an example that showcase them. Here is my
list: gc, ranges/slices, safety, foreach and immutability/const. It
would be nice to add template but I don't know if it is fair to assume
that most programming have a grasp of it.

Wait, what is wrong with the current word count example?

On Mon, Apr 4, 2011 at 9:52 PM, spir <denis.spir gmail.com> wrote:
 On 04/04/2011 11:02 PM, bearophile wrote:
 Andrei:

 We have a rather aged code example on www.d-programming-language.org.
 What would you think would be a good replacement? The ideal snippet
 would make a compelling tour of the language's and stdlib's most
 important features while at the same time being simple and concise.
If you try to cram most features in a simple small program you end with something that looks like a little Christmas tree. I don't think this is a good advertisement for D. On the rosettacode.org site there are many ways to implement the D solutions. The C solutions are often not much general, and too much low level. The C++ solutions are often over-engineered, over-generalized, and sometimes not easy to understand. The Go solutions are sometimes too much simple. A good D solution is quite short and to the point, simple, at the level required to solve the task, not too much slow, not too much optimized, very easy to read, easy to understand, not too much specific but not even too much generalized. Sometimes solutions in other languages are tagged as derived from the Python and D solutions, this means the D code was readable enough, this is how very publicly visible D code has to be. Readability first, generality but not too much of it, low level when necessary, high level when possible. It's a matter of style. People run away from C++ because sometimes it has an image of a messy and over-engineered language. I suggest to avoid this trap in D c
ode that everyone sees. Very well stated. The one example to find (one only, for the home page) is thus one piece of code shows clearly shows the *differential* advantage(s) of D over well known programming languages. Else, it's useless. Denis -- _________________ vita es estrany spir.wikidot.com
Apr 04 2011
prev sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I'd propose we make a "features" page. Many popular apps have this
sort of thing, showcasing some cool features the app has. We could do
the same thing with D. Instead of putting one huge and scary code
example, we could put various examples showcasing different features
on a single page, e.g.:

http://i.imgur.com/8PKoS.png
Apr 04 2011
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
Andrej Mitrovic wrote:
 I'd propose we make a "features" page.
I like it. I suggested a variant for the new home page proposed a while ago - a list of tabs you can click to load up the example in a live editor. (I whipped up that new home page, in D, shortly after it was proposed on the newsgroup if you want to see it: http://arsdnet.net/d-web-site/ )
Apr 04 2011
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 4/4/11 9:32 PM, Adam D. Ruppe wrote:
 Andrej Mitrovic wrote:
 I'd propose we make a "features" page.
I like it. I suggested a variant for the new home page proposed a while ago - a list of tabs you can click to load up the example in a live editor. (I whipped up that new home page, in D, shortly after it was proposed on the newsgroup if you want to see it: http://arsdnet.net/d-web-site/ )
Wonder what happened to that project :o). Andrei
Apr 04 2011
parent Adam D. Ruppe <destructionator gmail.com> writes:
Andrei Alexandrescu wrote:
 Wonder what happened to that project :o).
On my end, I got to ~90% of what I wanted to do (most the remaining 10% is my new newsreader and ddoc improvements. They all work, but leave some rough edges that need smoothing over) But then I got sidetracked by other things and haven't gotten back to it for a while now. I just have so many things I want to do and so little time to do it all... Thankfully, code has a pretty long shelf life, so when I do get back to it, should be able to pick up right where I left off.
Apr 04 2011
prev sibling parent reply Ary Manzana <ary esperanto.org.ar> writes:
On 4/4/11 5:03 PM, Andrei Alexandrescu wrote:
 We have a rather aged code example on www.d-programming-language.org.
 What would you think would be a good replacement? The ideal snippet
 would make a compelling tour of the language's and stdlib's most
 important features while at the same time being simple and concise.

 Andrei
I like the (guess what's I'm going to say... :-P) Ruby home page where it shows small snippets of specific features. This features are randomly selected on each page visit. http://www.ruby-lang.org/en/ What I like about it is that you can see in a glance that one feature of the language is really nice and simple to use and makes you think everything else must be like that. ;-) If you want to show every possible feature of the language it's kind of overkill, both for you and for the user who's going to read it. If the user wants to know more, point her to the full documentation, or to a short guide of the main features. Again, Ruby has a nice page for this: http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/ It shows you how to start programming in Ruby if you come from C++, or from Java, or from X. That's very nice because for C++ you can say "Shorter syntax, garbage collection, etc.", for Java you can say "You will have classes and interfaces, just like in Java", for Ruby you can say "You can have closures doing this and that", etc.
Apr 05 2011
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 4/5/11 9:19 AM, Ary Manzana wrote:
 On 4/4/11 5:03 PM, Andrei Alexandrescu wrote:
 We have a rather aged code example on www.d-programming-language.org.
 What would you think would be a good replacement? The ideal snippet
 would make a compelling tour of the language's and stdlib's most
 important features while at the same time being simple and concise.

 Andrei
I like the (guess what's I'm going to say... :-P) Ruby home page where it shows small snippets of specific features. This features are randomly selected on each page visit. http://www.ruby-lang.org/en/ What I like about it is that you can see in a glance that one feature of the language is really nice and simple to use and makes you think everything else must be like that. ;-)
That's pretty neat.
 If you want to show every possible feature of the language it's kind of
 overkill, both for you and for the user who's going to read it.

 If the user wants to know more, point her to the full documentation, or
 to a short guide of the main features.

 Again, Ruby has a nice page for this:
 http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/

 It shows you how to start programming in Ruby if you come from C++, or
 from Java, or from X. That's very nice because for C++ you can say
 "Shorter syntax, garbage collection, etc.", for Java you can say "You
 will have classes and interfaces, just like in Java", for Ruby you can
 say "You can have closures doing this and that", etc.
Thanks, those look nice. Andrei
Apr 05 2011