Hacker News new | ask | show | jobs
by bostonaholic 5032 days ago
}); is not a line of code. Please stop counting it as such. Here's a good rule of thumb:

"If it can be moved to the line above, without any other changes, it's not its own line of code."

The argument that CoffeeScript saves countless }); }); } } is invalid, IMO. I would even argue that function definitions are not lines of code. Example: (ruby)

def foo end

0 lines of code.

BTW, I'm not a CoffeeScript hater, just trying to level the playing field.

7 comments

The argument that CoffeeScript saves countless }); }); } } is invalid, IMO.

I agree that counting }); as a line isn't necessary, but CoffeeScript saving you doing any of that is a very valid benefit. It cleans up code dramatically- ignore line numbers and just think about all the extra stuff that ends up surrounding multiple function calls.

I'm thinking it doesn't happen that often, and I would counter with having you think just how much more cognitive effort is used in parsing and debugging the syntax of CS. Remember, debugging and reading "old" code dominates our days, so it doesn't add up for me. As well, if you and the many others that like to claim keystroke reductions, there is no difference in "fu<tab>" for "->" and numerous other comparisons.
just how much more cognitive effort is used in parsing and debugging the syntax of CS

Have you tried CS? It's far more readable, by virtue of not having "function() {}" splattered all over the page. I don't care/worry about keystroke reductions, I care about readable code. The lack of curly brackets and addition of significant whitespace absolutely does make for more readable code.

Sure, I've tried it. Function calls are never splattered all over my page, so I don't have to care about that. And at best, it only allows me to cram more crap onto a single line, which is also not often helpful. Instead, I get to -- have to -- think about and end every function with something sane, in the event, for example with jQuery's .each(), I can't have my function magically returning false -- the last evalutated variable -- and terminating the each mapping.

My code already has significant whitespace; it's required by styleguide and linting. CS has prolific issues with whitespace usage, especially when it comes to parsing function arguments and lines broken over multiple lines. Just look through this or any other thread on CS being pushed.

CS often has mind fucks, and I'd rather have to ignore a couple lines with } on them.

Note: I mostly write in Python, if that gives any indication into how I very much enjoy significant whitespace.

"If it can be moved to the line above, without any other changes, it's not its own line of code."

Under this logic, all Javascript files are 1 line of code.

'});' is absolutely a line of code. I would even consider ',' a line of code. Forgetting either one of those in a line of JS results in errors. Errors you have to spend mental effort looking out for. Don't discount the value of not having to match up all those ridiculous parentheses and curly braces. Oh and semicolons.

I have personally had more problems from not closing something than I ever had from assigning a variable.

> }); is not a line of code. Please stop counting it as such.

...then I hope that I never have to work with code you've written, because that certainly is given its own line for readability quite often.

What use is a LoC comparison that doesn't use conventional/reasonable formatting? Technically I can run a program of any length through jsmin and come out with one "line of code", but how is that at all useful?

I think OP mean that }); doesn't on its own affect program logic, and, realistically if you're reading JS all day your brain is filtering those characters out for you.

The other argument is that }); is line noise and therefore unnecessary, which I think boils down to preference.

>def foo end

>0 lines of code.

I'm having trouble understanding your point here, how exactly is that 0 lines of code when you've actually written 1 line of code which directly changed the method definitions of a class?

> }); is not a line of code.

CoffeeScript agrees.

It's not a LoC in terms of code complexity, but it is another line with symbols to parse when you're reading code and it's another few keystrokes to type out each time you have a function or object.