News for hackers. Stuff that matters.
Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by niklasni1 on Saturday December 13, 2014 @06:43AM (#8744956)
I've been writing JS for a few months, after years of hating it from a distance. I must say it's not as bad as I expected, inasmuch as you can basically pretend it's a somewhat wonky Scheme.

The nicest part of it is the built-in hash table type and the related syntactic sugar that everyone for whatever reasons insists on calling "object".

One thing that makes me freeze right up, though, is I hear they're adding classes and inheritance and that whole OO clusterfuck to what's a nice, trim little dynamic language.

Like the article, I think it's possible to write good code in JS as it is, by accepting what it is, rather than trying to force it to be an OO language, by emulation or extension.

Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by anon1385 on Saturday December 13, 2014 @07:51AM (#8745076)
>The nicest part of it is the built-in hash table type and the related syntactic sugar that everyone for whatever reasons insists on calling "object".

People call it an object because that is what it is. If your code is using Javascript objects as general purpose hash tables with the normal syntactic sugar then your code is broken[1]. The correct way to use an object as a hash table involves a bunch of ugly extra syntax that makes it more verbose than hash tables in any other language I'm aware of.

[1] http://www.devthought.com/2012/01/18/an-object-is-not-a-hash...

Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by nateroling on Saturday December 13, 2014 @12:04PM (#8745603)
Object.create(null) creates an empty object with no prototype that you can safely use as a hash, as mentioned in the article you linked.
Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by wslh on Saturday December 13, 2014 @08:16AM (#8745118)
> I must say it's not as bad as I expected,

Every programming language leaves you a flavor in your mouth, it can be bitter and sweet. I like the idea of having living object in the DOM, it feels a little bit like smalltalk from a distance. but the language itself? I prefer to run a neutral VM or a secure native client in the browser to run other languajes.

Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by thallian on Saturday December 13, 2014 @07:09AM (#8745006)
You summed up my thoughts about the language in a much better way than I could. I didn't want to touch it ever (especially after seeing what a coworker got up to with it). Then I built an interest in how to build something on Firefox OS and now I've come to really like it for some things.
Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by jimmaswell on Saturday December 13, 2014 @11:55AM (#8745568)
Objects? In /my/ Document-Object Model manipulation language? How inappropriate.
Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by bitanarch on Saturday December 13, 2014 @06:49AM (#8744975)
Well, just a curious question - do you lint your JavaScript code?
Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by niklasni1 on Saturday December 13, 2014 @06:57AM (#8744994)
I just ran a few of my longer files through jslint.com and it looked like all the errors were related to me using two spaces for indentation instead of four, and some missing semicolons. But I don't know what sort of errors I should be expecting?
Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by bitanarch on Saturday December 13, 2014 @07:18AM (#8745022)
If you're working on a project with just a few people and on the first version, you'd probably not see many of these problems. But imagine your project grows, you keep modifying the code, and often times you'd make typing mistakes..

Let's say originally you have this.

  // Run node to the end
  for (; node.next != null; node = node.next);
  doSomethingElse();
After a few months of team work on the same code, one day, somebody got careless with the "x" key in vim and deleted the semicolon after the for.

  // Run node to the end
  for (; node.next != null; node = node.next)
  doSomethingElse();
And your web page still works! It's just become mysteriously very slow, sometimes. Must be caused by the latest Chrome update.

There're lots of other ways for a pile of JavaScript code to accumulate bugs like this over time without a strict standard in place to lint everything. e.g. people forgetting to add "var" before variable declaration because they've been writing Python as well, causing namespace leaks that DON'T seem to break anything at first.

If you team has a standard practice to always lint everything, always do data binding in a certain way, never modify the DOM directly (combined with the proper libraries), etc. Then, yea, maybe you can scale up your team and the code size without always fixing funny bugs that pop up only after the original mistake was made 6 months ago.

But, standardized development practice with JavaScript? hmm.... how many hotshot frameworks and major updates to hotshot frameworks have we seen in the past 2 years? Compared to that, people using inheritance carelessly is just a minor problem.

Re:The Two Pillars of JavaScript: Part 1: How to Escape the ... by scrollaway on Saturday December 13, 2014 @08:11AM (#8745107)
> After a few months of team work on the same code, one day, somebody got careless with the "x" key in vim and deleted the semicolon after the for.

Not to detract from the subject at hand because you do have a point, but that sort of error is caught by patch reviews. Even on my own projects I review diffs before/after I commit them.