Re: Open Source
- Posted by Juergen Luethje <j.lue at g?x.d?> Oct 20, 2007
- 672 views
Matt Lewis wrote: > Juergen Luethje wrote: > > > > Matt Lewis wrote: > > > > Quote from that post: > > "I think goto's are fine, and they are often more readable than large > > amounts of indentation." > > > > That's the same like saying: "At night it's colder than outside." > > Fortunately, Linus had written some other stuff, which is considerably > > better. > > I don't follow your saying. It's actually a very interesting thread. Sorry, I hadn't read the whole thread, but only the one post that you had mentioned. > Here are two of the better posts advocating gotos: > > http://lkml.org/lkml/2003/1/12/134 In this post #134, the author writes: | | *judicious* use of goto can prevent code that is so cluttered with stuff [...] | I often have read something like that from people who are advocating "goto". That might be correct -- but after my experience, reality very often is different. When people say so, that reminds me of a funny situation here in Germany. We have a newspaper here, the content of which is on a level similar to the British "The Sun" -- not exactly the stuff you need to read when you are preparing your doctoral thesis. When you ask people in Germany, you'll come to the conclusion that all people agree that this newspaper is "trash", and that nobody does read it. The funny thing only is, that more than 3 million copies of it are sold daily ... This is somewhat similar to my experience with "goto". People who are advocating "goto" say it should be used "judicious", and they themselves of course are doing so. But when I look "in the wild", then I see something different. I know what I'm talking about, after having read literally Megabytes of PowerBASIC (which has a "goto" statement) source codeby many different authors. So althought there may be some rare situations when "goto" might be of some use (I never encountered such a situation, and I never needed to use "goto" with PowerBASIC.), according to my experience, in the overwhelming majority "goto" is used to produce spaghetti code, which is hard to read an to maintain. Of course it's also possible to write bad readable and bad maintainable code *witout* "goto" (as I have learned from the archieves, this is even possible with Euphoria), but "goto" makes this job *a lot* easier. In the same post above, it reads: | | The real problem is that C doesn't have a good multi-level "break" construct. | I can't actually say much about C, but the author seems to share my opinion: That "goto" is not necessary, when a language has good "modern" possibilities for controlling the program flow. Then it reads: | On the other hand, I don't know of any language that has a good one - some | allow "break 3;" to break 3 levels- but that's still bad because you get | screwed if somebody adds an 'if' clause.... Why will we get screwed if somebody adds an if clause? I don't understand that. Anyway, if "break n" oder "exit n" is not sufficient, then we should think about even more advanced statements, rather then using "goto", which simply has a bad use/risk ratio. > http://lkml.org/lkml/2003/1/12/252 > > Note: This post isn't actively advocating for gotos in euphoria-- I'm aware of that. > though > I think there's a place for them, especially in the form of something > like a "continue" statement. I'd actually appreciate a "continue" statement (which jumps from anywhere inside a loop to its beginning), too. Please note that this is not what I mean when I talk about "goto". With "goto" I mean a statement that allows to jump to (almost) every point in the code -- like "jmp" in assembler. > It's also amusing [to me] to note that > much of the speed of euphoria is due to gotos. I think it is in the C source code of the interpreter/translator, no? Don asked about "goto" *in Euphoria code*. I use conditional and unconditional jumps myself, when I do ASM programming. But I only use ASM code for small pieces of code, where speed is important. And I only write ASM programs, when I have slept very well the night before. I do not expect ASM code to be good readable or easily maintainable. That's the difference to a higher-level language like Euphoria. In my opinion, "goto" is obsolete *in such higher-level languages* -- not in lower-level languages such as C or ASM. Code in higher-level languages should be easy to read and maintain, they should allow the coder to concentrate on the problem he wants to solve. The language itself should be part of the soöution, not part of the problem. Regards, Juergen -- I didn't have time to write a short letter, so I wrote a long one instead. [Mark Twain]