basicprogramming.org


Welcome, Guest. Please login or register.
Did you miss your activation email?
Forum time; Jul 31. 2010, 06:01
Home Help Search Calendar Login Register
News: Have you got suggestions for BasicProgramming.org? Let's hear them!
Interested in creating your own programming language? Check out the QDepartment group!

+  BASIC programming forum
|-+  Interpreter Development
| |-+  yaBasic development forum. (Moderator: Thomas Larsen)
| | |-+  What would you like to see re-added to Yabasic 3?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 2 [3] 4 Go Down Reply Print
Author Topic: What would you like to see re-added to Yabasic 3?  (Read 879 times)
Jacob
Sr. Member
****
Offline Offline

Posts: 414


« Reply #30 on: Jan 28. 2010, 10:34 » Reply with quote

I'm not for or against keeping goto/label around, but if it is going to be a part of Yabasic, I think it should be considered what should be legal to do. In version 2.763, the only behavior I strongly dislike about it, and can cause unexpected things, is the ability to goto/gosub into a loop. I see the benefit of being able to goto out of a bunch of nested loops(Basically the easiest way to do this in Yabasic), BUT, things like this shouldn't be allowed:
Code:
for i = 1 to 10
print i
next

goto test

for i = 1 to 10
label test
print i
next
What does it print? The numbers [1,11], which is unexpected for a newcomer because the second for loop only runs in the range [1,10].

Now, my personal opinion is that goto and labels are more like jumps in assembly rather than something you should be using in a higher level-language, and that it makes the flow in a program harder to follow, but that's just my opinion, and I do see that there are several reasons why it would be useful to have it in a language, not only for backwards compatibility.

Personally I wouldn't touch a goto-statement if the language provided another way to accomplish it that would be easier to follow, but I know there's a large difference between how someone who just started out with programming and someone who has years of experience does things.

As for what it's like in assembler, take this example(didn't test this, but shouldn't be that much off):
Code:
i=1                     // mov eax, 1
limit=10                // mov ebx, 10
label for_loop_1        // for_loop_1:
if( i > limit ) then    // cmp eax, ebx
goto for_loop_end_1     // jg for_loop_end_1
endif                   // push eax
print i                 // call print '__cdecl print
                        // pop ecx 'using ecx as dc register
i=i+1                   // inc eax
goto for_loop_1         // jmp for_loop_1
label for_loop_end_1    // for_loop_end_1
I've seen BASIC code for a for-loop like functionality that looked like this(Hell, I probably even wrote some myself when I started out), now you may argue that everyone should know the pros and cons of using goto, but if you start writing code like that, you're working against the language and just making it harder for yourself. There's a reason for using loops and control-structures, it makes it easier to understand what's going on. You can call it a learning experience, but if you've spend any time helping people coming from a BASIC language to something like C and people can't get out of the way of thinking(Not true for all, but some don't go beyond goto), anything remotely complex becomes a massive task of figuring out duplicated labels and where you're actually ending up in your code when you goto something.
Quote
while compilers actually put it back in when they reach the assembly stage.
Compare my asm/goto example to the version using structured programming:
Code:
for i = 1 to 10
print i
next
What is easier to understand and follow? It's called abstraction and is a fundamental concept in computer science. Not that that means goto/label(and gosub) should be taken away, I just think one should teach new people when it's appropriate to use it and when it's not. Again, when you've helped people using goto like I illustrated, you want to kill the person who came up with the idea.
Report to moderator   Logged

"The truth is rarely pure and never simple."  - Oscar Wilde
psnake
Sr. Member
****
Offline Offline

Posts: 438



« Reply #31 on: Jan 28. 2010, 10:36 » Reply with quote

Yabasic was my first language and the first feature that I got a hold of was indeed goto. Now after years of learning some other programming languages and understanding their point of view I actually can see why goto can be useful / fun for newbies and seasoned basic programmers alike, but I learned not to use it when I'm writing more serious code. Still I'm in favor of its presence.

My first point: it's a lower-level feature that it's closer to our way of thinking. The goto is just: the programs goes to this label. It's easy to understand and easy to use. The gosub is little more complicated but still very easy to explain: the program goes to this label and when it finds a return it goes to the position where it was.

My second point: it's more linear to use than a while-loop, for-loop, etc. because what you think that the program will do is almost a match to what you're writing: (imagine a main loop of a game)
  • My loop starts here (code: label loop)
  • Do something here
  • If something happens then I jump out of the cycle (code: goto out_of_loop)
  • Do some more stuff
  • Now do everything again (code: goto loop)
IMHO, this is simples because what you're thinking (flow of the program) and what you have to write (actual code) follow very closely together with goto. Without goto, your thoughts aren't linear anymore:
  • My loop starts here (and you immidiatly have to answer these questions asked by the syntax of language: which type of cycle, what's the condition to end it)
  • Do something here
  • End loop
Note there are two items that you have to think earlier on the writing of the loop than on the previous example. Also in the previous example you can stop writing and test the code even if you don't have a stop condition, but you already need to have that decided (or just put a 1 in the condition which looks worst than a goto) in the second example.

For the gosub, it's a simple way to write a function: you don't have to worry about what arguments are passed (ie. none) and you don't need to worry about local variables.

This argument of what goes in the head of the programmer is to say that it's easier to learn how to use goto. And to someone who just wants some fun, doesn't want to think in more complicated things. I sometimes get home tired but I still want to program a small fun idea that I had earlier, so I don't want to go around and write well written code or anything, I just want something that works and have fun doing it.

yabasic, like other basics, are, like EKV said, a way of thinking and for me it's also a way to have fun. What I miss in other basics and I think yab3 has, is the possibility to use it both for fun projects and for more well-thought, well writen code.

To conclude goto = simpler thought, more fun. If you need more high-level constructs then don't touch it (but keep using yabasic Wink).

PSnake
Report to moderator   Logged

twitter: @PSnake89
Jacob
Sr. Member
****
Offline Offline

Posts: 414


« Reply #32 on: Jan 28. 2010, 10:48 » Reply with quote

For the gosub, it's a simple way to write a function: you don't have to worry about what arguments are passed (ie. none) and you don't need to worry about local variables.
Except you have to be very careful with the naming of the variables in the label you gosub to, and have to manually look up what the return value is to get the result:
Code:
for i = 1 to 10
some_var_1 = i
gosub calculate_square
print some_var_2
next

label calculate_square
some_var_2 = some_var_1 * some_var_1
return
Compared to:
Code:
for i = 1 to 10
print calculate_square(i)
next

sub calculate_square( i )
return i * i
end sub
And if you have more than one "function" that you use using gosub, then it starts getting hairy because you gotta keep track of the names of all the "return values", just like you have to keep track of all the internal variables in each "function" to make sure you dont accidentally overwrite a variable somewhere.
Report to moderator   Logged

"The truth is rarely pure and never simple."  - Oscar Wilde
menn
Hero Member
*****
Offline Offline

Posts: 571


« Reply #33 on: Jan 28. 2010, 10:53 » Reply with quote

To conclude goto = simpler thought, more fun. If you need more high-level constructs then don't touch it.

and that's good advice. i don't use goto anymore, since i can always find a way not to (although if i still used qbasic, you need it for on error. there's literally no other way.) after 25+ years of basic programming i don't need goto, but that's no reason for me to impose other things on any other 5 year old learning basic like i did.

if you wait until you're 12 to learn basic, you probably -won't- need to spend several years using goto like i did, you can probably spend about a week using it, or skip it entirely and use gosub. if you're under 14 (these are pretty arbitrary guesses about age, pippy is aimed at 3rd graders) and want to use locally scoped routines for everything, python is an example of making it pretty trivial and easy to use those.

but gosub is still easier, for programs with less than 12 to 20 subroutines. i don't use globally scoped routines in python, but i do in yabasic 2.7- because for small programs it really is easier and more fun (less tedious) to use gosub. after 20 subroutines it's truly gosub that is more tedious- but if someone really thinks it's easier to do 100 subs with global scope, i'm not going to try to stop them.
Report to moderator   Logged

an "all purpose" language calls for- as much as can possibly be reasonable- an "all purpose" forum. the worst thing happening to modern basic? too many pointless rules and painting everything into corners. most modern basic forums are like that too.
psnake
Sr. Member
****
Offline Offline

Posts: 438



« Reply #34 on: Jan 28. 2010, 11:02 » Reply with quote

I understand but when I talk about programs that use goto/gosub, they are not programs bigger than 200/300 lines. So usually those problems don't arise.
For bigger programs I'm for higher language constructs.

As for the example you gave, I'm not saying that it's only one way or the other. In this case it's really a case to use a function.

PSnake
Report to moderator   Logged

twitter: @PSnake89
Jacob
Sr. Member
****
Offline Offline

Posts: 414


« Reply #35 on: Jan 28. 2010, 11:07 » Reply with quote

I know it was a simplistic example, but I was feeling a bit lazy. I know that when you start out gosub/goto is an easy way to get started because your programs mostly are small enough to keep track of things manually and that, assuming you aren't a complete tool, you can name your labels and variables in a sensible way.

The problem I've seen being an teachers assistant in both C and C++ courses at university, is that some people never grow out of it and insist on writing C or C++ programs where they have one big main function with hundreds of lines and they jump all over the place with gotos, and trying to debug that is, to put it mildly, frustrating.
Report to moderator   Logged

"The truth is rarely pure and never simple."  - Oscar Wilde
menn
Hero Member
*****
Offline Offline

Posts: 571


« Reply #36 on: Jan 28. 2010, 11:11 » Reply with quote

goto should absolutely be removed from c and c++ Smiley

though since i use neither, i can't say i'm going to make any real efforts to that effect. i'll just leave c and c++ alone and let its users worry about it.
Report to moderator   Logged

an "all purpose" language calls for- as much as can possibly be reasonable- an "all purpose" forum. the worst thing happening to modern basic? too many pointless rules and painting everything into corners. most modern basic forums are like that too.
psnake
Sr. Member
****
Offline Offline

Posts: 438



« Reply #37 on: Jan 28. 2010, 11:26 » Reply with quote

goto in C/C++ is a really bad thing. In this case I think that the way they are taught to use goto needs to specify the pros and cons of using it so they know it's not meant to use everywhere and in every language that has it.

PSnake
Report to moderator   Logged

twitter: @PSnake89
Derek
Administrator
Hero Member
*****
Offline Offline

Posts: 1001



WWW
« Reply #38 on: Jan 28. 2010, 11:30 » Reply with quote

Hi,

someone has made a request for goto and gosub so I can't see why it should be left out and I hope we can discuss the merits of each suggestion in a civil manner.

I'm voting for execute() and compile() as well as the ability to choose to hide the console window if a graphic window is open. And finally... a pizza delivery command:
Code:
Pizza("Hawaiian", "deep")
wait 10
Answer_Door()

Derek.
Report to moderator   Logged

wget http://*
aurelB
Hero Member
*****
Online Online

Posts: 664



WWW
« Reply #39 on: Jan 28. 2010, 12:07 » Reply with quote

Quote
I'm voting for execute() and compile() as well as the ability to choose to hide the console window if a graphic window is open.

Yeah i vote for this to Smiley

by the way Creative Basic have excellent options for subs.
You can :

Gosub mysub
or
mysub()
or
mysub

all this 3 option works the same.
second  for sub

SUB mysub
----
-----
RETURN

or

LABEL mysub
-----
------
RETURN

or

mysub:
-------
-------
RETURN

All 3 way works same as sub.


Report to moderator   Logged

menn
Hero Member
*****
Offline Offline

Posts: 571


« Reply #40 on: Jan 28. 2010, 12:21 » Reply with quote

someone has made a request for goto and gosub so I can't see why it should be left out and I hope we can discuss the merits of each suggestion in a civil manner.

me too. and knowing full well i'm the main culprit here, i've talked about it with e.k. in pm (i pm'd him) and i think (considering we're basically walking amidst a flamewar that started about 40 years ago, cue billy joel) it's actually gotten more civil as the thread progresses, rather than degenerate further. that's a first in my experience. i hope i'm not the only person who sees the progress made in this thread, that it's not my imagination. in my view, where geeks are involved, heated arguments can't be avoided all the time. but very good people (including those of us arguing) can help cool them down.
Report to moderator   Logged

an "all purpose" language calls for- as much as can possibly be reasonable- an "all purpose" forum. the worst thing happening to modern basic? too many pointless rules and painting everything into corners. most modern basic forums are like that too.
OneHitWonder
Jr. Member
**
Offline Offline

Posts: 81



« Reply #41 on: Jan 28. 2010, 15:04 » Reply with quote

i'll be waiting for yabasic to have goto again, just on principle. that way people can really choose if they want to do things the way they were always done in basic, or your way. then they have a real choice. and if we go your way and remove that choice, i'll just use something else. it may not have goto, and that's ok so long as it doesn't have the word "basic" in the name. then it's fine- as i've said for years.

I repect everyones opinions of what there vision of basic is/should be. I just wanted to give you mine from a beginners point of view with less than 6 months experience. I don't think basic should be looked at from what it does or doesn't do, so what if it has goto, gosub or not, that doesn't mean it isn't basic, to me basic is how the synatx is written, easy to understand, not what it does.

EDITED: I wrote this without reading the later posts

OneHitWonder
« Last Edit: Jan 28. 2010, 15:06 by OneHitWonder » Report to moderator   Logged

I need a girl whose name doesn't end in .JPG Smiley
Juan
Guest
« Reply #42 on: Jan 28. 2010, 15:32 » Reply with quote

 Hello. I would like to see e good development environement in with you can step to step debugging and see the value of the variables, visual and very easy form design...
 Best regards and congratulation for your good work.  Smiley
Report to moderator   Logged
menn
Hero Member
*****
Offline Offline

Posts: 571


« Reply #43 on: Jan 28. 2010, 15:33 » Reply with quote

I don't think basic should be looked at from what it does or doesn't do, so what if it has goto, gosub or not, that doesn't mean it isn't basic, to me basic is how the synatx is written, easy to understand, not what it does.

there's some truth to that, there are a lot of features that don't decide whether it's basic or not, but i think there are some that probably do. we're also talking about yabasic, not only basic in general, and taking out features that are de facto standards across countless dialects (goto was in the original basic, gosub is even part of the ansi standard) you can certainly take things out of basic that you shouldn't. as for other things it should do, this list goes way back: http://en.wikipedia.org/wiki/BASIC#Early_years:_the_mainframe_and_mini-computer_era
Report to moderator   Logged

an "all purpose" language calls for- as much as can possibly be reasonable- an "all purpose" forum. the worst thing happening to modern basic? too many pointless rules and painting everything into corners. most modern basic forums are like that too.
OneHitWonder
Jr. Member
**
Offline Offline

Posts: 81



« Reply #44 on: Jan 28. 2010, 19:07 » Reply with quote

Quote
the ability to choose to hide the console window if a graphic window is open.

I think the graphical window is a great idea.

(slightly going of topic here)

What are Yabasics 3D features like if any at all?

OneHitWonder
Report to moderator   Logged

I need a girl whose name doesn't end in .JPG Smiley
Pages: 1 2 [3] 4 Go Up Reply Print 
« previous next »
Jump to:  
Atom RDF RSS 0.91 RSS 2.0


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!