On Tue, 2003-12-09 at 08:14, Bogdan Stancescu wrote:
Robert, I know your grief, been there, I know how it feels. I started my childhood with BASIC, which was /the/ "GOTO" programming language, learned Turbo Pascal when I was a teenager, and continued to use GOTO's (Pascal discourages but doesn't disallow GOTO's, so I was still able to "cheat" when "there was a need for it"). Well, later on when I started finding out how major projects are being developed, what structured programming really means and so on, I felt the way you feel now: cheated. "Why in God's name is GOTO bad? It's SO useful! They're mad!" Well, it simply isn't true -- the problem is that you have to change your mindset about programming, try to really structure the way you see a program, break it into efficient stand-alone functions, group those in classes, etc, and you'll see that there *is* no need for GOTO, ever. You do need to break out of loops, you do need to "short" a loop when a condition is met, you do need to break out of switches, if branches and the lot - but those tools you have in PHP. GOTO is not needed and harmful. Even simply learning to program without GOTO will coerce you into saner code.
Sorry if my message sounded melodramatic or something, I remembered the frustration feeling so strongly from your message that I wanted to reinforce the other people's messages with a personal "testimonial" if you wish.
Ummmm, I rarely use the goto statement, and I do not advocate it for regular everyday coding. I do know the difference between well structured code and otherwise. What I did say, is that goto <label> has it's uses, and sometimes it IS the best solution. Just because someone tells you something is bad, doesn't mean to say it is always bad. It's like someone saying salt is bad for you, and so you never take salt again and die from salt deficiency. People really need to change their mindset about being sheeple (yes sheep people) and blindly following preached dogma.
I don't mind your message sounding melodramatic, but it doesn't explain in any way why goto shouldn't be used. It just asserts that you found out how major projects are done, which IMHO doesn't lend support to why one shouldn't use the goto statement. In actual fact it makes me think you are missing a few points. For instance properly structured programming is often about the functions, objects, and methods, not about the code within a function that performs the logic. For this reason the use of goto statements within a given function that facilitates faster cleaner code is sometimes the best solution not to mention its contents can be considered a black box by the user of the function. Also your response seems to indicate that you think I am a newbie coder, well that would be a bit of an oversight. I've been coding for over 10 years (some hobby, some academic, and some professional) using many different styles (functional, procedural, and OOP) and so I am plenty aware of design paradigms, re-usability, and clarity. I also have extensive experience refactoring old spaghetti code.
Cheers, Rob.
While goto may be useful and even elegant for experienced programmers (although I see no reason to use it myself with well structured programs...there's always break), its inclusion in a language causes some programmers (newbies and those who don't yet understand clarity, etc.) to make habits which are harmful. It allows them shortcuts which get things done, but often lead to bugs and hard to read code.
<opinion>
Personally, I don't think goto should ever be used. Well structured programs can always be written to not need a goto and always just as elegantly. It may take restructuring of code, but it can always be done, and in the end the result is clearer.
You say that a funciton is a "black box" and while this is true for the user of a function, the maintainer of the code still has to deal with the contents of the function. If you wrote and understand it, then fine. The problem comes when others have to understand your code. Yes, a single goto isn't all that bad, especially when it is used right, but is it easier to screw up a code with a goto than a more structured statement, such as break.
</opinion>
-- paperCrane <Justin Patrin>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php