What does HackerNews think of javascript?

JavaScript Style Guide

Language: JavaScript

Having too many options leads to a lot of bikeshedding as the whole ecosystem ends up fragmenting and disagreeing with each other. It’s one of things I really dislike about JS compared to something like Go.

Personally, I stick to opinionated rulesets such as Standard[1], AirBnb[2] and Unicorn[3] since you won’t spend hours tweaking and selecting new rules.

[1] https://standardjs.com/

[2] https://github.com/airbnb/javascript

[3] https://github.com/sindresorhus/eslint-plugin-unicorn

"Standard" [1] and "Airbnb" [2] seem to capture some amount of sensible guidelines. Adding Prettier [3] gets you something akin to gofmt, and adopting standard eslint rules [4] can help too.

[1] https://standardjs.com/ [2] https://github.com/airbnb/javascript [3] https://prettier.io/ [4] https://eslint.org/

Would love to see better separation on the page between "Bad" and "Good" examples. While a good read, it's difficult to quickly distinguish between the two.

For example: https://github.com/airbnb/javascript

I would read through AirBnB's JS style guide. Very well structured, and most rules have reasons specified in the guide. It should cover all the unfamiliar parts for you. After that, the next biggest thing is tooling so it'd be picking a framework and seeing how the development process has changed with npm & webpack. Start with Vue, Angular, or React and go through their hello world examples. Not that you need to be a "framework developer", but they are probably the best spots to see how the development process has changed.

https://github.com/airbnb/javascript

I recently stumbled upon the Airbnb Javascript Style Guide, which I found showed a lot of good examples of how to use newer Javascript features: https://github.com/airbnb/javascript
In terms of design patterns, I wouldn't expect js to be that different from python. JS is a very non-opinionated language and so is the community. Just make sure you understand prototypical inheritance.

"Modern" js is mostly about syntactic patterns. Airbnb has a nice style guide that incorporates most of them https://github.com/airbnb/javascript

Ditto, this is the same thing I did for a 16,000+ line app.

I used eslint ( https://eslint.org ) and prettier ( https://prettier.io ), and using airbnb's JavaScript Style Guide as a reference point ( https://github.com/airbnb/javascript ), I would enable rules one by one. Then slowly rule by rule (commit by commit) I would clean up the code base.

Very helpful and great explanations. To me Airbnb's JS styleguide was also very helpful, which showcases best practices and lots of examples. https://github.com/airbnb/javascript
Not books per se, but you are probably interested in frontend specific stuff, as you mentioned Angular and Vue. (Not directly inner workings, but somewhat linked):

Coding Style: As a quick reference and to learn about some bad patterns (and how to avoid them), I can recommend the airbnb style guide [1]. They also link to eslint rules, which always have a reasoning why a rule is considered, e.g. the no new object rule [2]. A really interesting thing in the code style corner is prettier, which auto-formats source code pretty [3].

References: The Mozilla Developer Reference Manual, e.g. for String.match [4]. It also has explanations for browser APIs. To check if you already can use a certain browser feature, I recommend caniuse [5]

Now, as you also mentioned your an "old Java Programmer". I think it's quite interesting what goes on the JavaScript space and which features are ~~stolen~~ borrowed from which language. Good search queries to understand the language and it's features (especially the new ones) would be

- Javascript Classes vs Prototype

- Javascript Decorators

- Javascript Arrow Functions (Lambda)

- Node.JS Streams

- Reactive Extensions

- Flow vs. TypeScript

Well I hope that some of that info is usable for you, if you have any detail questions, please just comment :)

[1]: https://github.com/airbnb/javascript

[2]: http://eslint.org/docs/rules/no-new-object.html

[3]: https://github.com/prettier/prettier

[4]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[5]: https://caniuse.com/

Sometimes writing a custom rule makes sense, but it should be an exception and not the rule. Otherwise, you risk creating a sub-dialect only your team knows. That becomes a problem both for new hires, which have to take more time to ramp up, and for current dev switching jobs as they'll have a hard time abandoning what they learned.

That's why I like sticking as close as possible to AirBnB's guide[0], not because it's better than anything else, it's just that most developper seem to agree on it and it's familiar to most dev.

[0]: https://github.com/airbnb/javascript

Prettier goes such a long way to enforcing standards on a language and ecosystem which otherwise has none or few. What standards do exist are frequently arbitrary, or enforced by legacy code at random companies. For example, the Airbnb JS style guide [1] recommends single quotes in JS, but double quotes for JSX properties. Why the difference? Why not stick with double quotes everywhere, as they are required in JSX blocks? Answer: legacy code at Airbnb [2]

I'm hoping to see similar efforts on project file/folder structure at some point. How often do two node projects created by different engineering teams end up with the same folder/file structure? There's nearly no strong community convention, unlike many other languages/frameworks. Rails, for example, famously touts that any engineer can walk onto another Rails project and have a reasonable suspicion of where to find a particular piece of code.

1: https://github.com/airbnb/javascript 2: https://twitter.com/hshoff/status/784205839347232768

If you want a prebuilt eslint config, and you don't like the really popular ones (eg, airbnb[0]) because they default to requiring semicolons, then this is definitely the most popular of the ones that require you to omit semicolons.

Beyond that, there are no advantages. It's just a decent eslint config that requires you to omit semicolons wherever possible. If that's important to you, use it. If it's not important, or you'd rather not omit semicolons, or if you do want to omit semicolons but you're happy making a one line change to the airbnb preset, then there's nothing to set this apart from more, if you'll pardon the expression, "standard" options. :)

[0]: https://github.com/airbnb/javascript

Airbnb has a decent styleguide - https://github.com/airbnb/javascript "A mostly reasonable approach to js"

but style-guides should be just that style guides ...not standards

I'm not sure why/when the shift took place, but I do like it because it looks a lot cleaner than double quotes.

At work I use airbnb's linting configuration as shown here[1], which specifies the usage of single quotes for strings (no explanation for the preference though).

[1] https://github.com/airbnb/javascript

I'm not exactly sure why, but that seems to be the case. It might be due to the ubiquitous AirBnB JS Style guide (https://github.com/airbnb/javascript) which enforces single quotes. It's the style guide we use on my team.
I'm glad you made this comment because it's important to understand why this attitude is harmful. If people believe what you're saying, then they're less likely to attempt to steer their communities in helpful ways. Strong opinions that are widely distributed act as a frame of reference that lets people start from a common base of knowledge and explain where their opinions differ. I can now say, "I name my Clojure functions like Stuart Sierra, except for two differences..."

More people need to present their opinions as the best way to do things.

Some useful, widely-cited examples:

- https://github.com/airbnb/javascript

- http://12factor.net/

ESLint is a very solid tool. As others have noted, you do need to find a good config, but the airbnb JS style guide comes with a very, very good one: https://github.com/airbnb/javascript
It's not a project, but Airbnb have updated their Javascript style guide to ES6. It's a good read on how to write and structure javascript.

https://github.com/airbnb/javascript