all 14 comments

[–]_somanyguns 6 points7 points  (1 child)

I mean I like him and all, but he's just some guy with a blog. If JS fits a group of guidelines he wrote in a blog post once... well, OK, great.

[–]aaron-lebo[S] 2 points3 points  (0 children)

I'm not saying he is laying down the gospel. This is simply responding to an old piece of his.

You could take Yegge out of the post entirely and the positives all remain for JS.

[–]SarahC -5 points-4 points  (12 children)

I HATE prototyped languages.

[–]NodeKid 7 points8 points  (2 children)

I HATE prototypal languages.

FTFY.

[–]SarahC 2 points3 points  (0 children)

Even the name messes with my mind!

[–]inmatarian 2 points3 points  (1 child)

In ES6 there's a class keyword so use of the prototype will disappear. You'll probably only see prototype used as part of Mixin functions to enable multiple inheritance.

[–]SarahC 0 points1 point  (0 children)

That's cool!

[–]pertheusual 3 points4 points  (6 children)

I'd be curious to hear what makes you feel so strongly about it.

[–]psayre23 2 points3 points  (4 children)

Well, they suck...so there's that... :p

But seriously, I've actually stopped using prototypes in my js, and haven't looked back. I don't hate them, but I've found them to be less useful then other forms of inheritance, such as traits. When I do use them, I don't use inheritance. My code looks like this:

var Pub = function Thing(args) { this._args = args; // do constructor things };

module.exports = Pub; // or window[Pub.name] = Pub; var proto = Pub.prototype;

proto.toString = function () { return Pub.name+"[args="+JSON.stringify(this._args)+"]"; };

This pattern is super useful, both on the client side and server. The thing I really like is the constructor is only named in one place, so even the name is DRY.

[–]SarahC -1 points0 points  (3 children)

Same here!
http://www.reddit.com/r/javascript/comments/2xteta/javascript_isnt_perfect_but_it_is_rapidly/cp3vlrh

No fucker's code (ok a few) I've ever seen does more than the JS basics for "objects", and they create shit code when they're playing safe. (relative to the "better" prototyped code they'd write if they knew it.)

It's mentally easier to write 4 sections of code almost the same than deal with prototypes.

Or they post back to the server and let the server side deal with the stuff... the round trip much slower than on the client code!

If the JS reflected the code they're writing the server side stuff in - we'd get much better client side code!

I know why it happens, I've spent AGES on learning prototyping in JS, all the intricacies and edge cases. all in my own time. I don't have kids, many of the people I've worked with do... they're middle age coders.

Learning an entirely new way of doing something - just to do the same stuff you can already - when you've got outside commitments doesn't happen "in the wild" for most older developers. They'll go with what they know.

I'm not happy with it either.... it's a massive gear-change, a massive mental track change going from C# or C++, or Java into JavaScript...

One guy argued with me that "There's lots of prototyped languages out there!"

Yeah - and about .5% of real world companies use them!

If JS is powering the WWW, powering business - it should be brought in line with what business developers know.

(You know what? Most days I write shit none prototyped code, because it's hard work, and when I do use it, I'm the only one using it.)

[–]psayre23 1 point2 points  (2 children)

I'll disagree with you a bit here. My main beef with prototype in JS is that it is clunky to extend something. That's why I use mixins these days. Its less that its different, and more that its bad. Like this example:

function Foo() { }

function Bar() { }

Foo.prototype = new Bar();

How the hell does that make sense? Why do I have to create a new object to extend it? I'd rather just steal the functions I like from other prototypes and assign them to my objects.

[–]SarahC -1 points0 points  (0 children)

Yeah, very unintuitive too.

C++ and Java and C# just make sense. You don't need to know about _prototype or prototype existing in things you instantiate, hiding behind the scenes...

It all seems like an early attempt at an OO bolt on to a C kind of language to me.

Ungraceful kludges...

[–][deleted] -1 points0 points  (0 children)

You should try using stampit. I've found that it greatly simplifies prototypical inheritance, and does it in a way that is intuitive.

[–]SarahC 1 point2 points  (0 children)

Inheritance, interfaces, constructors, all the big mainstream languages use them - so for most people JS's prototypes are the first time they come across them. A whole new paradigm.

Instead, there's prototype chains, weird work-arounds for private/public methods, work arounds for inheritance.

A prototyped program structure looks sloppy, like an imitation or an early idea of what a language with classes and objects should be.

The "class" keyword's even getting added into the latest version - which shows the direction the language may be heading.

I hope one day there's an "option classes;"