Newbie... Strict Compilation mode

Jim Bufalini jim at visitrieve.com
Sat May 9 23:56:11 EDT 2009


Dear Jacque,

To each his/her own. ;-) And, of course, we all know you are a novelist (in
English) and one who probably doesn't use a spell checker. ;-)

But, just to clarify, so that what I said is not misinterpreted. I never
said there is anything you cannot "do" without explicitVariables turned on. 

What I was actually trying to communicate is that while it may take a little
more time up front, and add some chars to your code, it "can" save a
tremendous amount of time in the long run, especially if you work in
collaboration with others, are just starting out with the language, have to
work quickly with someone else's code, or have to return to code that you
wrote under a different mindset and with somebody else. 

In my case, I worked in collaboration for years with a person who spoke
English as a second language and refused to even look at, much less to work
with any code that didn't declare clearly descriptive  variables and handler
names, because he knew he was prone to English spelling errors and my
cryptic variable and handler names were meaningless to him. And, as it
turned out, I came to realize this benefited me also. ;-) The practice also
came in handy working with others whose primary language was C++ because
they were able to "read" my code.

I will give you a recent example. A bug was reported with ListMagic where
you couldn't set the alternating colors of lists to different colors for
multiple lists on the same card. I confirmed the issue and built a  test
stack, confident I would find the issue quickly. 

After a couple of hours, it seemed like issues were increasing incrementally
with everything I did! I even wrote Trevor to see if he had run into
anything like what I was seeing in his work on the Data Grid. You know what
it turned out to be? I was testing for alternating "stripes" and Eric had
them as alternating "strips" ;-)

Now it was right there in front of me the whole time. I was staring right at
the two words. But, I didn't "see" it because I was "looking" for other
things. Had they been variables, I would have caught the spelling issue the
very first time I hit compile on my first test stack. But, because it was a
string in a custom property, this is not caught by the compiler. I wasted
hours and as I later told Trevor barking up all the wrong trees for what
ultimately took 20 minutes to fix and was staring me in the face the whole
time.

So, I have come to believe that long, descriptive variable names and
explicit variables are the lazy man's programming because it has allowed me
to be lazy and let the compiler find my and other people's errors for me.
;-) It also requires less commenting. So this has become my personal
preference. You have yours. ;-)

However, personal preferences aside, the main strength of Revolution is not
that you don't have to declare variables, but that you can choose to declare
or not to declare depending on your circumstances. And, in fact, it is this
amazing flexibility in the language, not just in variable declaration, but
many, many other ways, that allows someone, like yourself, who has worked
with xtalk a long time, and someone who is just moving over from C++, and
another who needs a dictionary by their side to even read this list, all
find a convenient and familiar way to work with and learn the language, as
they each grow and experience their own ongoing "revolution."

So, my intention was not to convince others that they "should" use
expicitVariables, but only to point out the value that I have come to
appreciate of this "optional feature." 

Now if you'd like for me to write an argument of the advantages of extremely
short, non-declared, non-descriptive (except in the programmer's mind) var
and handler names and never putting multiple lines of code for what you can
squeeze into one line with parens, I can do it, because I used to write that
way when the memory and storage of machines were calculated in kilobytes.
Who knows, maybe for mobile devices, I will have to again. ;-)

But then Rev allows for this. Therein lies its real strength. ;-)

Aloha from Hawaii

Jim Bufalini




J. Landman Gay wrote:

> > - It allows you to distinguish globals from script locals and
> constants both
> > at the script level and handler level.
> 
> You can do that without declaring them explicitly too.
> 
> > - It allows you to declare globals from inside a handler (which
> creates a
> > "semi" global that is only available to other handlers that also
> declare the
> > same global).
> 
> You can also do this without turning on explictVars. It is, in fact, a
> direct feature port from HyperCard circa 1989. I also routinely declare
> script constants, locals and globals at the top of scripts, because
> that
> is the only way to get them. But that isn't the same as requiring a
> mess
> of declarations inside every single handler.
> 
> > - It makes your code much more readable, not only to others, but to
> > yourself, when you are troubleshooting a problem weeks or months or
> years
> > later.
> 
> Disagree. It makes your code messy, adds tons of extra lines that you
> have to skip over to get to the real code, isn't necessary, and
> clutters
> up the script with top junk. It isn't clean and I find it much less
> readable. I would go so far as to say it is inelegant. It is the
> opposite of writing the smallest, most concise code possible. To
> understand my scripts later, I add comments and choose self-commenting
> variable names. Declarations aren't as informative as good commenting.
> 
> > What, if any, is the advantage of NOT declaring variables? ;-)
> 
> Here's the response I gave 2 years ago when this came up:
> 
> 1. The main strength of xtalk is that you do not have to declare or
> type
> variables. Sticking them up there at the top of every handler removes
> one of the main advantages of using Rev in the first place.
> 
> 2. You can't comment out a long handler using a single set of hyphens
> before the "on" statement. (I often write multiple versions of handlers
> and switch between them.) As soon as you do that, all those "local"
> declarations become script locals and everything goes haywire. You have
> to comment out all of the declarations. If they aren't all at the top,
> you have to comment out the whole handler. That's more work than it
> needs to be if you're going back and forth between a few copies to see
> which one works best.
> 
> 3. It looks busy and it makes scripts denser and more complicated than
> necessary. I've seen handlers where the declarations can take up almost
> as much room as the code. It's hard to read other people's scripts if
> they use explicitVars because you have to skip over so much junk to get
> to the real business. In large projects it can add significantly to the
> file size on disk.
> 
> 4. If you change a variable name, you have to go back and change the
> declaration. It's more work to maintain, for something that isn't even
> required by the engine. (I have wondered if people sometimes do it to
> make their code look more like "real" programming to other people.)
> 
> 5. And finally, what's wrong with being lazy? :) The smart programmer
> finds the easiest way to do things. That's what Rev is all about.
> 
> None of these things is outweighed for me by the fact that explicitVars
> might catch a few typos. The engine catches most of those anyway and
> throws an error.
> 
> Back to today's response:
> 
> The debugger pinpoints the exact source of the misspelling if it
> happens; how hard is that? I'm a pretty good typist though, so I don't
> get caught out too often. I suppose if you are really as bad a typist
> as
> your theoretical example, then yes, you'd want some help. ;)
> 
> I once took over a project from someone who used explicit variables. I
> stripped out all the declarations so I could read the scripts
> comfortably. The stack size was cut in half (!). No lie. There were all
> kinds of handlers in there with something like 8 lines of declarations
> and three lines of actual script. Waste of time and space.
> 
> My fourteen cents.
> 
> --
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list