4 ms·
I like what raganwald writes but let's get real here. People asked for the class keyword because it made classes easier to write AND read. OOP with prototypes i
by aikah 11y ago
I like what raganwald writes but let's get real here. People asked for the class keyword because it made classes easier to write AND read. OOP with prototypes is dreadfull, from a "clean code" perspective.
Javascript should get the same perks for mixins, because going back to "builders" is going back to everybody writing his own flavor of the same stuff and doesn't make things readable anymore.
Is there a mixins proposal for ES7 ?
a simple thing would be to allow multiple inheritance :
class Foo extends Bar,Baz {}
just like Python
I think the Python way is the simplest one.
- angersock 11y agoYou know, given the sheer amount of JS that has been written successfully in the last ten years, I think it might be worth asking: is it really needed to continue mudballing that type of stuff onto the language? Especially with mixins and things, it's really easy to add so much magic to the code that getting up to speed on what something is doing becomes prohibitive. It's really great for flavor-of-the-week frameworks, but long term maintenance can become a nightmare and proper performance tuning difficult. Then again, maybe we don't care about maintenance and performance anymore.
- aikah 11y ago> You know, given the sheer amount of JS that has been written successfully in the last ten years, I think it might be worth asking: is it really needed to continue mudballing that type of stuff onto the language? That's a good question. If it helps write a specific pattern and make it more readable I think it's worth it. People are going to write these stuff anyway, why not help making things more readable for anybody else ? it's not going to change the nature of javascript, I'd argue that things like proxies or decorators are far more questionable than multiple inheritance, yet they made/are making it to the spec. Nobody can deny Python code looks usually clean and mostly readable. Nobody can deny that Javascript code is often unreadable because ES3/5 developers didn't have the syntax to convey specific ideas in a eloquent way(thus all the prototype plumbing, module pattern and co that made js code look like brainfuck,don't even get me started on ninja coding).
- marcus_holmes 11y agoJavascript is not readable to you because you're attempting to apply OO patterns to it. Javascript is not an OO language, it doesn't work like that. It is an incredibly powerful and elegant language, please take the time to learn how it works and appreciate its beauty. Then by all means make suggestions about how it should be changed. But only then, please. Not all languages would be improved by being "more like Python".
- aikah 11y ago> Javascript is not an OO language, it doesn't work like that. What ? it certainly is today with the "class" syntax. Or it is like saying neither Ruby or Python are object oriented. > elegant language, Elegance is in the eye of the beholder
- angersock 11y agoMinor point of order...Ruby is OO because it very much follows the Smalltalk-style message-as-function-invocation pattern. Javascript (at least before ES6) is perhaps too minimal in its language affordances to qualify for "true" OO status.
- marcus_holmes 11y agothere's a lot of people who objected to adding "class" syntax to Javascript purely for this reason. Javascript objects are not the same things as Python (or Smalltalk) objects, they don't work the same way and were never intended to. There is a good case to be made that Smalltalk-type OO with multiple inheritance (like Python) is a bad thing. Javascript's type of OO is a good way of avoiding that bad thing. I agree that elegance is purely subjective, and if you choose not to find javascript elegant because it lacks a certain "python-ness" then that's entirely your decision. However I would encourage you to expand your horizons a bit and stretch your understanding a little more.
- braythwayt 11y ago> Is there a mixins proposal for ES7 ? What’s more likely to make it to ES.whenever: 1. “Here’s a mixins proposal, it would make the language better.” 2. “People are writing mixins and like them, but some syntactic sugar would helps standardize the way they’re written. Here’s a proposal to do that.” :-)
- seanmcdirmid 11y agoI believe a form of mixins has already made it into TypeScript: https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Mixins.md https://github.com/Microsoft/TypeScript-Handbook/blob/master... Still would prefer them to be more built-in.
- aikah 11y agoActually no, you still have to write a mixin builder function in your code. Typescript just supports declaring mixin types, it doesn't do the actual implementation.
- chimeracoder 11y ago> OOP with prototypes is dreadfull, from a "clean code" perspective. > I think the Python way is the simplest one. FYI, Python actually does use prototypical inheritance under the hood. The difference between Python and ES5 is that Python uses the "class" keyword in such a way that you don't actually need to know about prototypical inheritance in order to use Python unless you're doing some really funky work with Python's metaclasses.
- marcus_holmes 11y agooh god no please not multiple inheritance. Javascript objects are composable at run-time: you can build your object out of whatever behaviours you need. They don't need multiple inheritance. Can we stop trying to make Javascript an OO language please?