Comments on: On Spaghetti https://rants.vastheman.com/2008/07/27/spaghetti/ Take a hit with V-Real Wed, 06 Aug 2008 12:49:57 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: Carl https://rants.vastheman.com/2008/07/27/spaghetti/#comment-46 Wed, 06 Aug 2008 12:49:57 +0000 http://rants.vastheman.com/?p=51#comment-46 I never liked exceptions… probably because I’m lazy and exceptions mean I have to write catches for them all… isn’t writing code that throws an exception an example of avoiding having to write some code that deals with a failure condition… I guess if you want to do all your error handling in a particular layer, and have all the catches their to do logging or something… but otherwise, just a different kind of pasta dish… fettucini perhaps…

I can’t remember the last time I wrote code that went out of bounds of an array… seriously…

]]>
By: Rob https://rants.vastheman.com/2008/07/27/spaghetti/#comment-45 Fri, 01 Aug 2008 15:09:02 +0000 http://rants.vastheman.com/?p=51#comment-45 Ah, I understand you now. Yes, I agree with you that it is a bit hypocritical, although I think a lot of the constructs are much more limited versions of goto and so therefore not quite so bad.

]]>
By: vastheman https://rants.vastheman.com/2008/07/27/spaghetti/#comment-44 Fri, 01 Aug 2008 14:09:40 +0000 http://rants.vastheman.com/?p=51#comment-44 That’s not really the point of the article. It was more a criticism of the hypocrisy that Dijkstra’s letter has bred: people wage war on the goto statement itself while encouraging the use of other constructs that are effectively the same thing.

And just to clear things up, when I code C++ (which is mostly at work – I do trading systems on Solaris) my usual way is to return status information, and throw exceptions under truly abnormal circumstances. I do use return statements throughout functions, and I do think loop control statements are appropriate at times (like using continue to skip an iteration of a loop when you encounter a value that should be ignored, for example).

]]>
By: Rob https://rants.vastheman.com/2008/07/27/spaghetti/#comment-43 Thu, 31 Jul 2008 18:58:01 +0000 http://rants.vastheman.com/?p=51#comment-43 I’ll agree with you on that one.

Personally I prefer the C way of doing things, where you return error codes depending on what happens. I’ll disagree with your original article where you say that the only exit point should be at the end of the function. As Torsten said, you either use return statements in the middle of the function, or have to nest to death. What’s worse? I’d rather have a nice simple return statement instead of a mess of indentations and curly brackets.

]]>
By: vastheman https://rants.vastheman.com/2008/07/27/spaghetti/#comment-42 Wed, 30 Jul 2008 11:15:02 +0000 http://rants.vastheman.com/?p=51#comment-42 IBM has it right with System Z: going over an array boundary should cause your program to die – that teaches you to code properly. An exception is better than undefined behaviour in this case. I don’t really have a problem with using exceptions to signal truly exceptional conditions, I just don’t think they’re really the best way to deal with normal error conditions.

]]>
By: Rob https://rants.vastheman.com/2008/07/27/spaghetti/#comment-41 Tue, 29 Jul 2008 17:05:46 +0000 http://rants.vastheman.com/?p=51#comment-41 I would have to agree completely with Torsten. Exceptions are great when used properly. For example, suppose you go over an array index, due to a typo. What should happen?
C++ answers this by saying “undefined behaviour”. You might get the thing called “segmentation fault” which is the same as saying “goto end of program”, or you might get other data overwritten which leads to nasty bugs.
Java answers it by throwing an exception. Therefore you know exactly where and why your program is crashing and can fix your typo.

Sure, you’re right in saying that exceptions introduce a “goto” where you don’t know the destination, but how else do you propose we compensate for the fact that we’re human and don’t write perfect code every time?

]]>
By: Torsten Curdt https://rants.vastheman.com/2008/07/27/spaghetti/#comment-40 Sun, 27 Jul 2008 18:27:56 +0000 http://rants.vastheman.com/?p=51#comment-40 Funny – I have had the same thought lately when dealing with some of the uif2iso4mac code. What are really the options if you exit on error conditions? Nesting to death or exceptions. Releasing resources really becomes a pain without “goto”s. I guess again it really just is a question of how you use them. Source bloat just because you try to avoid them I would consider harmful as well. Ideally you could break the code into smaller pieces and that will help. But sometimes that means passing around context information and delegating resource releasing responsibilities. So …just let’s just use “goto” properly and we should be good. I would still avoid it – if possible. But I don’t think it’s a big ugly no-no anymore.

]]>