Code Tidiness

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Code Tidiness

Post by bn » Mon Oct 22, 2018 3:25 pm

No reserved name starts with a "t".
OK, that was not correct, make that

No reserved name starts with a "t" except those that start with a "t". :)

Kind regards
Bernd

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Code Tidiness

Post by jacque » Mon Oct 22, 2018 5:08 pm

Subsidiary to that, is it better to keep code in the card or the stack, with the understanding that the whole thing is only ever going to be one card?
The general rule, which is by no means absolute, is to keep the code as close to the object that uses it as possible. If a button has a unique script not used elsewhere, put the script in the button. If several buttons use the same code, put the handler in the group (if they are grouped) or in the card. If the handler or function is used in objects across several cards, put the handler in the stack script.

Use of behavior scripts or libraries will alter placement. For example, libraries must have all their handlers in the stack script, by definition

My own preference is to put most of the functional handlers in the card and stack scripts and just call those from card objects. This makes it easier to locate handlers during development because everything is in a centralized location. I also prefer behaviors for objects that share the same scripts, wherever those objects may be in the stack.

Everyone has their own style. I tend toward one-liners whenever possible unless the line gets too contorted to read comfortably. Bernd is right that makes debugging harder, so I will split the line into several parts when debugging if necessary. Due to my compulsive need to write concise code, I usually recombine the line once it's working. But not everyone thinks that's normal behavior. :) One slight advantage of single lines is a small speed increase, generally too tiny to notice, and sometimes less memory usage if you are slinging around large variables.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Code Tidiness

Post by bogs » Mon Oct 22, 2018 6:48 pm

bn wrote:
Mon Oct 22, 2018 3:25 pm
No reserved name starts with a "t".
OK, that was not correct, make that

No reserved name starts with a "t" except those that start with a "t". :)
Sorry for my dubious sense of humor Bernd, but I remember reading a post by Jacque where someone else pointed that scenario out to her, and I couldn't resist :D

As for myself, I tend to use 3 letter prefixes with camel case, so I haven't (yet) been bitten by that bug. For example, using 'Ext' as a variable, I'd put it 'tmpExt' or 'lclExt' or 'glbExt', for temp, local, or global. The safety net it provides is worth the extra 3 or so letters typed imho.

*IF* I ever find a circumstance where that isn't enough, though, I'd go ahead and type out an entire word for a variable camel case :wink:
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”