STOP Using Classes In JavaScript | Prime Reacts

preview_player
Показать описание
Recorded live on twitch, GET IN

MY MAIN YT CHANNEL: Has well edited engineering videos

Discord

Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
Рекомендации по теме
Комментарии
Автор

the fact you'll highlight sentences but leave out the first and last character is somehow incredibly satisfying to watch, thank you the highlightagen

_bradleystrider
Автор

Javascript: A language where everything's an object but classes aren't real.

KX
Автор

Use classes when they make your code simpler. Don't when they don't.

sb_dunk
Автор

The article is a classic case of rationalization. The author started of with a conclusion and then went searching for arguments to support it, but failed to find any arguments that would support his conclusion or really make any sense at all.

Tempus
Автор

Prime is literally at a point where his name is the size of an average Java className.

Dev-Siri
Автор

Javascript objects are not 'just maps', chromium actually creates c++ structs to improve performance. It's extremely complicated and the compiler does a lot of smart things in the background.

FilipCordas
Автор

I have a colleague at work trying to create classes for everything and apply design patterns everywhere even for simple logic or single line of code.
It adds a LOT of abstraction for nothing making it harder to debug.

And if you tell him it may be not necessary, he will look down on you for not respecting OOP / Design patterns as taught at school. 😅

Sometimes I wish we would see more KISS in code nowadays.

voxpopuli
Автор

The article says that JS Classes are just "Syntactic sugar" . We should use them more then.
Having more readable code with barely any impact to performance is great.
(Like with anything in life, that involves sugar, you should not over do it though.)

AScribblingTurtle
Автор

Isn't OOP a concept and not something language specific? C has no concept of clases/objects, but you still can implement OOP with structs, functions and pointers etc

jordixboy
Автор

I don't know why I'm watching this. I've never touched JS.

Fan_of_Ado
Автор

4:55 when you're making tea and the water is hot enough

SelfCheckout
Автор

I love the argument "Because react devs told you not to use classes"

This guy seems severely confused what the difference is between a React class component and a JS class. If you don't understand why the react devs moved away from class components, don't write an article mentioning this as an argument against classes. This is so dumb.

renidan
Автор

A month ago, I attended a Node.js Course where I was taught a "thisless" approach in JS and I must say I love it

aleksanderjodowski
Автор

Programmers never stop to amaze me. When a normal person in their work environment doesn't see something useful they won't go online and write an article "Stop using something". But I have seen countless articles or videos of programmers saying "don't use classes, don't use else statements, don't have methods longer than 5 lines of code, don't use a for loop etc etc..." and will give you a few examples that fit their narrative. I can think of dozens of examples where they are useful and also as many where they shouldn't be used.

jakubswistak
Автор

Modern browsers are able to compile a lot of JS to native behind the scenes on the fly, but that is only really effective if you use classes, otherwise you'd need to hit the same object that did not change over and over again before the JIT bothers.

der.Schtefan
Автор

Edit: article is from 2020, private attributes were not widely available back then. :)
Private attributes exist in JS, see "Private class features" on MDN. (something the author of the article could've easily looked up before stating something wrong)

Also that "Classes are the same as in ES5" because if you transpile it to ES5 with Babel... was quite dumb :D
TL;DR: Just use JDSL.

ich
Автор

FP multiple dispatch functions may act like class methods (if they are dispatched on first argument alone), but they do not work like OOP methods. The reason is, if you know argument types, you know a method and can resolve it at compile time (even in dynamic language like Julia!). this means that dispatching can be implicitly made static most of the time, and when it is dynamic, it still should match one function with one argument collection.
dispatch functions also do not feel like class methods, they feel like dynamic pattern matching statements, if that makes sense. so your program looks like one giant function, cut into match statement arms.

Daniel_Zhu_af
Автор

One major thing overlooked here in this article: with a class definition, IDE’s and LSP’s have a much easier time figuring out how to help you program

JonathanTheZombie
Автор

One reason prototypal OO is more powerful, as far as I understand, is because you can do stuff like building/binding a missing "method" at runtime. In theory there is no limit of complexity in the inheritance scheme you can mimic. It's not necessarily better, it harder to optimise, but it's more powerful.

That being said, I like neither style of OO in JS. For very simple stuff, classes feel like an unnecessary abstraction. For more complex patterns, JS doesn't hide well the prototypes under the hood. And Prototypal syntax in JS is really ugly. And then there is the lack of operator overload, the lack of a type system and the lack of static dispatch, so OO in JS is really just glorified namespace, possibly with some ugly inheritance and poor interfacing. It has no synergy with other feature whatsoever that most other OO language have, baring iteration.

Lua IMO is prototypal OO done right. The approach is extremely minimalist, the syntax is very simple, and you code exactly what you need from OO, nothing more. The downside is you have to code it yourself, but come on, having to code in lua is more of an upside.

xelchess
Автор

JavaScript's OOP style was taken from Self, a language by Sun that took its syntax from Smalltalk, but switched to a new (at the time) prototype based OOP. There was a simple transpiler from Smalltalk to Self, so existing code could be used. NewtonScript for the Apple Newton was based on Self even more so than JavaScript was. JavaScript is more OOP (by the definition of "closer to Smalltalk") than C++ is. Classes actually are different, by the way. Try making an AudioWorklet using prototypes to see what I mean.

jaysistar