mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
* /goto: 'label' not found #40870 10/08/03 06:38 AM
Joined: Feb 2003
Posts: 2,669
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,669
When you use /goto label and :label isn't found, you'll get this error.

I know this isn't a bug, however, I would like to suggest that it /returns at that point rather than raising an error and halting. If this is not possible, I would like to suggest a silent .goto that acts in this manner.

The reason this is an issue, is many people use labels as a fast and effecient Case Select instead of using many If-ElseIf-Else statements. The only problem is, if the Case doesn't exist, the script errors and halts.

Example of actual use I've seen:
Code:
goto $devent
:sclick | do stuff | return
:dclick | do stuff | return
:edit | do stuff | return
This code will error on all mouse and other events unless a :label is created for each of them.

In more extreme cases, I see goto $did with number labels of each dialog object, but unfortunately they have to include objects that don't apply just to keep it from erroring.

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: * /goto: 'label' not found #40871 10/08/03 06:46 AM
Joined: Jun 2003
Posts: 130
O
obsessed Offline
Vogon poet
Offline
Vogon poet
O
Joined: Jun 2003
Posts: 130
I use this method eg.
goto $did
:1 do this
:2 do this
I had to do this for 200 processes even ones that did nothing ,this would imlimate the need for it. Nice suggestion.
.goto would be best way to go imo.

Last edited by obsessed; 10/08/03 06:49 AM.

If only women came with popup menus and online help.
Re: * /goto: 'label' not found #40872 10/08/03 08:46 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
There is a way to do it, shown here. It isn't documented in the help file and that's a shame.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: * /goto: 'label' not found #40873 10/08/03 01:49 PM
Joined: Feb 2003
Posts: 2,669
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,669
Thanks qwerty, great example!

Funny arguements in that thread. I've always found goto loops bench slightly faster than while loops, and dont know of any "self respecting programming language" that removed goto just because other 'proper' methods exist. I understand it's the most basic and important machine language instruction.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: * /goto: 'label' not found #40874 10/08/03 05:25 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
IMHO a better solution would be for Khaled to just listen to suggestions and add a select() feature to the language. Although seeing as how for() has been suggested hundreds of times and hasn't been added, maybe that will just never happen...

Re: * /goto: 'label' not found #40875 10/08/03 06:39 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
A select feature probably stands more chance of being implemented since it's not so easily/obviously replicated with current methods as a for loop can be.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: * /goto: 'label' not found #40876 10/08/03 08:09 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Umm select can be easily replicated.
select (%a) {
case 1:
.....
case 2:
......
default:
.....
}

:::

if (%a == 1) ........
else if (%a == 2) ........
else .........

Re: * /goto: 'label' not found #40877 10/08/03 08:27 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
It's not the same. That will only ever execute a single collection of commands, whereas a select statement woud perform all commands below the case position aswell unless broken out of. qwerty's way is the only way I can see of doing it, and it's not an obvious solution that would come into most people's heads.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: * /goto: 'label' not found #40878 10/08/03 08:52 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
if (%a == 1) {
.......
}
if (%a == 1 || %a == 2) {
.......
}
;default stuff goes here
.......

Re: * /goto: 'label' not found #40879 10/08/03 09:21 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Just add a check for the value of a variable to act as a break statement, and then keep appending to that condition for each case and you've got a working select statement (and some ugly, inefficient code).

In any case, yes it can be done and it's not rocket science, but it's not anywhere near as easy to do as the simple shifting of a variable creation and reassignment onto new lines that is required for a for loop to become a while loop.

Anyway, either would be quite nice to have in mIRC I guess.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: * /goto: 'label' not found #40880 11/08/03 02:37 AM
Joined: Feb 2003
Posts: 2,669
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,669
I don't see any speed improvements or syntax improvements by creating a switch () command and special structure that adds extra lag to the ever-bloating parcer.

Quote:
select (%a) {
case 1:
.....
case 2:
......
default:
.....
}

Code:
goto %a
:1
.....
:2
.....
:%a
.....

Less lines, less work, faster engine.

- Raccoon
"I hate mighty C coders."


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: * /goto: 'label' not found #40881 11/08/03 03:53 AM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Someone needs to learn how to count (us "mighty C coders" can count, you should try it too):

Lets try it, ok?

[1] goto %a
[2] :1
[3] echo -a it's a one
[4] goto end
[5] :2
[6] echo -a it's a two
[7] goto end
[8] :%a
[9] echo -a I don't know what it is!
[10] :end

[1] switch (%a) {
[2] case 1:
[3] echo -a It's a one
[4] break
[5] case 2:
[6] echo -a It's a two
[7] break
[8] default:
[9] echo -a I don't know what it is
[10] }

Now for the tough part... does 10 in fact equal 10? I hope that you can see it does.

I know, it's natural for you to hate us C coders for being able to count. Maybe one day you'll be able to count up to 10, then you'll be able to see that there are the same number of lines in both of those examples, and then you won't have to hate C coders anymore!

Oh by the way, you'll see that if you don't want a default case, the goto method is longer:

goto %a
:1
echo -a it's a one
goto end
:2
echo -a it's a two
:%a
:end

as opposed to
switch (%a) {
case 1:
echo -a it's a one
break
case 2:
echo -a it's a two
}

I hope you'll be able to count the difference there?

Re: * /goto: 'label' not found #40882 11/08/03 07:11 AM
Joined: Feb 2003
Posts: 2,669
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,669
nice essay.

care to share your thoughts on that which was bolded (aka, a point of greater significance that you conveniently overlooked) in 400 words or less?

btw, equal lines, less charactes... doesn't matter. any way you slice it, using /goto is much sexier than switch could ever be.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: * /goto: 'label' not found #40883 11/08/03 12:58 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The word that was bolded was part of 'Less lines, less work, faster engine'. codemastr pointed out that it wasn't less lines, which kinda destroys the line of thinking that you had going on in that sentence. Besides, less lines doesn't necessarily mean less work. Clean logic is more important. Having well structured flow to your code is more important. With that said, goto does not provide those things well, structured statements like while loops and select/case provide it by the bucketload.

BTW, I found goto loops to be approx. 5% slower than the equivalent while loop.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: * /goto: 'label' not found #40884 11/08/03 06:53 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Despite speed (whatever the outcome) i personall too prefer case as the all-too-known "spaghetti code" is much easier to reproduce in a goto system then a structured enviornment. Also (IMO) i feel people who use goto's have a much lesser understanding of how to execute a loop and what the bassis of a loop is. To me, it looks like you didn't take the time to continue your thought process of "what comes next after XXX executes" and just said "the hell with this, lets goto YYYY". Again, just my opnion.


-KingTomato
Re: * /goto: 'label' not found #40885 11/08/03 08:28 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Here is hard 100% PROOF that the goto method is BAD.
Load this alias:

alias blah {
goto $1
:1
echo -a 1 is a 1
goto end
:2
echo -a 1 is a 2
goto end
:$1
echo -a I don't know what 1 is
:end

goto $2
:1
echo -a 2 is a 1
goto end
:2
echo -a 2 is a 2
goto end
:$2
echo -a I don't know what 2 is
:end
}

Now type /blah 1 1 you get an infinite loop of "1 is a 1" because the labels conflict. Now try /blah 3 4, you get "* /goto: duplicate '1' found". On the other hand,

alias blah {
switch ($1) {
case 1:
echo -a 1 is a 1
break
case 2:
echo -a 1 is a 2
break
default:
echo -a I don't know what 1 is
}

switch ($2) {
case 1:
echo -a 2 is a 1
break
case 2:
echo -a 2 is a 2
break
default:
echo -a I don't know what 2 is
}
}

That would work fine. But I guess it takes a "mighty C coder" to see that HUGE flaw.

Re: * /goto: 'label' not found #40886 12/08/03 07:34 AM
Joined: Feb 2003
Posts: 2,669
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,669
All great things require discipline to master.

Just because the untrained programmer requires structure and restraint to be forced upon him, does not mean those with dicipline are without self emposed structure and restraint.

Your argument that "people who use /goto don't know what they're doing, and will always fail." reminds me of the paranoid mother who says "You'll shoot your eye out."

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: * /goto: 'label' not found #40887 12/08/03 10:33 AM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Quote:

Your argument that "people who use /goto don't know what they're doing, and will always fail." reminds me of the paranoid mother who says "You'll shoot your eye out."


Now your doing as you usually do to stress a point. That being moving words around so you look like you come out on top. i did not say you will always fail, nor did i say everyone who uses it has no clue what is going on. What I did say is that most whom use gotos have a weak understanding of a loop.


-KingTomato
Re: * /goto: 'label' not found #40888 12/08/03 07:23 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
What's your witty remark to my claim there? Or have you realized you don't know what you're talking about (yet again) and just refuse to admit it?

Quote:

Just because the untrained programmer requires structure and restraint to be forced upon him, does not mean those with dicipline are without self emposed structure and restraint.

When was the last time you did coding for a commercial product? Never? Well I have. And let me tell you, I had a project to do (which I really can't go into detail on for legal reasons), anyway I accomplished the goal, and the code I wrote was super fast. However, my code made use of several "dirty tricks" to allow for added speed and reduced memory usage, it also used some obscure techniques. As a result, if you didn't know what my code did, you could not figure it out, there were too many confusing parts. So I submitted it to my boss, and guess what happened? I was promptly told to do it over. I then told him that there was no faster way to do it. He responded with "do you think our users care about the difference between an operation that takes 2 microseconds and one that takes 4 microseconds?" He then went on to add, "It might be fast, but I can't tell what the damn thing does. That means no one except you is ever going to touch this code, and thats not good at all". Basically, I was forced to redo the code in straight normal C. The code was slightly slower, but now, even a 1st year programming student could look at the code and figure out what it does whereas before someone who had been working with C for 10 years would have had to give it some real thought. At the time I had the attitude "faster is better" but I've since changed that attitude simply because NO ONE in the computer programming field lives by that mantra. To quote my current professor "The grade for a computer program is 8 parts style, 2 parts speed." Meaning, the way the code looks is sometimes more important than the way it works. If you want to dispute that, well thats fine but I'll ask you this, show me your credentials? Where did you receive your degree in computer science? Where have you worked as a programmer professionally? Etc. Because I think you haven't a clue what you are talking about. If you disagree with me, you just prove you don't know the first thing about programming. There are whole books written on just C/C++ programming style, so it is a very important issue. And if you want to neglect it, then you prove that you're just arguing for the sake of arguing.

Re: * /goto: 'label' not found #40889 12/08/03 09:36 PM
Joined: Dec 2002
Posts: 4,586
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,586
And sexy is what we aim for grin

A 'case' statement would likely be slower than 'goto' since it would require more parsing, whereas the goto implementation is pretty zippy and minimal.

Always nice to have standard programming constructs ie. 'for' and 'case' but if they're going to be slower than existing constructs eg. 'while' and 'goto' which provide more or less the same functionality...

Then again, using /goto is something I avoid myself... I'll move select/case higher up on the to-do list smirk

Page 1 of 2 1 2