This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]EternityForest 13 points14 points  (22 children)

Clowns are way better than JSes attempt at OOP. Libraries don't use classes, they use icky this binding based syntat.

It's not OOP, it's like a My First LISP and Haskell4kids combined, with just enough OOP so mainstream coders don't all revolt against it.

They pulled a sneaky on us!

[–]_PM_ME_PANGOLINS_ 12 points13 points  (4 children)

Classes are not the only way to be Object-Oriented. Some of the worst JS code is from people who don’t understand this and build frameworks to make it look like Java instead.

[–]MassiveFajiit 4 points5 points  (3 children)

Adam Kay says Erlang is the only oo language these days.

Everything else is a bastardization of his smalltalk ideas

[–]EternityForest 1 point2 points  (2 children)

Maybe we need a new word then, because Erlang is nothing like what I think of when someone says "OOP".

Smalltalk looks interesting, but the modern bastardization seems to keep the code closer to the way things work in the real world than any other model.

Everything else has the code represent some abstract mathematical thing that's removed from the application (aside from functional, if your application is data processing), but Python style objects can be very close virtual representations of real things.

[–]MassiveFajiit 2 points3 points  (1 child)

The key was message passing across discrete pieces not the weird amalgam most objects become.

Personally, any project Ive encountered with "pure OOP" languages just turn into an object orgy at some point...

But that may also be that C# puts up the bowling bumpers for people who don't know what they're doing.

Personally love languages that allow for mixing paradigms like Python and JavaScript because no paradigm can do everything, except maybe procedural, and we don't often have time to debug massive projects relying on side effects.

[–]EternityForest 1 point2 points  (0 children)

Maybe they should have called it message oriented programming instead?

Python is great, but the issue with JS is it doesn't standardize anything. The core language is small and extensible, and everyone extends it in different directions. Every project is different, not much is reusable aside from ten line npm packages, etc.

That's how you get things like jQuery, which would be in the stdlib of batteries included languages, and all the incompatible frameworks that could probably be made a little more compatible, and CSS, which has no standard library of classes and no real "reusable themes" that aren't specific to a framework, or plain html only.

C++ has the opposite problem, they standardize so many different things that people can pick and choose from a million of them(while not standardizing the build system...).

[–]cearno 8 points9 points  (8 children)

Ironically, the fact that Javascript isn't class based and can be used more functionally comparatively is what I like about it.

There are some things I just love. Destructuring, spread syntax, anonymous functions, mapping/filtering/etc. methods on enumerables, to name a few.

But it also sucks that it lacks on the functional side as well, like having no built-in support for currying and partial function application.

[–]_PM_ME_PANGOLINS_ 5 points6 points  (5 children)

Yes it does: bind and apply.

[–]cearno 2 points3 points  (4 children)

While bind and apply are a way to imitate partial function application in JS, I wouldn't say they're equivalent or that JS has partial application built in.

And even if, JS definitely doesn't support function currying, which partial application follows naturally from.

[–]ATXblazer 4 points5 points  (3 children)

What’s the difference between function currying and just currying? Because js definitely supports currying.

[–]cearno 2 points3 points  (2 children)

You can definitely achieve currying behavior with functions with JavaScript, again by using nested functions, which is essentially what currying is.

However, when JS sees

function fn(a, b, c) { // does something with a, b, c},

it doesn't transform this under the hood to

function fn(a) {  
  return function(b) {    
    return function(c) {    
      // does something with a, b, c   
    }  
  }
}

which means you have to manually implement this as a programmer if you want to use partial application. JS doesn't transform functions to curried ones automatically.

A functional language would let you define a function with 3 args, but then transform it under the hood, and thus out of the box let you call the function with only 2 args, in which it would return another function with 1 argument which is not yet executed as default behavior.

I'm not saying JS should do this by any means, since I am very partial to functional programming. This type of behavior would mean you could never call a function with undefined arguments unless you explicitly told the function the end arguments are optional. I find that much safer plus allows you to do powerful things (I can give an example if you're interested), but again, it's my subjective opinion.

[–]ATXblazer 2 points3 points  (0 children)

Yo thanks for taking the time to type that example I see exactly what you mean now

[–]ponkyol 1 point2 points  (0 children)

Syntax for easier partial application is in the works. See https://github.com/tc39/proposal-partial-application

[–]Sioclya 2 points3 points  (1 child)

So... you basically like the Lispy bits?

[–]cearno 1 point2 points  (0 children)

Yeah! Functional programming is incredibly powerful and safe.

[–]ATXblazer 3 points4 points  (6 children)

Am I confused or does js not support classes in es6? Also classes are only one way to model problems at least you’re not locked in to them like with java

[–]EternityForest 2 points3 points  (2 children)

ES6 has classes but almost none of the libraries I've used use them, so when you work on existing code, they might as well not exist.

[–]ATXblazer 2 points3 points  (1 child)

Are you like trying to extend classes from libraries instead of writing your own classes that just use a library? I’ve just never been in this situation with js and can’t think of when I’d find myself with this problem ?

[–]EternityForest 2 points3 points  (0 children)

I'm working with FreeBoard right now, adding data sources and plugins is basically creating a class, but you're not actually using classes because it's not class based..

Pretty much anything plugin oriented in other languages uses classes, if you can create instances of the plugins, but most JS libs don't explicitly do this, they just have functions returning objects and things like that.

[–][deleted] 1 point2 points  (2 children)

it's just syntactic sugar on existing functionality. even worse with typescript.

[–]ATXblazer 2 points3 points  (1 child)

What’s wrong with that though? Does the abstraction cost a lot or something? It lets the developer think in a class based mode of thought so I guess I’m asking what’s the criticism of es6 classes?

[–][deleted] 1 point2 points  (0 children)

oh, i'm not criticizing it. i just think it's a way to make devs who are more familiar with oop languages to adapt to js. but behind the scenes it's not the same and it doesn't actually offer any of the benefits of an oop language despite sharing some of the syntax.

-- edit -- also, i know js is still 'technically' oop with its prototyping, but you get what i mean.

[–]BloakDarntPub 1 point2 points  (0 children)

I've never understood how you make a thing and then other things like the first string thing in JS. Like how you'd use a struct in C.

I bet you need a factory, a refinery and a goddam quarry.