I haven’t used TypeScript in a classically OOP way and it never felt like I was being urged to do so either.
It becomes quite OOP if you use it with React
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?
Proving that adding the
class
keyword to the ECMAScript spec was a mistake that leads folks down a path they should not travel 🙃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.
I’ve worked on projects with 10 000+ lines or typescript and maybe 3 classes total
But you have used objects I think.
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.
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.
With such a broad definition you could call even Haskell an oop language
So you’re arguing that “Object oriented” shouldn’t apply to languages that are oriented around objects?
Polymorphism just goes over my head.
Interfaces are great.
Inheritance is often a sign that the previous developer didn’t understand interfaces.
Prefer composition over inheritance. Though that doesn’t mean inheritance has no place in programming.
The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said “Master, I have heard that objects are a very good thing - is this true?” Qc Na looked pityingly at his student and replied, “Foolish pupil - objects are merely a poor man’s closures.”
Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire “Lambda: The Ultimate…” series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress.
On his next walk with Qc Na, Anton attempted to impress his master by saying “Master, I have diligently studied the matter, and now understand that objects are truly a poor man’s closures.” Qc Na responded by hitting Anton with his stick, saying “When will you learn? Closures are a poor man’s object.” At that moment, Anton became enlightened.
OOP is nice. Why do people hate it?
Because of inheritance.
I think the main problem is that people try to shoehorn OOP mechanics into everything, leading to code that is hard to understand. Not to mention that this is basically encouraged by companies as well, to look “futuristic”. A great example of this approach going horribly wrong is FizzBuzz Enterprise Edition.
OOP can be great to abstract complex concepts into a more human readable format, especially when it comes to states. But overall it should be used rarely, as it creates a giant code overhead, and only as far as actually needed.
I got as far as seeing they chose Java and opening the constants file, and immediately executed a strategic withdrawal. I love that people went to this level of detail
Multiple inheritance
If you ask me, the only reason for objects to exist are for preventing stale references. Anything more than this is unnecessary.
People (sometimes) use it far too much and in wrong ways.
Like inherit when you could just instantiate, or use a template.
Or when “everything should be a class” was also a bummer (inhetit “run()”), like I’d instantiate “main” twice (cool if it had worked I guess).
Or old code written by “wizards” where they cast cast cast instances onto other classes to use specific behaviour in crazily dangerous manners. And you’re the one to “fix it” because it doesn’t work well…
Otherwise OOP is good.
I used to think I was just a fanboy. But as time went on and I gained more and more experiences, I’ve only become all the more sure that ANSI C is the only language I ever want to write anything in.
I learnt Caml in the 90s at university, I was completely lost, in Prolog too.
C++ classes are fairly optional but if you’re already using cpp then it likely wasn’t your choice and neither will the choice of OOP.
Yeah, I like the sweet spot that C++ is in. It can do anything C can but then you have classes and STL and all that on top of it.
once i learned about defer it became a hard requirement. cpp kinda gives me that but other c like languages do it better.
Yeah, I wish C++ had function/scope epilogs and labeled loops/breaks, too. Those are the cases where the “never use goto” rule can be broken to make better code than adding all of the code that would be required to handle it the “right” way (setting up early exit flags and if statements after each level of nested loop to check the flag).
OOP was a mistake!
Its a great way to make simple code 300% bigger than necessarily.
Is OCaml going mainstream, hm
Using classes is nice tbh. Using inheritance usually isn’t. Inheriting from inherited class should be forbidden.
Just use C
It’s called Go
Excuse me if I don’t appreciate when the compiler adamantly refuses to do its job when there’s one single unused variable in the code, when it could simply ignore that variable and warn me instead.
I also don’t enjoy having to format datetime using what’s probably the most reinventing-the-wheel-y and most weirdly US-centric formatting schemes I have ever seen any programming language build into itself.
Why typescript? It allows you to make typesafe compositions
deleted by creator