4 ms·
To meet my new-language-style expectations, you would have to remove every single "const" in your code. You have multiple definitions, all simply executed in se
by developer2 9y ago
To meet my new-language-style expectations, you would have to remove every single "const" in your code. You have multiple definitions, all simply executed in sequence based on an initial caller. I was thinking of a single block that took all inputs to result in a single output.
Forgetting my expectations, the code example you linked is practically the antithesis for ES2015/ES6. You've abused the concept of "const". Your example is terrible, using "const" to define things that should have been defined as separate classes, without having to define so many global "const"s.
Even more critically... wtf are you doing with all those "const" definitions? That code is ultimately worse than what I saw in javascript in 1995. Please don't write code that way. :/
To go to the extreme, my ultimate reaction is that the code you linked is straight up unacceptable. You would fail an interview at my company with that code. It screams "I know ES6", while being the worst example of javascript I've ever seen, regardless of the Ecmascript version. You're overcompensating, trying way too hard to prove that you understand the latest spec. There are limits to what "modern javascript" means, and you have gone too far. A dozen global "const" declaration means you know ES6, but don't know how to write proper code.
tldr; Dial back a bit. Upgrading to ES2015/ES6 does not mean transforming all your code to be completely unreadable unless you know the latest spec. Your code should still look like javascript rather than 100% some-new-functional-language.
- azangru 9y agoWhat are you talking about? How is this code worse than what you might have seen in 1995? How has the concept of const been abused - it is just an assignment keyword, no worse than the var of 1995. If you attempt to compose functions out of smaller functions, then you need variables to hold on to those small functions. What's wrong with that? And why would you need "separate classes" for those smaller functions? What problem would "smaller classes" solve?
- mpfundstein 9y agoI don't understand your criticism. You asked for a functional program , I showed you one, and you start a rant against it because it looks functional?! It just happens to be in js but it could also be in common lisp or clojure or whatever.. The crucial thing to understand is, that those consts are just assignments for global modules that I use. They are NOT variables. But if you want to go to the full extreme and remove every single const: EASY! Just add all the modules to the environment of the most external Reader monad and inject them into the function chain. This would get rid of 99% of global consts that are not functions. I leave that as an exercise to you. The rest of the consts are just function assignments. Instead of const f = x => ... I could also write function f(x) { } .. but honestly, I prefer the former. It is more elegant in my opinion ... So in order to get rid of them, just rewrite it. This is trivial. Finally, you would want to get rid of the two local consts within the two functions putPublicationToElastic and createUploadDocument: Straightforward, they are just there for cosmetic. Again, they are NOT variables, they are just names to make some following lines a bit shorter. Again, exercise to you to remove them. So if we do all the three steps above, the only const we would have left would be the config variable. The rest is one big function, composed in order to achieve a goal. Mind that calling the function will not produce any output (You'd have to fork it), so the function is even 100% pure... Honest question to you: Why would I need a class here? I really don't see anything in that code that would profit from being put into a class. It's just a bunch of functions composed together and wrapped into a Reader monad. I can rename runApp to uploadSQLDocumentsToElastic and export it and have a perfectly fine, encapsulated logic. I don't think you could do better with a class. But if, please show me. I'm eager to learn! P.S. Please tell me the name of your company. Another one I would NEVER ever want to work for ;-) P.P.S. Sometimes people write code as an intellectual exercise. In order to try out some new paradigm, or coding style. I'd advise you to consider that next time before attacking their efforts.
- deleted 9y ago[deleted]
- deleted 9y ago[deleted]
- threatofrain 9y agodeveloper2, please do reveal the name of this company you work at, we're all very curious to know the name of this wonderful workplace.