scripting style issue
xbury.cs at clearstream.com
xbury.cs at clearstream.com
Tue Jan 14 08:24:01 EST 2003
Hey Richard,
Good effort. We all need better styles! I did lots of research in this
particularly more in Function naming and parameters but here's my two
bits...
Is it useful? Yes! Does it apply everywhere, im not sure... I've developped
my
own style so if it helps, here it is...
Since I use code across projects, stacks, stacksinuse and across different
applications,
I always use the same structure in naming conventions:
Functions and Handlers always start with an upper case letter.
Also, handlers and functions always start with a verb: GetAnswer,
ChooseFile, etc...
Globals are rare or should be used sparsely and so it doesn't really matter.
But to avoid confusion, globals start with a g for obvious reasons...
For a local variable however I have never used anything other than a lower
case
letter at the beginning and making sure the name is explicit as to what it
contains.
The locals I call usually as thefile, thisline, startpos, etc...
I prefer that they be clearly telling me what they are... This makes the
script
more readeable and even months after they dont get stale...
As far as arrays are concerned, I've made them explicitely obvious such as
stacklist, neurongroup, observations, objecttable...
But your notation could be useful. It could be even better if you put the
number
of dimensions in the array ga2NeuronConnections - but this could be
confusing
in certain neural network programs if you have separate genetic annealing
modules... ;))
But in the end I still prefer a good script editor to save you even more
time!
My editor (which is free and opensource) will list any local or global,
where they
are in use thanks to the index field. Improved coloring also helps to find
them faster.
As far as catching spelling errors, the best method is still the most
arcane:
use the explicit variables feature of MC, I was quite surprised myself!
Is this boring? Noooo! But I wouldn't abuse the subject! ;))
> -----Original Message-----
> From: Richard Gaskin [mailto:ambassador at fourthworld.com]
> Sent: 14 January 2003 10:13
> To: MetaCard List; use-revolution at lists.runrev.com
> Subject: scripting style issue
>
>
>
> As documented in the Script Style Guide at
> <http://www.fourthworld.com/embassy/articles/scriptstyle.html>
> , I'm fairly
> OCD when it comes to variable names, having adopted the sort of
> Hungarian-notation-lite that makes dissecting code just a
> little easier.
>
> There's an item not addressed in that document that's becoming an
> ever-bigger part of my scripting: arrays.
>
> It's useful to denote arrays distinctly because they require different
> syntax from other variable types. For example, you can get
> the value of an
> arrany element, but you can't get a displayable string from the array
> itself.
>
> For a long time I just added the word "Array" to the end of a
> variable name
> as a reminder, like "gMyOpenWindowsArray". As I use arrays
> more and more, I
> simply don't want to type that much, any more than I would type
> "globalMyOpenWindows"
>
> In recent weeks I've started adding an "a" after the type
> specifier as a
> shorter, arguably clearer, notation:
>
> string form: gMyOpenWindows
> array form: gaMyOpenWindows
>
> With script-locals being:
>
> string form: sMyOpenWindows
> array form: saMyOpenWindows
>
> Parameters:
>
> string form: pMyOpenWindows
> array form: paMyOpenWindows
>
> ...etc.
>
> While I've enjoyed this in my own scripting, I recognize
> there's a fine line
> between adding specificity and making things cumbersome.
>
> So three questions:
>
> 1. Does this convention seem useful? Specifically, should I
> bother adding it
> to the Script Style Guide?
>
> 2. How do you denote arrays?
>
> 3. Is this boring?
>
> --
> Richard Gaskin
> Fourth World Media Corporation
> Developer of WebMerge 2.1: Publish any database on any site
> ___________________________________________________________
> Ambassador at FourthWorld.com http://www.FourthWorld.com
> Tel: 323-225-3717 AIM: FourthWorldInc
>
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard
>
Visit us at http://www.clearstream.com
IMPORTANT MESSAGE
Internet communications are not secure and therefore Clearstream International does not accept legal responsibility for the contents of this message.
The information contained in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Any views expressed in this e-mail are those of the individual sender, except where the sender specifically states them to be the views of Clearstream International or of any of its affiliates or subsidiaries.
END OF DISCLAIMER
More information about the metacard
mailing list