Hmm. Anyone go chapter and verse on this one?

  • Thread starter The Natural Philosopher
  • Start date
T

The Natural Philosopher

Tim said:
The Natural Philosopher said:
Henry said:
On Oct 18, 4:03 pm, Randy Webb wrote:
GArlington said the following on 10/18/2007 9:51 AM:
<snip>
So when he/she runs the script document.getElementsByName('foo')[0]
refers to the FUNCTION foo and generates the error trying to access
attribute value which function WILL NOT have...
No, it doesn't. The function is not executed until you click on the
bold text in the original, the button in the latter. And, before
it is dreamed about, changing it back to a bold element didn't
make any difference either.
The code will not error on IE until someone puts the form elements
into a FORM element. At that point IE augments the scope chain of the
function that it creates from the intrinsic event attribute, and it
places the FORM element on that augmented scope chain. Thus when the
Identifier - foo - is resolved against this augmented scope chain an
object on the chain above the global object is found to have a 'foo'
property and the resulting value of - foo - is the value of that
property of the FORM element and not the global function.
After reading that 3 times, it almost makes sense.

Everybody else assumes that Javascript is included in head of the
page and so do NOT experience any errors.
Voodoo programming. Putting my script block before the closing body
tag had no impact on errors. I still don't get one.
It certainly is an odd proposition that moving the code into the HEAD
would make any difference.
I wouldnt know. My interest is avoiding pitfalls. Not becoming an expert
in a language I really think is rather badly written.

When I started, there was code that was easy to read and code that was
hard to understand.

Then suddenly everyone started waffling about 'structured programming'.
After a while I realized this was an academic term for what we had all
been doing anyway. Making code easy to read.

Well, to be fair, not everyone had been doing that. It takes discipline
to make code easy to read, and easy to maintain, particularly if you
expect it to be part of a bigger package that will be handed over to
others to look after. While at CERN, I once saw a FORTRAN subroutine
written by a physicist for an analysis program. It was 50 pages of code,
when printed out on the fanfold paper of the time.

I had little confidence that it was fit for purpose.

Indeed.

Hardest part is prevent programmers being too clever and getting them to
document what they are doing.
The the latest bollocks was 'object oriented'. But of course with
backwards compatiblity to procedural. Oh and lets throw typing away cots
its too hard for numpties.

Result is a fucking plate of spaghetti where to change three bytes in a
browser takes in interpreted variable name with more dots than a
golfball covered in brackets and completely impenetrable, since its
scope is implementation dependent, and, worse depends on where it sits
in some HTML as well.

I am coming to realise that Javascript is possibly the worst language I
have ever had to program in.

Your post made me chuckle and its no bad thing for pompous language
types to be needled from time to time. But I don't think JS *quite*
deserves this level of opprobrium.

Perl, on the other hand, does. That's a much shittier language than JS,
so feel free to mosey on over to their NG.

Ah PERL I agree its even worse BUT I did say 'that I have ever programmd
in' after sacking a bloke who spent a year not doing what would have
taken me less than three weeks in 'C' , and realising that the little
bits he HAD done were so slow as to make the whole project completely
inviable, I decided never to touch PERL if it could be avoided. To date
here has always been an alternatve.

And remember: poor programmers can write FORTRAN in any language.

Nothing wrong with fortran.

I wish there was a macro so I could compress GetElementById into gebd()
or somesuch.

Maybe there is? <"brightens visibly">
 
T

The Natural Philosopher

Tim said:
[snip]
The soundest comment I ever received from one of the tighest machine
code programmers ever was 'languages schamguages: its all just bits, in
silicon'

Has this guy ever written in anything other than machine code? If not, I
wouldn't pay any attention to him whatever.

Probably most of the device drivers in C for a lot of the hardware you
are probably typing your posts on.

It's like DIY typse and SDS drills in here. arguing endlessly on which
one has the most gadgets and features and how best to make a 9" hole in
a wall.

I am the guy who comes up and says 'a sledge hammer, a bag of cement and
a cold chisel is cheaper ad faster: Hit hard, collect what falls out and
reassemble the broken bits leaving the hole you want.

How does it go? "when the only tool you have is a hammer, everything
looks like a nail"

Working with javascript is more like using a CNC controlled router and
robot assembler when all you wanted to do was drive in a nail..
 
R

rf

Ah PERL I agree its even worse BUT I did say 'that I have ever programmd
in' after sacking a bloke who spent a year not doing what would have taken
me less than three weeks in 'C' ,

It took you a whole *year* to find out that he was goldbricking?

Chortle chortle.
 
D

Doug Miller

Henry wrote: [snip]
Says who? The snippets of your code that you have posted are already
bizarre; who uses - getElementsByName - to reference a form control?

I do. I could have used id I guess..

And that would be silly as well. Why don't you try learning about DOM
implementations before attempting to manipulate them with JavaScript?
That will save you a lot of future frustration.
Suggesting a way in which it *should* be done is more helpful than listing
ways in which it should *not*.
 
D

David Mark

Henry wrote: [snip]
Says who? The snippets of your code that you have posted are already
bizarre; who uses - getElementsByName - to reference a form control?
I do. I could have used id I guess..
And that would be silly as well. Why don't you try learning about DOM
implementations before attempting to manipulate them with JavaScript?
That will save you a lot of future frustration.

Suggesting a way in which it *should* be done is more helpful than listing
ways in which it should *not*.

I didn't list anything. And the OP didn't ask for any help.

Anybody who is unclear on how to reference form elements *should* read
the FAQ.
 
B

beegee

Working with javascript is more like using a CNC controlled router and
robot assembler when all you wanted to do was drive in a nail..

In my long (too long I think sometimes) programming career I have met
plenty of colleagues who spent way too much time complaining about the
language they were programming in. I, too, have been guilty of it.
Just last year I needed to make mods to ASP pages written in VBScript
and I complained up a storm.

In general, it is a waste of time. It really doesn't matter what
language you use, as you say, you are in the end, just moving bits.
After years of C++, C, Perl, Java (all the commercial software
languages) I find Javascript to be fairly fascinating. It's dynamic,
typeless architecture and it's prototype OO model were all new to me
and when I really started to delve into some of the more advanced
properties of the language like closures and native representation, I
was hooked. As I have said before, go view Crockford's video lectures
and read some of the archives here. You will see some amazing things.
At this point, I really wish I could use Javascript (or Ruby, another
dynamic, typeless language) for hardcore, standalone commercial
software programming.

I heard Douglas Crockford explain how the web platform is now (or is
becomming) the application platform. Users now expect their web
experience to be an application. One of the main reasons this has
come to be is Javascript. It was only when I suddently realized that
Javascript was not a "lame C" and in fact, was nothing like C that the
power of this language became clear to me.

Bob
 
T

Tim Streater

The Natural Philosopher said:
Tim said:
[snip]
The soundest comment I ever received from one of the tighest machine
code programmers ever was 'languages schamguages: its all just bits, in
silicon'

Has this guy ever written in anything other than machine code? If not, I
wouldn't pay any attention to him whatever.

Probably most of the device drivers in C for a lot of the hardware you
are probably typing your posts on.

Doesn't qualify him to comment on anything else, is my point.
It's like DIY typse and SDS drills in here. arguing endlessly on which
one has the most gadgets and features and how best to make a 9" hole in
a wall.

I am the guy who comes up and says 'a sledge hammer, a bag of cement and
a cold chisel is cheaper ad faster: Hit hard, collect what falls out and
reassemble the broken bits leaving the hole you want.

How does it go? "when the only tool you have is a hammer, everything
looks like a nail"

Working with javascript is more like using a CNC controlled router and
robot assembler when all you wanted to do was drive in a nail..

Well, I'll remember not to call on you when I want some panel pins put
in a picture frame.

Sledgehammer, indeed!
 
H

Henry

Precisely.

That is inconsistent. String typing cannot both be thrown away "cots
its too hard for numpties" and the result require an additional
discipline form the potential programmer.
All programs ever do is 'change bytes' mate.
Or did that one pass you by?

Javascript is specified entirely in terms of its behaviour. While the
underlying implementations may be changing bytes there is no reason to
expect any two implementations to be changing the same bytes in
response to any particular piece of javascript code. As a result there
is very little point in even thinking about anything lower level than
the explicit and implicit types used in javascript.

This oe is in my opinion a singularly bad one: its fashionably
object oriented,

Javascript is a functional programming language.
but its been cobbled together and it has no systematic
coherence: At lest with something like C or Fortran, there
existed a book or set of standards which defined the language.

Javascript has a standard that defines the language. Your comments
suggest a failure to differentiate between the language and the object
models that the language is used to script, but even the object models
are partly standardised.
I do. I could have used id I guess..

You could, but most here would favour referencing named form controls
as named members of the FORM element's - elements - collection, given
that that approach is both DOM standard and back-compatible with every
scriptable browser that has known what a form element is. Anything
else will introduce issues (while sacrificing compatibility) and as a
result make the task seem much harder than it could.
Sadly, if you want to get a browser to do tricks, it is.

But getting a browser to "do tricks" is itself optional.
 
T

The Natural Philosopher

Henry said:
But getting a browser to "do tricks" is itself optional.

Not if thats the smart terminal you have to use, and the tricks are part
of the product specification.
 
R

Richard Cornford

The said:
Talking to yourself again?
<snip>

The last person to spend their time on this group banging on about what
a bad language javascript is was bemoaning the lack of a goto statement
in javascript, because as someone with "decades of practical programming
experience(tm)" in assembly language programming for embedded
controllers he considered the absence of such a basic construct a
significant shortcoming. He wasn't taken very seriously by anyone,
though he wouldn't be told.

Experienced programmers who come to javascript tend to do so with a set
of preconceptions and expectations. Javascript is not the language they
expect it to be, and it is not necessarily the language they want it to
be. But it is the language that it is, and it is a very good language
for the context in which it is mostly used. Try to cope with the
inconsistencies in web browser DOMs in a strongly typed language like
Java and you would end up having to do so much reflection that the
results would run like treacle, even if the code itself was considerably
faster.

In the end (and regardless of any shortcomings it may have) javascript
is a very interesting language. Being a dynamic, functional programming
language introduces possibilities that are few and far between in other
languages. There may be a price for those possibilities, but that is
probably true everywhere. And the issues of designing and implementing
genuinely cross-browser scripts are sufficiently difficult to remain
challenging and so absorbing.

If you perceive yourself as having no choice but to use javascript now
then it does not really matter how much you would like javascript to be
different from the way it is, you have to get on with javascript the way
it is. That is inevitably going to take you some time (as was true for
everyone who came before you) and possibly your best starting action
would be to recognise your preconceptions and expectations for what they
are, and realise that they may not be applicable to javascript or the
issues of browser scripting.

And in the meanwhile all the time you spend whining is time wasted; it
will change nothing, at least not for the better. What it may change is
the willingness of people to help you. Peter Michaux is someone who
knows a thing or two about javascript, and seems to be someone
interested in going out of his way to help others (including previously
giving you sound advice), but how is your last comment above most likely
to influence his attitude towards you?

Richard.
 
T

Thomas 'PointedEars' Lahn

Peter said:
Sure you are able to vent or say anything you want on
comp.lang.javascript as it is a public group; however, if you want to
vent in public don't expect any help from the regulars. You will
likely be ignored.

Fortunately, people in Usenet who cannot be taken seriously and are most
likely trolls can be recognized by their apparent disregard for Netiquette
and their violation of Internet standards as demonstrated by their invalid
From/Reply-To header, and most of the time also by their anonymous appearance.

Unfortunately, (troll-)feeding followups like yours make those
time-and-nerves-saving filters largely ineffective. No offense meant.


PointedEars
 
F

f3l

actually, people in web 2.0 coding usually use a lib that do simething
like this:

function $(id){return document.getElementById(id)}

(or somewhat more complex, but that essentially it)
which allows them to stuff like

$("foo").value

pretty neat, heh?


The Natural Philosopher wrote:

[snip]
I wish there was a macro so I could compress GetElementById into gebd()
or somesuch.
Maybe there is? <"brightens visibly">

It's easy enough to roll your own:

gebd(x){return document.getElementById(x);}
Mick
 
D

Darko

Consider:

<script type="text/javascript" language="JavaScript">
function foo()
{
var dung;
dung=document.getElementsByName('foo')[0].value;
Alert(dung);}

</script>
<INPUT type="hidden" name="foo" value="shite">

<b onclick="foo()">Click here for an opinion on Javascript</b>

Works in everything except IE. IE6/7 seems to regard
document.getElementsByName('foo') as including the function itself and
gives an 'error in page' response. Or perhaps it finds it first, and
that's why the error occurs.

I am sure there s some reason why it works in other browsers but not in
IE, but what is it?

I had some problems recently with getElementsByName in IE, so I wrote
my own, probably
with speed cost, but at least I stopped yelling at the computer. It is
not so hard, maybe
you should try it yourself.

As for the argument, I really don't see how someone asking for help
and at the same
time being rude to them expects to get that help, and as an ordinary
observer of the
thread, I must say your tone is rude. I can believe this is not your
true nature,
and you act like that because you're frustrated with Javascript and
accompanying problems,
but that should be controlled when talking to others, especially if
you're asking them
for help.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top