goto poll;

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.

What do you think of goto?

I LOVE it! It's my favorite keyword!
1
3%
It's OK, I use it.
12
32%
It's OK, I don't use it though
10
27%
I am neutral
8
22%
I hate it.
5
14%
Whats goto?
1
3%
 
Total votes: 37

User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

goto poll;

Post by piranha »

What do you think of the goto keyword?

Good/Bad etc...
I don't use it, not because of a general rule, just because other ways look cleaner and are easier to read and deal with.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post by Colonel Kernel »

If there were an option in the poll that says "I use it as a last resort", that's what I would have picked. It can be handy for centralizing last-ditch cleanup code in C if you have no other choice (RAII in C++ is a much better way to do it). I wouldn't use it for any other purpose though.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

You have to be careful too. You can jump from a member in one class to a member in another, which really messes up the stack.

EDIT: My lecturer also said it's an instant fail if he finds a goto in one of our assignments.
My OS is Perception.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

EDIT: My lecturer also said it's an instant fail if he finds a goto in one of our assignments.
Well, I hope he knows about the jump command for the CPU.......it's freakin everywhere.
I bet he does, but yeah....

And it's true, goto isn't great.
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Being a basic programmer, the goto keyword is the only way to do exception handling, so yes, I use it on a regular basis. (and then there are those languages without function calls :twisted:)

That said, I probably would never use it in C though.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

I *do* use it in C occassionally, but only as a last resort for in-function exception handling. (For example, during construction of nested memory structures on the heap - if the second or third allocation fails, you have to clean up what you already allocated.) I could write my way around using goto, but sometimes the workaround would be even uglier.

I didn't vote any of the above because none of the options quite fit.
Every good solution is obvious once you've found it.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

The only time I use the goto: is when I am handling interrupts and do last minute error checking.
iammisc
Member
Member
Posts: 269
Joined: Thu Nov 09, 2006 6:23 pm

Post by iammisc »

I use it when i don't want to write code over and over like when i have a function that needs to lock/unlock mutexes but returns multiple times. Instead of retyping the unlocking and return sequence I just goto the label with the return statements under it. For anything else, it's pretty useless.
User avatar
FutureDomain
Posts: 7
Joined: Fri Aug 10, 2007 8:43 am
Location: Evansville, IN
Contact:

Post by FutureDomain »

I never use goto in C#. It's there, but I find it's better to use structured programming and exception handling. There are a couple circumstances where it might be the best option, but I've never hit those yet.
FutureDomain: Everybody's favorite software maverick.
Xenon: Rethinking the operating system.
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

Isn't "goto" in C the equivalent of a simple JMP instruction? I don't see any problems in using that. You have to use it. If you don't, people will die :roll:
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

XCHG wrote:Isn't "goto" in C the equivalent of a simple JMP instruction? I don't see any problems in using that.
It is still considered by many as bad programming practice. I take it as you haven't used C or C++ before? Well, it is a simple jump instruction, which may work fine in some situations (e.g. for a to jump over a block of code, or back to the beginning of a loop), but when you start jumping between functions, classes, and between scope within the same function, you can begin to screw up the stack and memory location of local variables. This is not to say you couldn't work out a way to do this in a safe manner.
XCHG wrote:You have to use it. If you don't, people will die :roll:
Of course you have to use the JMP instruction to divert program control to another section in memory, and goto isn't the only way to do this. C loops, conditions, and function calls removes the necessity of using goto. I don't even have a single "goto" in my OS which is 99%+ C++ (I do use jmp in assembly, but only occasionally, like to jump over my multiboot header and to jump to my main c++ function). This is only my opinion, and does not mean that you can't/shouldn't use goto just because I say so.

I could provide useful in some situations, like if you loaded a program and you wanted to jump to an address in memory. In my OS, I load the EIP into the thread's structure, which gets placed into memory on a context switch, avoiding the need for goto. If I had to jump to an address, I would create a function pointer to the address and then call the function.
My OS is Perception.
niteice
Member
Member
Posts: 59
Joined: Tue Oct 03, 2006 3:49 pm

Post by niteice »

Image
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

The moral of the story.. If you use goto's you'll be attacked and killed by prehistoric reptiles? :lol:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Post by SpooK »

XCHG wrote:Isn't "goto" in C the equivalent of a simple JMP instruction? I don't see any problems in using that. You have to use it. If you don't, people will die :roll:
Yes, and for people that let the compiler do most/all of the work... in there lies the problem of diverting program control in such a manner.
User avatar
babernat
Member
Member
Posts: 42
Joined: Tue Jul 03, 2007 6:53 am
Location: Colorado USA

Post by babernat »

I try hard not to use it. But to my everlasting shame I have used it in hobby code. Every time I have used it it has been because I did not truly understand the problem and the resulting solution...


http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF
Thanks for all the fish.
Post Reply