Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Dec 14, 2017 11:35 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 55 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: Various questions.
PostPosted: Wed Jan 30, 2013 10:52 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
"Advanced use cases"?

I defy anyone to come up with code using GOTO that cannot be refactored to NOT use GOTO

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Wed Jan 30, 2013 11:00 am 
Offline

Joined: Wed Jan 12, 2011 12:48 pm
Posts: 53
Location: Fresno, CA
DaveS wrote:
"Advanced use cases"?

I defy anyone to come up with code using GOTO that cannot be refactored to NOT use GOTO


But that's not really the point. It's like the OP asked, PushButton vs BevelButton. Depends on what you want to do.

It's cool you don't like it and don't allow others in your projects to use it. That doesn't mean it's "evil". It's just a keyword. Nothing more nothing less.

My point is it can be used in very interesting ways. Another example is mimicking javascript anonymous functions.

_________________
Thanks,
Phillip Zedalis
Managing Developer
http://www.1701software.com
773-236-1701


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Wed Jan 30, 2013 11:08 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
done arguing here..... GOTO is for procedural languages.... Not Event Driven Object Oriented ones.

RS should never have included it as "just a keyword"....

but you all do what you want...... I'm done trying to teach proper coding skills and standards.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Wed Jan 30, 2013 12:25 pm 
Offline

Joined: Fri Dec 01, 2006 3:09 pm
Posts: 650
Location: Tennessee, USA
I am 100% with Dave on this one. If you find a place where you think that you need to use a GOTO it is simply because your code is poorly written. I cannot remember the last time that I used a GOTO or even thought about GOTO. It just is not truly needed with good code in a language such as RS.


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Wed Jan 30, 2013 2:13 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
I've seen GOTO used in some big, hairy functions where at some point they need to bail out of the method gracefully. I agree, however, with the sentiment that GOTO should almost never be used. If you need to use it you probably need to refactor your code.

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Wed Jan 30, 2013 4:10 pm 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
:lol: Wow GoTo-less Programming wasn't that way back when Bob K was thrashing out Cobol with one of these

Image

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Thu Jan 31, 2013 4:18 am 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
It's not the first time I see this "GOTO is evil" flow of messages in this forum and I find it slightly dogmatic. I am not saying you are not right, I consider myself a novice programmer with very little experince so I wouldn't dare to. But I am a person who likes understanding, not just believing (although I do believe you). These are the kind of statement I most usually see when people speak against using GOTO:
Quote:
"THE USE OF 'GOTO' AND 'GOSUB' IN AN EVENT DRIVEN OBJECTED ORIENTED PROGRAMMING LANGUAGE IS EVIL"

Quote:
but I would NEVER counsel a beginner to use goto to skip code

Quote:
GoTo is an old idea from old languages... and it wasn't even that widely supported when it was around. It's really best to let code run in a top-down, nesting form than to jump around from one line to another. The closest being, as Dave said: Exit, Continue, and (I'll add) Return are the best ways to leave a section of code.
In my opinion, it'd be a good idea of RS to deprecate that feature altogether.

Quote:
GoTo is fine , if you are planning on making spaghetti for dinner

Quote:
GOTO's are not good. Why? There based on an idea that is 40 years old, even long before OOP said 'hi' in the programmers world.
GOTO is procedural, RS is mostly OOP based.



Only one person gave some reasons against using GOTO:
Quote:
Do "gotos" work? Sure... and for every GOTO you need a destination. Don't use a GOTO, you don't need a label gumming up the structure. Are Goto/Labels easily followed? In a small program, sure.. In a large one.. nope.
Maintenance.... with lousy structure comes difficult maintenace. On my development teams. READABILITY is #1, PERFORMANCE is #2 ..... and usually if they get #1 right, #2 follows automatically

I still don't think it would hurt to use GOTO where there is no risk to introduce bugs and the readability of the code is good (like for example, in a short mehod?).

By the way, in the little programming I do I NEVER use GOTO, I don't like it, but I can't explain why.

Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Thu Jan 31, 2013 5:00 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
An interesting read about the history of the GOTO command..

http://www.sonoma.edu/users/l/luvisi/goto/goto.pdf

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Thu Jan 31, 2013 6:28 am 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
shaosean wrote:
An interesting read about the history of the GOTO command..

http://www.sonoma.edu/users/l/luvisi/goto/goto.pdf

Thank you for that. The following text, written by Donald Knuth and referenced in the article of your link, also reflects my feeling that there is a widespread, excessive hatred against GOTO:
Quote:
"[U]ndisciplined go to statements make program structure harder to perceive, and they are often symptoms of a poor conceptual formulation. But there has been far too much emphasis on go to elimination instead of on the really important issues; people have a natural tendency to set up an easily understood quantitative goal like the abolition of jumps, instead of working directly for a qualitative goal like good program structure."


Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Thu Jan 31, 2013 9:24 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Quote:
people have a natural tendency to set up an easily understood quantitative goal like the abolition of jumps, instead of working directly for a qualitative goal like good program structure."


The funny thing with that statement..... If you ARE working directly for a qualitative goal like good program structure, then the abolition of jumps comes naturally and is no longer a quantitative goal

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Thu Jan 31, 2013 10:33 am 
Offline
User avatar

Joined: Mon Nov 29, 2010 7:01 pm
Posts: 446
harriew wrote:
I am 100% with Dave on this one. If you find a place where you think that you need to use a GOTO it is simply because your code is poorly written. I cannot remember the last time that I used a GOTO or even thought about GOTO. It just is not truly needed with good code in a language such as RS.


The last time I used GoTo was in the actual coding language BASIC. I think I was in 7th grade programming on floppy (legit floppy) discs. I'm certainly glad I learned not to use this with OOP languages and I've never had the need to look back.

I'm quite surprised at how much more efficient my coding has become since I started using RealStudio. And it continues to improve. I can look at code I wrote a month ago and make improvements.

Here are some of my favorites I learner over time.

The one-line if/then statement. It's nice you don't need an end statement too.

I also always use to do statements like
If me.visible = true then
me.visible = false
else
me.visible = true
end

//which over the course of programming, I now do
me.visible = not me.visible


In general I always use to do "if me.whatever = true then..." instead of "if me.whatever then..." which was silly

I also tend to subclass a lot of the RealStudio built in classes or at least extend them with a module. Instead of having to make sure I'm connected to a database every time I do a MySQL query and then checking for errors. It's easier to subclass it and have it auto-connect and msgbox an error if it occurs.


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Thu Jan 31, 2013 10:38 am 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
neonash7777 wrote:
I also tend to subclass a lot of the RealStudio built in classes or at least extend them with a module. Instead of having to make sure I'm connected to a database every time I do a MySQL query and then checking for errors. It's easier to subclass it and have it auto-connect and msgbox an error if it occurs.

There is another benefit to that. If you close the database in the subclass' Destructor, you can avoid jumping through hoops in case of error. If your method has to exit early, the instance will go out of scope and close itself.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Thu Feb 07, 2013 6:59 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
Briman,

You may not agree with Matt Neuburg (author of REALbasic: The Definitive Guide), but you and others may be interested in his comments on GoTo on pages 51-52 of his book:

"Finally, REALbasic provides a GoTo statement....

"GoTo was once the workhorse of flow control in many programming languages, since all by itself it can implement the equivalent of While, Do, or For, not to mention giving the programmer the ability to leap all over the place at will....

"The presence of GoTo in REALbasic is a nod to 'traditional' BASIC and its use is officially deprecaded. Nevertheless, there are situations, such as when one wishes to escape from more than one level of nested block, where,in my view, GoTo remains extremely convenient, and not at all harmful."

Do I remember my ever having used GoTo in a REALbasic (or Real Studio) program? No. But then again, I'm an amateur programmer and I do not have the expertise of someone like Matt Neuberg, although I'm sure that people today must have much better and yet still extremely convenient ways to escape from more than one level of nested block, don't they? For example, you're a professional programmer. How do YOU handle that situation? <grin>

Barry Traver


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Thu Feb 07, 2013 8:04 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
Kem,

Like you, I prefer "Next X", "Next Y", and "Next Z" as generally clearer than simply "Next".. That's why years ago I wrote a routine to change appropriately the latter to the former.

I just tried it on your "Before" code, and indeed it correctly changed "Next" to
"Next X", "Next Y", and "Next Z" as in your "After" code. It's amazing how adding a single letter (in this case "X", "Y", or "Z") can make code easier to follow.

Years ago I also wrote a routine to change "End", but I did not get any feedback on that routine, so it was neither finished or debugged. As I understand it, there are three kinds of "End": "End If", "End Select", and just plain "End." (That's all there is, right?) What I need is a routine to go through program code (usually saved in xml format) and decide when and when not to change "End" to "End If" or "End Select".

In case you're wondering about my unfinished, undebugged version of this routine: it changed "End" to "End If" where appropriate BUT didn't have a clue about "End Select".

Question: Is there a way to determine whether "End" in a program is simply "End" or a lazy way to use it as a substitute for "End Select" or "End If" or "End Select"? (Maybe I'll go back to finish that routine.)

Barry Traver

P,S, I also wrote routines to add comments to "Next" lines and "End If" lines. For example, the former routine changed this:

Next I

to something like this:

Next I // For I = 0 To 100 Step 2

That made it easier, for instance, to deal with nested For/Next loops.

All these routines were part of a CodeHelper program being written by an amateur program (me) with very little feedback from professional programmers, so it was never finished, although 95+% of the finished routines seem to work without error and some I use on a regular, almost daily (such as the one to remove blank lines from the source code).

As usual, the source code for CodeHelper is available for free to anyone interested in requesting a copy (but I won't hold my breath).


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Fri Feb 08, 2013 12:49 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
barrytraver wrote:
Do I remember my ever having used GoTo in a REALbasic (or Real Studio) program? No. But then again, I'm an amateur programmer and I do not have the expertise of someone like Matt Neuberg, although I'm sure that people today must have much better and yet still extremely convenient ways to escape from more than one level of nested block, don't they? For example, you're a professional programmer. How do YOU handle that situation?


If you are talking about multiple nested for statements, you can just use the exit command.. If you have something like the following (really quick simple code)

for i
for j
for k
exit i // will break out of the main loop
next
next
next

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 55 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group