PDA

View Full Version : about GOTO



zak
27-02-2010, 13:04
Hi
since Petr have used the statement: I must GOTO school now.
i have remembered reading that the mathematician John Forbes Nash, Jr., a Nobel Laureate in Economics,
http://en.wikipedia.org/wiki/A_Beautiful_Mind_(film)
was using GOTO extensively in his demonstrations using mathematica programming language; as reported in this amusing page:
http://forums.wolfram.com/mathgroup/archive/2005/Jun/msg00216.html

on the other hand GOTO can be used to denote "walking" to some place because it is nearby, while using more complex words relevant to something like call sub and so on, means that the place is far and we will use a more complex structures like cars, buses... .
just a fantasia

Michael Hartlef
27-02-2010, 13:10
Goto is possible? Where did Petr showed it?

zak
27-02-2010, 13:48
Hi Michael , here is the link:
http://community.thinbasic.com/index.php?topic=3246.msg24338#msg24338

Michael Hartlef
27-02-2010, 13:54
Ahh, I see. I misunderstood your post. Thanks anyway.

ErosOlmi
27-02-2010, 14:36
Well, all programming flow can be just summarized into IF and GOTO. With IF and GOTO you can just do whatever.
GOTO born has many programming historical reasons but now that old computers limitation are gone I think GOTO must go either.

Be sincere and tell me what you prefer of the two piece of code below that are doing exactly the same thing:


i = 0
20 i = i + 1
PRINT i; " squared = "; i * i
IF i >= 10 THEN GOTO 60
GOTO 20
60 PRINT "Program Completed."


FOR i = 1 TO 10
PRINT i; " squared = "; i * i
NEXT i
PRINT "Program Completed."

The problem is the abuse but if you have a GOTO in your language I'm sure that sooner or later many programmers will abuse of it because it is very simple to solve some kind of programming problems using a GOTO but will be a nightmare to maintain and understand that exactly piece of code during the time.

At least, for what is worth, this is my opinion.

Eros

Michael Hartlef
27-02-2010, 15:05
Eros, I know about how you can live without GOTO. :roll:

I was just curious if I missed something in the topics here.

ErosOlmi
27-02-2010, 15:19
Yes, I know.
I was just talking general about the introduction of the GOTO.
Sometimes I found also myself in search of the GOTO keyword in thinBasic so I mainly need to convince once again myself that not having GOTO is the right choice :D

I will see if I can post some code of my work boss.
He makes programs in an old Basic dialect called CBASIC (16 bit compiler from Digital Reasearch) and he just use IF, FOR and GOTO :grrrr:
Can you imagine how easy it is to maintain or trying to get the idea of what the program is doing?

zak
27-02-2010, 16:07
years ago a friend told me a myth that a programmer refused to give his approval to the marriage of his daughter to a programmer, because the father discovered that the suitor is using GOTO in his code, he said he can't trust him to be responsible enough in this complex world.
i can't believe this myth. but it is not impossible

Petr Schreiber
27-02-2010, 16:16
:lol:

That is nice story Zak, never heard it.

ErosOlmi
27-02-2010, 18:51
Nice .... I will keep in mind :D

Michael Clease
01-03-2010, 11:32
Sounds perfect to me

danbaron
18-03-2010, 09:02
[font=courier new]I vote to add GOTO.

I bet it would be relatively easy to do.

When I use HEAP_Alloc, POKE, and PEEK, I am responsible for making sure there is no memory corruption.

I don't know why I cannot be trusted to use GOTO.

It seems to me that sometimes, GOTO is just the easiest way to do things.

Because thinBasic does not have GOTO, when I would have used it, I instead have been using, DO, LOOP, ITERATE DO, and, EXIT DO.

The statement after the DO, is where the GOTO would have jumped to.

Like in PowerBASIC, if you had,

dog:

then you could say,

GOTO dog

Anyway, I don't think I can force Eros to add it.

I guess, I'll just have to suffer.

Dan :oops: :x :P

christianssen
18-03-2010, 10:04
i vote against it ;)

my reasons:

You shouldn’t use GOTO command, cause your produced code with more GOTO’s your program (perhaps 10, 100,1000) will be very unclear. You produce confused spaghetti code, nobody but you will understand it. The programmer will have some problems itself to understand after a while.

Logical structure of programming is very important. Compiler produces still enough confused code (with IF..THEN..ELSE…END…IF..FOR…NEXT and more). You needn’t GOTO for this spectacle anymore ;)

You are jumping from one mark to another and the program decreases his speed!
The years are gone for BASIC with linenumbers where didn’t exist SUBs. You can avoid using GOTO for 99 per cent I am thinking.

I don't use GOTO and I will not use it, that's for sure!

thanks, denis

Michael Hartlef
18-03-2010, 11:13
I would not mind to have GOTO/LABEL :)

John Spikowski
25-03-2010, 10:04
I wrote a function in ScriptBasic to emulate a keyword used in BaCon. Do you know of a better way to strip SPC/TAB/CR/LF from the both ends of a passed string?



FUNCTION CHOP(arg_str)

LOCAL pos, tmp

IF LEN(arg_str) = 0 THEN EXIT FUNCTION
SPLITA arg_str BY "" TO tmp
pos = LBOUND(tmp)

Next_Char:
IF INSTR(" " & CHR(9) & CHR(10) & CHR(13), tmp[pos]) AND pos < UBOUND(tmp) THEN
tmp[pos] = " "
pos += 1
GOTO Next_Char
END IF

pos = UBOUND(tmp)

Prev_Char:
IF INSTR(" " & CHR(9) & CHR(10) & CHR(13), tmp[pos]) AND pos > LBOUND(tmp) THEN
tmp[pos] = " "
pos -= 1
GOTO Prev_Char
END IF

CHOP = TRIM(JOIN("",tmp))

END FUNCTION

Petr Schreiber
25-03-2010, 16:35
One of many possible solutions of your code without using GOTO and without rebuilding the string char by char:


Function Chop(ByVal sTemp As String) As String
' -- Store length of string, we will use it multiple times
Dim sLen As Long = Len(sTemp)
If sLen = 0 Then Return ""

Dim i As Long

' -- Variable to store from to where we need to trim
Dim trimStart As Long = 1
Dim trimEnd As Long = sLen

' -- Overlay BYTE array over string to get ASCII values directly
Dim Characters( sLen ) As Byte At StrPtr(sTemp)

' -- Forward movements
For i = 1 To sLen
Select Case Characters(i)
' -- Naughty characters? Then advance
Case 9, 10, 13, 32
Iterate For

' -- Ok character, escape
Case Else
trimStart = i
Exit For
End Select
Next

' -- Backward movement
For i = sLen To trimStart Step -1
Select Case Characters(i)
' -- Naughty characters? Then advance
Case 9, 10, 13, 32
Iterate For

' -- Ok character, escape
Case Else
trimEnd = i
Exit For
End Select
Next

' -- Return the trimmed string
Return Mid$(sTemp, trimStart, trimEnd-trimStart+1)
End Function


The most straightforward way in context of TB would be to just pick existing function:


s = trim$(passedString, ANY $CR+$LF+$SPC+$TAB)


Petr

GSAC3
25-03-2010, 18:48
I can understand Eros' objection to GOTO. Its availability
can lead to very messy code, especially when used frequently.
However, I must say that I have found it to be very useful
at times when developing complex coding schemes. I have
been using GOTO (sparingly) for 50+ years in writing FORTRAN
programs and have found its judicious use does not adversely
affect coding quality or performance.

Don

John Spikowski
25-03-2010, 20:08
GOTO is used in ScriptBasic to jump out of FOR/NEXT and WHILE loops early as well.

There are times when a GOTO is just the best way of getting there. ;)


s = trim$(passedString, ANY $CR+$LF+$SPC+$TAB)

Sweet! I wish the ScriptBasic TRIM() function had an ANY clause. It only works removing spaces from the front and back of a string. It's also the reason I converted each character to a space so I could use TRIM() just before exiting out of the function.

John Spikowski
27-03-2010, 11:36
Sometimes I found also myself in search of the GOTO keyword in thinBasic so I mainly need to convince once again myself that not having GOTO is the right choice.

I view GOTO as a seasoned Basic programmer's way of code reuse without the fuss. :)

Jordi Vallčs
27-03-2010, 19:37
Every time I see a discussion about GOTO statement I remember a sentence of my first boss/teacher:

The GO TO statement is needed, but its use is an abuse referring to GO TO (two words) statement on PL / I language. I agree with this opinion on 99.9% of cases.