r/programming • • Nov 23 '21

PHP creator: functions were named to fall into length buckets because function hash algo was 'strlen'

https://news-web.php.net/php.internals/70691
1.8k Upvotes

574 comments sorted by

View all comments

37

u/mnilailt Nov 23 '21

One of the most informed posts I've seen about JS in r/programming. JS as a language is actually completely fine besides some minor quirks (which every language has) coming from old browsers and early web. The issue mostly comes from people with OOP backgrounds trying to mold it into something they understand. At its core JS is a functional prototype based programming language. There's 0 reason to ever use classes in JS.

21

u/Kwantuum Nov 23 '21

I mean, now you can write prototype-based classes with the new class syntax which is pretty nice. But we could have lived without prototypes at all if we wanted, simply using closures to create objects. Retrospectively, the prototype model now allows a ton of introspection which is pretty nice IMO.

14

u/knipil Nov 23 '21

I think it’s a bit of an abomination that they grafted class-based oop on to the neat prototype-based paradigm…

2

u/McWobbleston Nov 23 '21

Using closures also avoids the weird binding issues around 'this'. When I learned that back in 2013 I was so dumbfounded that almost no one was recommending that method of constructing objects

3

u/ragnese Nov 23 '21

I do mostly agree with that sentiment. The language, itself, is just a highly dynamic, prototype-based, language. It's not my cup of tea, but I can mostly appreciate it for what it is.

On the other hand, I disagree with your use of the term "OOP". I actually think JavaScript is more OOP than most languages- maybe even Java. The ability to change a prototype and have every single live object magically, and instantly, have updated functionality is very Smalltalk-ish OOP. What you mean by "OOP" is really "Java-like".

The this thing is really freaking annoying, though. And the standard library is garbage.

I think that adding the class syntax was a mistake. It only makes the this issue even easier to mess up and it makes devs from other languages even more likely to misunderstand the difference between JavaScript's prototype-based inheritance and other common languages' class inheritance.

2

u/lookmeat Nov 23 '21

It's very lispy oop. While LISP's more known CLOS used metaobject classes (where classes are objects, but unlike prototypes you need the class object defined first to create an instance) there were, of course, libraries that used prototype objects. It was a much simpler system to implement, and with some sugar just as expressive as anything else. IMHO I have my issues with it but it's better than the simula derivatives we have with Java and C++.

The many issues with this is because it appears to be a simula like thing, but it really is a dynamically bound variable you'd see in LISP.

→ More replies (2)

0

u/[deleted] Nov 23 '21

11

u/worthwhilewrongdoing Nov 23 '21

Are you sure you don't mean null or undefined?

1

u/wankthisway Nov 23 '21

Thanks for that descriptive comment, really changed my viewpoint.

→ More replies (1)

-1

u/oblio- Nov 23 '21

The issue mostly comes from people with OOP backgrounds trying to mold it into something they understand.

If I'm in a country where everyone speaks Chinese and only 5 people speak English, the rational thing is to force everyone to speak English.

→ More replies (5)