r/javascript • • Sep 12 '16

JavaScript Standard Style Guide

https://github.com/feross/standard
0 Upvotes

29 comments sorted by

14

u/PolarZoe Sep 12 '16

"Don't use ;", noped the fuck out.

1

u/kasperpeulen Sep 12 '16

10

u/PolarZoe Sep 12 '16

I've read the articles and that video you linked and those few little instances are the exact reason to enforce the semicolons.

I don't want to have to remember where I do need to use them, and don't want to live in fear that our juniors make a mistake remembering these rules, so no thinking necessary, always use semis.

Also, it gets confusing when mixing different languages.

Don't get me wrong I think a PSR like codestyle for JS would be great, but not with these rules unfortunately.

3

u/kasperpeulen Sep 12 '16

If you use this linter, then it will warn you in those cases you need to add a semi colon. You will be trained within a couple of days exactly where you have to add a semicolon.

But besides that, I don't see the problem about remembering one simple rule... Your juniors may make a mistake one time... So the program crashes, they figure out what they did wrong, and they fix it... Simple

1

u/mikrosystheme [κ] Sep 12 '16 edited Sep 21 '16

Also, it gets confusing when mixing different languages.

What is exactly your point? There are several programming languages (Elixir, Erlang, Go, any LISP, Nim, Ruby, Crystal, Python, Lua, Swift to name a few) that don't use semicolons as statement terminators or make them optional. Syntax is always trivial, and if your "juniors" are making mistakes because of it, maybe it is better to send them back to school.

0

u/g_b Sep 13 '16

Automatic semicolon insertion may lead to subtle bugs. Always use semi-colons ffs.

http://stackoverflow.com/questions/12745743/automatic-semicolon-insertion-return-statements

3

u/Klathmon Sep 13 '16

You can't turn off ASI just by using semicolons. Your linked bug will still happen regardless of if you use semicolons or not.

ASI is there, it's ALWAYS going to insert semicolons when they aren't there, so not using them doesn't change anything besides have less typing.

There are exactly 3 places where you need a semicolon. if a line starts with [, (, or ` and in those cases you can just prepend the line with a semicolon like so:

;['one', 'two', 'three'].forEach((thing) => console.log(thing))

1

u/Klathmon Sep 13 '16 edited Sep 13 '16

I'd recommend trying it at least once. It felt wrong at first (and i'm actually the one in my team that fought it until the end!), but now I can't go back.

That being said, if you really, truely, absolutely can't stand to not type ; all the time when it's not necessary, then you can use SemiStandard which is the same as Standard, but with semicolons.

Edit: I will say that using something like Standard, SermiStandard, Happiness, or another "no changes allowed" style system was a big plus for us. We had a lot of internal arguing over things like Spaces vs Tabs, where the open brace should go, should we use " or ' for strings, etc...

Standard solved it in a way that I didn't think was possible. It pretty much made everyone angry at some part of it, but it turns out that code style really doesn't matter to your productivity, as long as it stays the same. After a week of bickering if standard was worth it, we all just moved on.

16

u/MoTTs_ Sep 12 '16

Space after function name

function name (arg) {  
  // ...  
}

When and how did that become a thing?

8

u/notTheAggressorHere Sep 12 '16

Adding a space after the name feels yucky to me. Will not do.

4

u/scunliffe Sep 13 '16

Never needed a space there for the past 20 years, not gonna start adding one now.

4

u/azium Sep 12 '16

Not sure how to answer this question, but I've been doing this myself for quite some time. It helps me quickly scan what is a function definition vs a function call.

But then again nowadays I never use the function keyword, so shrug

1

u/Klathmon Sep 13 '16

That's the reasoning. The space vs no-space helps determine definition vs invocation.

6

u/_HlTLER_ Stackoverflow searcher Sep 12 '16

It's like writing a math function as f (x) instead of f(x). It's just off-putting.

-8

u/mikrosystheme [κ] Sep 12 '16

The world is going to end because of that, isn't it?

5

u/MoTTs_ Sep 12 '16

Did I say that?

Actually I just genuinely want to know how that became a thing.

-2

u/mikrosystheme [κ] Sep 12 '16

Probably the same way the color magenta became the preferred color to someone.

17

u/inu-no-policemen Sep 12 '16

Airbnb's is better and also closer to being a standard.

https://github.com/airbnb/javascript

-1

u/PolarZoe Sep 12 '16

I like it!

9

u/ghostfacedcoder Sep 12 '16

God I hate this jerk off. If my name is Bob and I make a style guide it's "Bob's Style Guide". If an international consortium of web developers agrees on a style guide, then that is a "Standard Style Guide".

But you don't just get to declare yourself the standard.

6

u/bitter_cynical_angry Sep 12 '16

The great thing about standards is that there are so many to choose from. Also, there's a relevant xkcd.

-1

u/Klathmon Sep 13 '16

Nobody tell him that manual transmissions are called "standard" in some parts of the world. Or that the "US Units" are often called "standard". Or that the word standard can mean other things, like how this guide lets you follow some basic "standards" to prevent bugs in your code and to make it more readable.

0

u/[deleted] Sep 13 '16

[deleted]

1

u/Klathmon Sep 13 '16

Well, the idea was to make a "standard" that wasn't up for modification by the person using it. To perhaps eventually get some consistent code across more than one project. To stop the bikeshedding about if you should use X vs Y, or how to style this or that. And I personally think it's doing a pretty good job.

Now you can get your panties in a bunch and complain about how it's wrong that he's "misleading people" or something, but I just can't believe that anyone out there thinks that this is an "ECMA standard" (especially because the only mention of ECMA is in the FAQ header called "But this isn't a real web standard!"). It's not like the author gets anything by getting people to use his style guide. It's not like you need to pay him $20 every time you use it, it's a FOSS style guide and associated tools, linters, formatters, and plugins.

You can write it off because of a cheeky name if you want, but it's improved consistency in our code, stopped bikeshedding, and enough of some pretty big projects have started using it that i'm pretty sure aren't being "swindled" that i'm happy to use it (some of those projects include karma, fs-extra, yargs, npm, nyc, and - in a bit of an ironic twist - semistandard)

1

u/ghostfacedcoder Sep 13 '16

Well, the idea was to make a "standard" that wasn't up for modification by the person using it.

Words in English (well, in any language) have meanings. Standard doesn't mean "something that's not up for modification made up by one person." It means (according to Miriam-Webster at least) "something established by authority, custom, or general consent as a model or example".

The author was not an authority, and there was no established custom or general consent to use his personal style. So it's simple: he deliberately mis-used English get popularity for his project.

0

u/Klathmon Sep 13 '16 edited Sep 13 '16

Kind of funny that you took the time to look up the definition of the word 'standard' on merriam-webster and just so happened to look over the first 2 definitions. I'll put them here:

  • a level of quality, achievement, etc., that is considered acceptable or desirable

  • something that is very good and that is used to make judgments about the quality of other things

By those definitions, "Standard JS" is definitely a standard. It brings a level of quality to the code that makes it desirable.

But even if we decide to use your definition (which was weirdly 4th in the list...), I'd argue that "Standard" fits because the person installing it is acting as the authority. The "user" is standardizing on standard. Just because it's not your standard doesn't mean it's not a standard.

Either way, i'd prefer to go with the 3rd definition:

  • a conspicuous object (as a banner) formerly carried at the top of a pole and used to mark a rallying point especially in battle or to serve as an emblem

It's a flag!

0

u/ghostfacedcoder Sep 27 '16 edited Sep 27 '16

Words also have different meanings in different contexts. Normal human beings understands this, but if you try to argue like a robot and blindly follow the highest dictionary definition ... well you're going to have a much success communicating with other human beings as a robot does (a modern robot; I'm not talking sci-fi).

If you're playing baseball it doesn't matter if "you're out" normally means "leave", even if that's the #1 dictionary definition, because in the context of baseball "you're out" just means you go back to the club house and your team has one less "out" left in the inning.

Same thing with standard: there's the clear, obvious definition of the word in a programming (or indeed any technical) context, and there's a bunch other definitions. You can use those other definitions if you want, or make up your own definition for the word, but if you don't use the proper definition for a word given the context it's used in, you're not speaking English.

1

u/Klathmon Sep 27 '16

Hey dude whatever you say, I'm not a linguist.

But by that line of thinking, gulp, grunt, broccoli, node, react, angular, backbone, ember, and most other names are just as bad...

I'll just keep referring to standard js as the fancy banner that denotes that style, and you can continue on your crusade against names.

0

u/[deleted] Sep 13 '16

[deleted]

2

u/azium Sep 13 '16

He's also a superstar developer who happens to be a really nice guy. There's nothing wrong with making something you know is gonna raise some eyebrows, it's just a package after all.

We all need to be more light hearted like Feross!

-2

u/bitter_cynical_angry Sep 12 '16

Spaces for indentation? Fuck that, didn't even read the rest.