Radio buttons to show/hide group

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

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Radio buttons to show/hide group

Post by dave.kilroy » Sat Oct 11, 2014 7:31 pm

No I'm lazier, asking you rather than testing myself (actually am surprised it even compiles without the "the") - however I don't think I'll be using that construct and so was just idly curious...
"...this is not the code you are looking for..."

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Radio buttons to show/hide group

Post by jacque » Sat Oct 11, 2014 8:24 pm

I got curious and unlazy so I did a timing test. I see no significant difference when using or omitting "the" for properties, so my objection is purely stylistic. Do as you like and I will learn to live with it. ;)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: Radio buttons to show/hide group

Post by keram » Sun Oct 12, 2014 12:54 am

jacque wrote:I'd recommend not using semicolons to concatenate two lines of code.
I actually never do it in my real project. This time I did it since you've mentioned somewhere using just one line of code so I thought 'let's make it as short as possible' so
dunbarx wrote:It is TERRIBLE to append multiple lines of code that way.
yes Craig, you are right and I'll never do it again :)

And about the 'the' keyword - I simply forgot it...
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Radio buttons to show/hide group

Post by jacque » Sun Oct 12, 2014 1:44 am

keram wrote: And about the 'the' keyword - I simply forgot it...
As I just found out, no harm done. :-)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Radio buttons to show/hide group

Post by [-hh] » Sun Oct 12, 2014 5:26 am

Because I'm having some of these bad habits mentioned until now I would like to explain my impassionate use of it.

Sometimes people have a reason to do some things in a more compact manner or in a somewhat superfluous manner:

(1) Concatenating script lines with semicolon can be a good practice

I use to do this as often as I can and my reason is:
My eyes are not best and I use to have a big textsize. But I can read scripts very fast. Sometimes I have to rotate my monitor to get an *overlook* about scripts from others. For example ...
... this takes a quarter height of a scripteditor screen:
put item 1 of a into a1
put item 2 of a into a2
put item 3 of a into a3

Now compare to this line:
put item 1 of a into a1; put item 2 of a into a2; put item 3 of a into a3

Compact and readable with double speed. I have to read the first part of this line in order to know what fills up the rest of the line. For important parts of the script I always start a new line or mark it, as you do.

Or take a switch with N cases:

Code: Select all

switch k
  case 1
   action1
   break
  case 2
   action2
   break
  ...
end switch
and now scroll down Nx3 lines. What's so important in a "break" to have its own line? I know how a switch works and if I use one where some cases are without break then the breaks are important and have their own line. Else I have for each case ONE line (if not too long):

Code: Select all

switch k
  case 1; do action1; break
  case 2; do action2; break
  ...
end switch
Very compact and I have to scroll down N lines only.

Last example (I use this often when I create an image by script)

Code: Select all

set script of img 1 to "on mouseDown;grab me;end mouseDown"
One line. Very clear, always the same.

(2) When to use "the" and when avoid it?

The use of "the" is optional, as mentioned above. Very good. So I can use it (almost always) this way:

Whenever I GET a property, I use "the": get the property of btn 1,
whenever I SET a property, I avoid "the": set property of btn 1 to myString.

In other words, using "the" with a property is for me a mnemonic that I have a return value (may be empty).
Avoiding "the" sets for me an association, that I have a result value (may be empty).
This is a well-considered logic that makes my scripts very fast readable for me, faster than having to read a lot of superfluous "the".

The recommendation to use always "the" is certainly of educational type and not because the engine slows down without it. (At least with my tests there is a difference of < 1 millisecond with 1 million repeats.)

Let me now praise one thing that not enough people here are using:

(3) Please set superfluous parentheses!

(a) Math operators (incl. "or", "and", "not") have a very clear precedence order. It is for people who are used to do math easy to read a rather complicated expression in correct order. For some other people, who have their mental strength in other fields, it is VERY important that one sets and that they set superfluous parentheses, simply to make it better understandable. And this can speed up the engine measurably (I tested also), the engine loves a clear structure.

(b) Moreover to write (expression), that is parentheses around an expression, in order to ensure the evaluation of expression, is a mostly superfluous, but also valuable style. For example:
"set hilite of me to (the mouse is down)"
is as soon as got one time much clearer and 'cause and effect' better understandable then
"if the mouse is down then set hilite of me to true; else set hilite of me to false"

Applying my last point to (part of ) the thread gives:

Code: Select all

on mouseUp
  put (1 + the label of the target) into tNr
  repeat with x = 2 to the num of grps of this cd 
      set visible of grp x of this cd to (x is tNr)
  end repeat 
end mouseUp
shiftLock happens

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: Radio buttons to show/hide group

Post by keram » Sun Oct 12, 2014 7:22 am

Thanks Hermann for your comments - very valuable.
The only thing that I don't understand is the text in your signature :?
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Radio buttons to show/hide group

Post by Simon » Sun Oct 12, 2014 8:31 am

Hi -hh,
Yeah I get this:
lock screen; lock messages
It's one line, I see the "lock" and I'm done, I know what the rest of the line is.
This is great for repeated "modules" across projects.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Radio buttons to show/hide group

Post by dave.kilroy » Sun Oct 12, 2014 11:50 am

Always interesting to hear how others code - let a thousand flowers bloom I say and lets hear everyone's pet hates and good ideas (I have to say that global variables that aren't prepended with "g" make me nervous...)
"...this is not the code you are looking for..."

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Radio buttons to show/hide group

Post by [-hh] » Sun Oct 12, 2014 4:40 pm

Hi all, I forgot to say:

As soon as I can detect a logic behind the style of others it is all OK for me. And I'll even try, if there is enough time to do so, to using their style for the answer (learned from Simon, look at his answers).

@keram: I don't understand my signature too, because I'm a dialect speaker (German). That's the trick with it. Originally I had a very long list of nations prepared, but signatures are here limited in length (certainly a good practice).

@Simon: Allow me for one time to misuse your funny signature:
I used to be a newbie with teh properties but then I learned to leave out "teh" and now I'm a noob!

@dave.kilroy: Aren't there even a lot of words that should be protected names in order to avoid misuse by "g" or "t" variable naming rules? For example Bone, Shirt or Spot? How do you name these variables: iBone, iShirt, or iSpot?
shiftLock happens

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Radio buttons to show/hide group

Post by jacque » Sun Oct 12, 2014 5:56 pm

jacque wrote:
keram wrote: And about the 'the' keyword - I simply forgot it...
As I just found out, no harm done. :-)
On second thought. there's one exception that will throw someone who routinely omits "the" - - "target" . It means two different things depending on whether "the" precedes it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Radio buttons to show/hide group

Post by [-hh] » Sun Oct 12, 2014 7:26 pm

This is now a point where I would like to be pedantic, because until now the discussion was about "the" before the names of properties.

But this possible use of "the" is the function equivalent:

"target" is a keyword, not a property.
"the target" is a function, equivalent to "target()".

We can't "set target" or "set the target".

Anyway, thanks, good to know this speciality.
This keyword "target", for fields a shortcut for "the value of the target" or "value(target())", is presumably there from historical reasons (HC/MC)?
shiftLock happens

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Radio buttons to show/hide group

Post by jacque » Sun Oct 12, 2014 8:25 pm

It's from HC. "The target" is the object. "Target" is the text if "the target" is a field. And the text of the field is a property, so this is an anomaly in the syntax. We can't change it though, because there are almost 30 years worth of scripts using it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Radio buttons to show/hide group

Post by [-hh] » Sun Oct 12, 2014 9:38 pm

Because I'm forced to be 'exact' in my daily life I would like to use this distinction after your info:

At first, as a memo:
target() < > target [ but target() = the target ].

If GETTING:
target = the text of the target (if the target is a field).

If SETTING:
target < > the text of the target.
(Because the "text of the target" is also settable, being a property of the target, "target" is not settable.)

Positive Example (wonderful 'shortcut'):
get target = do ("get" && the target) = get the text of the target

True?
So there is another reason to use always (if available) "the" when getting something, if it's not "target" :-)
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Radio buttons to show/hide group

Post by dunbarx » Mon Oct 13, 2014 12:07 am

Hermann.

Putting "break" right after the last line in a case statement list seemed, at first read, like a great idea. But then I realized that having to add another line or two at the end of that list would require, er, breaking out the "break".

I am too old to change how I use "the", target or not. And so I will stick to my old-fashioned style. But I take many of your points.

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Radio buttons to show/hide group

Post by [-hh] » Mon Oct 13, 2014 1:08 am

Hi Craig.

The most frequent fault with switch I've seen came from missing breaks: People (me included) simply copy the until-that-last-case to append another one and are wondering why this until-that-last-case doesn't work any more (the action falling through to last case now). So setting a superfluous last "break" is kind of a scripting insurance for me.
Craig wrote:I am too old to change how I use "the", target or not.
Let me answer this with another quote:
Sam Roberts, Feb 18 , 2008 (NYT) wrote:“When Hemingway killed himself he put a period at the end of his life,” Kurt Vonnegut once said. “Old age is more like a semicolon.”
Another reason to use semicolons!

Hermann
(I'm currently looking into Tom Pittman's CompileIt! on MacPlus, emulated on my Raspi. You and Bernd once mentioned that software. A brilliant piece of software; what an excellent approach, to jump with HyperTalk-like syntax Assembler-like around in the ROMs of a MacPlus.)
shiftLock happens

Post Reply