7 ms·
A praise of 'prototypal inheritance' in 2014? Doesn't sound like an escape from JavaScript hell.
by ExpiredLink 12y ago
A praise of 'prototypal inheritance' in 2014? Doesn't sound like an escape from JavaScript hell.
- niklasni1 12y agoI'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.
- bitanarch 12y agoWell, just a curious question - do you lint your JavaScript code?
- niklasni1 12y agoI 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?
- bitanarch 12y agoIf 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.
- scrollaway 12y ago> 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.
- thallian 12y agoYou 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.
- anon1385 12y ago>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/ http://www.devthought.com/2012/01/18/an-object-is-not-a-hash...
- deleted 12y ago[deleted]
- nateroling 12y agoObject.create(null) creates an empty object with no prototype that you can safely use as a hash, as mentioned in the article you linked.
- wslh 12y ago> 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.
- jimmaswell 12y agoObjects? In /my/ Document-Object Model manipulation language? How inappropriate.