6 ms·
I didn't like programming in JavaScript so much because I think the syntax makes it a little harder to read than necessary. However, I confess that after adopt
by haolez 6y ago
I didn't like programming in JavaScript so much because I think the syntax makes it a little harder to read than necessary.
However, I confess that after adopting ESLint in my workflow, things have improved considerably. I can ask it to warn me on unused stuff, to enforce the lack of semicolons, to format and indent my code correctly on save... it's a very useful tool. If you have something against JavaScript in general, give it a try.
- Bishonen88 6y agoYou can do most of that without ESLint for any programming language with an IDE. Speaking about jetbrains intellij/pycharm from my own experience.
- haolez 6y agoThe IDEs will sometimes use their in-house solution, and sometimes integrate one of these external tools that focus on doing just one thing very well. My setup is VSCode + ESLint when dealing with JavaScript.
- Kaze404 6y agoThe point of these tools is that the configuration is specified in the project, and works regardless of the developer's workflow.
- deleted 6y ago[deleted]
- vorpalhex 6y agoI also recommend `prettier`. It can be configured to obey eslint and will reformat your code on the fly to fit standards so you can spend less time fighting spacing and more time just writing code. While `eslint --fix` is a thing, prettier parses the underlying AST to do it's transformations and it's a very impressive tool.
- tomduncalf 6y agoYeah, prettier rocks. I was skeptical for a long time and if I’m honest and think about it I still don’t like some of the formatting choices it makes, but I don’t notice because of how fluid and pleasant it makes writing code. As an aside, often the “workarounds” result in clearer code, e.g. long formulas getting split up weirdly leads to me splitting stages of the calculation into named variables, which actually reads much better when I return to it months later. No worrying about formatting code as I type, no worrying about checking style on PRs... definitely worth the trade offs for me, I enable it on every project I work on now.
- Drdrdrq 6y agoAnd if you are working in a team it makes those arguments about styling moot. One of the best aspects of JavaScript.
- tomduncalf 6y agoYeah that’s what I mean about PRs - such a time saver to not discuss trivial code style issues and be able to just focus on the code itself!
- _virtu 6y agoI'll never forget getting our team of 90+ devs to move to prettier because of this argument and then having team members proceed to strong arm me to change the configs to things that they preferred six months after we made the move and we had adopted it across over 10 different repos. Talk about counter to the whole point of using such a wonderful tool.
- tomduncalf 6y agoThat must have been frustrating - I do feel like perhaps they made a mistake adding configuration to prettier at all! But especially for matters of preference such as single vs double quotes where ultimately it makes very little difference. Luckily my team are happy with the defaults + slightly longer line length
- traes 6y ago> to enforce the lack of semicolons Why would... you want that? You're trading minimal syntactic noise for possible ambiguity errors. You don't really gain anything.
- bdefore 6y agoIn combination with other linting rules to catch reckless conditionals and multiline returns, it is absolutely safe to enforce no semicolons. And the visual noise is, at least to my eyes, a significant impact.
- wildpeaks 6y agoIf visual noise is an issue, I made a VSCode theme specifically for muting things like quotes and semicolons, that way I don't have to choose between explicit semicolons and reduced visual clutter: https://marketplace.visualstudio.com/items?itemName=wildpeaks.wildpeaks-theme https://marketplace.visualstudio.com/items?itemName=wildpeak... The theme was primarily made for me, but I published it because others might find the idea useful.
- dlbucci 6y agoI used always have semi-colons too, but now that my code is always transpiled, I just let the transpiler handle it (and TypeScript does a good job catching ambiguities/unintended code pretty well too).
- hombre_fatal 6y agoYou need to know when semicolons are necessary whether you use them or not. And the whole point here is that tooling eslint/prettier prevents bugs. Prettier will turn this: const x = foo() [1, 2, 3].forEach(...) into this: const x = foo()[1, 2, 3].forEach(...) Which makes the problem pretty obvious. Btw, if you decide to avoid semicolons, one of the only rules you need to know is to prefix any line with a semicolon if it starts with "[(.
- traes 6y agoIntroducing any mental overhead to eliminate a single character per line at most seems a tad ridiculous.
- hkai 6y agoTypeScript.
- haolez 6y agoMy use of JavaScript is mainly for small code bases. The gains of TypeScript are less relevant in this scenario over the bureaucracy that it brings to the game.
- hkai 6y agoWhat does this bureaucracy look like? Asking because to me personally it seems that it's easy to create a new TypeScript app from a template with zero configuration, and then it just works. Perhaps I'd need to spend 5 minutes to write the type for the API responses or some other basic stuff like that.
- bound008 6y agoTypeScript. ( + ESLint, + Prettier ). It has made writing JavaScript tolerable. Classes as you expect them. With proper editor support, you get real errors, and the whole thing starts to feel more like writing code in python. It is no python, but at least it feels significantly less foreign. Its very progressive in the sense that regular JavaScript is valid TypeScript, and everything else is just a cherry on top. And it is easy to include the typing outside of the source file, so many libraries not written at all in TypeScript have typing support built in (likely by simple PRs from the community)