8 ms·
Proposed JavaScript Standard Style
- feross 10y agoWhy is this posted under the title "Proposed JavaScript Standard Style"? I am the author of `standard` and I did not propose that this becomes any kind of official JavaScript style standard. It's just my own code standard -- you're free to use it if you want.
- shanefgan 10y ago2 spaces for indentation? No :(
- deleted 10y ago[deleted]
- Kyoushu 10y agoMy first thought as well
- arunitc 10y agoI always use a tab and set the IDE to show two spaces for each tab. Visual Studio has a setting for this. In the same project if someone wants 4, they can just change it to 4 spaces. In the file, its always stored as a tab
- GrantSolar 10y agoI agree. The number of spaces for indentation is completely irrelevant in a style guide as it can be configured in the editor on a personal basis.
- audessuscest 10y agoNo it's not, because it's not just an editor configuration, it's something in the code structure. People with different indentation working on the same files is a problem, so it's really relevant to try to set a standart about this, at least for open source project.
- jdmichal 10y agoYes, the code is structured with tab characters, so there is no different indentation. Only different renderings of the same semantic characters.
- audessuscest 10y agowhich lead to very useless and annoying conflict and different coding style in same files
- emodendroket 10y agoI'm all about two spaces but this is a pointless argument
- catpolice 10y agoI started skimming the rules and was like "this all seems fine" and then noticed "no semicolons". YOU'LL PRY THEM FROM MY COLD, DEAD HANDS FIRST
- Khao 10y agoI hope they enjoy their subtle and extremely hard to find errors.
- untog 10y agoI alternate between projects with and without semicolons, and I'm yet to run into a single error as a result of omitting a semicolon. I don't understand what kind of code other people are writing that does.
- apo 10y agoCould you cite some examples? It seems that using the rest of the conventions might eliminate many, if not all, of them.
- deleted 10y ago[deleted]
- agency 10y agoThey address this directly - the only edge case with omiting semicolons is starting lines with ( or [ and they check this for you. See: https://github.com/feross/standard/blob/master/RULES.md#semicolons https://github.com/feross/standard/blob/master/RULES.md#semi...
- emodendroket 10y agoThat is a really bizarre choice since I think "no semicolons" is the less popular position by far.
- phpnode 10y agoLet's just say that coupling this preference with the name "standard" is an extremely contentious decision (search the github issues).
- emodendroket 10y ago"Standard" for whom? This is just some guy enshrining his preferences.
- petetnt 10y agoThis is addressed in the README But this isn't a real web standard! Of course it's not! The style laid out here is not affiliated with any official web standards groups, which is why this repo is called feross/standard and not ECMA/standard. The word "standard" has more meanings than just "web standard" :-) For example: This module helps hold our code to a high standard of quality. This module ensures that new contributors follow some basic style standards.
- emodendroket 10y agoI don't claim a project has to be an "official" Web standard to be a standard, but I'm seeing a hard time how this one is a standard in any meaningful sense.
- Touche 10y agoYes, basically. I actually like the premise: > No decisions to make. That can be good, certainly Go developers benefit from the lack of bikeshedding over style. But the authors of standard didn't take this advise; they did make decisions, the ones that they prefer. If they would have just grepped through NPM to figure out the most popular style choices I would have respected the idea a bit more.
- deleted 10y ago[deleted]
- bigethan 10y agoI switched to this style a few months ago, and really like it. Makes javascript read more like python, clean and specific. Downside is that very few other authors are using it, so when you share code people are concerned about its format (no semicolons in particular).
- Ghostium 10y agoReminds me of that: https://xkcd.com/927/ https://xkcd.com/927/
- Normal_gaussian 10y agoThis is not a solution to any problem, except the problem of not enough standards https://xkcd.com/927/ https://xkcd.com/927/
- vcarl 10y agoThis seems like a great style, but it's not going to catch on because it's a separate dependency. If this were distributed as a configuration file for the most commonly used linters, I'd be interested. Since it's its own linter with its own plugins etc, hard pass.
- petetnt 10y agoThere's ESLint config available too: https://github.com/feross/eslint-config-standard https://github.com/feross/eslint-config-standard (and a React flavor for it too under eslint-config-standard-react)
- tlrobinson 10y agoIn case it's not obvious, this is definitely not a "standard" of any kind. It was named "JavaScript Standard Style" as a joke, and has since become moderately popular. I disagree with some of the rules, but there's clearly merit to having one opinionated, zero-configuration linter-enforced style.
- untog 10y agoI've been lucky enough to avoid having to deal with a style guide in a long time. The general idea is sound, but such a guide is always accompanied by hours-long meetings of senior developers hurling their egos at each other over an issue like semicolon usage. Such a waste of everyone's time.
- emodendroket 10y agoI mean, eventually you've got to make decisions; you can't all just be writing with your own style (I've experienced that scenario and it really obscured meaningful changes to have tons of style changes in each commit)
- diggan 10y agoYeah, that's the whole point of this "standard" project. So instead of adopting for example eslint and then sit in a meeting and decide which rules to follow or not, you adopt standard and say, we are using this now, deal with it.
- igl 10y agoUse this if you want the readme badge. Use eslint if you are serious.
- mikewhy 10y ago... This uses eslint https://github.com/feross/standard/blob/master/package.json#L15-L21 https://github.com/feross/standard/blob/master/package.json#...
- kuschku 10y agoRegarding the "no semicolon" stuff, is there actually any way to write this type of formatting list.map(func1) .filter(func2) .map(func3) .reduce(func4); in JavaScript? As far as I know, the semicolon rules would automatically terminate the statement after map(func1). EDIT: Ah, thanks – the things I read never mentioned JS doing lookahead during ASI. This makes it a lot nicer, tbh.
- dagw 10y agoThat's fine in JavaScript and will work as expected.
- vkjv 10y agoIt depends on the engine, but most, when parsing, will look-ahead and see that `.` in `.filter(func2)` is an invalid start to an expression and assume it is part of the previous line.
- gberger 10y agoNo, ASI (automatic semicolon insertion) does not insert a semicolon on the first line (or the 2nd or 3rd) in this case. The code works as expected.
- nvader 10y agoIn most cases[0], Js "looks" at the next line to see if it could continue the current statement, in which case no semicolon is inserted. [0] Not true for "restricted productions", which include naked returns, and some other "special" cases.
- kuschku 10y agoWhat do you mean? Would return list.map(func1) .filter(func2); work?
- WorldMaker 10y agoYes, but this return list.map(func1) .filter(func2); has never worked in the history of JS because JS terminates the return at the newline and returns undefined.
- karn09 10y agoOne (more) standard to rule them all.
- distances 10y agoNo semicolons, two space indentation, space after function name, single quotes for strings? There's no way this would fly with a majority of developers.
- jsmith0295 10y agosinglequotes for strings is very much a standard thing in JS. And two space indentation is fairly common as well. The no semicolons and space after function name are really the weird things here.
- sratner 10y agoI thought so too at first, as those were the only things that disagreed with my previous style. However, I've been using "standard" for a bit now, and have to say that both of those decisions have really grown on me in light of ecma2015 features. Space after function name works well with generator functions and yield. Semicolon placement has become somewhat less consistent with the new object literal and class syntax and skipping them everywhere has saved me from constantly trying to remember whether I need one after a particular function or method definition.
- Grue3 10y agoWhy would you prefer single quotes over double quotes? An apostrophe is not just punctuation in English, it is necessary to preserve the meaning of certain words (like "its"/"it's"). So in a way, it can be considered to be another, albeit rare, letter of the alphabet. Now if somebody proposed to delineate strings with the character "x" everyone would agree it's a bad idea. For the same reason, using "'" to delineate strings is also bad, and shouldn't be encouraged.
- robin_reala 10y agoBecause a lot of JS developers have traditionally manipulated strings of HTML, which have standardised on double quotes for attributes. Also, straight quotes as punctuation are ugly; ‘ and ’ look much nicer.
- 10y ago
- diggan 10y agoFunny that a project that is supposed to fight debates about style, creates so much debate! As a experience of actually adopting standard (this very project) in a company, I must say it's refreshing to not having any discussions about coding style anymore. Process before was to discuss which eslint rules we want to follow and then sometimes it changes. With "standard", we just asked ourselves "Can we adopt these rules and stand with them?". Most people agreed and then we implemented the support company wide and now we never discuss coding style in our javascript projects anymore, which is a pleasure. If you find yourself discussing coding styling, see if you can adopt something like standard, and then just go with it.
- cfluffy 10y agostandard is a really bad name for this.
- WhiteDawn 10y agoWhile I'm not the biggest fan of this style, mostly because of the semicolon thing, I like packages like these. When you're starting a new project with more than one developer you're going to run into people talking about this stuff more than actually making the project. Pre-bundled linting rules just gets everyone on the same page immediately and stops all the discussion. I honestly don't care what the style is, 99% of them are sane and readable, consistency is what matters. Nothing worse than working in a project with 5/no styles all over the place.
- mrighele 10y agoWe have been using for some time js-beautify [1] together with a pre-commit hook to enforce the style of our JS code. This doesn't seem much different, am I missing something ? [1] https://github.com/beautify-web/js-beautify https://github.com/beautify-web/js-beautify
- kolme 10y agoNo semicolons? REALLY? We've already spoke about this, people. Let's see what Brendan Eich has to say about this: > My two cents: be careful not to use ASI as if it gave JS significant newlines. [1] and > ASI is (formally speaking) a syntactic error correction procedure. If you start to code as if it were a universal significant-newline rule, you will get into trouble. Calling it "standard JS" struck me as pretentious at first. But calling it "standard JS" and calling for not using semicolons is absolutely delusional. Let me be clear here: - ASI (Automatic semicolon insertion) is a correction mechanism, designed to prevent silly errors, thus making the language "friendly". - ASI does not work in many cases, where you do need a semicolon. So much for consistency! All the rest of things in that list are just a matter of personal preference, but not the semicolons though. That's just plain wrong. And if people begin using this "standard" the bugs will come to bite them. [1] https://brendaneich.com/2012/04/the-infernal-semicolon/ https://brendaneich.com/2012/04/the-infernal-semicolon/
- feross 10y agoI recommend reading the following articles before you assume that omitting semicolons is dangerous. An Open Letter to JavaScript Leaders Regarding Semicolons http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding http://blog.izs.me/post/2353458699/an-open-letter-to-javascr... JavaScript Semicolon Insertion – Everything you need to know http://inimino.org/~inimino/blog/javascript_semicolons http://inimino.org/~inimino/blog/javascript_semicolons Are Semicolons Necessary in JavaScript? https://www.youtube.com/watch?v=gsfbh17Ax9I https://www.youtube.com/watch?v=gsfbh17Ax9I Spreading FUD doesn't help anyone out.
- voidr 10y agoI know I can write a working JS application without semicolons, however I can also write a working JS application where with `eval` and `with`. The issue is not whether or not one individual can learn to use dangerous feature X. If you are writing code by yourself for your own use, you can use nested eval's and no semicolons with a little bit of `with` here and there, nothing wrong with that. However when you are writing code that is supposed to be developed by people other than you, you might want to write less clever code. I could write code without semicolons, however that would mean that I would have to constantly keep an eye out for that case where I absolutely need to add it to prevent ASI from doing the wrong thing. It takes probably 100ms to hit that semicolon key, however it takes a lot more time to debug code without semicolons. If you hat semicolons with a passion for some reason, you could use Coffee Script or some other language which was designed without semicolons and has clear semantics around it.
- mikeokner 10y ago> Space after function name function name (arg) { ... } Never, you fucking monster.
- onestone 10y agoThe title is misleading. This isn't "proposed" in any relevant standards body. The project itself has a misleading name too, because it's not "standard" in any meaningful way, it's just a set of questionable personal preferences.
- smitherfield 10y agoThere's no real good reason why, but my mild OCDish tendencies get intensely triggered by looking at Javascript with no semicolons.
- tbolt 10y agoAirbnb has a decent styleguide - https://github.com/airbnb/javascript https://github.com/airbnb/javascript "A mostly reasonable approach to js" but style-guides should be just that style guides ...not standards
- draw_down 10y agoThe idea is that you stop trying to have humans match the style guide, playing trial-and-error with the linter, and instead just have a tool fix the style. We have more interesting problems to solve than matching the style guide. Computers can take care of that. Plus then you don't have to talk about it in code reviews. It's not a very interesting topic, honestly.
- draw_down 10y agoThis is what my team and I have used for a while now. It's nice. I recommend it. edit: ha, I got downvoted for saying something is good and recommending it. You guys are silly
- k__ 10y agoWell, I like it... but it's pretty much the style I'm already using.