"R.Wieser" <***@not.available> wrote
| Although I agree with you that you shouldn't use stupid namings, there is
| nothing wrong with using a method that is largely unknown to others (and
it
| seems that that is all it is).
|
Shouldn't anyone who does coding use some kind
of system to make their code clear, at least to
themselves? To me that's common sense. A great
example of the problem of not doing that is so-called
"minified" code. Something like:
BooExists = FileExists(FilePath)
becomes:
a = b(c)
That's done partly to obfuscate. It's unreadable code.
I usually use data type or element indicators for things:
iTotal = iSomething * 3
TDMain.padding = 0
When I use someone else's code I usually rename
all the variables as part of my process of familiarizing
myself with the code and making it more readable.
It's the same as if I took over someone else's kitchen.
I'd want to put the plastic wrap in a drawer and put the
plates in the cabinet over the sink. Not because that's
the "right" way to do it but because it's my system
and it works for me.
There's actually a name for prepending variables
with identifiers. I think it's called Hungarian notation.
(I have no idea where that came from.) Many people
in VB use such a notation, prepending s for string,
L for long, Col for collection, etc. Many other people
use prepends like m or g to indicate a variable at
module scope or global scope. Some use both:
gsFilePath.
Whatever works to make your code clear for you
makes sense to me. But it should be clear. You should
be able to read your own code and make sense of it.
If you've got a DIV with a name that sounds to you
like a script variable then you're in trouble. In that case
you're probably a person who looks in every kitchen
cabinet every time he needs a plate.
A related issue of interest: There's a notable difference
between VB* and C-ish code like C++ and javascript.
The former is non-case-sensitive, which helps to make
more readable variable names, like iTotal or AReadingList().
It also means that we can use editors that auto-adjust
variable case, which helps a lot to notice mis-spelled
variables. In other words, if I have sBookListFile and
type sbooklitfile my editor won't capitalize the B, L, F,
which makes it easier for me to see that I mis-spelled it.
C-ish programmers often make fun of that, but all it
really means for them is that they have less options.
Javascript variables end up being nearly all lower case
because it's easier not to have any case at all when it's
case sensitive. But itotal and areadinglist are not as
readable.
Which is right? Whichever works for you. To my
mind C-ish code is a monstrosity that should have
been erased before it spread. But now it's considered
normal and lots of people like it. If it works for them
it's none of my business.
| Having said that, it definitily would (as always) be a good idea to
mention
| when you're using something different than the widely-known-and-used
| methods. If only to forego any confusion. :-)
|
You're heading for a fringe position when you start
thinking of it that way. What you may regard as widely
used is neither here nor there. Both methods are
legitimate methods of browser DOM for all browsers.
I've never used getElementById. I've written a lot
of HTA utlities and webpages, never finding a need for
that method. The fact that Evertjan wasn't familiar
with the ability to refer to an ID as an object doesn't
make it quirky. It just means he didn't know about it.
Everyone has their favorites and everyone
has things they don't like. In VB I've never really
got the point of the IIf method, for instance. But
that's my problem. The fact I don't like it doesn't
make it illegitimate or "not widely used". It's an
official, functional part of the VB language. No more
and no less than any other method. The same is
true of IDs as object referrents in browser DOM.
Div1.innerText is in no way less official than
x = getElementById("Div1").innerText. The former
is also a lot more compact and readable.
While I can accept the idea that some people
want to use getElementById because they're not
comfortable keeping their variables clear, I regard
that as inferior coding practice, excessive complexity,
and wasted functionality. That's just my opinion.
Fortunately, we can all use whatever code we like,
as long as it's valid and it works. Anyone who doesn't
like that can go rant on Twitter:
#IWantToBeOffendedToo :)