r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

Show parent comments

18

u/fucking_passwords May 28 '19

Gotta shake that attitude, if adjusting how you code makes you really upset, you are setting yourself to have a bad time in this industry.

I use airbnb core, but with a few rules adjusted to my liking. It took a while to get used to, and some of my teammates complained, but you know what, now our PRs all look consistent. I don’t care how much people complain, it’s worth it

5

u/verymickey May 28 '19

Where do you adjust the rules? (Non coder here just want to pass this along)

3

u/HansonWK May 28 '19

Do you know anywhere that has good explanations for why some of the rules exist in the airbnb style guide? The team I'm on is going to start using a style guide soon as we have expanded the team, and looking through the airbnb styleguide, about half of the rules I don't really understand what they are for. I don't want to use AirBnB's if we are going to end up ignoring half the rules, and go for something less strict instead at least to begin with.

3

u/acemarke May 28 '19

Yeah, I used to recommend Airbnb's style guide, but it's gotten way too over-opinionated in the last couple years (especially on the React side).

I'd suggest using eslint-config-react-app as a baseline, as it only warns about things that are actually likely to cause issues.

2

u/fucking_passwords May 28 '19

The official repo explains all the rules. At my company we ended up making our own config that extends the airbnb one, and I’m generally fine with people ignoring certain very opinionated rules in their projects if they want.

No regrets. Our projects are much more consistent, and nobody has really complained

3

u/HansonWK May 28 '19

It really doesnt though. It has one line for what the rules does without why it's needed, what its there to prevent. It seems like overkill for smaller teams where people mostly work on their own code, but still want it to match.

2

u/fucking_passwords May 28 '19

https://i.imgur.com/yv8LHg5.png

Looks like there is a "Why" statement for many rules/examples. The ones that lack a "Why" seem to mostly just be "because consistency".

I gradually learned what each rule does, by reading their docs and googling the rule if I still didn't understand it. Might not be ideal, but honestly I learned a ton by doing this.

I'm conflicted. I've worked alone, on small teams, and large teams. I now lead a medium sized team and oversee the projects of other teams. I've used airbnb to varying degrees, also standardjs. Now I don't like working without it. It took some getting used to, to feel like the linter wasn't getting in the way, but now I would never go back, even in personal projects.

At some point you have to compromise. Not everybody is going to love every single rule, especially if you use Airbnb out of the box.

People on your team may only work on their own projects, but what happens when someone quits? Now somebody else has to take over that project, and the closer it is to a common linting config, the easier that process is going to be.

1

u/imguralbumbot May 28 '19

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/yv8LHg5.png

Source | Why? | Creator | ignoreme| deletthis

1

u/HansonWK May 28 '19

I 100% agree with you. I'm all on board with using a style guide, I just think we'll chose one with better explanation of the reasons behind the rules. AirrBnB seems to be the strictest out of the popular styleguides, yet the documentation has the least explanation as to why some of the rules are there. The 1 sentence above each rules doesn't do a good job of explaining most.

1

u/calligraphic-io May 28 '19

Try reading the eslint page for each rule. Most of them discuss the reason why the rule might be used.

1

u/HansonWK May 29 '19

Perfect, just what I was looking for! Wish all the style guides had something like this so we could choose the one the suits us best instead of just the one with the best documentation!

1

u/calligraphic-io May 29 '19

I agree, I've found the eslint rule pages really handy for understanding why they've included something. Would be nice in all the style guides, especially AirBnB.

1

u/ingrown_hair May 28 '19

I’m trying to avoid monkeying with each rule I don’t like. I’d end up back where I started.

1

u/fucking_passwords May 28 '19 edited May 28 '19

I mean first I’d start with the reason you don’t like it. Is it because it’s unfamiliar? If so, fix that. Or Is it because it’s actually not a super essential rule?

The main rules I tend to disable are things like the strict arrow function rules (they are very very opinionated and are not essential for using arrow functions at all), comma dangle (airbnb requires dangling commas for better git diffing but most people I know hate this rule, it’s not essential), don’t require file extensions for import, etc.

It takes some expertise to fairly judge what is essential and what is too much opinion. If you lack this expertise, there’s an easy fix for that, start learnin! :)

Another thought: I generally start a discussion when we are looking at changing our linting rules so anyone can voice their opinions. I will push back any feedback like “that looks weird”, “I’ve never heard of that so I don’t want it”, because those are not valid arguments for making an informed decision. Everyone is entitled to an opinion, but nobody is entitled to force others to be affected by this opinion, they have to back it up with a convincing argument.

1

u/ingrown_hair Jun 04 '19

I'm all about code formatting and good-practice (e.g. using const). I'm not sure that I need to warned about every console.log in my code. It's distracting to work flow and AirBnB marks a lot of things as erros that could be warnings.

Is 'comma dangling' the requirement for a comma to be after the last element in a static object?

2

u/fucking_passwords Jun 04 '19

Yes, that is what comma-dangle refers to (that and arrays).

I hear ya, and honestly if you are working on a project by yourself then do whatever you want. But when you start working with a team, consistency is much more important. I don't want to reverse engineer someone else's code every time I jump into a new project.

I agree that airbnb is not perfect, which is why we've adjusted it at my company, to more closely fit everyone's liking. It wasn't the easiest process to all agree on, but it has made an enormous impact on our productivity. Code reviewing a PR is so much easier now, and we can focus on important things like architecture, patterns, paradigms, and naming, rather than on basic issues and arguing about style.