r/devhumormemes • • 3d ago

Keep It Simple

Post image
84 Upvotes

42 comments sorted by

7

u/A1oso 3d ago

Class inheritance also exists in JavaScript, and almost all objects (including arrays) inherit from the Object class. Interfaces don't exist in JavaScript, but in TypeScript.

0

u/Professional-You4950 3d ago

I mean interfaces do kind of exist in Javascript. just at runtime don't mess it up kinda way.

3

u/A1oso 3d ago

You can't write them down in JavaScript code, so I would actually say they don't exist.

-1

u/olzk 3d ago

There’re no classes in JS, in the same sense as in Java, for instance. The class keyword in JS is syntax sugar. There’s inheritance and it’s so called prototype inheritance

3

u/theScottyJam 3d ago

JavaScript lets you return whatever value from the constructor - doesn't have to be an instance of the class? Python does that too. JavaScript lets you mutate class properties after the fact? Python lets you do that too. JavaScript lets you change which class an instance is connected to? Python lets you do that too.

And yet, no one claims that Python classes aren't real.

Most behaviors you see in JavaScript classes come from the fact that JavaScript (like Python) treats classes as mutable values and Java does not. Prototype inheritance plays a much smaller role than you might imagine.

0

u/olzk 2d ago

What do I imagine? Prototype inheritance plays as big a role as class based inheritance for the mere fact it’s a usable tool in the language toolset. Whether you use it or not in your code, doesn’t mean you don’t use it [at all]. Go to Wikipedia, type Prototype-based inheritance for a sneak peek.

I’m glad for Python. Usually, you get this kind of flexibility in interpreted languages, which Java isn’t.

Where did I say classes in JS aren’t real?

Open dev tools in your browser, type in the console: class A{}; typeof A

MDN, W3Schools and others from the first page of a search engine results only cover surface level of the languages. You’re gonna have to go deeper into the language specs to get the idea

2

u/theScottyJam 2d ago

Where did I say classes in JS aren’t real?

 There’re no classes in JS, in the same sense as in Java

This sentence format is often used to make the former item sound lesser than the latter. "There's no pizza in the US, not in the same sense that italy makes it", makes it sound like US pizza is less real, less authentic - Italy's Pizza is the definition of pizza and US pizza is not "real pizza" due to its differences.

If you weren't trying to imply that JavaScript classes are less real due to its differences from Java, then sorry for misinterpreting, my entire comment would be irrelevant.

1

u/olzk 2d ago edited 2d ago

, in the same sense as in Java

Did you read this part at all?

This sentence format is often used to make the former item sound lesser than the latter

Often used by whom?

Class inheritance also exists in JavaScript,

Also, did you read this part of your own sentence?

Do you understand that in JS it's prototype inheritance, not class inheritance?

If you're into policing others' speech, start with yours

1

u/theScottyJam 2d ago

From what it looks like to me: Multiple people got confused by your comment. You called me out on my misinterpretation. I thought I'd explain how I arrived at that interpretation, I guess that means I'm policing speech.

I think I understand your position now, still don't fully agree, but I think I'll be done engaging here.

1

u/A1oso 3d ago

Classes being implemented as syntax sugar doesn't mean that classes don't exist.

1

u/olzk 2d ago

You’re gonna have to read what I wrote again, to understand what I mean

1

u/Ronin-s_Spirit 2d ago edited 2d ago

JS has classes as a separate concept. Unlike factory functions ("sugar") JS classes can be used as type information more reliably and can create private fields. Idk how Java does classes, maybe you can't change fileds? You can do that to JS objects as well (so you can do it to class instances) - you can freeze an object or freeze specific properties on it.

1

u/olzk 2d ago

You could create private fields in objects pre-ES6, that is, before class sugar was introduced. JS classes are syntax sugar to avoid using old way of defining an object with its own constructor, that is, via a function. The old way of doing it still works, it was just cumbersome and confusing as hell. They added the keywords but under the hood it’s still class-less prototype-based OOP

2

u/Ronin-s_Spirit 1d ago

Private fields were widely implemented in around 2022 I believe (the hashtag syntax), what are you actually talking about? I'm so confused. Classes are factually not equivalent to factories anymore so cannot be considered sugar.

3

u/lmarcantonio 3d ago

lua: table

c++: please spare me, I just want to store stuff

1

u/didntplaymysummercar 3d ago

Lua is cute about that but in practice it's not nice when you hit serialization or hole issues. Same for JS. Python has a happy middle with tuple, set, dict and list. C++ has not that many built in but people with tighter requirements implrment their own.

1

u/drwho496 2d ago

What are you talking about?

C++ has all of what you listed for python (ordered and unordered, and a multiset exists aswell) and way more. It displays an extensive standard library.

1

u/didntplaymysummercar 2d ago

They're not built in. You can write replacements that are as good or better than them in C++ itself and never use them. You can't write a better table in Lua or list or dict in Python. Part of C++'s language design philosophy is not to make things special or part of the language if they can be just in standard library.

1

u/drwho496 2d ago

The standard library of C++ has an extensive amount of storage types. More than in many other programming languages.

3

u/janyk 2d ago

Honestly, this makes the Collection framework look smaller and more manageable than I thought. Very little cognitive load to recall this when necessary. List, Queue, Set, Map are fundamental abstract data structures that you would learn in any intro DSA course and each has a couple different implementations.

I'd swap the "Implements" and "Extends" in the key, though.

2

u/blaues_axolotl 3d ago

the larp is getting stronger

1

u/lightlord20990 3d ago

JS : objects in array 

Java : Nooooo . You can't do that 

1

u/PerepeL 3d ago

There should've been Scala instead of Java.

1

u/olzk 3d ago

The trend died out relatively quickly

1

u/theScottyJam 3d ago

JavaScript also has sets, maps, weak sets, weak maps, iterators, array-like values that aren't true arrays, and so forth.

Both sets and weak sets could be said to follow a set-like interface. Same with maps and weak maps.

And I wish it had a SortedMap.

1

u/wrd83 2d ago

Funnily enough I have used all the listed java collections for a reason so far.

1

u/Trang0ul 2d ago

1

u/Dinokknd 1d ago

Actually the end state is a rewrite to rust. no matter the language.

1

u/funplayer3s 1d ago

You beat me to it, except mine was going to be about a javascript array hitting 400 layers of string checkers.

1

u/Alternator24 1d ago

But when I say I like FP everyone hates me

1

u/sebbdk 1d ago

OOP is not really about inheritance tho, it was intended originally more like microservices sending typed message between eachother.

Then Java happened, C# took notes and here we are.

1

u/pixxelkick 16h ago

Well, only in the hands of idiots who use throwing exceptions as a form of logic flow control.

Unfortunately such idiots are extremely common and like a solid 15% of my job, at times, is coming in and undoing such a fuck up.

1

u/Trang0ul 13h ago

This goes in pair with catching the exceptions, and then re-throwing them (usually improperly, with the stack trace from the original cause lost) - at every layer: util, service, helper, ... And in the end you get a CustomException with a very helpful message "Something bad happened". Damn, just let the original exceptions bubble through the layers, and handle them only in the final one.

1

u/Ronin-s_Spirit 2d ago

JS feels like the nice middle ground where you don't have to perform zealous OOP.

1

u/AndreasMelone 2d ago

Well, to be fair, there is a reason it is that way in Java

This is kinda like comparing apples to oranges tbh

1

u/PiratedComputer 2d ago

You only need ArrayList and HashMap

1

u/thE_29 1d ago

Mostly.. If you work with threads or want something to be sorted, you will use others.

1

u/pixxelkick 16h ago

Objectively false, tonnes of algorithms care very much depending on if you use a Stack, Queue, SortedHashMap...

Also of course lets not forget about the power of sparse array systems, which really shine in stuff like game dev.

1

u/LuckyOneAway 1d ago

PHP: Array is enough. It will behave as Object when needed.

1

u/Flaky-Low-2262 1d ago

Fuck JS
Its just rage bait to challange professionals