Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[OT] The wonders of Javascript...

148 views
Skip to first unread message

Simon Clubley

unread,
Mar 1, 2015, 9:16:10 AM3/1/15
to
[Yes, I know it's OT for comp.os.vms, but I thought some might
find the following interesting.]

Due to a mistake (I got distracted), I ran the following line of code
before adding code to define and initialise resume_offset elsewhere:

ndm_database[this.db_idx].file_size =
conn_database[this.db_idx].channel.contentLength
+ ndm_database[this.db_idx].resume_offset;

Turns out that in Javascript integer + undefined variable equals a
silent NaN and not a syntax error:

info: ndm: file_size = NaN, contentLength = 72306438, resume_offset = undefined

Even better, at some point along it's path from the addon script to the
front end content script (Firefox isolates addon and content scripts
and requires you to communicate by posting messages between them), the
NaN had been transformed in a way which rendered the formatted value as
zero on the front end HTML display instead of as a NaN...

Oh, the wonders of Javascript (part 482!)...

As well as adding features which make modern languages nicer to use
than traditional languages, it would be nice if some modern language
designers also included the robustness features from traditional
languages. In no sane language should it be possible to add using an
undefined variable without generating a syntax error.

The above info: line was generated by a console.log() statement
immediately following the above addition and the fact the Javascript
interpreter even executed the console.log() call after the above error
instead of aborting execution says a lot about Javascript... :-)

Simon.

--
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world

Simon Clubley

unread,
Mar 1, 2015, 10:56:53 AM3/1/15
to
On 2015-03-01, Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> wrote:
>
> Turns out that in Javascript integer + undefined variable equals a
> silent NaN and not a syntax error:
>

And before someone pulls me up on it, yes, I know that's (floating point)
number + undefined variable and not an integer + undefined variable.
I was thinking of the integer length present in the HTTP headers when
I wrote that.

Add the language standard level lack of a real integer datatype to the
list of issues I have with Javascript.

johnwa...@yahoo.co.uk

unread,
Mar 1, 2015, 11:13:27 AM3/1/15
to
Judging by the mild element of pained surprise, I'm guessing you may
not yet seen Gary Bernhardt's five minute WAT talk from CodeMash 2012.

He starts with Ruby but JS gets a mention fairly soon, and he
continues in the same vein.

The original should be at
https://www.destroyallsoftware.com/talks/wat
but the video there won't play for me right now.

The wayback machine has a copy that works for me:
https://archive.org/details/wat_destroyallsoftware

Five minutes. That's all it'll take if you watch from start to end
uninterrupted. You'll to watch as well as listen, and might want to
be ready on the rewind button.

The wonders of modern technology.

Have a lot of fun.

johnwa...@yahoo.co.uk

unread,
Mar 1, 2015, 11:56:59 AM3/1/15
to
My missing-word checker appears to broken.

Simon Clubley

unread,
Mar 1, 2015, 12:38:06 PM3/1/15
to
On 2015-03-01, johnwa...@yahoo.co.uk <johnwa...@yahoo.co.uk> wrote:
>
> Judging by the mild element of pained surprise, I'm guessing you may
> not yet seen Gary Bernhardt's five minute WAT talk from CodeMash 2012.
>

Yes, I've seen it (I was pointed to it recently) and I've just watched
it again. There's a number of stupid design issues in there which are
consistant with what I have come across, but even so, number + undefined
variable = NaN (instead of syntax error) is a new low. :-)

This is in the Firefox Javascript interpreter, so I don't know if this
behaviour is specific to that interpreter.

JF Mezei

unread,
Mar 1, 2015, 2:35:36 PM3/1/15
to
On 15-03-01 11:13, johnwa...@yahoo.co.uk wrote:

> The original should be at
> https://www.destroyallsoftware.com/talks/wat
> but the video there won't play for me right now.


You can click on "download" below the video window and you will get the
working .mov file which can run on quicktime.


Verry funny.

hb

unread,
Mar 1, 2015, 2:49:25 PM3/1/15
to
On 03/01/2015 06:37 PM, Simon Clubley wrote:
> There's a number of stupid design issues in there which are
> consistant with what I have come across, but even so, number + undefined
> variable = NaN (instead of syntax error) is a new low.:-)
>
> This is in the Firefox Javascript interpreter, so I don't know if this
> behaviour is specific to that interpreter.

For what it is worth, with a simplified example, iceweasel (32.0.3) and
chrome (37.0.2062.120) report a "ReferenceError: xxx is not defined" or
"Uncaught ReferenceError: xxx is not defined" in the "console log" each
pointing to the source line.

I don't have Firefox on the system I'm currently logged in, but I expect
it to show something similar in that log. And from experience I know
that Firefox displays an error count, in my configuration at the bottom
of the window, which is "clickable" and transfers me to the console log.

On the other hand, is there really a "syntax error"?

PS: Regardless whether I like Javascript or not, I use or have to use it
to run some code on the client side of a web application. Or is there
something else to check user input before/without transmitting it over
the net?

Simon Clubley

unread,
Mar 2, 2015, 3:29:13 AM3/2/15
to
On 2015-03-01, hb <end...@inter.net> wrote:
> On 03/01/2015 06:37 PM, Simon Clubley wrote:
>> There's a number of stupid design issues in there which are
>> consistant with what I have come across, but even so, number + undefined
>> variable = NaN (instead of syntax error) is a new low.:-)
>>
>> This is in the Firefox Javascript interpreter, so I don't know if this
>> behaviour is specific to that interpreter.
>
> For what it is worth, with a simplified example, iceweasel (32.0.3) and
> chrome (37.0.2062.120) report a "ReferenceError: xxx is not defined" or
> "Uncaught ReferenceError: xxx is not defined" in the "console log" each
> pointing to the source line.
>

Did your simplified example try referencing an undefined standalone
variable or a non-existant member of an object (which is what I
was doing) ?

There were _no_ errors reported in my case, either in the cfx debugging
log or even in the Firefox Error Console log itself.

> I don't have Firefox on the system I'm currently logged in, but I expect
> it to show something similar in that log. And from experience I know
> that Firefox displays an error count, in my configuration at the bottom
> of the window, which is "clickable" and transfers me to the console log.
>
> On the other hand, is there really a "syntax error"?
>

Good point. A better description would be an undefined variable error.

Richard Maher

unread,
Mar 2, 2015, 4:58:33 AM3/2/15
to
On 3/2/2015 4:28 PM, Simon Clubley wrote:
>
> Good point. A better description would be an undefined variable error.
>

A SSCCE is always good but your moaning implies a couple of lines posted
here could reproduce it?

While Javascript certainly has its share of issues I (and a big slice of
the development world) love it!!! And the debugging available today on
FireFox, Chrome, Opera and even IE is soooo good you'd have to be pretty
damn thick to not trap a simple bug such as you suggest. Sure
phone/mobile emulation is not quite there yet but is getting better
every release. And turning CSS attributes on/off at will - outstanding.

Tell you what, why don't you get VSI to bring out DECForms 3. People
like you and Phillip and Brian long for the good ol' DECWindows days,
why not an IFDL capable browser??? Remember those wondrous debugging
capabilities? "You are on the left side of the equation." :-(

I just wish Oracle hadn't killed Applets 'cos now I'm having to use a
web worker to re-scan my array of Markers to see if their LatLng is
inside or outside the (0.5 opacity) circle that the user is dragging
over the Google Map. Still, it frees up the event loop and all the
worker thread has to do is feed back hit/miss so the GUI/main thread can
update the screen.

Yep you keep developing character-cell apps in BASIC, or use the
worst-performing most out-of-date browser on the planet on your
DECWindows workstation and consign VSI to go down the toilet with the
very same dumb-fucks who killed Digital with DECForms (please don't say
you've hired any?).



Simon Clubley

unread,
Mar 2, 2015, 9:02:52 AM3/2/15
to
On 2015-03-02, Richard Maher <maher_rj...@hotmail.com> wrote:
> On 3/2/2015 4:28 PM, Simon Clubley wrote:
>>
>> Good point. A better description would be an undefined variable error.
>>
>
> A SSCCE is always good but your moaning implies a couple of lines posted
> here could reproduce it?
>
> While Javascript certainly has its share of issues I (and a big slice of
> the development world) love it!!! And the debugging available today on
> FireFox, Chrome, Opera and even IE is soooo good you'd have to be pretty
> damn thick to not trap a simple bug such as you suggest. Sure
> phone/mobile emulation is not quite there yet but is getting better
> every release. And turning CSS attributes on/off at will - outstanding.
>

First off, Javascript development is still a new area for me.

Second, when developing a Firefox addon, and are debugging the Javascript
code driving the addon, you have access to the cfx log and the Firefox
Error Console log. Neither of these showed what the problem was but it
didn't take me too long to work out what was going on.

> Tell you what, why don't you get VSI to bring out DECForms 3. People
> like you and Phillip and Brian long for the good ol' DECWindows days,
> why not an IFDL capable browser??? Remember those wondrous debugging
> capabilities? "You are on the left side of the equation." :-(
>

Please don't bundle me in with Phillip. :-)

In case you haven't been paying attention, I'm the one wanting all the
new DCL/filesystem/other features which would bring VMS up to a level
comparable to other environments.

Oh, and the last time I used a GUI browser _on_ VMS was over a decade
ago and I only use Lynx _very_ rarely for some quick network/system
availability testing.

Tom Adams

unread,
Mar 2, 2015, 10:38:26 AM3/2/15
to
I have been using Google Web Toolkit (GWT) to convert Java to Javascript for deployment of my web site that helps one pick the best entry sheet for the NCAA pool: www.poologic.com

GWT has worked well, but I am not an expert. I write code in Java and deploy in Javascript.

I already had the site written in Java. I wanted to eliminate use of the Java Virtual Machine because it was not widely supported was becoming user unfriendly after Homeland Security declared jihad against Java applets a while back.




hb

unread,
Mar 2, 2015, 4:34:31 PM3/2/15
to
On 03/02/2015 09:28 AM, Simon Clubley wrote:
> Did your simplified example try referencing an undefined standalone
> variable or a non-existant member of an object (which is what I
> was doing) ?

A variable. (I'm not sure what "standalone" should mean in
this/Javascript context.) In Javascript, referencing a non-existant
member of an object is not an error. The name or property to
identify/reference a member of an object is not a variable.

The simplified example was based on the OP:

Richard Maher

unread,
Mar 2, 2015, 7:05:25 PM3/2/15
to
On 3/2/2015 10:02 PM, Simon Clubley wrote:
> Please don't bundle me in with Phillip. :-)
>

My apologies. I knew I'd gone too far as soon as I'd written it :-)

Simon Clubley

unread,
Mar 3, 2015, 9:03:09 AM3/3/15
to
On 2015-03-02, hb <end...@inter.net> wrote:
> On 03/02/2015 09:28 AM, Simon Clubley wrote:
>> Did your simplified example try referencing an undefined standalone
>> variable or a non-existant member of an object (which is what I
>> was doing) ?
>
> A variable. (I'm not sure what "standalone" should mean in
> this/Javascript context.) In Javascript, referencing a non-existant
> member of an object is not an error. The name or property to
> identify/reference a member of an object is not a variable.
>

Yes, in my example, the undefined reference was supposed to be a property
(which should contain an integer value) of an object instead of how
I loosely called it a variable.

What I meant by standalone variable was something declared as "var test1;"
instead of something which is a property of an object.

BTW, and IMHO, Javascript _not_ throwing an error when you reference a
non-existent property in a maths operation (but instead silently setting
the LHS of the assignment to a NaN) is absolutely insane. There is no
reason why something like that would ever be valid code.

I really hope no-one is using Javascript for safety critical code. :-)

hb

unread,
Mar 3, 2015, 12:22:28 PM3/3/15
to
On 03/03/2015 03:02 PM, Simon Clubley wrote:

> BTW, and IMHO, Javascript_not_ throwing an error when you reference a
> non-existent property in a maths operation (but instead silently setting
> the LHS of the assignment to a NaN) is absolutely insane. There is no
> reason why something like that would ever be valid code.

Maybe I already said it, I use Javascript, that's all. So I don't want
to argue, but that's the way Javascript works. Referencing a
non-existant member of an object returns an undefined value (which is a
"primitive value") and an undefined value used in an arithmetic
expression is converted to a NaN - because Javascript
"performs automatic type conversion as needed" as described in the
specs. There are more (unexpected?) automatic conversions like that.

Conversion as needed is not unusual to readers of c.o.v:
$ write sys$output "true"+1

Simon Clubley

unread,
Mar 3, 2015, 12:41:15 PM3/3/15
to
On 2015-03-03, hb <end...@inter.net> wrote:
> On 03/03/2015 03:02 PM, Simon Clubley wrote:
>
>> BTW, and IMHO, Javascript_not_ throwing an error when you reference a
>> non-existent property in a maths operation (but instead silently setting
>> the LHS of the assignment to a NaN) is absolutely insane. There is no
>> reason why something like that would ever be valid code.
>
> Maybe I already said it, I use Javascript, that's all. So I don't want
> to argue, but that's the way Javascript works.

Don't worry hb, I most certainly was _not_ arguing with you :-) as I
was just making an observation about Javascript.

Now I know Javascript a lot better than I did a few months ago, I've
found some of the language design decisions to be rather, erm,
"interesting". :-)
0 new messages