digitalmars.D - foreach ... else statement
- Brian (5/5) Jan 03 2009 any chance we could see something like pythons else statement on
- bearophile (6/11) Jan 04 2009 It seems everyone has ignored this post, but this isn't a proposal comin...
- Nick Sabalausky (43/57) Jan 04 2009 I had never heard of that before, but it certainly seems like something ...
- Daniel de Kok (10/31) Jan 04 2009 It's a common pattern indeed, but I am not sure if this is the prettiest...
- bearophile (8/11) Jan 04 2009 In my dlibs there are things that allow to do that, but the code is slow...
- BCS (9/24) Jan 04 2009 Wait, that's not the way I would expect else to work. You (and and it wo...
- Denis Koroskin (3/27) Jan 04 2009 Same here, I expected the for/else pair to work similar to if/else, i.e....
- bearophile (10/13) Jan 05 2009 The good thing of "else" is that you don't need a new keyword. But it's ...
- Christopher Wright (7/18) Jan 05 2009 foreach (a, b; aa)
- Don (2/10) Jan 05 2009 Actually Walter loves goto, so DMD copes really well with it.
- bearophile (5/6) Jan 05 2009 When possible it's better to use structured programming and avoid gotos....
- grauzone (34/39) Jan 05 2009 I don't know how relevant this is, but: LLVM uses SSA for registers, and...
- Don (3/54) Jan 05 2009 It's possible to create grotesque configurations of 'goto' which are
- Danny Wilson (6/6) Jan 05 2009 foreach(languageStatement; AllProgrammingLanguages)
- Walter Bright (2/4) Jan 06 2009 For a human, yes. For well-known optimization algorithms, no.
- Brian (9/36) Jan 06 2009 neither of those seem necessary in that example, whats wrong with this:
- Daniel Keep (17/27) Jan 06 2009 A few things I can think of:
- Robert Fraser (2/6) Jan 06 2009 Like "on error resume next"...? ;-P
- Daniel Keep (5/12) Jan 07 2009 While not the best practice, I'd take that any day over Java's insane
- Walter Bright (6/24) Jan 06 2009 I don't know what they're talking about. The D optimizer has no trouble
- Andrei Alexandrescu (9/35) Jan 06 2009 The challenge the paper addresses is constructing the SSA form in one
- Walter Bright (10/18) Jan 06 2009 The two-entry-points-to-a-loop is the essential characteristic of an
- Don (13/22) Jan 05 2009 Structured programming does not mean no gotos. You should really read
- Walter Bright (11/17) Jan 06 2009 The problem with goto is it is easy to get into a human readability
- Benji Smith (2/3) Jan 06 2009 Sign me up!
- BCS (2/4) Jan 06 2009 That would be fun. If I could, I'd show up.
- Sean Kelly (12/26) Jan 07 2009 goto's jump to a label, so it's not like the compiler has no idea where
- Walter Bright (10/15) Jan 07 2009 That's true. I learned the theory taking a compiler construction course
- Bill Baxter (4/19) Jan 07 2009 You mean massless points? Or was that deliberate?
- Andrei Alexandrescu (5/24) Jan 07 2009 I think there were two jokes actually: frictionless brakes (used instead...
- Bill Baxter (6/38) Jan 07 2009 Hmmm. Oh yeh. I'm gonna claim lack of my first morning cup o coffee
- Walter Bright (9/41) Jan 07 2009 School physics problems always start out with "assume there is no
- Andrei Alexandrescu (3/50) Jan 07 2009 Well that should be taken with the traditional grain of salt.
- Bill Baxter (12/71) Jan 07 2009 In my experience just about any academic paper has to be digest with a
- Walter Bright (11/19) Jan 07 2009 Some are better than others, sure. I found out the hard way. But even in...
- Andrei Alexandrescu (6/31) Jan 07 2009 Without saying anything about this paper in particular, quality of
- Walter Bright (2/7) Jan 07 2009 I wondered if anyone would notice that (!). Yes, it's deliberate.
- BCS (2/13) Jan 07 2009 OTOH test often have their share of red harring as well!
- Tomas Lindquist Olsen (3/22) Jan 07 2009 It doesn't :P
- Walter Bright (2/10) Jan 07 2009 That's good to hear!
- Robert Fraser (2/3) Jan 07 2009 *cough* NWCPP *cough*
-
Walter Bright
(4/8)
Jan 07 2009
I'd like to do a paid one
. - BCS (2/16) Jan 08 2009 Video! Video! ?? (for those of us not in Seattle)
- Walter Bright (2/20) Jan 08 2009 See www.nwcpp.org. Ask Bartosz!
- Rioshin an'Harthen (3/4) Jan 08 2009 A net-seminar, please, so that those of us who want to attend actually c...
- Nick Sabalausky (5/10) Jan 08 2009 Yes :). Things like this never make their way out to Cleveland (or anywh...
- Walter Bright (6/18) Jan 08 2009 When we did the Astoria Seminar in 2007, the consistent feedback was
- Nick Sabalausky (6/25) Jan 08 2009 Agreed. Which is why it's dissapointing that any good programming-relate...
any chance we could see something like pythons else statement on iterative loops in D (Might be useful on regular for loops too but not as much)? http://docs.python.org/tutorial/controlflow.html#break-and-continue- statements-and-else-clauses-on-loops
Jan 03 2009
Brian:any chance we could see something like pythons else statement on iterative loops in D (Might be useful on regular for loops too but not as much)? http://docs.python.org/tutorial/controlflow.html#break-and-continue- statements-and-else-clauses-on-loopsIt seems everyone has ignored this post, but this isn't a proposal coming from a clueless alien. Such "else" has a little but true purpose, it helps avoid gotos in some situations, and this in turn may help the optimizer, because I think gotos aren't much well digested by modern C/D compilers. More on the topic: http://leonardo-m.livejournal.com/2008/08/07/ Bye, bearophile
Jan 04 2009
"bearophile" <bearophileHUGS lycos.com> wrote in message news:gjqpt0$1lr5$1 digitalmars.com...Brian:I had never heard of that before, but it certainly seems like something I'd find useful. Any time I'm using for or foreach to find something, I end up having to use some sort of "isFound" flag and check that after the loop. A for...else would be much nicer, for example: bool isFound=false; foreach(char[] key, Foo f; fooAA) { if(f.someFlag && key in barAA && f.someVal > barAA[key].someVal) { isFound = true; break; } } if(!isFound) Stdout.formatln("Missing!"); // vs: foreach(char[] key, Foo f; fooAA) { if(f.someFlag && key in barAA && f.someVal > barAA[key].someVal) break; // found } else Stdout.formatln("Missing!"); This could also be good in conjunction with a couple things that have been discussed for the future of D: - Non-nullable references: In the above example, if I wanted to introduce a "Foo theFoo" to hold the Foo that was found, I could normally eliminate the "isFound" flag, and just encode that information into theFoo as null vs. non-null. But this means that there would be no excess variable that could be eliminated by using for..else (in fact, the *only* change made by using for...else in this case would be "if(!theFoo)" -> "else"). This would make it seem like for...else would be useless in his case, but what if we had non-nullables and you wanted theFoo to be non-nullable? Then you'd have to either reintroduce the "isFound" flag or make theFoo nullable...or use "for...else". - Increased emphasis on functional programming: Eliminating that "isFound" means one less bit (pardon the pun) of mutable state. Granted, it's a very small improvement in any case, and there are certainly plenty of features that would make a far bigger difference, but this would still be nice to have.any chance we could see something like pythons else statement on iterative loops in D (Might be useful on regular for loops too but not as much)? http://docs.python.org/tutorial/controlflow.html#break-and-continue- statements-and-else-clauses-on-loopsIt seems everyone has ignored this post, but this isn't a proposal coming from a clueless alien. Such "else" has a little but true purpose, it helps avoid gotos in some situations, and this in turn may help the optimizer, because I think gotos aren't much well digested by modern C/D compilers. More on the topic: http://leonardo-m.livejournal.com/2008/08/07/ Bye, bearophile
Jan 04 2009
On Sun, 04 Jan 2009 14:01:41 -0500, Nick Sabalausky wrote:bool isFound=false; foreach(char[] key, Foo f; fooAA) { if(f.someFlag && key in barAA && f.someVal > barAA[key].someVal) { isFound = true; break; } } if(!isFound) Stdout.formatln("Missing!"); // vs: foreach(char[] key, Foo f; fooAA) { if(f.someFlag && key in barAA && f.someVal > barAA[key].someVal) break; // found } else Stdout.formatln("Missing!");[...]- Increased emphasis on functional programming: Eliminating that "isFound" means one less bit (pardon the pun) of mutable state.It's a common pattern indeed, but I am not sure if this is the prettiest solution. The slightly awkward idiom in the first example is needed because a for loop is not a function you can return from. Wouldn't it be more adequate to rewrite this as a function/method that takes a predicate? if (range.exists(predicate)) {} or if (exists(range, predicate) {} -- Daniel
Jan 04 2009
Daniel de Kok:Wouldn't it be more adequate to rewrite this as a function/method that takes a predicate?<In my dlibs there are things that allow to do that, but the code is slower. --------------- BCS:Wait, that's not the way I would expect else to work.<See the answer by Guido V. R. himself to that post I have given the URL.I think your expectation would be a good feature but I can't really see else being the right keyword to use.<I agree, with a better naming it can be good feature to have. (I don't like its naming in Python too). Bye, bearophile
Jan 04 2009
Reply to Nick,I had never heard of that before, but it certainly seems like something I'd find useful. Any time I'm using for or foreach to find something, I end up having to use some sort of "isFound" flag and check that after the loop. A for...else would be much nicer, for example:[...]// vs: foreach(char[] key, Foo f; fooAA) { if(f.someFlag && key in barAA && f.someVal > barAA[key].someVal) break; // found } else Stdout.formatln("Missing!");Wait, that's not the way I would expect else to work. You (and and it would seem python) would have the else clause run if the loop is terminated by the for/foreach rater than a break/goto. I would expect that the else clause would be executed if the loop is terminated before the first iteration. I think your expectation would be a good feature but I can't really see else being the right keyword to use. How about "finally"? Or another option with scope(*) like "fallthrough"?
Jan 04 2009
On Mon, 05 Jan 2009 01:11:34 +0300, BCS <ao pathlink.com> wrote:Reply to Nick,Same here, I expected the for/else pair to work similar to if/else, i.e. only one of the branches to be executed. Perhaps I could get used to the syntax, though.I had never heard of that before, but it certainly seems like something I'd find useful. Any time I'm using for or foreach to find something, I end up having to use some sort of "isFound" flag and check that after the loop. A for...else would be much nicer, for example:[...]// vs: foreach(char[] key, Foo f; fooAA) { if(f.someFlag && key in barAA && f.someVal > barAA[key].someVal) break; // found } else Stdout.formatln("Missing!");Wait, that's not the way I would expect else to work. You (and and it would seem python) would have the else clause run if the loop is terminated by the for/foreach rater than a break/goto. I would expect that the else clause would be executed if the loop is terminated before the first iteration. I think your expectation would be a good feature but I can't really see else being the right keyword to use. How about "finally"? Or another option with scope(*) like "fallthrough"?
Jan 04 2009
BCS:I think your expectation would be a good feature but I can't really see else being the right keyword to use. How about "finally"? Or another option with scope(*) like "fallthrough"?The good thing of "else" is that you don't need a new keyword. But it's not intuitive. A better keyword may make the code much more readable. For example: foreach (key, f; fooAA) if (f.someFlag && key in barAA && f.someVal > barAA[key].someVal) break; unbroken writefln("Missing!"); It looks a little silly, but I think it's easy to understand the meaning :-) Bye, bearophile
Jan 05 2009
Nick Sabalausky wrote:bool isFound=false; foreach(char[] key, Foo f; fooAA) { if(f.someFlag && key in barAA && f.someVal > barAA[key].someVal) { isFound = true; break; } } if(!isFound) Stdout.formatln("Missing!");foreach (a, b; aa) if (weLike(a, b)) goto found; // else: assert (false, "nothing we like!"); found: I think my coworkers would kill me if I tried that.
Jan 05 2009
bearophile wrote:Brian:Actually Walter loves goto, so DMD copes really well with it.any chance we could see something like pythons else statement on iterative loops in D (Might be useful on regular for loops too but not as much)? http://docs.python.org/tutorial/controlflow.html#break-and-continue- statements-and-else-clauses-on-loopsIt seems everyone has ignored this post, but this isn't a proposal coming from a clueless alien. Such "else" has a little but true purpose, it helps avoid gotos in some situations, and this in turn may help the optimizer, because I think gotos aren't much well digested by modern C/D compilers.
Jan 05 2009
Don:Actually Walter loves goto, so DMD copes really well with it.When possible it's better to use structured programming and avoid gotos. That construct can avoid gotos in some common situations. And regarding the compiler back-end, I think it's also better to start thinking what's good for LDC :-) Bye, bearophile
Jan 05 2009
bearophile wrote:Don:I don't know how relevant this is, but: LLVM uses SSA for registers, and it seems to be simpler to convert code to SSA if there are no gotos: "We show that it is possible to generate SSA form in a single pass (even during parsing) if the program contains only structured control flow (i.e., no gotos). For such programs the dominator tree can be built on the fly, too." http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4503 I also think that almost all common uses of gotos could be replaced by introducing some new statements for structured control flow. Like allowing the programmer to jump to the begin or end of a block using break/continue, similar to loops. For example, in the Linux kernel, they do the following for error handling: void somefunction() { do_stuff(); if (error) goto error_exit: do_more_stuff(); return; error_exit: handle_error(); } This could be replaced by something like this: void somefunction() { error_exit: { do_stuff(); if (error) break error_exit; do_more_stuff(); return; } handle_error(); } D's scope can do the same thing.Actually Walter loves goto, so DMD copes really well with it.When possible it's better to use structured programming and avoid gotos. That construct can avoid gotos in some common situations. And regarding the compiler back-end, I think it's also better to start thinking what's good for LDC :-)
Jan 05 2009
grauzone wrote:bearophile wrote:It's possible to create grotesque configurations of 'goto' which are extremely difficult to analyze. But most uses of goto are simple.Don:I don't know how relevant this is, but: LLVM uses SSA for registers, and it seems to be simpler to convert code to SSA if there are no gotos: "We show that it is possible to generate SSA form in a single pass (even during parsing) if the program contains only structured control flow (i.e., no gotos). For such programs the dominator tree can be built on the fly, too." http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4503Actually Walter loves goto, so DMD copes really well with it.When possible it's better to use structured programming and avoid gotos. That construct can avoid gotos in some common situations. And regarding the compiler back-end, I think it's also better to start thinking what's good for LDC :-)I also think that almost all common uses of gotos could be replaced by introducing some new statements for structured control flow. Like allowing the programmer to jump to the begin or end of a block using break/continue, similar to loops. For example, in the Linux kernel, they do the following for error handling: void somefunction() { do_stuff(); if (error) goto error_exit: do_more_stuff(); return; error_exit: handle_error(); } This could be replaced by something like this: void somefunction() { error_exit: { do_stuff(); if (error) break error_exit; do_more_stuff(); return; } handle_error(); } D's scope can do the same thing.
Jan 05 2009
foreach(languageStatement; AllProgrammingLanguages) Stdout.format( "It's possible to create grotesque configurations of '{}' which are "~ "extremely difficult to analyze. But most uses of {} are simple.", languageStatement ).newline;
Jan 05 2009
Don wrote:It's possible to create grotesque configurations of 'goto' which are extremely difficult to analyze.For a human, yes. For well-known optimization algorithms, no.
Jan 06 2009
On Mon, 05 Jan 2009 11:13:49 +0100, grauzone wrote:void somefunction() { do_stuff(); if (error) goto error_exit: do_more_stuff(); return; error_exit: handle_error(); } This could be replaced by something like this: void somefunction() { error_exit: { do_stuff(); if (error) break error_exit; do_more_stuff(); return; } handle_error(); } D's scope can do the same thing.neither of those seem necessary in that example, whats wrong with this: void somefunction() { do_stuff(); if (error) handle_error(); else do_more_stuff(); }
Jan 06 2009
Brian wrote:[snip] neither of those seem necessary in that example, whats wrong with this: void somefunction() { do_stuff(); if (error) handle_error(); else do_more_stuff(); }A few things I can think of: 1. You're mixing error handling code with the other code. This breaks the flow and makes the logic harder to follow. 2. If you've got more than one point in the function where you need to do error handling, then you're going to be duplicating code; error handlers are very rarely just a single function call. 3. The point was that execution "fell out" after the handler. If you want to use conditionals, you can end up with really deeply indented code which is a bugger to read. It's rather ironic, but one thing that struck me going from Visual Basic to Python was that VB had much nicer error handling; instead of having error handling all over the place, it was all localised to the end of the function. This is why I absolutely adore scope statements. Of course, you're technically correct; in that specific example, you could do it either way. :) -- Daniel
Jan 06 2009
Daniel Keep Wrote:It's rather ironic, but one thing that struck me going from Visual Basic to Python was that VB had much nicer error handling; instead of having error handling all over the place, it was all localised to the end of the function. This is why I absolutely adore scope statements.Like "on error resume next"...? ;-P
Jan 06 2009
Robert Fraser wrote:Daniel Keep Wrote:While not the best practice, I'd take that any day over Java's insane "OMG THIS MIGHT THROW!!!!111oneoneone" mentality. Seriously, javac; some times, I just don't care. -- DanielIt's rather ironic, but one thing that struck me going from Visual Basic to Python was that VB had much nicer error handling; instead of having error handling all over the place, it was all localised to the end of the function. This is why I absolutely adore scope statements.Like "on error resume next"...? ;-P
Jan 07 2009
grauzone wrote:bearophile wrote:I don't know what they're talking about. The D optimizer has no trouble whatsoever building dominator graphs, no matter what rat's nest of gotos are used. This technology was well understood in 1980. In fact, the front end deconstructs *everything* into gotos, and that's all the optimizer works with.Don:I don't know how relevant this is, but: LLVM uses SSA for registers, and it seems to be simpler to convert code to SSA if there are no gotos: "We show that it is possible to generate SSA form in a single pass (even during parsing) if the program contains only structured control flow (i.e., no gotos). For such programs the dominator tree can be built on the fly, too." http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4503Actually Walter loves goto, so DMD copes really well with it.When possible it's better to use structured programming and avoid gotos. That construct can avoid gotos in some common situations. And regarding the compiler back-end, I think it's also better to start thinking what's good for LDC :-)
Jan 06 2009
Walter Bright wrote:grauzone wrote:The challenge the paper addresses is constructing the SSA form in one shot. There are indeed algorithms that build the SSA in several passes. My vague recollection from a compiler construction class is that there are a number of static analyses that need to do a fixed-point computation on loops. Such analyses can deal with any jumps except a particular one: jump forward from the outside of a loop in the middle of it. Does anyone know what analyses were those? Andreibearophile wrote:I don't know what they're talking about. The D optimizer has no trouble whatsoever building dominator graphs, no matter what rat's nest of gotos are used. This technology was well understood in 1980. In fact, the front end deconstructs *everything* into gotos, and that's all the optimizer works with.Don:I don't know how relevant this is, but: LLVM uses SSA for registers, and it seems to be simpler to convert code to SSA if there are no gotos: "We show that it is possible to generate SSA form in a single pass (even during parsing) if the program contains only structured control flow (i.e., no gotos). For such programs the dominator tree can be built on the fly, too." http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4503Actually Walter loves goto, so DMD copes really well with it.When possible it's better to use structured programming and avoid gotos. That construct can avoid gotos in some common situations. And regarding the compiler back-end, I think it's also better to start thinking what's good for LDC :-)
Jan 06 2009
Andrei Alexandrescu wrote:The challenge the paper addresses is constructing the SSA form in one shot. There are indeed algorithms that build the SSA in several passes. My vague recollection from a compiler construction class is that there are a number of static analyses that need to do a fixed-point computation on loops. Such analyses can deal with any jumps except a particular one: jump forward from the outside of a loop in the middle of it. Does anyone know what analyses were those?The two-entry-points-to-a-loop is the essential characteristic of an "irreducible flow graph". Such can be transformed into reducible ones, but it is not worth the effort because such are fairly rare, even in spaghetti goto code. <nose-in-air>I've known for 25 years that it's freaking easy to do optimizations if you can assume there are no goto's. But you wind up with a crippled compiler technology suitable only for toy languages. That's why real compilers aren't written that way.</nose-in-air> I only read part of the paper, but I don't see the point of it.
Jan 06 2009
bearophile wrote:Don:Structured programming does not mean no gotos. You should really read the original paper "Goto considered harmful", you'll find it's actually about the evil of spaghetti code, such as in BASIC. In C family-languages, including D, there is no spaghetti goto. So actually it's nearly impossible to abuse goto in D in the way that the original paper was talking about. I still avoid goto because I was told to. But eventually I realised that it's 100% propaganda. I actually think my code would be cleaner if I used it; it would allow lots of local flag variables to be eliminated. But I still have this residual prejudice against 'goto' which is really hard to get rid of.Actually Walter loves goto, so DMD copes really well with it.When possible it's better to use structured programming and avoid gotos.That construct can avoid gotos in some common situations.And regarding the compiler back-end, I think it's also better to start thinking what's good for LDC :-)Yes, but I doubt any compiler would have a problem with goto.Bye, bearophile
Jan 05 2009
Don wrote:I still avoid goto because I was told to. But eventually I realised that it's 100% propaganda. I actually think my code would be cleaner if I used it; it would allow lots of local flag variables to be eliminated. But I still have this residual prejudice against 'goto' which is really hard to get rid of.The problem with goto is it is easy to get into a human readability problem with it. No such problem exists for optimization algorithms.Yes, but I doubt any compiler would have a problem with goto.The last time I even heard of a compiler that fell over and gave up optimizing if it saw a goto was in the early 80's. I have a hard time believing LDC has problems with it, but if it does, the authors should hit the books <g>. I keep thinking I should put on a "Compiler Construction" seminar! P.S. There are problems with goto'ing out of a finally block, and there's a problem in the optimizer with goto'ing from one try block to another, but that's not the issue here.
Jan 06 2009
Walter Bright wrote:I keep thinking I should put on a "Compiler Construction" seminar!Sign me up!
Jan 06 2009
Reply to Walter,I keep thinking I should put on a "Compiler Construction" seminar!That would be fun. If I could, I'd show up.
Jan 06 2009
== Quote from Walter Bright (newshound1 digitalmars.com)'s articleDon wrote:goto's jump to a label, so it's not like the compiler has no idea where entry points might be, anyway. And in the extreme case of languages with inline asm containing jump-to-address operations, I would think that the address would have to be computed at run-time, which is obviously after any optimization has been done. I suppose I'm failing to see the problem with goto's, assuming a structured language like D (as opposed to goto's in BASIC).I still avoid goto because I was told to. But eventually I realised that it's 100% propaganda. I actually think my code would be cleaner if I used it; it would allow lots of local flag variables to be eliminated. But I still have this residual prejudice against 'goto' which is really hard to get rid of.The problem with goto is it is easy to get into a human readability problem with it. No such problem exists for optimization algorithms.Yes, but I doubt any compiler would have a problem with goto.The last time I even heard of a compiler that fell over and gave up optimizing if it saw a goto was in the early 80's. I have a hard time believing LDC has problems with it, but if it does, the authors should hit the books <g>.I keep thinking I should put on a "Compiler Construction" seminar!You should. The academic courses do a good job with theory and general application, but that isn't quite the same as one based on practical experience. Sean
Jan 07 2009
Sean Kelly wrote:That's true. I learned the theory taking a compiler construction course at Standford, and then tried to apply it. It turns out that there's a lot they left out <g> that's needed to actually get those optimizations to work. Loop induction variables was a big one, because the theory never takes into account the fact that you're replacing a signed loop index with an unsigned loop pointer. Oops! It's like in physics class you're always dealing with frictionless brakes and pointless masses.I keep thinking I should put on a "Compiler Construction" seminar!You should. The academic courses do a good job with theory and general application, but that isn't quite the same as one based on practical experience.
Jan 07 2009
On Thu, Jan 8, 2009 at 5:54 AM, Walter Bright <newshound1 digitalmars.com> wrote:Sean Kelly wrote:You mean massless points? Or was that deliberate? --bbThat's true. I learned the theory taking a compiler construction course at Standford, and then tried to apply it. It turns out that there's a lot they left out <g> that's needed to actually get those optimizations to work. Loop induction variables was a big one, because the theory never takes into account the fact that you're replacing a signed loop index with an unsigned loop pointer. Oops! It's like in physics class you're always dealing with frictionless brakes and pointless masses.I keep thinking I should put on a "Compiler Construction" seminar!You should. The academic courses do a good job with theory and general application, but that isn't quite the same as one based on practical experience.
Jan 07 2009
Bill Baxter wrote:On Thu, Jan 8, 2009 at 5:54 AM, Walter Bright <newshound1 digitalmars.com> wrote:I think there were two jokes actually: frictionless brakes (used instead of e.g. frictionless pulleys) which is an oxymoron, and a pun on point masses (objects that can be approximated by a point). AndreiSean Kelly wrote:You mean massless points? Or was that deliberate?That's true. I learned the theory taking a compiler construction course at Standford, and then tried to apply it. It turns out that there's a lot they left out <g> that's needed to actually get those optimizations to work. Loop induction variables was a big one, because the theory never takes into account the fact that you're replacing a signed loop index with an unsigned loop pointer. Oops! It's like in physics class you're always dealing with frictionless brakes and pointless masses.I keep thinking I should put on a "Compiler Construction" seminar!You should. The academic courses do a good job with theory and general application, but that isn't quite the same as one based on practical experience.
Jan 07 2009
On Thu, Jan 8, 2009 at 6:46 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Bill Baxter wrote:Hmmm. Oh yeh. I'm gonna claim lack of my first morning cup o coffee as my excuse for missing that. Cute. --bbOn Thu, Jan 8, 2009 at 5:54 AM, Walter Bright <newshound1 digitalmars.com> wrote:I think there were two jokes actually: frictionless brakes (used instead of e.g. frictionless pulleys) which is an oxymoron, and a pun on point masses (objects that can be approximated by a point).Sean Kelly wrote:You mean massless points? Or was that deliberate?That's true. I learned the theory taking a compiler construction course at Standford, and then tried to apply it. It turns out that there's a lot they left out <g> that's needed to actually get those optimizations to work. Loop induction variables was a big one, because the theory never takes into account the fact that you're replacing a signed loop index with an unsigned loop pointer. Oops! It's like in physics class you're always dealing with frictionless brakes and pointless masses.I keep thinking I should put on a "Compiler Construction" seminar!You should. The academic courses do a good job with theory and general application, but that isn't quite the same as one based on practical experience.
Jan 07 2009
Bill Baxter wrote:On Thu, Jan 8, 2009 at 6:46 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:School physics problems always start out with "assume there is no friction, and the point has no mass." Academic papers on compiler optimizations always start out with "assume there are no pointers, no references, no arrays, no exceptions, no threads, no aliasing, no overflows, no signed/unsigned, there are infinite registers available, registers are orthogonal, etc." Or they just go ahead and let you discover that they assumed that. Useful languages are a lot messier in the real world.Bill Baxter wrote:Hmmm. Oh yeh. I'm gonna claim lack of my first morning cup o coffee as my excuse for missing that. Cute.On Thu, Jan 8, 2009 at 5:54 AM, Walter Bright <newshound1 digitalmars.com> wrote:I think there were two jokes actually: frictionless brakes (used instead of e.g. frictionless pulleys) which is an oxymoron, and a pun on point masses (objects that can be approximated by a point).Sean Kelly wrote:You mean massless points? Or was that deliberate?That's true. I learned the theory taking a compiler construction course at Standford, and then tried to apply it. It turns out that there's a lot they left out <g> that's needed to actually get those optimizations to work. Loop induction variables was a big one, because the theory never takes into account the fact that you're replacing a signed loop index with an unsigned loop pointer. Oops! It's like in physics class you're always dealing with frictionless brakes and pointless masses.I keep thinking I should put on a "Compiler Construction" seminar!You should. The academic courses do a good job with theory and general application, but that isn't quite the same as one based on practical experience.
Jan 07 2009
Walter Bright wrote:Bill Baxter wrote:Well that should be taken with the traditional grain of salt. AndreiOn Thu, Jan 8, 2009 at 6:46 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:School physics problems always start out with "assume there is no friction, and the point has no mass." Academic papers on compiler optimizations always start out with "assume there are no pointers, no references, no arrays, no exceptions, no threads, no aliasing, no overflows, no signed/unsigned, there are infinite registers available, registers are orthogonal, etc." Or they just go ahead and let you discover that they assumed that.Bill Baxter wrote:Hmmm. Oh yeh. I'm gonna claim lack of my first morning cup o coffee as my excuse for missing that. Cute.On Thu, Jan 8, 2009 at 5:54 AM, Walter Bright <newshound1 digitalmars.com> wrote:I think there were two jokes actually: frictionless brakes (used instead of e.g. frictionless pulleys) which is an oxymoron, and a pun on point masses (objects that can be approximated by a point).Sean Kelly wrote:You mean massless points? Or was that deliberate?That's true. I learned the theory taking a compiler construction course at Standford, and then tried to apply it. It turns out that there's a lot they left out <g> that's needed to actually get those optimizations to work. Loop induction variables was a big one, because the theory never takes into account the fact that you're replacing a signed loop index with an unsigned loop pointer. Oops! It's like in physics class you're always dealing with frictionless brakes and pointless masses.I keep thinking I should put on a "Compiler Construction" seminar!You should. The academic courses do a good job with theory and general application, but that isn't quite the same as one based on practical experience.
Jan 07 2009
On Thu, Jan 8, 2009 at 10:28 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Walter Bright wrote:In my experience just about any academic paper has to be digest with a large grain of salt. Most of the ones I have become intimately familiar with have big limitations not mentioned by the authors that only become apparent once you start trying to repeat what they did. But maybe graphics papers are particularly susceptible to this phenomenon. A typical graphics paper shows three or four nice results, and says "see look! it works!", but unfortunately that's no proof of general effectiveness. It just proves it works for those 3-4 images. --bbBill Baxter wrote:Well that should be taken with the traditional grain of salt.On Thu, Jan 8, 2009 at 6:46 AM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:School physics problems always start out with "assume there is no friction, and the point has no mass." Academic papers on compiler optimizations always start out with "assume there are no pointers, no references, no arrays, no exceptions, no threads, no aliasing, no overflows, no signed/unsigned, there are infinite registers available, registers are orthogonal, etc." Or they just go ahead and let you discover that they assumed that.Bill Baxter wrote:Hmmm. Oh yeh. I'm gonna claim lack of my first morning cup o coffee as my excuse for missing that. Cute.On Thu, Jan 8, 2009 at 5:54 AM, Walter Bright <newshound1 digitalmars.com> wrote:I think there were two jokes actually: frictionless brakes (used instead of e.g. frictionless pulleys) which is an oxymoron, and a pun on point masses (objects that can be approximated by a point).Sean Kelly wrote:You mean massless points? Or was that deliberate?That's true. I learned the theory taking a compiler construction course at Standford, and then tried to apply it. It turns out that there's a lot they left out <g> that's needed to actually get those optimizations to work. Loop induction variables was a big one, because the theory never takes into account the fact that you're replacing a signed loop index with an unsigned loop pointer. Oops! It's like in physics class you're always dealing with frictionless brakes and pointless masses.I keep thinking I should put on a "Compiler Construction" seminar!You should. The academic courses do a good job with theory and general application, but that isn't quite the same as one based on practical experience.
Jan 07 2009
Andrei Alexandrescu wrote:Walter Bright wrote:Some are better than others, sure. I found out the hard way. But even in the paper cited in this thread: "We do not deal here with alias problems caused by assignments to array elements, to parameters passed by reference, and to variables that are referenced via pointers. These problems can be dealt with in the same way as described in [5]." and this: "This is useful for languages such as Simula[3], Modula-2 [13] or Oberon [14] that lack goto statements at all." Who uses Simula, Modula-2 or Oberon?Academic papers on compiler optimizations always start out with "assume there are no pointers, no references, no arrays, no exceptions, no threads, no aliasing, no overflows, no signed/unsigned, there are infinite registers available, registers are orthogonal, etc." Or they just go ahead and let you discover that they assumed that.Well that should be taken with the traditional grain of salt.
Jan 07 2009
Walter Bright wrote:Andrei Alexandrescu wrote:Without saying anything about this paper in particular, quality of research papers has a very top-heavy distribution. Outside a few conference proceedings and journals, where only a few institutions publish, the quality of research publications decreases drastically. AndreiWalter Bright wrote:Some are better than others, sure. I found out the hard way. But even in the paper cited in this thread: "We do not deal here with alias problems caused by assignments to array elements, to parameters passed by reference, and to variables that are referenced via pointers. These problems can be dealt with in the same way as described in [5]." and this: "This is useful for languages such as Simula[3], Modula-2 [13] or Oberon [14] that lack goto statements at all." Who uses Simula, Modula-2 or Oberon?Academic papers on compiler optimizations always start out with "assume there are no pointers, no references, no arrays, no exceptions, no threads, no aliasing, no overflows, no signed/unsigned, there are infinite registers available, registers are orthogonal, etc." Or they just go ahead and let you discover that they assumed that.Well that should be taken with the traditional grain of salt.
Jan 07 2009
Bill Baxter wrote:On Thu, Jan 8, 2009 at 5:54 AM, Walter BrightI wondered if anyone would notice that (!). Yes, it's deliberate.It's like in physics class you're always dealing with frictionless brakes and pointless masses.You mean massless points? Or was that deliberate?
Jan 07 2009
Reply to Walter,Bill Baxter wrote:OTOH test often have their share of red harring as well!On Thu, Jan 8, 2009 at 5:54 AM, Walter BrightI wondered if anyone would notice that (!). Yes, it's deliberate.It's like in physics class you're always dealing with frictionless brakes and pointless masses.You mean massless points? Or was that deliberate?
Jan 07 2009
Content-Disposition: inline On Wed, Jan 7, 2009 at 6:07 AM, Walter Bright <newshound1 digitalmars.com>wrote:Don wrote:It doesn't :PI still avoid goto because I was told to. But eventually I realised that it's 100% propaganda. I actually think my code would be cleaner if I used it; it would allow lots of local flag variables to be eliminated. But I still have this residual prejudice against 'goto' which is really hard to get rid of.The problem with goto is it is easy to get into a human readability problem with it. No such problem exists for optimization algorithms. Yes, but I doubt any compiler would have a problem with goto.The last time I even heard of a compiler that fell over and gave up optimizing if it saw a goto was in the early 80's. I have a hard time believing LDC has problems with it, but if it does, the authors should hit the books <g>.I keep thinking I should put on a "Compiler Construction" seminar! P.S. There are problems with goto'ing out of a finally block, and there's a problem in the optimizer with goto'ing from one try block to another, but that's not the issue here.
Jan 07 2009
Tomas Lindquist Olsen wrote:On Wed, Jan 7, 2009 at 6:07 AM, Walter Bright The last time I even heard of a compiler that fell over and gave up optimizing if it saw a goto was in the early 80's. I have a hard time believing LDC has problems with it, but if it does, the authors should hit the books <g>. It doesn't :PThat's good to hear!
Jan 07 2009
Walter Bright wrote:I keep thinking I should put on a "Compiler Construction" seminar!*cough* NWCPP *cough*
Jan 07 2009
Robert Fraser wrote:Walter Bright wrote:I'd like to do a paid one <g>. BTW, Bartosz has graciously offered the Jan NWCPP speaking engagement to me. I'll be talking about mixins and templates. All are welcome, of course.I keep thinking I should put on a "Compiler Construction" seminar!*cough* NWCPP *cough*
Jan 07 2009
Reply to Walter,Robert Fraser wrote:Video! Video! ?? (for those of us not in Seattle)Walter Bright wrote:I'd like to do a paid one <g>. BTW, Bartosz has graciously offered the Jan NWCPP speaking engagement to me. I'll be talking about mixins and templates. All are welcome, of course.I keep thinking I should put on a "Compiler Construction" seminar!*cough* NWCPP *cough*
Jan 08 2009
BCS wrote:Reply to Walter,See www.nwcpp.org. Ask Bartosz!Robert Fraser wrote:Video! Video! ?? (for those of us not in Seattle)Walter Bright wrote:I'd like to do a paid one <g>. BTW, Bartosz has graciously offered the Jan NWCPP speaking engagement to me. I'll be talking about mixins and templates. All are welcome, of course.I keep thinking I should put on a "Compiler Construction" seminar!*cough* NWCPP *cough*
Jan 08 2009
"Walter Bright" <newshound1 digitalmars.com> kirjoitti viestissä news:gk1dag$ptn$1 digitalmars.com...I keep thinking I should put on a "Compiler Construction" seminar!A net-seminar, please, so that those of us who want to attend actually can.
Jan 08 2009
"Rioshin an'Harthen" <rharth75 hotmail.com> wrote in message news:gk4kfh$ri3$1 digitalmars.com..."Walter Bright" <newshound1 digitalmars.com> kirjoitti viestissä news:gk1dag$ptn$1 digitalmars.com...Yes :). Things like this never make their way out to Cleveland (or anywhere within a three-hour drive, which is about the max I could realistically do). (Heck, *decent* programmers are never out this way.)I keep thinking I should put on a "Compiler Construction" seminar!A net-seminar, please, so that those of us who want to attend actually can.
Jan 08 2009
Nick Sabalausky wrote:"Rioshin an'Harthen" <rharth75 hotmail.com> wrote in message news:gk4kfh$ri3$1 digitalmars.com...When we did the Astoria Seminar in 2007, the consistent feedback was that what the attendees liked most was the ambiance and getting together with like-minded professionals and face time with experts. I do think that the one-on-one in person is an essential ingredient to making seminars a valuable experience."Walter Bright" <newshound1 digitalmars.com> kirjoitti viestissä news:gk1dag$ptn$1 digitalmars.com...Yes :). Things like this never make their way out to Cleveland (or anywhere within a three-hour drive, which is about the max I could realistically do). (Heck, *decent* programmers are never out this way.)I keep thinking I should put on a "Compiler Construction" seminar!A net-seminar, please, so that those of us who want to attend actually can.
Jan 08 2009
"Walter Bright" <newshound1 digitalmars.com> wrote in message news:gk6150$n63$1 digitalmars.com...Nick Sabalausky wrote:Agreed. Which is why it's dissapointing that any good programming-related stuff is usually too far for me. I know a lot of people travel large distances for many of these things, but I'm rarely able spend the money on the travel and lodging. But videos are better than nothing though."Rioshin an'Harthen" <rharth75 hotmail.com> wrote in message news:gk4kfh$ri3$1 digitalmars.com...When we did the Astoria Seminar in 2007, the consistent feedback was that what the attendees liked most was the ambiance and getting together with like-minded professionals and face time with experts. I do think that the one-on-one in person is an essential ingredient to making seminars a valuable experience."Walter Bright" <newshound1 digitalmars.com> kirjoitti viestissä news:gk1dag$ptn$1 digitalmars.com...Yes :). Things like this never make their way out to Cleveland (or anywhere within a three-hour drive, which is about the max I could realistically do). (Heck, *decent* programmers are never out this way.)I keep thinking I should put on a "Compiler Construction" seminar!A net-seminar, please, so that those of us who want to attend actually can.
Jan 08 2009