29 ms·
You lost me at avoid formal typing and lodash. At least to me, Lodash is absolutely necessary even in new projects — such a wealth of functionality and most of
by sergiomattei 4y ago
You lost me at avoid formal typing and lodash.
At least to me, Lodash is absolutely necessary even in new projects — such a wealth of functionality and most of it isn’t available OOB in the standard library. It’s easily tree shakable as well.
As for formal typing, TypeScript was a boon for my productivity. Curious about any examples of use where it’s been inadequate?
- Osiris 4y agoThe lodash functions have built in guards so you can do _.map() and not have to care if the argument you pass in is, in fact, an Array. I can’t tell you how many times I see “can’t call function toLowerCase of undefined”, etc. “but Typescript!”, doesn’t do runtime type checking. I very much prefer defensive programming. Assume nothing.
- factormeta 4y ago>I can’t tell you how many times I see “can’t call function toLowerCase of undefined”, etc. Think that should be addressed by optional chaining now.
- Osiris 4y agoPartly but optional chaining doesn't make sure that the function actually exists on the target. So if "const a = 10" and you call "a?.toLowerCase()" you'll still get an error.
- yamtaddle 4y agoShit, TypeScript's the first time JavaScript's been not-terrible. If I squint and tilt my head it sometimes even looks almost good. I'm also a fan of "class" since it makes the deeply-embedded-but-awful OO system actually usable without twisting into a pretzel or engaging in a whole lot of "OMG why, why did you do that?".
- somewhereoutth 4y agoI prefer to have data structures (records, arrays, primitives), then organise the functions operating over those structures into logically sensible places, instead of tying them into the structures themselves via classes. Occasionally it is necessary for structures to act polymorphically, thence it is but a simple matter to put a function in the structure for that behaviour (maybe with a reference to the enclosing structure in scope)
- somewhereoutth 4y agoPerhaps avoid lodash if possible, i.e. prefer the new built-ins. Otherwise it becomes yet another way of doing a simple thing. Typescript is another language layer, devs will tend to write even more code for a given problem - often not helpful. It should be possible to do a lot of static type checking without annotations.
- zelphirkalt 4y agoIt should be possible, but probably is not very well due to how crazy JS does implicit type conversions and other footguns.
- yamtaddle 4y ago> Typescript is another language layer, devs will tend to write even more code for a given problem - often not helpful. That "even more code" is communication. It's documentation that you ought to be recording somewhere anyway, for the most part. The nice part about using TypeScript for that particular documentation is that then your tools can help you with both the reading and the writing.