r/javascript • • May 15 '17

Don't Overcomplicate Javascript #0

https://bits.ristic.io/dont-overcomplicate-javascript-0
35 Upvotes

34 comments sorted by

View all comments

18

u/fforw May 15 '17

Why are people hysterically afraid of maybe having to type a few characters more? BOILERPLATE!!!1

All of the arguments for having named constants are sound, especially if you are developing with a good IDE. I don't need to type the named constants imports, the IDE autocompletes and auto-formats them for me. It can follow usage across my project, renaming constants is a lot easier, I can just go into my constant definition, rename the constant and it will be changed everywhere, somewhat safe, whereas the string replacement is just that: brittle string replacement. ("Oopps.. that name was also a sub-name in that? unfortunate..)

He miuses Cargo Cult Programming for this architectural pattern. Cargo Cult is when you do stuff that you apply magic value to without being able to explain how it works. As I said before: There are valid reasons for this, just because you choose to ignore them doesn't make it Cargo Cult.

More often than not, the best solution is the simplest one.

Or it produces brittle scripty-hacky programs that need to be completely rewritten next year.

edit: If you're code-golfing your silly TODO app examples, go ahead. Personally I wouldn't be using redux if I didn't need it to write maintainable applications of non-trivial complexity.

8

u/XanarchyZA May 15 '17

Also agree here and honestly couldn't the problems he describes very easily fixed by ES6 classes with static constants?
That way you would not need all those silly imports and keep the constants to their specific regions like
import EventConstants from './EventConstants.'
case EventConstants.loadRequest
case EventConstants.addFailure
etc etc

2

u/Jsn7821 May 15 '17

I wouldn't go quite so far as to say that not importing all your actions in redux is brittle and hacky...

1

u/fforw May 15 '17

Who knows what he's going to think is "just easier" next? Might be reducers with side-effects.

1

u/dada_ May 15 '17

All of the arguments for having named constants are sound, especially if you are developing with a good IDE.

Exactly, not to mention eslint and the like won't be able to warn you if anything is wrong if you just use pure strings.

-1

u/veydar_ May 15 '17

I agree with everything so here's an upvote instead of me formulating the same reply