mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
#104270 05/12/04 05:31 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
since all i hear from the people in here is that its uggly and dont look nice, then why should people learn from it ? even due its messy it works, and it does what i want it to do, and still no one could tell me why goto is so bad to use ? thats what i trying to figure out, not how to hide my code, it's messy yes, but nothing i do on purpose, i just want it to work the way i want it to. and if it working with "goto", then people tell me NOT to use goto, why cant somone answer me why i shouldent use goto ?


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
#104271 05/12/04 11:45 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The reason, as I've said at least twice already, is readability and maintainability. If you want to use goto then that's fine, but for anyone interested in making code that's easy to read, edit, maintain, and learn from then goto is rarely the appropriate tool.

In fact judging from the code you've given in your original post in this thread, your understanding of goto is flawed. If %rkickmsg doesn't equal 1 the script will attempt to ban and kick the same person twice - something that would've been easily spotted using structured code.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#104272 06/12/04 12:31 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Quote:
still that didnt explain why goto is bad to use ?

I did say why it is "bad" to use: it lacks logic, it is unorganised code, and it is harder to follow the script. Since goto's jump, in order to follow how the script's logic works, you also have to jump to different parts when reading it.

Using if, elseif, else is far better as it creates a logic framework.

if (condition) {
commands
}
elseif (other condition) {
other commands
}
else {
commands to do when all other conditions failed
}

You can read and follow the logic with these constructs, as if you're reading a book line per line. Commands are grouped between the braces after each condition, so you see perfectly what will happen given a certain condition.

With goto's you have to jump along with them to follow the logic. It's like reading some stuff on one page of a book, and then jumping back to another part etc. It's messy.

Quote:

and if it works, then how can it be bad?

Because something works, doesn't necessarily mean it's good.


Gone.
#104273 06/12/04 10:18 PM
Joined: Dec 2003
Posts: 261
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Dec 2003
Posts: 261
I was talking about cases when you can not replace goto with if, elseif, not about replacing goto in general.


velicha dusha moja Gospoda
#104274 07/12/04 08:24 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I was talking about the same things also, that you dont NEED got anywhere, it can always be managed without a exact execution location jump, but no worries, theads pretty dead.

Page 2 of 2 1 2

Link Copied to Clipboard