Which is easier to read:

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

BigWinston78

Junior Member
Jul 30, 2008
7
0
0
In my opinion, putting parameters (or anything of multiples for that matter) on their own separate line is just stupid. It takes up way too much screen space and doesn't make the code any easier to read.

What I am used to (and I develop in a very process driven industry with strict style guidelines) is that you should never exceed 80 characters per line, so if you want to print of your code for a review (or whatever) it all fits on one line and doesn't wrap.

Anything else is fair game.

Slap him and tell him to stop being so anal. Its not HIS code.
 
Sep 29, 2004
18,665
67
91
1) The person you are working with is unprofessional. No one should ever edit another persons code without permission! There is something called sense of accomplishment and if someone is doign this, it is totally inappropriate, especially if it is a superior of yours like a software lead.

2) The new format is the worst way of doing things. That siad, to many parameters on one line also sucks.

The only real answer is that you need to make it clean and human readable while not wasting space. I usually wrap long lines following the 80 column rule. I'd possibly do this.
ProductItem productItem = new ProductItem(pd.RGB, pd.Name,
index, pd.ProductGroup,
"User Defined");

You can not see it, but each line would line up with the opening parenthesis from the first line.

Any way you do it, you should try to be consistent through a project and there should be style guidelines. REMEMBER THOUGH, GUIDELINES ARE NOT REQUIREMENTS.

It is my opinion that code should be as compact vertically as is possible. Within reason of course. That way, it is easier to read and understand the flow.
 
Sep 29, 2004
18,665
67
91
Originally posted by: techfuzz
Originally posted by: degibson
I like to maintain 80-character (or depending on the project style restraints, sometimes 60 or 70) width. I wrap parameters to maintain that width... I don't believe in using one style in all cases. It also varies by language.
However, my default is no wrapping.

Get a wider monitor

techfuzz

I think the 80 column rule is antiquated. We do not print code out much anymore and monitors can support more columns. Form palying around though, you can't do much more than 80. 100 is pretty good but if you were to do 100+ things start getting messy.
 
Sep 29, 2004
18,665
67
91
Also, many people do not do it, but on average every 5 lines of code should have a comment. You think your code will be perfect for you and never need maintenance but I can tell you from experience that if you think this you are naive.
 

JACKDRUID

Senior member
Nov 28, 2007
729
0
0
in this case, there is only 5 items in parameter.

but if its something over 10 items, option #2 would be better.

also, option #2 should be like this

ProductItem productItem = new ProductItem
(
pd.RGB
, pd.Name
, index
, pd.ProductGroup
, "User Defined"
);
 
May 8, 2007
86
0
0
I like to code using option #2 a lot myself for a variety of reasons. Mainly its easy to check for syntax errors in your code, and generally it gives a sense of code hierarchy that option 1 does not. IMO its like coding in sentences vs coding in bullet points. Your method may code fine, but when you want to review the i/o in a function call its going to a little bit harder.

As others have mentioned, when you get functions w/ many inputs a one-liner makes it that much harder to align input with function variables.
 
Oct 27, 2007
17,010
1
0
Originally posted by: Common Courtesy
#2 ONLY IF you are going to self document each parameter

They should be documented at the method declaration. There are situations where the call should be separated onto two lines but one line for each parameter is just weird and wasteful.
 

Net

Golden Member
Aug 30, 2003
1,592
2
81

int x
= 5;

val
=
5
+
6
%
2

i guess in crazy land this might be good way to program?
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: IHateMyJob2004
Originally posted by: techfuzz
Originally posted by: degibson
I like to maintain 80-character (or depending on the project style restraints, sometimes 60 or 70) width. I wrap parameters to maintain that width... I don't believe in using one style in all cases. It also varies by language.
However, my default is no wrapping.

Get a wider monitor

techfuzz

I think the 80 column rule is antiquated. We do not print code out much anymore and monitors can support more columns. Form palying around though, you can't do much more than 80. 100 is pretty good but if you were to do 100+ things start getting messy.

I also rarely, if ever, print code. The 80 column rule for me comes from various projects' style guides: If the code I'm working on has a style guide, I follow it to the best of my sanity.

Otherwise, I format it such that I can read it conveniently on a framebuffer console. I prefer a windowing environment, but I try not to assume one.
 

alocurto

Platinum Member
Nov 4, 1999
2,173
0
76
Originally posted by: Drakkon
ive used one param per line when setting up fairly lengthy calls (i.e. when it wraps to 1 or more lines) but not for ALL calls.

 

nakedfrog

No Lifer
Apr 3, 2001
58,570
12,874
136
Originally posted by: drebo
Option 1 is much easier to read.

I've used similar to Option 2, but only ever in very long SQL queries.

For general programming, Option 2 is a waste of time and screen space.

Maybe he works under the Peter Principle.

Yeah, it works for Wall of SQL... hate trying to pick through a 4,000 character SQL statement to see which value is somewhere.
 

Snapster

Diamond Member
Oct 14, 2001
3,917
0
0
Originally posted by: drebo
Option 1 is much easier to read.

I've used similar to Option 2, but only ever in very long SQL queries.

For general programming, Option 2 is a waste of time and screen space.

Maybe he works under the Peter Principle.

^^
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
These debates are always stupid. Get a code formatter and run it to your prefered style when you work on it, he can do he same when he does.
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
I prefer the first one. I hope the other guy did other more productive things besides wasting his time reformatting your code.
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
I use both styles, it depends on what parms are being passed. For example, in web development, some jquery ui or extJS calls would be wrapping around my screen if I did not break then down into individual lines.
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
I use both styles. Depending on what I'm doing, I usually opt for Style 1, but if I have a funky function I go for Style 2. That keeps me keen to all that's going on.
 

zach0624

Senior member
Jul 13, 2007
535
0
0
Originally posted by: techfuzz
1

2 is just painful to look at

techfuzz

I'm just learning how to program but I like to keep my code all neat and on one line(option 1) because it is much easier to read and fix my many, many mistakes.
 

Hyperblaze

Lifer
May 31, 2001
10,028
1
81
I use whatever style is easier to understand and read.

Sometimes this requires me to break things down in mutiple lines (sql queries especially)

If I have trouble reading and understanding code quickly, there is a problem right there.

My time should be spend coding. Understanding lines of code should be easy if done in a clean and efficient manner
 

AyashiKaibutsu

Diamond Member
Jan 24, 2004
9,306
3
81
I consider horizontal whitespace to be valuable. You want logical sections of code to fit on one screen since it makes it a lot easier to understand code as a whole. Goofy seperation of calls definitely impedes this...
 

KingGheedora

Diamond Member
Jun 24, 2006
3,248
1
81
#2 is perfectly acceptable if doing #1 would require scrolling to read any part of that line of code. Sometimes this is necessary even with 5 or fewer variables because you are in line of code that is nested levels deep within code constructs (i.e. namespace->class->method->loop->boolean->etc) and therefore have a high number of indents on the line of code. I hate having to scroll left and right when reading or working with code.
 
Sep 29, 2004
18,665
67
91
Originally posted by: degibson
Originally posted by: IHateMyJob2004
Originally posted by: techfuzz
Originally posted by: degibson
I like to maintain 80-character (or depending on the project style restraints, sometimes 60 or 70) width. I wrap parameters to maintain that width... I don't believe in using one style in all cases. It also varies by language.
However, my default is no wrapping.

Get a wider monitor

techfuzz

I think the 80 column rule is antiquated. We do not print code out much anymore and monitors can support more columns. Form palying around though, you can't do much more than 80. 100 is pretty good but if you were to do 100+ things start getting messy.

I also rarely, if ever, print code. The 80 column rule for me comes from various projects' style guides: If the code I'm working on has a style guide, I follow it to the best of my sanity.

Otherwise, I format it such that I can read it conveniently on a framebuffer console. I prefer a windowing environment, but I try not to assume one.

The only problem with style guides is that "experienced" software people tend to write them. The 80 column guide is antiquated but still around for one reason. People with more experience (aka: used to doing things the way they used to) write the guides and put in the 80 column rule for the sake of putting in the 80 column rule.
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,674
145
106
www.neftastic.com
Frankly the latter is one of the reasons I hate Delphi ... seems like most Delphi programmers do that. One friggin line please so I don't look at half lines of code trying to figure out what it does.
 

Kyteland

Diamond Member
Dec 30, 2002
5,747
1
81
Our style guide states that if you do any wrapping at all then you should put each parameter on it's own line. Whether to wrap or not is left to the discretion of the individual.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |