this post was submitted on 30 May 2024
393 points (94.6% liked)

Programmer Humor

32410 readers
432 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 38 points 5 months ago (2 children)

I haven't used TypeScript in a classically OOP way and it never felt like I was being urged to do so either.

[–] [email protected] 11 points 5 months ago* (last edited 5 months ago) (1 children)

I've worked on projects with 10 000+ lines of typescript and maybe 3 classes total.

[–] [email protected] 1 points 5 months ago (1 children)

But you have used objects I think.

[–] [email protected] 6 points 5 months ago (2 children)

Of course, but OOP is typically about putting methods on classes, inheritance of behaviour etc.

JS Objects aren't typically used that way, they tend to be used as pure data containers. At least, that's how we mostly use them.

Occasionally, we'll use objects to simplify passing multiple arguments including arrow functions, but I'd say that doesn't really count unless the arrow function mutates the object it's a part of.

[–] [email protected] 2 points 5 months ago (1 children)

Of course, but OOP is typically about putting methods on classes, inheritance of behaviour etc.

You’re referring to one subtype of OOP. That may be what most people mean when they say OOP, but that doesn’t make it correct. Object-oriented programming is programming with objects, which does not require inheritance or classes.

[–] [email protected] 5 points 5 months ago (1 children)

With such a broad definition you could call even Haskell an oop language

[–] [email protected] 0 points 5 months ago

So you’re arguing that “Object oriented” shouldn’t apply to languages that are oriented around objects?

[–] [email protected] 1 points 5 months ago

And maybe you have some functions that interact with them but don't keep them super public so they're only used by specific modules/store/redux thingy?

[–] [email protected] -4 points 5 months ago (1 children)

It becomes quite OOP if you use it with React

[–] [email protected] 14 points 5 months ago (1 children)

Huh? I've worked with TypeScript + React for the last 5yrs and the only time I see OOP is when someone's done something wrong.

Maybe you're thinking of old react with class based components?

[–] [email protected] 1 points 5 months ago (1 children)

Proving that adding the class keyword to the ECMAScript spec was a mistake that leads folks down a path they should not travel 🙃

[–] [email protected] 2 points 5 months ago

I completely agree. I taught JS/TS for 5yrs and I always emphasised that the 'class' keyword was just syntactic sugar for what was already available in prototype inheritance of JS.