digitalmars.D - The Many Faces of D - slides
- Walter Bright (2/2) Oct 03 2010 The slides for my Sep. 15 talk at NWCPP:
- Emil Madsen (5/7) Oct 03 2010 --
- Walter Bright (2/3) Oct 03 2010 It was actually one of the most fun ones I've done. The audience was ver...
- retard (5/8) Oct 03 2010 On a side note, I noticed that Walter is still using OpenOffice 2.4 from...
- Jonathan M Davis (4/13) Oct 03 2010 I just use latex for everything. That way I can use vim. It's much more ...
- Russel Winder (17/19) Oct 03 2010 leasant=20
- Andrei Alexandrescu (10/18) Oct 03 2010 I agree, though I'd also add that the likes of PowerPoint don't make it
- Justin Johansson (9/17) Oct 03 2010 Ahh, while that is a polite observation, it is not (to me at least) very
- Dave Mustaine (2/22) Oct 03 2010 I bet all democrats and friends of heavier music like me enjoyed it :)
- Walter Bright (3/5) Oct 03 2010 I can say it was a very friendly and engaging audience, and they asked g...
- Justin Johansson (2/7) Oct 04 2010 Congrats. Sounds like speaker and audience alike enjoyed the talk.
- Walter Bright (3/12) Oct 04 2010 Intriguingly, the audience showed a lot of interest in D's scripting
- Walter Bright (4/8) Oct 03 2010 The last time I upgraded Ubuntu it destroyed all the installed software,...
- Nick Sabalausky (9/17) Oct 03 2010 Heh, I'm still using OpenOffice 1.1 just because it doesn't have those
- retard (8/28) Oct 03 2010 This is what OpenOffice 3.2.1 looks like [on Linux] (sorry for having a
- Puneet Goel (7/14) Oct 03 2010 Nick
- bearophile (27/30) Oct 03 2010 Thank you for the slides.
- Russel Winder (43/50) Oct 03 2010 I continue to be intrigued by people who believe that code, unlike text,
- bearophile (11/15) Oct 03 2010 I guess it's a matter of personal preferences. But non-proportional font...
- Peter Alexander (6/10) Oct 03 2010 good thing (it helps "chunking" in the mind of the programmer).
- bearophile (6/10) Oct 03 2010 That's many times worse than the Python syntax. Array/range comprehensio...
- SiegeLord (3/8) Oct 03 2010 YMMW. Back when I was programming Python I found the array comprehension...
- bearophile (11/12) Oct 03 2010 Python devs have introduced list comps only after asking about their "er...
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (12/28) Oct 03 2010 rgonomicity" level to many people. And for most of those people code lik...
- bearophile (4/6) Oct 03 2010 Because I've never seen people write it that way, and because for me it'...
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (10/17) Oct 03 2010 Oh, I agree that it's less readable, but wasn't that your point?
- Andrei Alexandrescu (8/19) Oct 03 2010 You'd need to bring a pointer to a document that confirms that (and how)...
- bearophile (7/14) Oct 03 2010 It's a theory of mine :-) This too needs psychology experiments, but I n...
- Peter Alexander (6/8) Oct 03 2010 while I don't have the same problems in Python.
- Andrei Alexandrescu (23/51) Oct 03 2010 That's not the way for "me", it would be a simple application of the
- bearophile (17/26) Oct 03 2010 One of the first times I've seen a rationale behind the removal of reduc...
- Jimmy Cao (10/40) Oct 03 2010 The Python version:
- Peter Alexander (8/16) Oct 03 2010 If you write it as:
- bearophile (6/8) Oct 03 2010 A standard library is kind of the extension of a language.
- Peter Alexander (3/6) Oct 03 2010 Then we must agree to disagree :-P
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (11/33) Oct 04 2010 Given that you can do the same but shorter in Python, then I'd say
- BCS (7/21) Oct 04 2010 Bingo. While it might be possible to make a single line of code in propo...
- Simen kjaeraas (58/61) Oct 03 2010 Probably this:
- bearophile (5/8) Oct 03 2010 Summing an iterable is a really common operation, and using reduce is no...
- Simen kjaeraas (33/62) Oct 03 2010 Sorry, code was wrong. Update:
- Andrei Alexandrescu (6/78) Oct 03 2010 I wonder to what extent this improves
- Peter Alexander (4/15) Oct 03 2010 It would be nice if we could just write:
- Simen kjaeraas (6/9) Oct 03 2010 Mostly because it isn't implemented yet, I think. Well, it is for arrays...
- Simen kjaeraas (11/19) Oct 03 2010 In my opinion, it improves it by looking more like math language (with
- Walter Bright (3/6) Oct 03 2010 This can be defined instead as:
- Peter Alexander (21/23) Oct 03 2010 But then you have to write:
- Walter Bright (12/21) Oct 04 2010 This works:
- Peter Alexander (5/16) Oct 04 2010 But then this doesn't:
- Walter Bright (2/22) Oct 04 2010
- Walter Bright (14/46) Oct 03 2010 This is quite deliberate on my part, and I'm glad it piqued your interes...
- retard (7/42) Oct 03 2010 Is this also true for Haskell/OCaml/SML/Erlang/Clojure/Lisp programmers?...
- Daniel Gibson (3/13) Oct 03 2010 If you're gonna use the "functional features" in D you'll want to
- Walter Bright (11/17) Oct 03 2010 If they're already using D, they don't have to learn a totally new gramm...
- Jonathan M Davis (3/8) Oct 03 2010 Oh course it's sad. That 90% should be using D instead. ;)
- Michel Fortin (8/13) Oct 03 2010 But isn't postblit used only when doing a copy? I think the last word
- Walter Bright (6/18) Oct 03 2010 Right.
- Max Samukha (17/19) Oct 04 2010 Structs are ok. Classes are not. Do you really want to forbid this use c...
- Simen kjaeraas (5/27) Oct 04 2010 I don't see how that is incompatible with what Walter said. Of course
- Max Samukha (4/34) Oct 04 2010 He said "movable using memcpy()". He didn't say anything about adjusting...
- Walter Bright (4/7) Oct 04 2010 The moving GC would adjust the pointers, but the memcpy() means that oth...
- Max Samukha (2/9) Oct 05 2010 Now I see what you meant. Thanks for the explanation.
- Walter Bright (4/7) Oct 03 2010 I normally prefer monospaced fonts for code, but using a proportional fo...
- bearophile (9/11) Oct 03 2010 A reduced test case:
- Walter Bright (2/2) Oct 03 2010 Looks like it hit reddit:
- Gary Whatmore (3/6) Oct 03 2010 Their already criticizing D. We must defend ourselves.
- Gary Whatmore (4/9) Oct 04 2010 http://www.reddit.com/r/programming/comments/dm8n8/the_many_faces_of_d_s...
The slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdf
Oct 03 2010
Interesting, would have loved to be there :) On 3 October 2010 12:28, Walter Bright <newshound2 digitalmars.com> wrote:The slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdf-- // Yours sincerely // Emil 'Skeen' Madsen
Oct 03 2010
Emil Madsen wrote:Interesting, would have loved to be there :)It was actually one of the most fun ones I've done. The audience was very engaging.
Oct 03 2010
Sun, 03 Oct 2010 03:28:09 -0700, Walter Bright wrote:The slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdfOn a side note, I noticed that Walter is still using OpenOffice 2.4 from March 2008. 9 new releases have been announced after that :-) I doubt it has any effect on these slides, but the latest versions might offer better user experience.
Oct 03 2010
On Sunday 03 October 2010 04:01:10 retard wrote:Sun, 03 Oct 2010 03:28:09 -0700, Walter Bright wrote:I just use latex for everything. That way I can use vim. It's much more pleasant that way. - Jonathan M DavisThe slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdfOn a side note, I noticed that Walter is still using OpenOffice 2.4 from March 2008. 9 new releases have been announced after that :-) I doubt it has any effect on these slides, but the latest versions might offer better user experience.
Oct 03 2010
On Sun, 2010-10-03 at 04:40 -0700, Jonathan M Davis wrote: [ . . . ]I just use latex for everything. That way I can use vim. It's much more p=leasant=20that way.Also you can put the material into version control since the source is mergeable -- unlike OOo files. Sadly though LaTeX, even with the beamer package, just isn't up to doing what is easy with OOo. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel russel.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Oct 03 2010
On 10/03/2010 06:57 AM, Russel Winder wrote:On Sun, 2010-10-03 at 04:40 -0700, Jonathan M Davis wrote: [ . . . ]I agree, though I'd also add that the likes of PowerPoint don't make it easy to create good presetations. In PowerPoint et al you are forced to focus on a flat structure that gets you boggled in details. For example it's trivial in PowerPoint to move slides around, which should be rare and odd in a well-conceived presentation. However imparting hierarchy to a presentation is not a feature. Though a text-based presentation engine does not help with structure either, at least it doesn't stay in the way. AndreiI just use latex for everything. That way I can use vim. It's much more pleasant that way.Also you can put the material into version control since the source is mergeable -- unlike OOo files. Sadly though LaTeX, even with the beamer package, just isn't up to doing what is easy with OOo.
Oct 03 2010
Sun, 03 Oct 2010 11:00:43 -0500, Andrei Alexandrescu wrote:On 10/03/2010 06:57 AM, Russel Winder wrote:LyX (lyx.org) provides an alternative with WYSIWYM GUI and TeX export (LyX is very close to LaTeX). The only problem is, embedded TeX code blocks sometimes do not work and sometimes LyX stumbles into parsing bugs or fails to produce valid LaTeX for the backend. If I have to choose between the real PowerPoint and OpenOffice Impress, PowerPoint beats OpenOffice hands down.On Sun, 2010-10-03 at 04:40 -0700, Jonathan M Davis wrote: [ . . . ]I agree, though I'd also add that the likes of PowerPoint don't make it easy to create good presetations. In PowerPoint et al you are forced to focus on a flat structure that gets you boggled in details. For example it's trivial in PowerPoint to move slides around, which should be rare and odd in a well-conceived presentation. However imparting hierarchy to a presentation is not a feature. Though a text-based presentation engine does not help with structure either, at least it doesn't stay in the way.I just use latex for everything. That way I can use vim. It's much more pleasant that way.Also you can put the material into version control since the source is mergeable -- unlike OOo files. Sadly though LaTeX, even with the beamer package, just isn't up to doing what is easy with OOo.
Oct 03 2010
retard wrote:Sun, 03 Oct 2010 11:00:43 -0500, Andrei Alexandrescu wrote:I have good experience with making a presentation with Lyx, even starting with almost zero knowledge of Latex. Some things with beamer you get for free are more cumbersome to do with PP / Impress.On 10/03/2010 06:57 AM, Russel Winder wrote:LyX (lyx.org) provides an alternative with WYSIWYM GUI and TeX export (LyX is very close to LaTeX). The only problem is, embedded TeX code blocks sometimes do not work and sometimes LyX stumbles into parsing bugs or fails to produce valid LaTeX for the backend. If I have to choose between the real PowerPoint and OpenOffice Impress, PowerPoint beats OpenOffice hands down.On Sun, 2010-10-03 at 04:40 -0700, Jonathan M Davis wrote: [ . . . ]I agree, though I'd also add that the likes of PowerPoint don't make it easy to create good presetations. In PowerPoint et al you are forced to focus on a flat structure that gets you boggled in details. For example it's trivial in PowerPoint to move slides around, which should be rare and odd in a well-conceived presentation. However imparting hierarchy to a presentation is not a feature. Though a text-based presentation engine does not help with structure either, at least it doesn't stay in the way.I just use latex for everything. That way I can use vim. It's much more pleasant that way.Also you can put the material into version control since the source is mergeable -- unlike OOo files. Sadly though LaTeX, even with the beamer package, just isn't up to doing what is easy with OOo.
Oct 03 2010
On 3/10/2010 10:01 PM, retard wrote:Sun, 03 Oct 2010 03:28:09 -0700, Walter Bright wrote:Ahh, while that is a polite observation, it is not (to me at least) very interesting. What would be more interesting is some indication of interest to take up D as a PL from this (C++) audience***. *** http://www.nwcpp.org/ May I ask Walter if, as coming away from the meeting, you felt that there might be converts (to D) amongst this group? Cheers Justin JohanssonThe slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdfOn a side note, I noticed that Walter is still using OpenOffice 2.4 from March 2008. 9 new releases have been announced after that :-) I doubt it has any effect on these slides, but the latest versions might offer better user experience.
Oct 03 2010
Justin Johansson Wrote:On 3/10/2010 10:01 PM, retard wrote:I bet all democrats and friends of heavier music like me enjoyed it :)Sun, 03 Oct 2010 03:28:09 -0700, Walter Bright wrote:Ahh, while that is a polite observation, it is not (to me at least) very interesting. What would be more interesting is some indication of interest to take up D as a PL from this (C++) audience***. *** http://www.nwcpp.org/ May I ask Walter if, as coming away from the meeting, you felt that there might be converts (to D) amongst this group?The slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdfOn a side note, I noticed that Walter is still using OpenOffice 2.4 from March 2008. 9 new releases have been announced after that :-) I doubt it has any effect on these slides, but the latest versions might offer better user experience.
Oct 03 2010
Justin Johansson wrote:May I ask Walter if, as coming away from the meeting, you felt that there might be converts (to D) amongst this group?I can say it was a very friendly and engaging audience, and they asked good questions.
Oct 03 2010
On 4/10/2010 6:35 AM, Walter Bright wrote:Justin Johansson wrote:Congrats. Sounds like speaker and audience alike enjoyed the talk.May I ask Walter if, as coming away from the meeting, you felt that there might be converts (to D) amongst this group?I can say it was a very friendly and engaging audience, and they asked good questions.
Oct 04 2010
Justin Johansson wrote:On 4/10/2010 6:35 AM, Walter Bright wrote:Intriguingly, the audience showed a lot of interest in D's scripting capabilities (thanks, Andrei!).Justin Johansson wrote:Congrats. Sounds like speaker and audience alike enjoyed the talk.May I ask Walter if, as coming away from the meeting, you felt that there might be converts (to D) amongst this group?I can say it was a very friendly and engaging audience, and they asked good questions.
Oct 04 2010
retard wrote:On a side note, I noticed that Walter is still using OpenOffice 2.4 from March 2008. 9 new releases have been announced after that :-) I doubt it has any effect on these slides, but the latest versions might offer better user experience.The last time I upgraded Ubuntu it destroyed all the installed software, all my vmware subsystems, etc. I had to wipe the hard disk, reformat, and start over. Since then, I've been reluctant to upgrade.
Oct 03 2010
"retard" <re tard.com.invalid> wrote in message news:i89npm$tst$2 digitalmars.com...Sun, 03 Oct 2010 03:28:09 -0700, Walter Bright wrote:Heh, I'm still using OpenOffice 1.1 just because it doesn't have those terribly ugly menubar/toolbar gradients (an old screenshot I used to demonstrate it to the boneheaded OOO developers who tried to tell me that it was just my system and not OpenOffice: http://www.semitwist.com/download/OpenOfficeVisualCompare.jpg They ended up ignoring it.) I know that's a really trivial reason, but I haven't had any problems with 1.1, so I've had no real reason to upgrade either.The slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdfOn a side note, I noticed that Walter is still using OpenOffice 2.4 from March 2008. 9 new releases have been announced after that :-) I doubt it has any effect on these slides, but the latest versions might offer better user experience.
Oct 03 2010
Sun, 03 Oct 2010 16:46:19 -0400, Nick Sabalausky wrote:"retard" <re tard.com.invalid> wrote in message news:i89npm$tst$2 digitalmars.com...This is what OpenOffice 3.2.1 looks like [on Linux] (sorry for having a bit larger resolution): http://www.freeimagehosting.net/image.php?72b470923c.png Last time I heard, the next OpenOffice/LibreOffice might switch to the ribbon style, though. The more recent versions have lots of new features. For example compatibility with the unholy office xml formats is much better.Sun, 03 Oct 2010 03:28:09 -0700, Walter Bright wrote:Heh, I'm still using OpenOffice 1.1 just because it doesn't have those terribly ugly menubar/toolbar gradients (an old screenshot I used to demonstrate it to the boneheaded OOO developers who tried to tell me that it was just my system and not OpenOffice: http://www.semitwist.com/download/OpenOfficeVisualCompare.jpg They ended up ignoring it.) I know that's a really trivial reason, but I haven't had any problems with 1.1, so I've had no real reason to upgrade either.The slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdfOn a side note, I noticed that Walter is still using OpenOffice 2.4 from March 2008. 9 new releases have been announced after that :-) I doubt it has any effect on these slides, but the latest versions might offer better user experience.
Oct 03 2010
Heh, I'm still using OpenOffice 1.1 just because it doesn't have those terribly ugly menubar/toolbar gradients (an old screenshot I used to demonstrate it to the boneheaded OOO developers who tried to tell me that it was just my system and not OpenOffice: http://www.semitwist.com/download/OpenOfficeVisualCompare.jpg They ended up ignoring it.) I know that's a really trivial reason, but I haven't had any problems with 1.1, so I've had no real reason to upgrade either.Nick OpenOffice (at least version 3.2 that I have on my Ubuntu box), picks up the menu and toolbar styling from your Desktop theme. And I am using the Gnome Desktop. Well, I am also trying to tell you that it might be just your system :-) Regards - Puneet
Oct 03 2010
Walter Bright:The slides for my Sep. 15 talk at NWCPP: http://nwcpp.org/images/stories/nwcpp-2010-09.pdfThank you for the slides. Few comments: Page 10, and in other pages I'd like a non-proportional font for the code, because I find it a little more readable (even better if it's colorized, there are online tools able to produce colorized HTML from D1 code too). Page 19:Unlike C++, values can be moved in memory Postblit is used to “adjust” things after a move<OK, so a moving GC needs to call the Postblit each time it moves a struct. Page 20: is that functional? It even contains a mutable "sum" value. It may be seen as kind-of-functional. A more functional style is to use a reduce (fold) there, from std.algorithm. Page 30: that little concurrent test program gives me an error: ...\dmd\src\phobos\std\typecons.d(336): Error: no property 'length' for type 'immutable(char)' This is the part of typecons.d that gives the error: static string injectNamedFields() { string decl = ""; foreach (i, name; staticMap!(extractName, fieldSpecs)) { auto field = text("Identity!(field[", i, "])"); auto numbered = text("_", i); decl ~= text("alias ", field, " ", numbered, ";"); if (name.length != 0) // line 336 { decl ~= text("alias ", numbered, " ", name, ";"); } } return decl; } Bye, bearophile
Oct 03 2010
On Sun, 2010-10-03 at 09:59 -0400, bearophile wrote: [ . . . ]Page 10, and in other pages I'd like a non-proportional font for the code, because I find it a little more readable (even better if it's colorized, there are online tools able to produce colorized HTML from D1 code too).I continue to be intrigued by people who believe that code, unlike text, is more readable in a monospace font. Personally I think monospace fonts make code unreadable, I always prefer proportional fonts for code. Currently I use Ocean Sans MT. Colourized though, I agree, makes things more readable -- as long as the colourization theme matches the semantics of the code fragment, obviously. [ . . . ]Page 20: is that functional? It even contains a mutable "sum" value. It may be seen as kind-of-functional. A more functional style is to use a reduce (fold) there, from std.algorithm.I agree this is a weird sort of an example of "functional". sum_of_squares as a function has no external side-effects (though clearly the iteration has a side effect internally) and is referentially transparent. So as a thing that can be used as a "functional programming" function it is fine, its implementation is though very much imperative programming -- at its worst ;-) Given an imperative language with no tail recursion capability then one has to declare a non-functional floor even when doing functional style programming. In effect the execution graph has to be allowed to have leaqf nodes that are implemented imperatively. Coming from a Pythonic realization of these ideas, list comprehensions seems to be the best way out of this sort of thing, so instead of: def sumOfSquares ( sequence ) : sum =3D 0.0 for item in sequence : sum +=3D item * item return sum it is better to write: def sumOfSquares ( sequence ) : return sum ( [ item * item for item in sequence ] ) =20 So the question is whether there is an idiomatic D version of this. [ . . . ] --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel russel.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Oct 03 2010
Russel Winder:I continue to be intrigued by people who believe that code, unlike text, is more readable in a monospace font. Personally I think monospace fonts make code unreadable,<I guess it's a matter of personal preferences. But non-proportional fonts have two advantages: - it's easy to count spaces, vertical alignments and so on; - often if the non-proportional is well designed it's simpler to tell apart glyphs like Jl1j0oO;:.Given an imperative language with no tail recursion capabilityBoth DMD and LDC (and probably GDC too) currently are able to turn some cases of tail recursion to iterative code.def sumOfSquares ( sequence ) : return sum ( [ item * item for item in sequence ] )Since many years and many versions of Python the pythonic way to write that is to use a lazy iterable: def sumOfSquares (sequence): return sum(item * item for item in sequence) I have suggested few times a list/lazy comp syntax for D too, and I have tried to explain why it's a good thing (it helps "chunking" in the mind of the programmer). Bye, bearophile
Oct 03 2010
== Quote from bearophile (bearophileHUGS lycos.com)'s articleSince many years and many versions of Python the pythonic way to write that is to use a lazy iterable: def sumOfSquares (sequence): return sum(item * item for item in sequence) I have suggested few times a list/lazy comp syntax for D too, and I have tried to explain why it's agood thing (it helps "chunking" in the mind of the programmer). Out of curiosity, what syntax did you propose? I definitely agree that lazy range comprehensions would be a Good Thing (tm). That said, the current D way of writing it isn't all that different from Python: return reduce!("a+b")(map!("a*a")(sequence), 0);
Oct 03 2010
Peter Alexander:Out of curiosity, what syntax did you propose?http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=73868That said, the current D way of writing it isn't all that different from Python: return reduce!("a+b")(map!("a*a")(sequence), 0);That's many times worse than the Python syntax. Array/range comprehensions are syntax sugar, their point is to give something clean and readable that helps chunking: http://en.wikipedia.org/wiki/Chunking_%28psychology%29 Bye, bearophile
Oct 03 2010
bearophile Wrote:That's many times worse than the Python syntax. Array/range comprehensions are syntax sugar, their point is to give something clean and readable that helps chunking: http://en.wikipedia.org/wiki/Chunking_%28psychology%29 Bye, bearophileYMMW. Back when I was programming Python I found the array comprehension syntax unreadable, so I always used the map equivalent. It's helpful to realize that the definitions of "clean" and "readable" differ from person to person, and may in fact be the exact opposite between two people. -SiegeLord
Oct 03 2010
SiegeLord:Back when I was programming Python I found the array comprehension syntax unreadable, so I always used the map equivalent.Python devs have introduced list comps only after asking about their "ergonomicity" level to many people. And for most of those people code like this: result1 = [x * x + 5 for x in xrange(10)] result2 = {x: x * x for x in xrange(20)} Allows the programmer to see code purpose better and create higher-level mental chunks than code like: result1 = map(lambda x: x * x + 5, xrange(10)) result2 = {} for x in xrange(20): result2[x] = x * x Bye, bearophile
Oct 03 2010
bearophile wrote:SiegeLord: =20tax unreadable, so I always used the map equivalent.Back when I was programming Python I found the array comprehension syn==20 Python devs have introduced list comps only after asking about their "e=rgonomicity" level to many people. And for most of those people code like= this:=20 result1 =3D [x * x + 5 for x in xrange(10)] result2 =3D {x: x * x for x in xrange(20)} =20 Allows the programmer to see code purpose better and create higher-leve=l mental chunks than code like:=20 result1 =3D map(lambda x: x * x + 5, xrange(10)) result2 =3D {} for x in xrange(20): result2[x] =3D x * x =20Why didn't you write the second like this to keep it functional: result2 =3D dict (map (lambda x: (x, x*x), xrange (20))) Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Oct 03 2010
Jérôme M. Berger:Why didn't you write the second like this to keep it functional: result2 = dict (map (lambda x: (x, x*x), xrange (20)))Because I've never seen people write it that way, and because for me it's less readable than the normal imperative code. Bye, bearophile
Oct 03 2010
bearophile wrote:J=C3=A9r=C3=B4me M. Berger: =20's less readable than the normal imperative code.Why didn't you write the second like this to keep it functional: result2 =3D dict (map (lambda x: (x, x*x), xrange (20)))=20 Because I've never seen people write it that way, and because for me it==20Oh, I agree that it's less readable, but wasn't that your point? After all, the functional list generation with "map" is also less readable than the corresponding imperative code. Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Oct 03 2010
On 10/03/2010 10:37 AM, bearophile wrote:Peter Alexander:This entails there's a way to measure that. How?Out of curiosity, what syntax did you propose?http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=73868That said, the current D way of writing it isn't all that different from Python: return reduce!("a+b")(map!("a*a")(sequence), 0);That's many times worse than the Python syntax.Array/range comprehensions are syntax sugar, their point is to give something clean and readable that helps chunking: http://en.wikipedia.org/wiki/Chunking_%28psychology%29You'd need to bring a pointer to a document that confirms that (and how) array and range comprehensions have helping chunking as their point. I googled for array comprehensions help chunking to no avail. Andrei
Oct 03 2010
Andrei Alexandrescu:Probably the only way good for you is to take a group of programmers and perform some experiments of experimental psychology, similar to the experiments of ergonomics done to find if the design of a car gear shift stick is good enough for most users.This entails there's a way to measure that. How?return reduce!("a+b")(map!("a*a")(sequence), 0);That's many times worse than the Python syntax.You'd need to bring a pointer to a document that confirms that (and how) array and range comprehensions have helping chunking as their point.It's a theory of mine :-) This too needs psychology experiments, but I need a backup life to find the time to perform them. In my code I have seen that I need several tries to catch a correct way to write those reduce!(...)..., while I don't have the same problems in Python. In Python3 they have even removed the built-in reduce (and moved it into the standard library) because practical experience has shown that many newbies and Python programmers find the semantics of reduce() not so easy to understand (like when they read code written by other people). S the usage of reduce() is a bit discouraged in normal Python code. This is also why I have suggested (http://d.puremagic.com/issues/show_bug.cgi?id=4725 ) to add a sum() to Phobos2. Bye, bearophile
Oct 03 2010
== Quote from bearophile (bearophileHUGS lycos.com)'s articleIt's a theory of mine :-) This too needs psychology experiments, but I need a backup life to find thetime to perform them.In my code I have seen that I need several tries to catch a correct way to write those reduce!(...)...,while I don't have the same problems in Python. That's interesting, because I have no trouble at all using reduce/map/filter etc. I think the difference is between top-down thinkers and bottom-up thinkers, but this is just a theory of my own as well :-)
Oct 03 2010
On 10/03/2010 01:24 PM, bearophile wrote:Andrei Alexandrescu:That's not the way for "me", it would be a simple application of the scientific method that could impart credibility to the argument. And it's more similar to the experiments done routinely in software engineering research than in automotive industry.Probably the only way good for you is to take a group of programmers and perform some experiments of experimental psychology, similar to the experiments of ergonomics done to find if the design of a car gear shift stick is good enough for most users.This entails there's a way to measure that. How?return reduce!("a+b")(map!("a*a")(sequence), 0);That's many times worse than the Python syntax.Not labeling it as such hurts the quality of the conversation.You'd need to bring a pointer to a document that confirms that (and how) array and range comprehensions have helping chunking as their point.It's a theory of mine :-)This too needs psychology experiments, but I need a backup life to find the time to perform them.Again, it's a common method in software engineering research. The point is one shouldn't make claims without being able to substantiate them.In my code I have seen that I need several tries to catch a correct way to write those reduce!(...)..., while I don't have the same problems in Python.Alright, there's one user experience. A few more and we can collect some statistics :o).In Python3 they have even removed the built-in reduce (and moved it into the standard library) because practical experience has shown that many newbies and Python programmers find the semantics of reduce() not so easy to understand (like when they read code written by other people).A link to a document that illustrates that motivation would be great. For all I know Python 3 also transformed print from a statement into a function, but for very different reasons.S the usage of reduce() is a bit discouraged in normal Python code. This is also why I have suggested (http://d.puremagic.com/issues/show_bug.cgi?id=4725 ) to add a sum() to Phobos2.Yeah, sum() is probably popular enough to deserve a special case. Anyway, I just changed filter: http://www.dsource.org/projects/phobos/changeset/2081 in ways that it should allow: assert(equal(compose!(map!"2 * a", filter!"a & 1")([1,2,3,4,5]), [2,6,10])); assert(equal(pipe!(filter!"a & 1", map!"2 * a")([1,2,3,4,5]), [2,6,10])); both of which group operations in separation from their inputs. Andrei
Oct 03 2010
Andrei:Not labeling it as such hurts the quality of the conversation.one shouldn't make claims without being able to substantiate them.You are right, sorry.A link to a document that illustrates that motivation would be great. For all I know Python 3 also transformed print from a statement into a function, but for very different reasons.One of the first times I've seen a rationale behind the removal of reduce() was here, page 4, a text by Guido van Rossum, the Python main designer: http://www.python.org/doc/essays/ppt/regrets/PythonRegrets.pdf* reduce() –nobody uses it, few understand it –a for loop is clearer & (usually) faster < Later this was the answer, by Guido still: http://www.artima.com/forums/flat.jsp?forum=106&thread=211200Q. If you're killing reduce(), why are you keeping map() and filter()? A. I'm not killing reduce() because I hate functional programming; I'm killing it because almost all code using reduce() is less readable than the same thing written out using a for loop and an accumulator variable. On the other hand, map() and filter() are often useful and when used with a pre-existing function (e.g. a built-in) they are clearer than a list comprehension or generator expression. (Don't use these with a lambda though; then a list comprehension is clearer and faster.)< I have used reduce() only a 2 or 3 times in some years of Python usage. Most other times a sum() or product() was enough. A simple implementation of product() using reduce():362880import operator product = lambda seq: reduce(operator.mul, seq) product(xrange(1, 10))Yeah, sum() is probably popular enough to deserve a special case.Good :-) Bye and thank you, bearophile
Oct 03 2010
The Python version: sum(item * item for item in sequence) can be translated to English as: "Sum of (item * item) foreach item in sequence" While the D version: reduce!("a+b")(map!("a*a")(sequence), 0); looks to me like: Reduce! a plus b map! a times a (sequence) (and a random 0 here). On Sun, Oct 3, 2010 at 12:59 PM, Andrei Alexandrescu < SeeWebsiteForEmail erdani.org> wrote:On 10/03/2010 10:37 AM, bearophile wrote:Peter Alexander: Out of curiosity, what syntax did you propose?This entails there's a way to measure that. How? Array/range comprehensions are syntax sugar, their point is to givehttp://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=73868 That said, the current D way of writing it isn't all that differentfrom Python: return reduce!("a+b")(map!("a*a")(sequence), 0);That's many times worse than the Python syntax.something clean and readable that helps chunking: http://en.wikipedia.org/wiki/Chunking_%28psychology%29You'd need to bring a pointer to a document that confirms that (and how) array and range comprehensions have helping chunking as their point. I googled for array comprehensions help chunking to no avail. Andrei
Oct 03 2010
== Quote from Jimmy Cao (jcao219 gmail.com)'s articleThe Python version: sum(item * item for item in sequence) can be translated to English as: "Sum of (item * item) foreach item in sequence" While the D version: reduce!("a+b")(map!("a*a")(sequence), 0); looks to me like: Reduce! a plus b map! a times a (sequence) (and a random 0 here).If you write it as: auto sum(Range)(Range r) { return reduce!("a+b")(r, 0); } alias unaryFun("a*a") square; alias map!(square) squares; return sum(squares(sequence)); then it looks better than Python :-) Or can we only judge a language by what's in its standard library?
Oct 03 2010
Peter Alexander:then it looks better than Python :-)No, it doesn't, at all :-)Or can we only judge a language by what's in its standard library?A standard library is kind of the extension of a language. And sum() and list comps are built-in in Python. Bye, bearophile
Oct 03 2010
== Quote from bearophile (bearophileHUGS lycos.com)'s articlePeter Alexander:Then we must agree to disagree :-P But at least we can take this as evidence that different people have quite different views on this matter.then it looks better than Python :-)No, it doesn't, at all :-)
Oct 03 2010
Peter Alexander wrote:=3D=3D Quote from Jimmy Cao (jcao219 gmail.com)'s articleGiven that you can do the same but shorter in Python, then I'd say yes. Especially since even when choosing an obscure way to define "squares" it's still more readable... squares =3D lambda s: type (s) (x*x for x in seq) return sum (squares (sequence)) Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.frThe Python version: sum(item * item for item in sequence) can be translated to English as: "Sum of (item * item) foreach item in sequence" While the D version: reduce!("a+b")(map!("a*a")(sequence), 0); looks to me like: Reduce! a plus b map! a times a (sequence) (and a random 0 here).=20 If you write it as: =20 auto sum(Range)(Range r) { return reduce!("a+b")(r, 0); } alias unaryFun("a*a") square; alias map!(square) squares; =20 return sum(squares(sequence)); =20 then it looks better than Python :-) =20 Or can we only judge a language by what's in its standard library? =20
Oct 04 2010
Hello bearophile,Russel Winder:Bingo. While it might be possible to make a single line of code in proportional font as readable as in mon-space, as soon as you have more than one line you can't make things line up, and I want that way to often to give it up.I continue to be intrigued by people who believe that code, unlike text, is more readable in a monospace font. Personally I think monospace fonts make code unreadable,<I guess it's a matter of personal preferences. But non-proportional fonts have two advantages: - it's easy to count spaces, vertical alignments and so on;def sumOfSquares (sequence): return sum(item * item for item in sequence) I have suggested few times a list/lazy comp syntax for D too, and I have tried to explain why it's a good thing (it helps "chunking" in the mind of the programmer).I believe that you can do it via map/reduce. -- ... <IXOYE><
Oct 04 2010
Russel Winder <russel russel.org.uk> wrote:def sumOfSquares ( sequence ) : return sum ( [ item * item for item in sequence ] ) So the question is whether there is an idiomatic D version of this.Probably this: auto sum( R )( R range ) { return reduce!"a+b"( 0, range ); } auto sumOfSquares( R )( R range ) { return sum( map!"a*a"( range ) ); } I have written an implementation of list comprehensions for D, but it is not perfect. Usage example: ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ) "2 * a" and "a & 1" may be replaced by any callable or a string mixin, just like functions in std.algorithm. [1,2,3,4,5] may be replaced with any range. This is actually two parts, so the following are also allowed usages: ( list!"2 * a" | [1,2,3] ) ( [1,2,3] & where!"a & 1" ) Using this, the solution to the above would be: auto sum( R )( R range ) { return reduce!"a+b"( 0, range ); } auto sumOfSquares( R )( R range ) { return sum( list!"a*a" | range ); } //////////////////////////////////////////////////////////////// module listcomp; import std.algorithm; import std.range; import std.array; struct List( alias pred ) { auto opBinary( string op : "|", Range )( Range other ) { return map!pred(other); } } struct Where( alias pred ) { auto opBinaryRight( string op : "&", R )( R range ) { return filter!pred(range); } } property whereImpl!pred where( alias pred )( ) { Where!pred result; return result; } property listImpl!pred list( alias pred )( ) { List!pred result; return result; } unittest { assert( equal( ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ), [2,6,10] ) ); assert( equal( ( list!"2 * a" | [1,2,3] ), [2,4,6] ) ); } -- Simen
Oct 03 2010
Simen kjaeraas:auto sum( R )( R range ) { return reduce!"a+b"( 0, range ); }Summing an iterable is a really common operation, and using reduce is not an intuitive&easy thing. So I think a sum() needs to be added to std.algorithm, this was my enhancement request for it: http://d.puremagic.com/issues/show_bug.cgi?id=4725 Bye, bearophile
Oct 03 2010
Simen kjaeraas <simen.kjaras gmail.com> wrote:Russel Winder <russel russel.org.uk> wrote:Sorry, code was wrong. Update: module listcomp; import std.algorithm; import std.range; import std.array; struct List( alias pred ) { auto opBinary( string op : "|", Range )( Range other ) { return map!pred(other); } } struct Where( alias pred ) { auto opBinaryRight( string op : "&", R )( R range ) { return filter!pred(range); } } property auto where( alias pred )( ) { Where!pred result; return result; } property auto list( alias pred )( ) { List!pred result; return result; } unittest { assert( equal( ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ), [2,6,10] ) ); assert( equal( ( list!"2 * a" | [1,2,3] ), [2,4,6] ) ); } -- Simendef sumOfSquares ( sequence ) : return sum ( [ item * item for item in sequence ] ) So the question is whether there is an idiomatic D version of this.Probably this: auto sum( R )( R range ) { return reduce!"a+b"( 0, range ); } auto sumOfSquares( R )( R range ) { return sum( map!"a*a"( range ) ); } I have written an implementation of list comprehensions for D, but it is not perfect. Usage example: ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ) "2 * a" and "a & 1" may be replaced by any callable or a string mixin, just like functions in std.algorithm. [1,2,3,4,5] may be replaced with any range. This is actually two parts, so the following are also allowed usages: ( list!"2 * a" | [1,2,3] ) ( [1,2,3] & where!"a & 1" ) Using this, the solution to the above would be: auto sum( R )( R range ) { return reduce!"a+b"( 0, range ); } auto sumOfSquares( R )( R range ) { return sum( list!"a*a" | range ); }
Oct 03 2010
On 10/03/2010 10:21 AM, Simen kjaeraas wrote:Simen kjaeraas <simen.kjaras gmail.com> wrote:I wonder to what extent this improves assert(equal(map!"2 * a"(filter!"a & 1"([1,2,3,4,5])), [2,6,10])); One thing that's nicer with comprehensions is that you save a bit on nested parens. AndreiRussel Winder <russel russel.org.uk> wrote:Sorry, code was wrong. Update: module listcomp; import std.algorithm; import std.range; import std.array; struct List( alias pred ) { auto opBinary( string op : "|", Range )( Range other ) { return map!pred(other); } } struct Where( alias pred ) { auto opBinaryRight( string op : "&", R )( R range ) { return filter!pred(range); } } property auto where( alias pred )( ) { Where!pred result; return result; } property auto list( alias pred )( ) { List!pred result; return result; } unittest { assert( equal( ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ), [2,6,10] ) ); assert( equal( ( list!"2 * a" | [1,2,3] ), [2,4,6] ) ); }def sumOfSquares ( sequence ) : return sum ( [ item * item for item in sequence ] ) So the question is whether there is an idiomatic D version of this.Probably this: auto sum( R )( R range ) { return reduce!"a+b"( 0, range ); } auto sumOfSquares( R )( R range ) { return sum( map!"a*a"( range ) ); } I have written an implementation of list comprehensions for D, but it is not perfect. Usage example: ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ) "2 * a" and "a & 1" may be replaced by any callable or a string mixin, just like functions in std.algorithm. [1,2,3,4,5] may be replaced with any range. This is actually two parts, so the following are also allowed usages: ( list!"2 * a" | [1,2,3] ) ( [1,2,3] & where!"a & 1" ) Using this, the solution to the above would be: auto sum( R )( R range ) { return reduce!"a+b"( 0, range ); } auto sumOfSquares( R )( R range ) { return sum( list!"a*a" | range ); }
Oct 03 2010
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s articleOn 10/03/2010 10:21 AM, Simen kjaeraas wrote:It would be nice if we could just write: assert(equal(iota(1,6).filter!("a&1").map!("2*a"), [2,6,10])); Incidentally, why doesn't the uniform function call syntax allow this?unittest { assert( equal( ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ), [2,6,10] ) ); assert( equal( ( list!"2 * a" | [1,2,3] ), [2,4,6] ) ); }I wonder to what extent this improves assert(equal(map!"2 * a"(filter!"a & 1"([1,2,3,4,5])), [2,6,10])); One thing that's nicer with comprehensions is that you save a bit on nested parens. Andrei
Oct 03 2010
Peter Alexander <peter.alexander.au gmail.com> wrote:It would be nice if we could just write: assert(equal(iota(1,6).filter!("a&1").map!("2*a"), [2,6,10])); Incidentally, why doesn't the uniform function call syntax allow this?Mostly because it isn't implemented yet, I think. Well, it is for arrays, but not for any other type, like the lazier ranges returned from iota, filter and map. -- Simen
Oct 03 2010
Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:0]assert( equal( ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ), [2,6,1=) ); assert( equal( ( list!"2 * a" | [1,2,3] ), [2,4,6] ) ); }I wonder to what extent this improves assert(equal(map!"2 * a"(filter!"a & 1"([1,2,3,4,5])), [2,6,10])); One thing that's nicer with comprehensions is that you save a bit on =nested parens.In my opinion, it improves it by looking more like math language (with which I am familiar, but this is of course a subjective measure): ( list!"2 * a" | [ 1, 2, 3, 4, 5 ] & where!"a & 1" ) vs { 2 * a | a =E2=88=88 [ 1, 2, 3, 4, 5 ], a & 1 !=3D 0 } I also feel it is less cluttered and 'flows' better than your example, but this may very well be the same issue as above. -- = Simen
Oct 03 2010
Simen kjaeraas wrote:auto sum( R )( R range ) { return reduce!"a+b"( 0, range ); }This can be defined instead as: alias reduce!"a+b" sum;
Oct 03 2010
== Quote from Walter Bright (newshound2 digitalmars.com)'s articleThis can be defined instead as: alias reduce!"a+b" sum;But then you have to write: sum(sequence, 0) which is very unintuitive. Haskell has foldl1 and foldr1 in addition to foldl and foldr, which partially take care of this issue (by assuming a non-zero length list), but this is not ideal as it's perfectly reasonable to expect a sum of a zero-length range of integers to be 0. In an ideal world, we would be able to define reduce something like: auto reduce(alias Func, Range)(Range range, ElementType!Range init = Identity!(Func, ElementType!Range)) where Identity!("a+b", int) = 0 Identity!("a*b", int) = 1 Identity!("a~b", char[]) = ""; etc. However, what if people wrote reduce!((a, b) { return a+b; })(...) instead? There's no way you could easily relate the two; you would have to try and equate the expression trees of the functions, which I imagine would be no easy task, and even then you have to figure out a common syntax for Identity... Actually, I'm now curious as to how Andrei plans on adding sum to the standard library in a way that supports all summable types. Simply using 0 as the initialiser is incorrect, as it won't work for vectors or matrices, and requiring the user to specify the 0 (for ints) seems unacceptable in my opinion.
Oct 03 2010
Peter Alexander wrote:== Quote from Walter Bright (newshound2 digitalmars.com)'s articleThis works: import std.stdio; import std.algorithm; alias reduce!"a+b" sum; auto sumOfSquares( R )( R range ) { return sum( map!"a*a"( range ) ); } void main() { writeln(sumOfSquares([1,2,3])); }This can be defined instead as: alias reduce!"a+b" sum;But then you have to write: sum(sequence, 0) which is very unintuitive.
Oct 04 2010
== Quote from Walter Bright (newshound2 digitalmars.com)'s articleThis works: import std.stdio; import std.algorithm; alias reduce!"a+b" sum; auto sumOfSquares( R )( R range ) { return sum( map!"a*a"( range ) ); } void main() { writeln(sumOfSquares([1,2,3])); }But then this doesn't: int[] xs = []; writeln(sum(xs)); but mathematically the sum is well-defined as 0 (and the product as 1).
Oct 04 2010
Peter Alexander wrote:== Quote from Walter Bright (newshound2 digitalmars.com)'s articleDarn!This works: import std.stdio; import std.algorithm; alias reduce!"a+b" sum; auto sumOfSquares( R )( R range ) { return sum( map!"a*a"( range ) ); } void main() { writeln(sumOfSquares([1,2,3])); }But then this doesn't:int[] xs = []; writeln(sum(xs)); but mathematically the sum is well-defined as 0 (and the product as 1).
Oct 04 2010
Russel Winder wrote:On Sun, 2010-10-03 at 09:59 -0400, bearophile wrote:This is quite deliberate on my part, and I'm glad it piqued your interest. D's support for functional programming is NOT about all data being immutable. It is about being able to draw a circle around a block of code (i.e. a function) and saying that "THIS block of code has no side effects." If it modifies variables internally that is of no import if those modifications are not visible outside of that block. This is, in my not so humble opinion, of great value in that one does NOT have to rethink one's approach to coding in order to gain the advantages of functional programming. I.e. one can write a normal loop such as the sum one, rather than trying to figure out list comprehensions and tail recursion. It's like what's wrong with C++ metaprogramming - you have to learn a whole new language. D metaprogramming can be done using ordinary D functions. Nothing new to learn.Page 20: is that functional? It even contains a mutable "sum" value. It may be seen as kind-of-functional. A more functional style is to use a reduce (fold) there, from std.algorithm.I agree this is a weird sort of an example of "functional". sum_of_squares as a function has no external side-effects (though clearly the iteration has a side effect internally) and is referentially transparent. So as a thing that can be used as a "functional programming" function it is fine, its implementation is though very much imperative programming -- at its worst ;-) Given an imperative language with no tail recursion capability then one has to declare a non-functional floor even when doing functional style programming. In effect the execution graph has to be allowed to have leaqf nodes that are implemented imperatively. Coming from a Pythonic realization of these ideas, list comprehensions seems to be the best way out of this sort of thing, so instead of: def sumOfSquares ( sequence ) : sum = 0.0 for item in sequence : sum += item * item return sum it is better to write: def sumOfSquares ( sequence ) : return sum ( [ item * item for item in sequence ] ) So the question is whether there is an idiomatic D version of this.
Oct 03 2010
Sun, 03 Oct 2010 12:43:07 -0700, Walter Bright wrote:Russel Winder wrote:Is this also true for Haskell/OCaml/SML/Erlang/Clojure/Lisp programmers? Nothing new to learn when using the "functional" features of D? Does TCO work well? Other common optimizations such as common deforestation techniques? The sad fact is, there's no need to learn new stuff ONLY when one comes from C/C++. Users of every other language have very much to learn. Not necessarily in a good way.On Sun, 2010-10-03 at 09:59 -0400, bearophile wrote:This is quite deliberate on my part, and I'm glad it piqued your interest. D's support for functional programming is NOT about all data being immutable. It is about being able to draw a circle around a block of code (i.e. a function) and saying that "THIS block of code has no side effects." If it modifies variables internally that is of no import if those modifications are not visible outside of that block. This is, in my not so humble opinion, of great value in that one does NOT have to rethink one's approach to coding in order to gain the advantages of functional programming. I.e. one can write a normal loop such as the sum one, rather than trying to figure out list comprehensions and tail recursion. It's like what's wrong with C++ metaprogramming - you have to learn a whole new language. D metaprogramming can be done using ordinary D functions. Nothing new to learn.Page 20: is that functional? It even contains a mutable "sum" value. It may be seen as kind-of-functional. A more functional style is to use a reduce (fold) there, from std.algorithm.I agree this is a weird sort of an example of "functional". sum_of_squares as a function has no external side-effects (though clearly the iteration has a side effect internally) and is referentially transparent. So as a thing that can be used as a "functional programming" function it is fine, its implementation is though very much imperative programming -- at its worst ;-) Given an imperative language with no tail recursion capability then one has to declare a non-functional floor even when doing functional style programming. In effect the execution graph has to be allowed to have leaqf nodes that are implemented imperatively.
Oct 03 2010
On Mon, Oct 4, 2010 at 12:44 AM, retard <re tard.com.invalid> wrote:Sun, 03 Oct 2010 12:43:07 -0700, Walter Bright wrote:If you're gonna use the "functional features" in D you'll want to learn "normal" D and its syntax anyway, so what's your point?It's like what's wrong with C++ metaprogramming - you have to learn a whole new language. D metaprogramming can be done using ordinary D functions. Nothing new to learn.Is this also true for Haskell/OCaml/SML/Erlang/Clojure/Lisp programmers? Nothing new to learn when using the "functional" features of D? Does TCO work well? Other common optimizations such as common deforestation techniques? The sad fact is, there's no need to learn new stuff ONLY when one comes from C/C++. Users of every other language have very much to learn. Not necessarily in a good way.
Oct 03 2010
retard wrote:Is this also true for Haskell/OCaml/SML/Erlang/Clojure/Lisp programmers? Nothing new to learn when using the "functional" features of D? Does TCO work well? Other common optimizations such as common deforestation techniques? The sad fact is, there's no need to learn new stuff ONLY when one comes from C/C++. Users of every other language have very much to learn. Not necessarily in a good way.If they're already using D, they don't have to learn a totally new grammar/style when deciding to use a functional style. Really, *why* force people to rewrite their loops to use tail recursion? It's a giant turn-off, and completely unnecessary. And D does do tail call elimination, if you *want* to write your code that way. The point is, D doesn't require it if you don't like it. I also think you're way, way overstating your case when you argue that the only language D is grammatically similar to is C and C++. It's also similar to Java covering 90+% of the programmers out there. That's a feature, not something sad.
Oct 03 2010
On Sunday 03 October 2010 16:05:19 Walter Bright wrote:I also think you're way, way overstating your case when you argue that the only language D is grammatically similar to is C and C++. It's also a feature, not something sad.Oh course it's sad. That 90% should be using D instead. ;) - Jonathan M Davis
Oct 03 2010
On 2010-10-03 09:59:16 -0400, bearophile <bearophileHUGS lycos.com> said:Page 19:But isn't postblit used only when doing a copy? I think the last word in the quote should be "copy", not "move". So a moving GC does not have to call postblit. -- Michel Fortin michel.fortin michelf.com http://michelf.com/Unlike C++, values can be moved in memory Postblit is used to “adjust” things after a move<OK, so a moving GC needs to call the Postblit each time it moves a struct.
Oct 03 2010
Michel Fortin wrote:On 2010-10-03 09:59:16 -0400, bearophile <bearophileHUGS lycos.com> said:Right. In D, all struct (and class) instances are, by definition, movable using memcpy(). The advantage is not just enabling a moving GC, but it also enables a whole host of optimizations that are not possible in C++. C++0x tries to address this problem with rvalue references and moving constructors.Page 19:But isn't postblit used only when doing a copy? I think the last word in the quote should be "copy", not "move". So a moving GC does not have to call postblit.Unlike C++, values can be moved in memory Postblit is used to “adjust” things after a move<OK, so a moving GC needs to call the Postblit each time it moves a struct.
Oct 03 2010
On 10/03/2010 10:47 PM, Walter Bright wrote:In D, all struct (and class) instances are, by definition, movable using memcpy().Structs are ok. Classes are not. Do you really want to forbid this use case: class A { private A _parent; private A[] _children; this(A parent) { if (parent !is null) { _parent = parent; _parent._children ~= this; } } } auto parent = new A; auto child = new A(parent); ?
Oct 04 2010
Max Samukha <spambox d-coding.com> wrote:On 10/03/2010 10:47 PM, Walter Bright wrote:I don't see how that is incompatible with what Walter said. Of course one would need to update pointers to the moved classes. -- SimenIn D, all struct (and class) instances are, by definition, movable using memcpy().Structs are ok. Classes are not. Do you really want to forbid this use case: class A { private A _parent; private A[] _children; this(A parent) { if (parent !is null) { _parent = parent; _parent._children ~= this; } } } auto parent = new A; auto child = new A(parent); ?
Oct 04 2010
On 10/04/2010 10:47 PM, Simen kjaeraas wrote:Max Samukha <spambox d-coding.com> wrote:He said "movable using memcpy()". He didn't say anything about adjusting pointers. A moving GC should and will adjust pointers, but I don't see how the memcpy() is relevant here.On 10/03/2010 10:47 PM, Walter Bright wrote:I don't see how that is incompatible with what Walter said. Of course one would need to update pointers to the moved classes.In D, all struct (and class) instances are, by definition, movable using memcpy().Structs are ok. Classes are not. Do you really want to forbid this use case: class A { private A _parent; private A[] _children; this(A parent) { if (parent !is null) { _parent = parent; _parent._children ~= this; } } } auto parent = new A; auto child = new A(parent); ?
Oct 04 2010
Max Samukha wrote:He said "movable using memcpy()". He didn't say anything about adjusting pointers. A moving GC should and will adjust pointers, but I don't see how the memcpy() is relevant here.The moving GC would adjust the pointers, but the memcpy() means that other things would not need to be done, such as incrementing counters, all the things that non-trivial copy constructors do.
Oct 04 2010
On 10/05/2010 02:42 AM, Walter Bright wrote:Max Samukha wrote:Now I see what you meant. Thanks for the explanation.He said "movable using memcpy()". He didn't say anything about adjusting pointers. A moving GC should and will adjust pointers, but I don't see how the memcpy() is relevant here.The moving GC would adjust the pointers, but the memcpy() means that other things would not need to be done, such as incrementing counters, all the things that non-trivial copy constructors do.
Oct 05 2010
bearophile wrote:Page 10, and in other pages I'd like a non-proportional font for the code, because I find it a little more readable (even better if it's colorized, there are online tools able to produce colorized HTML from D1 code too).I normally prefer monospaced fonts for code, but using a proportional font here made it easier to fit more code on the slide. Presenting meaningful code on a slide is always a big problem.
Oct 03 2010
Page 30: that little concurrent test program gives me an error: ...\dmd\src\phobos\std\typecons.d(336): Error: no property 'length' for type 'immutable(char)'A reduced test case: import std.concurrency: spawn, send; void foo() {} void main() { foreach (b; [cast(immutable(ubyte)[])[1]]) send(spawn(&foo), b); } Bye, bearophile
Oct 03 2010
Looks like it hit reddit: http://www.reddit.com/r/programming/comments/dm8n8/the_many_faces_of_d_slides_pdf/
Oct 03 2010
Walter Bright Wrote:Looks like it hit reddit: http://www.reddit.com/r/programming/comments/dm8n8/the_many_faces_of_d_slides_pdf/Their already criticizing D. We must defend ourselves. - G.W.
Oct 03 2010
Gary Whatmore Wrote:Walter Bright Wrote:http://www.reddit.com/r/programming/comments/dm8n8/the_many_faces_of_d_slides_pdf/c11d2ie There's a new tough comment that would make our efforts look amateurish if some reddit troll manages to answer it too quickly! - G.W.Looks like it hit reddit: http://www.reddit.com/r/programming/comments/dm8n8/the_many_faces_of_d_slides_pdf/
Oct 04 2010