Live data from Hacker News

React: Mixins Considered Harmful

facebook.github.io

141–150 of 205 posts

Re: React: Mixins Considered Harmful

#141
Mixins have their place, but perhaps we are at the point where we need general advice (like the class "Prefer composition over inheritance") for mixins ("Prefer traits over mixins"), especially as there's a good analog between the two. Matthijs Hollemans wrote an article which argues for that as well:

http://matthijshollemans.com/2015/07/22/mixins-and-traits-in...

Re: React: Mixins Considered Harmful

#142
post #21

Earlier quoted context omitted.

No we've known and said it for a long time but not very loudly. People haven't used them sparingly and they tend to infect a codebase. Now we're just making a more concerted effort to communicate more broadly that they can be bad.

Thanks for replying -- I assume in whatever planning/architecture meetings went on before react was released that this was a measured decision you all chose to take, weighing the potential dangers less dangerous than the initial usefulness. Is this assumption correct? If you could do it again, would you leave in mixins or would you keep them out?

It was the right decision at the time - it made React much more familiar for people at FB who were writing PHP/Hack (Dan called this familiarity out in the post). It also enabled some great things that are still awkward with other patterns - https://github.com/reactjs/react-timer-mixin/issues/4 is an interesting case. That functionality is nice and elegant with mixins but not so with classes.

I think if we had to do it again (and get to keep the knowledge of the last few years), we'd probably skip mixins. We'd surely do some other things differently too though :)

Re: React: Mixins Considered Harmful

#143
post #132

Earlier quoted context omitted.

Python REPL: >>> 0.3 - 0.1 0.19999999999999998 Ruby REPL: 0.3 - 0.1 => 0.19999999999999998

https://repl.it/Cbqb unless your Python compiler runs on some sort of JavaScript (-:

  Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
  [GCC 5.4.0 20160609] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> 0.3 - 0.1
0.19999999999999998

Python 3.5.1 yields the same result

Re: React: Mixins Considered Harmful

#145
post #132

Earlier quoted context omitted.

Python REPL: >>> 0.3 - 0.1 0.19999999999999998 Ruby REPL: 0.3 - 0.1 => 0.19999999999999998

https://repl.it/Cbqb unless your Python compiler runs on some sort of JavaScript (-:

I don't use python, but print-like functions(or in this case, statements) usually format their output. https://repl.it/Cbqb/1

From the documentation:

> print evaluates each expression in turn and writes the resulting object to standard output (see below). If an object is not a string, it is first converted to a string using the rules for string conversions.

I can't even find what the rules for string conversions are in the documentation :/ Oddly enough they're not described under https://docs.python.org/2/reference/expressions.html#string-...

Re: React: Mixins Considered Harmful

#146
post #95

I like how core features of React are being considered harmful. First it was component internal state, now it's mixins and next thing will be the lifecycle methods. React components will then boil down to pure render functions. React will then be replaced by simpler VirtualDOM implementation. JS function declaration boilerplate will be removed from render functions, so they will be more HTML with some JS as the other…

> easy-to-reason-about redux-style state reducers

This buzz phrase "easy to reason about" is so popular in the React world. I feel like I'm the only one who finds it oxymoronic. Especially with regard to Redux, which I think is anything but.

Angular 1/2, Ember, Backbone are all pretty "easy to reason about", so much so that it is rarely pointed out.

Re: React: Mixins Considered Harmful

#147
post #33

Earlier quoted context omitted.

I added "to pick one" because I don't particularly want to start a flame thread over frameworks. Everyone can choose their own tools for their jobs. However, to the point about style guide/anti-patterns: I guess we haven't been working in the same codebases.. I've worked on a handful of different projects and most have scope flying all of the place, with controllers and directives used interchangeably (not to mention…

Well, I commented mainly because of this > There's One Way™ to do things correctly. Using anti-pattern "hacks" will work for a little bit, but in the long run come back to bite you as your software grows and scales. This is true, but in the given context that this is not true in the Angular world, that is definitely false. Some of the things you've mentioned are considered known abuses/anti-patterns/etc.

I'd consider large parts of the Angular 1 framework to be anti-patterns. I believe that's the reason why they completely remade the framework with Angular 2, to avoid all these pitfalls. Given that, I find it the complaint that React is doing the same odd :)

Re: React: Mixins Considered Harmful

#148
post #36

Implementing mixins correctly in JS (which React does not) is already a well explored problem space. I like https://leanpub.com/javascript-spessore for great explorations and derivations of various mixin patterns. It's not that mixins are bad in general, it's that React doesn't implement them well in particular.

Thank you! The code in JavaScript Spessore is ES5-specific, but I stand by the ideas discussed, including the one central to TFA: Naïve mixins solve the many-to-many dependency problem, but not the open recursion problem. You can read the book online for free, but if you prefer the ebook format, here is a coupon for a free copy, good for today only: http://leanpub.com/javascript-spessore/c/hackernews

Wow! Very cool to have the infamous Reggie drop in. Perhaps this is a good chance to say thank you for JS Allonge, which was my introduction to writing proper JavaScript. Before it I wrote code to make a feature work; now, it is equal parts getting it to work and crafting something elegant. Thank you!

Re: React: Mixins Considered Harmful

#150
post #146
post #95

I like how core features of React are being considered harmful. First it was component internal state, now it's mixins and next thing will be the lifecycle methods. React components will then boil down to pure render functions. React will then be replaced by simpler VirtualDOM implementation. JS function declaration boilerplate will be removed from render functions, so they will be more HTML with some JS as the other…

> easy-to-reason-about redux-style state reducers This buzz phrase "easy to reason about" is so popular in the React world. I feel like I'm the only one who finds it oxymoronic. Especially with regard to Redux, which I think is anything but. Angular 1/2, Ember, Backbone are all pretty "easy to reason about", so much so that it is rarely pointed out.

What do you find hard to reason about when it comes to Redux? There is some terminology, but the heart of Redux is a pure function that takes a state, new information, and returns a new state. That's hardly rocket science.
Post reply on HN