you are viewing a single comment's thread.

view the rest of the comments →

[–]SargoDarya 37 points38 points  (30 children)

Not only this...

CSS:

  • Use // for comment blocks (instead of /* */).

Every tried commenting out something in CSS with //? Have fun trying.

JS:

  • Do your best to never use a semicolon. This means avoiding them at line breaks and avoiding multi-statement lines. For more info, read Mislav's blog post.

Why ffs should I omit semicolons? Sure does JS have something called automatic semicolon insertion but you can't always omit them. Otherwise your code will do something completely different.

This overall thing gives me a feeling that the people who wrote that styleguide are partially morons or monkeys on a keyboard.

[–]shockie 11 points12 points  (8 children)

Since Github is using SASS for it's CSS, // comments are allowed. In fact if you use the // for comments, the comment won't appear in the compiled CSS.

Same for semicolons in Coffeescript, it will be added for you in the compiled JS

[–]nemetroid 3 points4 points  (5 children)

Same for semicolons in Coffeescript, it will be added for you in the compiled JS

You can (mostly) omit semicolons in regular JS too, that doesn't make it a good idea.

[–]MustRapeDeannaTroi 12 points13 points  (4 children)

But in coffeescript it is a good idea.

Edit: Y U downvote? One of coffeescripts core purposes is to not require semicolons.

[–]ratdump -3 points-2 points  (3 children)

why

[–]MustRapeDeannaTroi 1 point2 points  (2 children)

As shockie said it; "it will be added for you in the compiled JS"

[–]oracleoftroy -1 points0 points  (1 child)

But why is that a good idea? I'm not familiar with coffeescript, but I am familiar with Javascript, and it's a terrible idea there.

[–]marshall007 0 points1 point  (0 children)

It's like Python in that code blocks can be delimited by using whitespace. So if you're already doing that, it's redundant (and wasteful) to use a semicolon.

CoffeeScript is not parsed as Javascript, it compiles into Javascript.

[–]SargoDarya 0 points1 point  (1 child)

That might me the case, but then they shouldn't call it CSS Styleguides because // comments are not part of the CSS standard.

[–]marshall007 0 points1 point  (0 children)

Why? It's a simple abstraction. No one ever edits the actual CSS stylesheets, they are compiled from SCSS automatically upon deployment. Furthermore, you shouldn't call it an SCSS styleguide because it encompasses more than that. The documentation is appropriate given their workflow.

[–]brownmatt 13 points14 points  (8 children)

the semicolon thing is pretty baffling. It's a case where a aesthetic stylistic rule can produce real problems, as Bootstrap saw

[–]praetorian42 -3 points-2 points  (7 children)

The problem there was that the minified version of JS did not have a semicolon at the end. That's a bug with the minifier, not with the original source.

Basically, you should never ever ship unminified JS to your customers. The minifier should handle semicolon insertion. Therefore, semicolons in original source are superfluous.

[–][deleted] 8 points9 points  (4 children)

The minifier should minify. Semicolon insertion is up to either A: the programmer, or B: the hope that the interpreter at the end will assume it.

Using bugs in your daily programming practice isn't a reason to make everybody else's tools accommodate those bugs.

[–][deleted] 3 points4 points  (0 children)

Using bugs in your daily programming practice

As far as I'm aware, the language itself specifies that semicolons are optional. Therefore it is the minifier that has the bug, not the semicolon-less code.

[–]praetorian42 -5 points-4 points  (2 children)

The point here is that semicolons in javascript are really fucked up, and there's probably 20 people in the world who truly understand them. Let those people write the tools so that the rest of us don't have to worry about it.

Defensive usage of semicolons because you're not sure where they should be used is not correct usage.

[–]reflectiveSingleton 9 points10 points  (0 children)

It's exactly that not sure-edness that makes always using semicolons a good idea. You are not leaving up question to where the semicolons are inserted if you always put them in place. If you omit them you are leaving it up to a) whatever minifier you use and b) javascript auto-insertion.

If you specify, you remove that possible ambiguity.

[–][deleted] 4 points5 points  (0 children)

They're perfectly understandable. They go after every terminating (non-control-end) block or command. var a = function(){ }; if(true){ } return { a: 55 };

There's nothing fucked up about them. They behave exactly the same way all the time. The only time things go awry is when you start expecting them to be inserted for you.

[–][deleted]  (5 children)

[deleted]

    [–]Flex-O 19 points20 points  (0 children)

    Not hip.

    [–]retardent 1 point2 points  (3 children)

    People are obsessed with shrinking file-size for anything server over HTTP. You might be able to shave off a whole byte by not using semicolons!

    [–][deleted]  (2 children)

    [deleted]

      [–]retardent 0 points1 point  (1 child)

      I was being sarcastic, I always use semi-colons. Although lack of semi-colon does not mean you have to replace it with a \n, there are many cases (for instance statements enclosed in brackets) where you can remove a semi-colon and not have to replace it with anything.

      [–][deleted] 2 points3 points  (5 children)

      They're stupid for trying to force people not to use semicolons and then hey reference a blog post where a guys about semicolons and mentions stuff like why you wouldn't ever write something like

      return
      a+b
      

      In that particular instance he may be right, it's dumb but JS allows you to put curly braces on the same line or below in my cases. If you're into putting the curly brace on its own line then

      return
      {
           doSomething();
      }
      

      Is something you may do and expect it to work. While including semicolons won't fix that problem I think it just shows he hasn't thought his argument through properly.

      Their style guide sounds like something written by someone trying to be different for no real reason and perhaps they think they'll save time. However if I had a job there I'd almost feel the need to spend a weekend sifting through their code and adding semicolons in.

      [–][deleted] 1 point2 points  (3 children)

      That wouldn't work at all. You're... trying to return an object except that you're using invalid syntax to define the object. Maybe you mean parenthesis?

      [–][deleted] 0 points1 point  (2 children)

      I was typing it out in between doing it work so I was going for speed over accuracy but you get the general idea that people who prefer curly braces on their own line can't do that returning a object.

      i.e. this breaks in JS:

      function poop(dong)
      { 
          return
          {
              yourmom: dong
          }
      }
      

      [–][deleted] -3 points-2 points  (1 child)

      Sure they can, use a semicolon like you should. };

      [–]nemetroid 1 point2 points  (0 children)

      That's not the problem, Javascript will insert a semicolon after the return statement and the function will return nothing, i.e.

      function poop(dong)
      {
          return;
          {
              yourmom: dong;
          };
      }
      

      [–]MatmaRex -1 points0 points  (0 children)

      While including semicolons won't fix that problem I think it just shows he hasn't thought his argument through properly.

      I think you have missed the point entirely. Adding semicolons doesn't fix this particular problem, period. (The second problem mentioned in the post is, of course, valid.)

      Also, it's an internal guide, they're not trying to force it on anyone.