|
Oooooooo, look at how easy that is to maintain now!! :drool:
Jeremy Falcon
|
|
|
|
|
if (condition) { this.DoThis(); } else { this.DoThat(); }
You probably meant
Ian Shlasko wrote: It's not properly formatted until there's only one token per line in the entire application. I guess it's theoretically possible...
My blog[ ^]
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}
|
|
|
|
|
Way back in my College days the Software Lecturer told us (the class) it wasn't possible to do the above. I proved her wrong by writing a short Pascal (I think) program with no returns all on one line, ah Youth
|
|
|
|
|
The end of the story -
"...and that's how I got to repeat introduction to programming!!"
|
|
|
|
|
Quite. The maturity of a programming language may (in part) be calculated by how many newlines are required. A proper language requires none.
|
|
|
|
|
PIEBALDconsult wrote: Quite. The maturity of a programming language may (in part) be calculated by how many newlines are required. A proper language requires none.
Just for making that statement, you should be forced to a maintain decade-old Perl CGI system.
|
|
|
|
|
Perl is a scripting language; not a programming language.
|
|
|
|
|
Yeah true, you really need to be pedantic about a joke?
|
|
|
|
|
No, but I really need to be demeaning of Perl.
|
|
|
|
|
Of course it is, or at least, it was. That's what we used to do when programming in APL. There were execution costs for each new line you used.
|
|
|
|
|
You guys need to investigate APL, a language described by one of my fellow students as "the ultimate in elegance"
Jim
|
|
|
|
|
Totally agree...but for a very spesific reason. I'm using a Braille display with a maximum of 40 chars per line, so it have a influence on my format preferences...
Seriously though,
if (condition)
{
Action1();
}
else
{
Action2();
}
is my real preference, and there's a plus to that, whenever the situation change to have more than one statement for the if test, the person who has to change it doesn't have to remember to go and fill in the {}.
|
|
|
|
|
That looks good to me
|
|
|
|
|
Too much whitespace/not enough whitespace. The "Great Debate" goes on.
Some programmers get paid by LOC, so they're induced to spread things out. Some programmers like to show how smart they are, so they try to condense everything to one line of cryptic functions. Other programmers heard "this" is the right way to do it.
For me, the key is "consistency". I want my code and all my programmers' code to look identical. It should be totally transparent who wrote the code. And the code needs to be clear, quickly comprehensible and understandable, yet concise.
I don't want to spend my time figuring out what John Doe was doing and maybe miss some key element when I'm under pressure to fix a problem or develop a new capability.
I tell my programmers that "I was around long before you came and I will be around long after you leave. Do it my way because I will have to maintain it later."
I just had to work on a one-liner script from another company that incorporated at least 12 function calls. Took me the better part of a week to figure out where the bug was. Yes it looked slick, but a week wasted is two weeks lost.
That's my thoughts--clear, comprehensible, concise.
|
|
|
|
|
I'm not lazy, but I'll still use the latter. There's no point in always having to use a bracket so I don't, unless it makes things easier to read. Which in your example it doesn't. Wasting space just makes a source code file longer anyway and harder to navigate. Concise wins, unless it's hard to read.
Jeremy Falcon
|
|
|
|
|
it doesn't make anything easier to read, and it definitely makes things harder to maintain.
|
|
|
|
|
Chris, you can't BS me, come on man. You honestly expect me to buy that not using brackets for a single-line if condition makes code harder to maintain? Seriously? Where's the joke icon?
Jeremy Falcon
|
|
|
|
|
Sure it's easy, until another developer adds a second line and forgets to add brackets.
I've been working in some source code that didn't use brackets for single statements. I introduced a few bugs by not adding them when I had to and I've been wondering more than once if the original developer REALLY meant not to add brackets....
if (condition)
DoThis();
else
DoThat();
DoAnotherThing(); is really weird to look at and at the very least makes you wonder if it was intended...
Especially if DoAnotherThing(); isn't properly in/outdented!
My blog[ ^]
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}
|
|
|
|
|
Ok, you have a good point with that, but it's still not worth the trade off of having really extra long files / routines. Besides, it gives you something to spot the new guys with so you can give them a hard time.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: it's still not worth the trade off of having really extra long files / routines It's really very much worth it. Look at it this way, if (it prevents a subtle bug from going into production (and dependent on your internal processes that chance may be a considerable risk)) { you may have saved that company downtime or wrong data and dependent on the size of that company a whole lot of money! } else { you just scroll a bit extra (it's negligable) and no one gets hurt... }
Jeremy Falcon wrote: so you can give them a hard time. If the new guy screws up I'm the one responsible and I can get to fix whatever he broke, so that joke's on me
My blog[ ^]
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}
|
|
|
|
|
Not being able to see your code as a whole can also cause much harder to spot subtle bugs as well. Still not worth the trade off.
Besides, you're forgetting this[^].
Jeremy Falcon
|
|
|
|
|
Your automated tests should prevent a subtle bug even making it into the testing environment.
No object is so beautiful that, under certain conditions, it will not look ugly. - Oscar Wilde
|
|
|
|
|
It's 2014, who cares how long the code file is. It's easier to read with the extra {}, it's easier to maintain with the extra {}. The only downside is typing extra {}. Don't you get paid per line anyway??
|
|
|
|
|
I care. Being able to see more at a glance is nice. It's also less convoluted when it's a simple statement. And I don't get paid per line, nobody does. I get paid to deliver a product that's useful. Nobody cares about line count except other nerds / devs.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: Ok, you have a good point with that, but it's still not worth the trade off of having really extra long files / routines. Besides, it gives you something to spot the new guys with so you can give them a hard time.
Who cares how long the files are? They aren't being printed on paper (hopefully), and scrolling is not so hard.
Setting a trap for junior programmers that introduces a bug is not responsible programming. If you do that, you are responsible for the bug, not the newbie, and you should be "given a hard time" for compromising the code base just to be a jerk.
|
|
|
|