From: "Hal E. Fulton" Date: 2002-12-08T04:04:06+09:00 Subject: Re: (OT) Re: elseif? ----- Original Message ----- From: "Tim Hunter" Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Saturday, December 07, 2002 12:36 PM Subject: (OT) Re: elseif? > On Sat, 7 Dec 2002 14:03:50 +0900, "Hal E. Fulton" > wrote: > > > > >Actually, what I've always wished for is a multiway Boolean > >branch that was *obviously* such, not merely a special case > >of 'if'. > > > >In grad school I created a toy language that had a 'test' > >statement. (I'm not advocating this for Ruby, BTW, though > >I personally wouldn't mind seeing it.) > > > > Hal, have you ever used FORTRAN's computed GOTO statement? IIRC, you > supply an expression followed by a list of line numbers (line numbers > are the same as C labels, except they're, well, numbers). Control > branches to the 1st, 2nd, 3rd, whatever line number based on the value > of the expression. > > (This is based on my >20 year old memory of FORTRAN 77, so I could be > off in the details. I believe "computed GOTO" is deprecated in current > FORTRANs. :-) As far as I recall, your memory of FORTRAN (which I have struggled to block) is correct. But that's a different animal. What I want/wanted was an elegant, simple way to express successive (Boolean) tests as a multiway branch. The if/elsif/.../end solution is widespread, and there is nothing really wrong with it. But I like mine better. Many or most people, of course, will not. It's an unfamiliar construct. I don't doubt that when the switch or case statement was introduced, a lot of people said, "Why would you want that?" After all, a chain of ifs will do the same thing. (Was it ALGOL that introduced this concept? Or BCPL? Or what?) I've noticed with amusement over the years that every Blub programmer disdains minor improvements, deeming them more minor than they actually are. I recall when I was a freshman arguing the merits of the for-loop (in Pascal or BASIC) versus the DO-loop of FORTRAN. The other person was a die-hard FORTRAN programmer, not even F77 which was not widespread then, who had spent so much time on assembly (and perhaps even machine language) that FORTRAN seemed like a paradise to him. And I asked him something like, How would you make a loop go backwards, from a high value to a low? And his reply was: "Well, all you do is..." and told how he would keep a separate variable that was the difference of the high value and the counter. And, in a sense, he was right. That's "all you do." Create another variable and do a subtraction. But why bother? Whenever I have argued for a baby-step forward, a minor improvement over an older way of doing something, the most common response I have ever heard is: "All you do is..." But of course, it's the kai-zen principle at work. Take a hundred baby steps forward, and suddenly it looks like a giant quantum leap. That, I think, is why we like Ruby -- or part of the reason -- or that's true for me, anyway. But as for the multiway successive Boolean test: Frankly, I'd suggest it as an RCR -- I do feel strongly enough about it -- but I don't think it would ever be accepted. And really, in the long run, who cares? Hal