Page 1 of 2

Half Strict Compilation mode

Posted: Fri Jul 29, 2011 12:47 am
by BarrySumpter
Can we have a Half Strict Compilation mode.
Or in Strict Compilation mode -
a way to exclude " around object names that do NOT have spaces?

Re: Half Strict Compilation mode

Posted: Fri Jul 29, 2011 2:17 am
by Mark
Hi ...,

Why wouldn't you want to put quotes around object names? Keep your scripts neat and clean for those who come after you, even if you don't think you will be sharing your scripts at this point :-( The day will come when you will be unable to read your own scripts.

You can set the explicitVariables to false in the preferences window, but I don't think it is meant for this purpose. I believe it is rather meant to avoid declaring local variables.

Mark

Re: Half Strict Compilation mode

Posted: Fri Jul 29, 2011 3:35 am
by BarrySumpter
I usually already know how to use these feature enhancements I'm requesting.
And am reqesting a more effecient way for my style of using the mouse and keyboard.

Having spaces in my control names makes the script hard to read and requires " ".
Having to type " around my control names is 4 extra key strokes per name.
Having a 3 chr prefix to my control names tells me its a control. txt, lbl, lst, cbo, dgd etc.
Making it not only easier to read in the script but in the Application Browser as well.

Would prefer NOT having to tell the compiler my object is a field or a player etc.

I've long ago gotten over the pretention that anyone would waste time rating any of my scripting style.
Prefering the script be readable and to get the job done in the most efficient way possible.
Which is one of the main reasons to move to LiveCode.

Re: Half Strict Compilation mode

Posted: Fri Jul 29, 2011 1:54 pm
by BvG
The problem is, unquoted names are hell for beginners. Consider this simplified example:

Code: Select all

on mouseUp
  --works as expected
  put test into field aFieldName
  put any line of theList into aFieldName
  --hmm randomness is random
  put test2 into field aFieldName
end mouseUp
Now imagine a lot of other script before the second comment. Someone looking at the code after working on something else however will randomly break the code much easier then when the field references and the strings would be quoted. Sure, a perfect coder can remember everything, or use a prefix like "FLD" if it's a field, but no one is a perfect coder.

Said that, If you like unquoted literals so much, why don't you disable strict mode, and code however you want?

Re: Half Strict Compilation mode

Posted: Fri Jul 29, 2011 5:28 pm
by jacque
Unquoted literals, such as control names, can sometimes work but decrease the speed of code execution. The compiler has to first determine if there is a variable with that name; if not, it needs to scan all the controls to see if there is one that matches. One of the first things I do when converting or updating client stacks is to go through and quote all the literals, to avoid errors and ensure the code is running as fast as possible.

The ability of the compiler to accept unquoted literals is a leftover that has remained in place for HyperCard compatibility, though LiveCode is more strict about it than HC was. If you don't quote literals, you will eventually find yourself in a situation where your code errors and you don't know why. Not all unquoted literals will work; it depends on where in the command line the literal occurs.

The benefits are worth the 2 keystrokes.

Re: Half Strict Compilation mode

Posted: Fri Jul 29, 2011 11:23 pm
by BarrySumpter
H Bvg,

In my opinion,
I think you're writing a bit too much about others as if you represent someone other than yourself.
Just make your point as best you can.
Take a break and come back to this if you feel it's really important enough to spend you're time on.
And not jut something to write about.
Otherwise, in my opinion, this is not a reasonable argument.

I wouldn't use the prefix fld on any object name.
It's too generic and defeats the purpose of using a prefix.

And truely its my job as a software developer, when working on legacy code, to not only come to terms with someone elses style of writing scripts but to adapt to it quickly and update the scripts and enhance the scripts in a way that no one knows that another developer updated or enhanced the script other than the change log.
I was doing this long before someone came up with "egoless coding".

I've seen scripting in my time that looks like a dogs breakfast.
Which the developers were happy to put their names to it.
I found out laster that one of the developer had a really good name in the company.
They though he was the best thing since sliced bread and were sorry he left to go work for M$.
LOL
So I prefer not to waste my time anymore discussing others scripting style.

Re: Half Strict Compilation mode

Posted: Fri Jul 29, 2011 11:28 pm
by BarrySumpter
Hi Jaque,

Again, just my opinion.

If there is a time differenct then it would be in milliseconds.
And the point is probably an urban ledgend. Based on truth but no longer really relivant.

And it's probably wasting your time and your clients money double quoting.
Where the client would get more benifit puttin the money towards a faster computer.

If it were that importand RunRev needs to udpate the script editor
to insert a spaceDoubleDoubleQuote afte each word 'field', DataGrid, Lable, etc
expecting an object name.

And if it were that importand I should have read about it in the Put and Set commands.

Its 4 key strokes per object name while I'm scripting.

Re: Half Strict Compilation mode

Posted: Sat Jul 30, 2011 12:09 am
by FourthWorld
BarrySumpter wrote:If there is a time differenct then it would be in milliseconds.
Microseconds, actually. About 0.01 microseconds, to be precise (at least on my machine). A few microseconds here, a few microseconds there, and sooner or later you could be looking at a whole millisecond wasted. ;)

But seriously, I see no harm and some usefulness in adopting performance-enhancing habits where practical, even if the per-instance benefit is low.
And the point is probably an urban ledgend. Based on truth but no longer really relivant.
While a small performance difference, it's quite real and even measurable, and logically deducible given Jacque's explanation: Any quoted string is known at compile time to be a literal, but unquoted strings need to be compared against a list of known tokens and only when no match is found is it assumed to be a string. Quoting literals bypasses that lookup.
And it's probably wasting your time and your clients money double quoting.
For myself, the biggest benefit of quoting literals isn't for the machine but for the human. When I go back to code six months later, or bring a new programmer on the team reading my code for the first time, quoted strings are immediately recognizable as literals, without having to remember all the variable names I might be using at the time.

IMO anything that improves the skimmability of code is money well spent, esp. if the cost is as low as adopting a habit of typing two extra characters.
If it were that importand RunRev needs to udpate the script editor
to insert a spaceDoubleQuote afte each word 'field' expecting a name.
But what if the scripter intends to use another form of reference, like "field 1" or "field tMyVarialbleContainingAFieldNameOrNumber"?
And if it were that importand I should have read about it before now.
If you'd been working in this family of languages as long as Jacque has you probably would have. :)

Respectfully, it may just be that others don't feel it's as inconvenient as you do. Few languages allow unquoted literals at all, so it may be that most folks just picked up this habit long ago and haven't thought much about it since.
Its 4 key strokes per object name while I'm scripting.
Hunting and finding would add to that time.
It might be handy if there was a way to know for sure that the scripter is intending to use the string following the "field" keyword as a literal. If you can come up with an algo for that I'd submit it to the RQCC for you.

Re: Half Strict Compilation mode

Posted: Sat Jul 30, 2011 12:44 am
by BvG
Of course you can ignore any argument by claiming I do not talk about whatever you want to talk about. My question still is why setting the strict mode to off is not suitable for your goals?

Re: Half Strict Compilation mode

Posted: Sat Jul 30, 2011 1:02 am
by BarrySumpter
bvg,
I've eplained it as best I can.
If you can't understand it there's nothing more I can offer.

Re: Half Strict Compilation mode

Posted: Sat Jul 30, 2011 1:25 am
by jacque
BarrySumpter wrote:Hi Jaque,

Again, just my opinion.
Sure. I'm not clear on why you're against turning off an option, but you must have reasons. I never run with explicitVariables turned on, but some people swear by it. It's one of those religious arguments. That and color coding, which makes me blind.
And it's probably wasting your time and your clients money double quoting.
Where the client would get more benifit puttin the money towards a faster computer.
Nope, as Richard said, it really helps not only the computer but me. But get this: remember the custom backscript I told you about? The one you put in a custom plugin? Mine also has a custom frontscript. I can quote literals with one keystroke. Beat that. :P

If you're nice to me, I might tell you how.
Its 4 key strokes per object name while I'm scripting.
Okay, I give. You're counting the shift key separately, maybe?

Re: Half Strict Compilation mode

Posted: Sat Jul 30, 2011 1:48 am
by BvG
BarrySumpter wrote:bvg,
I've eplained it as best I can.
If you can't understand it there's nothing more I can offer.
I reread the whole thread, and nowhere did i see you explaining why having strict mode off does not offer you what you need, respectievly why you don't like that?

Re: Half Strict Compilation mode

Posted: Sat Jul 30, 2011 11:34 pm
by BarrySumpter
Not sure why this didn't post yesterday:


Hi ForthWorld,
Having a hard time following your - measurable in micoSeconds savings but do it anyway logic.
LOL
Hard to teach an old dog new tricks I guess. ;)

Again, not following about beginners.
If they are new then they are either learning your coding style or mine or someone elses.
And probably a conglomeration of all if its legacy.
So it would be best I tought them to open their mind and be ready for various coding styles.

Can't see me using "Field 1" as a field name and expect to be able to understand the logic an hour later?
Instead use
field txtPostCode
or
field lstStates
as compared to
field txtState
as compared to
label lblState
as compared to
datagrid dgdStates

15 years of experience is long enogh to develop a habit that is no longer neccessary.
Try 30+ years and bad habits start to out number good ones. LOL

No tlooking for anthing near perfection. Just efficient.

Is <space>field<space> unique enough for the script editor to recognize?
Sould be since the compiler recognizes it.
And again, another option in preferences to turn on or off.

I'd prefer the compiler do all the work
and recognise my txt and dgd prefixes as a field and datagrid respectively.
So I wouldn't have to qualify using field or datagrid.

Perhaps its every compiler for a language that needs the qualifier:
Dim dgdStates as DataGrid, etc.

or
With dgdStates as DataGrid
...
Set the contents of dgdStats to Empty
...
end with

----

Also, along these lines can I force the test editor to capitalize these reserved workds?
field - FIELD
label - LABEL
datagrid - DATAGRID

Re: Half Strict Compilation mode

Posted: Thu Aug 04, 2011 1:04 am
by mwieder
Is <space>field<space> unique enough for the script editor to recognize?
not at all. Consider

Code: Select all

  put "CustomerName" into tFldname
  put "Milo Fenderbender" into field tFldname
vs

Code: Select all

  put "Milo Fenderbender" into field CustomerName
How's the compiler supposed to recognize the difference between tFldname and CustomerName and put one in quotes while leaving the other intact?

Re: Half Strict Compilation mode

Posted: Thu Aug 04, 2011 3:11 am
by jacque
Good point. And there's the oft-used:

Code: Select all

repeat for each item i in tFieldList
  put empty into field i
end repeat
Which would result in: Error, no such object.