News for hackers. Stuff that matters.
Re:JavaScript Errors: An Exceptional History by z3t4 on Tuesday November 05, 2019 @10:26AM (#21453167)
I remember that in IE all you got was a yellow alert sign in the status bar that there was a JavaScript error somewhere and you added alert boxes on every 100:ed line eg. alert("line 200") alert("line 220") until you had located the error. This is still how you do it on some mobile/tv browsers. Some browsers will not even tell you there is an error - and fail silently.
Re:JavaScript Errors: An Exceptional History by icedchai on Tuesday November 05, 2019 @10:59AM (#21453502)
This was the 90's Javascript debugging experience and why I still hate JS to this day. The language felt like mush.
Re:JavaScript Errors: An Exceptional History by mr_toad on Tuesday November 05, 2019 @06:21PM (#21457943)
But these days the dev tools built into every modern browser rival the debugging tools in the best IDEs, and they’re free.
Re:JavaScript Errors: An Exceptional History by icedchai on Wednesday November 06, 2019 @08:58AM (#21462602)
Yes, modern browser dev tools are great. But it's still Javascript.
Re:JavaScript Errors: An Exceptional History by mettamage on Tuesday November 05, 2019 @11:31AM (#21453884)
Wait, so when did console.log start to appear?

I remember alert without console.log as well but I was too young to understand the context.

For ios mobile dev I use Safari as a debugger. If I have to use Chrome, I basically use a scrappy console that I made on the HTML page itself.

Re:JavaScript Errors: An Exceptional History by allannienhuis on Tuesday November 05, 2019 @11:50AM (#21454102)
Sometimes dumping data to a pre tag is the simplest thing, especially on mobile. I did it just yesterday :)

Be careful about using JSON.stringify on objects as a debugging technique though, because you may not be able to see properties on the prototype chain ('inherited' properties), and some objects customize their serialization to JSON (supply a custom toJSON method) which in some cases can be misleading. Things like that have contributed to a number of my grey hairs. Yes, I'm talking about you, Geolocation Coordinates! :)

Chrome has really nice support for remote debugging on Android.

If you can't get physical access to the device to configure them for remote debugging, there are some other nice remote debugging tools. One example: https://jsconsole.com/remote-debugging.html

Re:JavaScript Errors: An Exceptional History by mishac on Tuesday November 05, 2019 @11:47AM (#21454059)
IIRC console.log was a non-standard addition made by FireBug.
Re:JavaScript Errors: An Exceptional History by boothby on Tuesday November 05, 2019 @01:09PM (#21454937)
> If I have to use Chrome, I basically use a scrappy console that I made on the HTML page itself.

Back in the day when I was working on the Sage Notebook, there weren't good javascript consoles. I can't recall if Firefox had one at the time (around 2007, I think), but it was certainly missing from Safari, IE, and Opera. But, it was an interactive notebook -- so I hijacked the "input cell" we were using to concoct what was essentially a console.

Re:JavaScript Errors: An Exceptional History by thrower123 on Tuesday November 05, 2019 @12:49PM (#21454696)
I can remember when console.log would break certain versions of IE... I believe even in IE8, console.log would only work if you had the developer JS console opened up, unless you polyfilled it.

Thank god I don't have to support IE anymore, what a mess it was.

Re:JavaScript Errors: An Exceptional History by reificator on Tuesday November 05, 2019 @11:30AM (#21453872)
> This is still how you do it on some mobile/tv browsers. Some browsers will not even tell you there is an error - and fail silently.

That sounds surprising, because I thought most of those were based on Chromium. Do they not allow you to expose a remote debugging port that you can connect to from a desktop instance of Chrome?

Re:JavaScript Errors: An Exceptional History by niteshade on Tuesday November 05, 2019 @06:30PM (#21458033)
I'm fairly sure they're based on WebKit, actually. Can't say I've ever seen Chromium inside non-Android mobile/TV browsers, but I could be wrong.
Re:JavaScript Errors: An Exceptional History by bagol on Tuesday November 05, 2019 @11:15AM (#21453684)
I feel bad for javascript for it always blamed for the fault of the environment where it lives.
Re:JavaScript Errors: An Exceptional History by coldtea on Tuesday November 05, 2019 @11:32AM (#21453902)
The language didn't have other error reporting mechanisms, traces or exceptions, so it was not "the environment where it lived", it was the language itself...
Re:JavaScript Errors: An Exceptional History by duxup on Tuesday November 05, 2019 @11:30AM (#21453867)
And to some extent the acts of bad actors using it.

I just got into webdev a year or so ago and on HN and other places the moral panic about JavaScript on the web is endless because some jerks are out there doing it wrong and everyone thinks of their US local news website (those are a mess) when they talk about it ... and they want to throw the baby out with the bathwater. Meanwhile I'm just trying to write some handy web apps that do it right but can't escape the "omg javascript" medium type articles.

I wonder if folks write some nasty stuff in C ... do people blame C?

Re:JavaScript Errors: An Exceptional History by blotter_paper on Tuesday November 05, 2019 @02:42PM (#21455892)
> the moral panic about JavaScript on the web is endless because some jerks are out there doing it wrong

To be fair, the language allows them to do it wrong by default with all that implicit type conversion and whatnot -- even in the original equality operator! You can write good JavaScript, but you have to purposefully avoid weird behavior that just isn't present in some other modern languages like Python and Ruby. JavaScript had a weird history, got expanded upon accidentally (i.e. through some browser vendor or another deciding to implement something) many times, and has always valued backwards compatability more than languages that feel comfortable expecting the user to install the relevant runtime.

Re:JavaScript Errors: An Exceptional History by strbean on Tuesday November 05, 2019 @05:02PM (#21457221)
Python has

    > a = 100
    > a is 100
    True
    > a = 1000
    > a is 1000
    False
Re:JavaScript Errors: An Exceptional History by blotter_paper on Tuesday November 05, 2019 @05:25PM (#21457435)
CPython stores integers above 256 as individual pieces of data, but a normal Python script doesn't. I think it's technically undefined behavior.
Re:JavaScript Errors: An Exceptional History by peteradio on Tuesday November 05, 2019 @01:42PM (#21455307)
People complain about c all the time. Javascript is 20% footgun.
Re:JavaScript Errors: An Exceptional History by mishac on Tuesday November 05, 2019 @01:22PM (#21455104)
People totally blame C (and C++). There's entire classes of use-after-free and buffer flow errors not possible in other languages, which is what leads to people advocating for Rust or Go (or ADA for that matter, though it's obviously not popular anymore).
Re:JavaScript Errors: An Exceptional History by purple_ducks on Tuesday November 05, 2019 @02:01PM (#21455482)
http://www.devsanon.com/rants/stupid-javascript/

Until Javascript removes the stupid from it's language, it will remain an embarrassment to developers. Completely inexcusable.

Re:JavaScript Errors: An Exceptional History by reificator on Tuesday November 05, 2019 @06:03PM (#21457757)
> http://www.devsanon.com/rants/stupid-javascript/

> Until Javascript removes the stupid from it's language, it will remain an embarrassment to developers. Completely inexcusable.

From that link:

> > typeof NaN

> > "number"

> > NaN == NaN

> > false

> > Ok, so the type of Not a Number is a number? And it also does not equal itself? Oh, well. Let’s try equality with other stuff.

Compliance with IEEE 754 is stupidity that is completely inexcusable? That NaN is non-reflexive is certainly irritating but a standards-compliant language is expected to adhere to that.

Re:JavaScript Errors: An Exceptional History by mr_toad on Tuesday November 05, 2019 @06:27PM (#21458000)
Makes sense to me. 1/0 is not the same as 2/0, etc.
Re:JavaScript Errors: An Exceptional History by dlbucci on Tuesday November 05, 2019 @10:51AM (#21453421)
I had no idea JavaScript shipped without Arrays. Too bad they didn't just let objects take anything as a key, like in Lua. Then you wouldn't have all the edge cases Arrays cause in JS. Oh well!
Re:JavaScript Errors: An Exceptional History by rodinia on Tuesday November 05, 2019 @11:41AM (#21453986)
This (anything can be a key) was eventually added with the Map class. They're an iterable type too, so they're much more useful than Objects imo.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:JavaScript Errors: An Exceptional History by dlbucci on Tuesday November 05, 2019 @12:55PM (#21454768)
I agree! They are more useful! That's why I wish objects behaved that way to begin with!
Re:JavaScript Errors: An Exceptional History by gnode on Tuesday November 05, 2019 @11:10AM (#21453614)
> Too bad they didn't just let objects take anything as a key

They do, except they get coerced to strings in whacky ways. Objects can be used largely like arrays, and Arrays are Objects, but Array is more suited for an ordered collection of numerically indexed elements, and so has relevant properties and methods, like length and indexOf.

Re:JavaScript Errors: An Exceptional History by dlbucci on Tuesday November 05, 2019 @12:58PM (#21454811)
Yeah, but the weirdness inherent to them being objects but also not objects leads to all sorts of bullcrap, like `Array.isArray` being a thing. I greatly prefer the Lua approach where you only have one map type (tables), and there are methods that allow you to easily use the tables as an array.
Re:JavaScript Errors: An Exceptional History by tdy_err on Wednesday November 06, 2019 @09:54AM (#21463132)
The initial v1 JavaScript was written in about ten days:

https://thenewstack.io/brendan-eich-on-creating-javascript-i...