Live data from Hacker News

How JavaScript works: 3 types of polymorphism

blog.sessionstack.com

1–10 of 52 posts

Re: How JavaScript works: 3 types of polymorphism

#3
I'd say inheritance is NOT a good use-case for Person / Employee

A person can play many roles, at the same time. Composition is better in this case. A person has many roles

Inheritance is better for types of legal parties though (see The Party Model). A person is a legal party. An company is an organisation is a legal party

Re: How JavaScript works: 3 types of polymorphism

#4
post #3

I'd say inheritance is NOT a good use-case for Person / Employee A person can play many roles, at the same time. Composition is better in this case. A person has many roles Inheritance is better for types of legal parties though (see The Party Model). A person is a legal party. An company is an organisation is a legal party

Love to see this line of thinking taking over in the industry. Languages like Go make this type of object relationship super easy.

Re: How JavaScript works: 3 types of polymorphism

#6

The very title is kinda scary, in the context that everything was kind of hacked onto JS. While it's probably important to understand, the 'answer' I think, without being ham-fisted, is probably to use Typescript in most cases.

This isn’t the sort of website where you can criticize tools and languages like a hacker might. This is a forum for people with hire people who will inevitably be forced to make products using these tools for this tower of babel-esque dumpster heap we call the web stack.

Just because this forum is called hacker news don’t get your expectations twisted. We’re only here to boost engagement for acquisitions and “growth hacking”

Re: How JavaScript works: 3 types of polymorphism

#7
post #3

I'd say inheritance is NOT a good use-case for Person / Employee A person can play many roles, at the same time. Composition is better in this case. A person has many roles Inheritance is better for types of legal parties though (see The Party Model). A person is a legal party. An company is an organisation is a legal party

I'd say that inheritance, with method overriding, is the worst anti-pattern of mainstream OOP, which contains a number of otherwise sound ideas, like encapsulation.

I like the Go's approach to that (taken from Oberon), and the Rust's system of traits.

In one large codebase I saw there was a rule to make classes either abstract (without implementation of key parts), or final. Everything else is done via interfaces and composition.

See https://en.m.wikipedia.org/wiki/Composition_over_inheritance

Re: How JavaScript works: 3 types of polymorphism

#8
post #3

I'd say inheritance is NOT a good use-case for Person / Employee A person can play many roles, at the same time. Composition is better in this case. A person has many roles Inheritance is better for types of legal parties though (see The Party Model). A person is a legal party. An company is an organisation is a legal party

I personally think composition is better in almost every imaginable case. But I suppose that's an argument for another thread.

Re: How JavaScript works: 3 types of polymorphism

#9
There is a lot of wrong in this article: inability to articulate what polymorphism is, misunderstanding of prototypes, bad JS practices (`var`, `.__proto__`), falsehoods on programming languages including JS itself, confusion around ECS, unfinished examples... I suspect the author is in the early stages of their learning journey and Dunning-Kruger is in full effect.

Re: How JavaScript works: 3 types of polymorphism

#10
post #9

There is a lot of wrong in this article: inability to articulate what polymorphism is, misunderstanding of prototypes, bad JS practices (`var`, `.__proto__`), falsehoods on programming languages including JS itself, confusion around ECS, unfinished examples... I suspect the author is in the early stages of their learning journey and Dunning-Kruger is in full effect.

You might be right but your last sentence is the reason why people are apprehensive about sharing their work and writing more articles. There's no need for it.
Post reply on HN