r/javascript • u/vahidpg • Jan 24 '18
JavaScript best practices got 11k stars on Github
https://github.com/wearehive/project-guidelines5
u/coderitual Jan 24 '18
Avoid URLs like this: GET /blogs/:blogId/posts/:postId/summary
For nested resources, use the relation between them in the URL. For instance, using id to relate an employee to a company. GET /schools/2/students/31
I assume it was created by different people but I spotted this after 3 mins of reading.
1
u/vahidpg Jan 24 '18
The first url is referring to a property rather than resource itself hence the suggestion to avoid it.
2
u/coderitual Jan 24 '18
I think you might be right. Still a bit confusing.
1
u/vahidpg Jan 25 '18 edited Jan 25 '18
After each bullet point there is ‘why’ section (it is quite hard to miss to be fair). On this one it says: “This is not pointing to a resource but to a property instead. You can pass the property as a parameter to trim your response.”
12
u/lucy_in_the_skyDrive Jan 24 '18
Yeah, but it's a little confusing to have two separate examples when you could have probably explained it better w/ the same one.
bad: /blogs/:blogId/posts/:postId/summary
good: /blogs/:blogId/posts/:postId
Then get summary off of the Post response object instead of building a strange query to get one property.
42
u/crazyfreak316 Jan 24 '18
For the record, these are not "Javascript best practices" but Javascript project best practices. The difference is important.
3
30
Jan 24 '18
Organize your files around product features / pages / components, not roles. Also, place your test files next to their implementation.
Thank. You.
Even a tightly scoped project can get downright unreadable if you're dumping everything into a components folder.
3
3
2
u/Kingsizepeanut Jan 24 '18
Thanks, this is something I've been looking for for ages! Seems to be well formatted and concise.
Thanks for posting!
1
-23
u/faded_filth Jan 24 '18
Stars, upvotes, downvotes ... what is this obsession? Meaningless. They are literally just clicks of a button made by users, bots and trolls.
1
u/LogicMirror Jan 25 '18
Your comment ... what is this obsession? Meaningless. It's literally typing of letters by someone who can only see in black & white.
-11
u/faded_filth Jan 24 '18
gets 17 downvotes in 6 hours
aww you peopleHHHHH trendy javascript developers make me feel special _^
1
0
Jan 24 '18
[deleted]
16
u/dedben Jan 24 '18
it still recommends using "stage-2 features"...
TL;DR on why this is bad for JS newbies like me?
23
u/adbachman Jan 24 '18
Stage-2 is mostly stable but still draft / incomplete. They are features that are likely to be included in the next JS specification, but they’re not final.
Just means you might be learning something that’s going to change in 6 months, but what else is new?
The description over at Babel.js has more detail about what it actually includes: https://babeljs.io/docs/plugins/preset-stage-2/
0
Jan 24 '18
[deleted]
8
u/Mingli91 Jan 24 '18
Stage 2 is generally the place that many people start using new features since at that stage of the TC39 process the syntax is covered but more importantly the APIs have already been decided, so if the internals change then it makes no difference.
With Babel, you run no risk whatsoever putting this in production code. Many of the big players use stage 2 as their starting point. Facebook is a good example - you can see evidence of it in their OSS projects (check out React Native, which includes stage 2 features by default).
Worst comes to worst and the spec changes, the Babel plugin or polyfill isn't going anywhere, and you have the simple task of removing the new features from your code.
Full stage 2 description:
Draft: all major semantics, syntax and API are covered, but TODOs, placeholders and editorial issues are expected
Obviously it's up to the individual or the company, but the only risk is losing a couple of hours if the spec does change dramatically.
0
u/Tomseph Jan 25 '18
Stage 2 means "We're close to final draft" but it doesn't mean that it will become an accepted feature. Stage 3+ is the only assurance that the feature will become part of the Javascript. Object.observe was at Stage 2 before it was withdrawn.
3
-6
6
Jan 24 '18
Yeah, that's bad advice by default.
I disagree with those who wouldn't use ESNext features in production projects, but equally I don't think you should be chucking an entire stage preset into your project.
Use stable by default, and then add in individual features as plugins as needed (for example https://github.com/OpenSourceCTF/website/blob/develop/.babelrc.js#L33).
3
1
u/cogman10 Jan 24 '18
I mean, the feature should bring a lot before you deviate from stable. Because every unstable feature you add is a potential hitch that will prevent you from using new features and newer transpilers. Something that really should be avoided if possible.
3
Jan 25 '18
I agree. For me object spread is always worth it, for example, as it's a lot nicer to work with than Object.assign.
4
Jan 24 '18
And after all this time, and comments on reddit
you'll still find some trivial shit to nitpick...
1
u/madwill Jan 24 '18 edited Jan 24 '18
I'm quite lazy, could you say which ones ?
edit: Oh nevermind, it straight up recommend to use stage2.
Anybody had an actual problem using stage 2 things at some point where their use case was broken by a change in specifications ?
I mean i use decorators, absolutif love them, a lot more than HoC in react. I use an old converter for them, i have no know problem and don't expect any if it updates its implementation.
16
u/vahidpg Jan 24 '18
Last year in order to achieve some consistency in setting up our javascript projects, we put together a set of best practices and asked the community to contribute. Thanks to your feedback (mostly on reddit) this documentation is in a much better state now. It has been translated in 3 languages, covers more aspects of a JS project and has achieved more than 11K stars on github. Our plan for the coming months is to add a section for GraphQL best practices as well as adding more translations.