Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Dec 15, 2018 4:42 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 55 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Various questions.
PostPosted: Sat Jan 26, 2013 7:16 am 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
hi,
I use RS 2012r1 version and I have not fully understood the following topics:
1) bevelbutton vs pushbutton. Are there pushbuttons's features that bevelbutton misses, so that in some occasions pushbuttons are more suitable than bevelbuttons?
2) Some controls (listbox, textfield etc.) list in the property pane a "database Binding" section with "datasource" and "datafield" properties. What are they for?
3) the statements "if...then..else....end if" and "if...then..else...end" do behave the same ?

thanks for helping.


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Sat Jan 26, 2013 10:12 am 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
1) Pushbuttons are system native controls. BevelButtons are controls created by RS. To that end, bevelbuttons CAN be more problematic to use, but also have features (icons, menus, etc.) not available from the pushbuttons. Use which ever best suits your needs.

2) Just completely forget "database binding". They are a holdover from many years ago and were deprecated long ago.

3) Yes. You can conclude an "if...then" conditional with only "end" with no problem. RS allowed the "end if" construct for those of us who started with BASIC years ago when, on some compilers, it was required. I still type "end if" out of habit, but "end" works exactly the same.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Sat Jan 26, 2013 10:32 am 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Thanks Roger,

as for issue 1) why can the bevelbutton be problematic ?

As for the end if question, I imagine the same apply with the for..next cycle

for a = 1 to 10
next


for a = 1 to 10
next a


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Sat Jan 26, 2013 10:52 am 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
1) All depends on the situation. Search the forums and the NUG on BevelButton. I don't mean to suggest it's not useful And I believe some problems from years ago are resolved.
2) Yes, they are the same.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Sat Jan 26, 2013 10:59 am 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Thanks very much for helping, Roger.
antonio


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Sat Jan 26, 2013 11:07 am 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
Yes, that works with all loop constructs and Select Case ... End.

I always use the "complete" End because, in long code, it's easy to lose your place. I try to comment them for the same reason. For example:
if something then
tester = SomeTest()
if tester and whatever then
for x as integer = 0 to 1000
t = someMethod
for y as integer = 0 to 100
t = DoSomething
select case t
case firstCase
for z = 1 to 10
SomeMethod( z )
next
case secondCase
if this or that then
DoNext()
end
else
BranchAway()
end
SomethingElse
next
MoreStuff()
next
end
end

I would write it like this:
if something then
tester = SomeTest()
if tester and whatever then
for x as integer = 0 to 1000
t = someMethod
for y as integer = 0 to 100
t = DoSomething
select case t
case firstCase
for z = 1 to 10
SomeMethod( z )
next z
case secondCase
if this or that then
DoNext()
end if // this or that
else // Select t
BranchAway()
end select // t
SomethingElse
next y
MoreStuff()
next x
end if // tester and ...
end if // something

_________________
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: Sat Jan 26, 2013 11:23 am 
Offline

Joined: Sat Feb 04, 2012 1:26 pm
Posts: 86
Location: Italy
Kem,
I see. It would be quite difficult to read the code whitout the "complete" end.
apart of the complete "end", does the same apply to "0exit" and "exit sub"..?


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Sat Jan 26, 2013 11:46 am 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
Within loops, yes, I like to use "exit for var" or "exit while // condition". But for a method, I recommend against "exit". Use "return" for a method and "return val" for a function. That's easier to follow.

Having said that, you should try to avoid leaving your method early. For example, consider this code:
select case x
case 1
return val1
case 2
return val2
else
DoSomething()
return val3
end select

It can easily be rewritten as this:
dim r as string // or whatever
select case x
case 1
r = val1
case 2
r = val2
else
DoSomething()
r = val3
end select
return r

This is a very simple example, but if you start to write complex code with "return" (or "exit") in various places, it's an invitation for hard-to-track-down bugs. Personally, I'll do a parameter check at the top of the method, return if the parameters are invalid in some way, and otherwise return at the end of the method.

_________________
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: Sat Jan 26, 2013 12:05 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
It is correctly said that programming is both a science and an art. As an art, it allows for many personal choices, habits, and preferences which develop over the years. In the previous example which Kem submitted, I have come to prefer the first example over the second. In my experience, and we are talking about more complex code than these simple examples, the introduction of a (useless?) variable (r in the example) is more a source of tricky bugs than simply returning the needed value as soon as it is available to your code.
Who's right? There is no "Right". It's a matter of your personal coding style and the habits you develop. I will say, however, that consistency is the key to making your code maintainable.

Happy coding.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Sat Jan 26, 2013 12:15 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
Right, there is no "right". Except I'm right. :-)

Seriously, Roger is spot on, which is why I prefaced everything with "I recommend" instead of "you must do it this way".

Even though you should do it my way. (Still j/k :-) )

_________________
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: Mon Jan 28, 2013 11:34 am 
Offline

Joined: Wed May 25, 2011 10:18 am
Posts: 33
My preference is to return methods as early as possible. It also reduces the nesting levels which makes code less complicated.
I also use sometimes Goto to skip code, reduces complexity also:

if Not something then return
tester = SomeTest()
if Not (tester and whatever) then return

Dim counter as integer

for x as integer = 0 to 1000
for y as integer = 0 to 100
t = DoSomething()
select case t
case firstCase
Goto MethodEnd
case secondCase
Goto xLoopEnd
else // Select t
BranchAway()
end select // t
SomethingElse()

next y
MoreStuff()

xLoopEnd:
counter = counter +1
next x

MethodEnd:
// Doing final things

return something




Kind regards
Christian

_________________
me.self works with:
Real Studio Pro (always the latest), 10.7.x, Mac mini i5, Love


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Mon Jan 28, 2013 11:56 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Quote:
I also use sometimes Goto to skip code, reduces complexity also:



While I agree programming is an art, and there is no "right" way, there is alot of "WRONG" ways....

And I will speak up here and say

"THE USE OF 'GOTO' AND 'GOSUB' IN AN EVENT DRIVEN OBJECTED ORIENTED PROGRAMMING LANGUAGE IS EVIL"

And should be avoided at all cost..... [along with data bindings]

Other than that... the rest is up to you


The use of CONTINUE, BREAK and EXIT should be considered first.

_________________
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: Mon Jan 28, 2013 12:12 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
I have to agree with Dave here. I'm sure your style works for you, but I would NEVER counsel a beginner to use goto to skip code.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Tue Jan 29, 2013 9:12 am 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
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. ;)

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: Various questions.
PostPosted: Tue Jan 29, 2013 3:53 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 9:27 am
Posts: 249
Location: USA, CA
GoTo is fine , if you are planning on making spaghetti for dinner :D

_________________
-Briman


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 55 posts ]  Go to page 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