Saturday, March 10, 2007

Go, what?

Well, to day I was working on some file. And for the first time I asked my self if I should use a 'Goto'. The goto statement is probably one of the most controversial things I've ever read of in computing history.

The problem was, I had the option of repeating several lines of code at several conditionals in a if-elif-else construct. I thought about using a goto to walkk on over to that. So as to only right it once. When I asked my self, Do I even remember the syntax for a Goto ! LMAO !!! I can't even ever remember using a Go to in any language. The only time I recall learning about using was breifly in an historical C tutorial by by Brian W. Kernighan. Then I thought, since I didn't want to clutter things by getting repetitive - Why not get off my lazy arse and wrap it in a function?

Really the only purpose of using goto often I could see would be to avoid using functions at all. The best usage of it I can see, which could still be wrapped in a function if wanted. Although I'm sure thats not always best. I don't see any thing wrong with goto, but I don't see it as an excuse not to use functions, if-elif-else, switch/case, for/while/do-while e.t.c. what ever constructs the language provides.

I think, in my opinion this would be a good clause to use the 'infernal goto'

for condintion
  do
      code
      if true
            goto handle
      else
            skip
 A number of things like this and eventually 

      handle:
            code to handle false
  done

As a method of keeping some exception handling at the end of a loop rather then packing it some where with a nice interface or some thing. I dunno, personally I like doing things in a manor that I know is crystal clear.

For example, column stacking on a door for a bang & clear. It should be clear as can be who is banging, who is openning, and which one enters first, e.t.c.

No comments:

Post a Comment