by jrimbault · 8y ago · 0 comments
You could argue the placement of braces with lots of valid arguments both way, but this... to reduce LOC ? Doesn't feel like a valid reason in any language using braces...
uh ? for me the less code on each line and the easier it is to read
Sometimes more verbose code is more readable, and sometimes it is the presentation, and sometimes this is "superfluous lines", that increase LOC.
The argument against placing braces on their own line is that this:
if (a)
{
print(a)
}
conveys exactly as much information as this: if (a) {
print(a)
}
while taking up more space. The thing the brace tells you is already told by the indentation, so the brace is on a superfluous line. if (user.exists()) {
destroyHuman(user);
hideRemains(user);
}Which is true, and of course begs the question: why do you even need the braces?
Maybe I am mentally disabled, but I can only focus on one logical task at a time. Can other programmers multi-task their coding?
I more meant it in the sense that it's nice to be able to soak in more of the code at once and avoid unnecessary scrolling.
The less scrolling, tab management, and other context switching I have to do to look at those "2" functions, the easier it is on my memory.
I don't disagree, but the sentiment seems to be "fit everything on the screen at all times", which seems like one of those rules that may take more time to implement than it saves in actual time.
I work on projects with upwards of 100k lines of code consistently, the very idea that anything relevant will fit on one screen is absurd, so I am always curious what kinds of projects people work on where the relevant code is literally within a half screen of each other.
void foo(int x) {
if(x == 0) {
bar() }} public class Main {
public static void main(String[] args) {
System.out.println("Hello world!") ;}}
We had a good laugh. (that was fine with him, of course as long as it's a joke)PS: getting back to the original topic, imo, formatting style should be project-wide rules set at the beginning or during refactoring. Don't get too hung up on style as long as it stays consistent.
void foo(int x)
{ if(x == 0)
{ bar(); } }
That is workable. I have adhered to it (mostly) in this Yacc grammar file: http://www.kylheku.com/cgit/txr/tree/parser.yJust in the grammar; not in the supporting functions.
It's an attractive style for C statements embedded in another language, because they look more like capsules somehow.
It's not really a valid reason. Unfortunately, there are still a lot of people who think LOC is a valid metric.
/**
* Get the foo
*
* @return the foo
*/
int getFoo();
/**
* Get the bar
*
* @return the bar
*/
float getBar();
/**
* Set the foo
*
* @param foo the foo
*/
void setFoo(int foo);
/**
* Set the bar
*
* @param bar the bar
*/
void setBar(float bar);
Compare with what any sane project would do: int getFoo();
float getBar();
void setFoo(int foo);
void setBar(float bar);
Multiply that by a dozen such attributes, and what should fit on a single screen spans now hundreds of lines. What you could see at a glance, you have to search for. There's simply no way those utterly redundant comments increase readability. (Yes, the real comments in the real code were just as redundant.)LOC is more valid as a metric than most care to admit.
case class Baz(foo: Int, bar: Float)
Gives you a free hashCode, equals and copy as well.
int foo; float bar;
That can later be changed, when the need arises.
>LOC is more valid as a metric than most care to admit.
It's not.
Not all of it, actually.
> nobody had to physically type that
We totally had to read that.
> And usually no developer will be dwelling on this object or this area of the object.
Well… yes, usually. Sometimes however we did want to pay more attention than usual. At that point the original dev would have made a real comment. And that comment was lost in the noise, so you couldn't even distinguish between real comments and useless boilerplate.
I'll repeat my current gut feeling. Intrinsic measures of software quality are terrible as guides for how to write code. They are decent at predicting quality, but are not usable in a prescriptive way to write quality code.