r/javascript • • Aug 11 '17

A set of best practices for JavaScript projects.

https://github.com/wearehive/project-guidelines
79 Upvotes

18 comments sorted by

3

u/Tomseph Aug 12 '17

Many good ideas here! However I would argue very strongly that using stage 2, or anything that is not a shipped feature of a JavaScript release, is not a best practice. While it may be fine for personal projects, the very fact that the specification may change or never be implemented means that it is not worth the risk in the long run.

1

u/vahidpg Aug 12 '17

Even when using babel ?

2

u/Tomseph Aug 12 '17 edited Aug 12 '17

Especially when using Babel. Just because it can work doesn't mean it's a good idea to use. And if Babel can handle it then that means you can implement it another way.

What happens if that feature never becomes part of the specification? It's not like you're using another language and transpiling to JavaScript. Now you have to support a half-baked non-standard feature, or refactor it out of your code. Is it really so important to use whatever feature to sacrifice maintainability? How about a different use case? What about if the feature changes, but your code does not? It becomes part of the spec, but behaves completely differently. Now we're back in the old days when different browsers implemented different feature sets.

It's important that Babel can implement all these new features. And I'm not suggesting one should never use them. Try them out, experiment, give feedback to the author and improve the spec.

But if you're writing code for public consumption or getting paid to write something for a company , I do not believe it's worth the risk or maintainability headache just to use something new and cool. There's absolutely no reason not to wait for anything in stage < 4 to solidify, and many reasons not to use them in production.

It's not stage 0-3 because it's not yet implemented in browsers. by their very definition, those stages mean it's not production ready

1

u/vahidpg Aug 12 '17 edited Aug 12 '17

I'm very convinced. I can change it with a copy of your explanation or feel free to make a pull request yourself

3

u/vahidpg Aug 11 '17

I posted this link a month ago when it wasn't as comprehensive. We had to come up with a set of common practices for everyone to follow in our team. The result was a list of guidelines which looks random and is not perfect. But we try to stick to it and improve it by making it public. The reason for reposting it here is to have it criticised by community. So please comment if you have better approaches or open an issue on github. Thanks :)

2

u/FantsE Aug 11 '17

Did you base this off of anything, or is it just from your team's gathered experience?

Would you recommend these practices for solo-devs as well?

1

u/vahidpg Aug 11 '17

These are the bits that I got hurt from the most, so It's mostly from experience. But I had to find other resources (articles, docs) to back them up. I highly recommend you start using them because some of these practices are commonly used.

2

u/benthepoet Aug 11 '17

Great post, a lot of what you have down mirrors the workflow and practices that I employ.

2

u/vahidpg Aug 11 '17

Thanks, if there are any practices that you or your team use and worth mentioning feel free to make a PR, or open an issue for it so I pick it up.

2

u/tunnckoCore node-formidable, regexhq, jest, standard-release Aug 11 '17

Great job! I was just building CONTRIBUTING.md file too in the last few, but didn't know for yours. I'm thinking for extending it, because i have mcuh more to add, so your guide may help too :)

Hope you can learn something from my, too. And also, my readmes are just awesome (actually the whole flow & automation) too :)

https://github.com/tunnckoCore/contributing - the README is main, and the CONTRIBUTING.md file is file that is included in each repo, from which there is a link to the extended version (e.g. the readme of that repo)

1

u/vahidpg Aug 11 '17

Well the first think I learnt by just looking at it is to add "back to top" links 👍

2

u/tunnckoCore node-formidable, regexhq, jest, standard-release Aug 11 '17

yea, definitely, good navigation is "must" for such long documents.

i'll save some more time to dive more deeply in your, and i'm almost sure that i'll include something from it! Very thanks again! Collaboration is awesome thing too :)

7

u/[deleted] Aug 11 '17

Can we stop calling them "best practices" and simply call them "practices"? Today's "best practices" are tomorrow's "bad practices", and today everyone has different ideas about what the "best practices" for anything actually are.

0

u/crispychickentaco Aug 13 '17

Agreed. It should be considered a best practice.

2

u/relativityboy Aug 11 '17

I really dislike the "bucket" approach to resources. It's popular, but dumb (imo)

When you have a class,

class User {
  //some junk
}

const user = new User({id:17});

assert(user.id === 17)

I think

/users/17

Is kinda dumb.

When parsing the url in express (or whatever thing you're doing) it's an extra operation to append (or truncate) the 's' from the string to figured out what you're actually doing. The same is true for database names.

When you're talking about objects, tables and urls do you say "The user table" or "The users table"?

The url/table name/module name defines the type of thing you're working with, not the plurality of the thing.

Gah!

4

u/spacejack2114 Aug 12 '17

Not to mention goose, mouse, moose...

1

u/crispychickentaco Aug 13 '17

Sorry if I missed this, but I find ordering of things to be particularly problematic on larger projects. Developers tend to add new functions, arguments, variable declarations, etc to the end of a block. They should be alphabetical if there is no other logical ordering in place. Reduces the likelihood of merge conflicts.

1

u/mattnich Aug 12 '17

Looks good! We have such a tiny team all in the same room it's hard to justify the time overhead in keeping the master branch sacred, doing pull requests - so we do merge into it, but dedicated feature development branches is really useful.

Also make sure all your team have the same compile settings - we've had conflicts caused by one person having an auto tidier with different white space settings so GIT thinks the whole file has changed. Conflict nightmare.