Log in

View Full Version : "White space"


cooldude8181
17-03-2009, 23:20
Who uses white space???

(if you don't know what that is, it is like making your programs easy to read)

virtuald
17-03-2009, 23:23
Why wouldn't you use white space?

Joe Ross
17-03-2009, 23:31
I use it so I can read my code.

R.C.
17-03-2009, 23:33
Why wouldn't you use white space?

You would be surprised, some people just don't like to organize their code after its written.

virtuald
17-03-2009, 23:36
You would be surprised, some people just don't like to organize their code after its written.

I know that some people don't use whitespace, I'm just questioning why one would want to do so (ie, it seems like the OP is trying to make a case for not using whitespace). As Joe pointed out, using whitespace makes your code easier for you (and everyone else) to read.

Generally, the argument is for how much whitespace is enough, and usually boils down to personal opinion. Personally, I like white space.

ChuckDickerson
17-03-2009, 23:47
Why wouldn't you use white space?

It adds too much weight to the robot. Each space = ~0.0001327 oz. Tabs are either 4 or 8 times that depending on your editor settings. Count up all the white space in your code sometime and calculate how much weight it adds.


:p

R.C.
17-03-2009, 23:52
I know that some people don't use whitespace, I'm just questioning why one would want to do so (ie, it seems like the OP is trying to make a case for not using whitespace). As Joe pointed out, using whitespace makes your code easier for you (and everyone else) to read.

Generally, the argument is for how much whitespace is enough, and usually boils down to personal opinion. Personally, I like white space.

Oh, don't get me wrong I totally agree with you. But some people are lazy and tend not to use whitespace. Using whitspace makes code easier to read and it allows for easy editing. Comments are another big issue that some people do not use (cough our programmer sometimes).

EricVanWyk
18-03-2009, 00:02
Did anyone else think of the programming language whitespace (http://en.wikipedia.org/wiki/Whitespace_(programming_language))?

After writing a bit in Python (http://en.wikipedia.org/wiki/Python_(programming_language)), I more fully appreciate proper formatting for code. Programming is codified communication, with the machine and with the human. I don't over kill on it in other languages, but I do try to maintain some semblance of order, even if I'm just writing a short script to check my calculations.

Cow Bell Solo
18-03-2009, 02:16
I like to use white space, especially since I'm not the only one working or reading the code. Also my dad is a software engineer, and he has shared with me when he looks at code that a group is working on and they don't comment or orginize their code. Especially when others have to understand and read the code.

swamp_child
18-03-2009, 07:38
It adds too much weight to the robot. Each space = ~0.0001327 oz. Tabs are either 4 or 8 times that depending on your editor settings. Count up all the white space in your code sometime and calculate how much weight it adds.


:p
for the same reason we usually don't use comments.

Bongle
18-03-2009, 07:47
I love whitespace! If the OP is trying to argue against it, he's in for a surprise if he ever gets a programming job. Even if you can read non-whitespaced code, nobody else can.

Some kids I've mentored in the past didn't use tabs at all, and it was painful to look at. It was impossible to tell, at a glance, when functions started, the scope of loops, etc. It was all either memorization or bracket-counting.

The Lucas
18-03-2009, 09:21
This year I found the majority of compilation errors that I helped my students fix were due to mismatched braces (usually with inconsistent indention). Whitespace is good, especially if you want quick help.

Helpful Windriver tip: Select your code and press Ctrl-I to auto indent your code

Mr. Freeman
18-03-2009, 13:35
I know that some people don't use whitespace

There are people that write their programs on a single line?

billbo911
18-03-2009, 14:06
I use it as much as possible.
I tend to follow the statement I believe Alan Anderson made: "Software is documentation that compiles into code". I my have mis-quoted that, but you get the idea.

basicxman
18-03-2009, 14:18
It adds too much weight to the robot. Each space = ~0.0001327 oz. Tabs are either 4 or 8 times that depending on your editor settings. Count up all the white space in your code sometime and calculate how much weight it adds.


:p

I sincerely hope you're joking. Extra code doesn't add any weight.

Alan Anderson
18-03-2009, 16:01
Extra code doesn't add any weight.

Right. It's the other way around. The erased state of flash memory is a logic one, so adding code actually removes bits. :p

EricVanWyk
18-03-2009, 16:04
Right. It's the other way around. The erased state of flash memory is a logic one, so adding code actually removes bits. :p

Bah, the weight savings of a few electrons in flash are nothing. We added a few vandegraph generators to the bot to remove some real electrons!

billbo911
18-03-2009, 16:25
We added a few vandegraph generators to the bot to remove some real electrons!

And you wonder why we are getting static charge build up this year.

:rolleyes:

Lord_Jeremy
18-03-2009, 17:13
I love white space. I do stuff like this:
function(
int parameter 1 , //comment
int parameter 2 , //comment
...
word parameter20 ) //more comment


Unfortunately the other programmers would do stuff like:
function(int parameter1,int parameter2, ... word parameter20)
All on one line. And when I space it out they complain! It's horrible!

writchie
18-03-2009, 19:46
Right. It's the other way around. The erased state of flash memory is a logic one, so adding code actually removes bits. :p

Ahhh, but the process of writing a "zero" is done by injecting electrons into the float gate. So a programmed device has the mass of these electrons (which is of course negligible).

dooey100
18-03-2009, 21:22
You are missing an option on that poll:

"I can't even read my own code"

basicxman
19-03-2009, 00:18
Sorry I didn't specify, adding or removing code does not change the weight!! :p

Anyways, here's some sample code from my joystick for FTC, this is how I like things whitespaced


while (true) { //whitespace after an important conditional or loop

getJoystickSettings(joystick); //single linebreak for basic commands and function calling
setMotors("default"); //double linebreak when another main conditional is about to appear

if (joystick.joy1_y1 > 40 || joystick.joy1_y1 < -40) { //single linebreak for a final conditional in nests
motor[motorD] = joystick.joy1_y1;
}

}

EricH
19-03-2009, 01:01
I love white space. I do stuff like this:
function(
int parameter 1 , //comment
int parameter 2 , //comment
...
word parameter20 ) //more comment
Unfortunately the other programmers would do stuff like:
function(int parameter1,int parameter2, ... word parameter20)All on one line. And when I space it out they complain! It's horrible!

It actually makes more sense (to me) to have it on one line with a few spaces in between. Ideally, you've chosen descriptive variable names, so comments are not totally necessary.

Now, if a line is getting too long, I will break it between parameters to for readability.

And no, I haven't had anyone complain about not enough whitespace yet. The parameters for my C++ class last semester were something like 1 extra line between groups of lines (say, between 2 for loops) and 3 lines between functions, plus the comment lines. I think I had about 650+ lines for a "voting machine" program, including whitespace and comment after comment after comment--and throw in some code for good measure.:D

Actually, one quote I've seen on here in the spotlights is: "A programmer's job is to write documentation that just happens to compile.", or something like that. Because it's documentation, it needs to be readable. I'd have a hard time reading the code above, due to the fact that having all the parameters separate from the header makes them look like variable declarations within the function. That's probably why they're complaining--they can't tell whether or not you're declaring variables or parameters. If you do do it this way, you might want to indicate in the comment that it's a parameter before anything else.

Lord_Jeremy
19-03-2009, 15:48
It actually makes more sense (to me) to have it on one line with a few spaces in between. Ideally, you've chosen descriptive variable names, so comments are not totally necessary.

Now, if a line is getting too long, I will break it between parameters to for readability.

I usually only space out the parameter list when there's a large number of parameters. In the example I tried to show that there were 20 parameters :P

EricH
19-03-2009, 15:50
I usually only space out the parameter list when there's a large number of parameters. In the example I tried to show that there were 20 parameters :P
What I prefer to do is to put a parameter list in the header comment. No extra comments... and the list is right behind it.

Then again, you should see some of my if statements and the conditions in them...

Andrew Schreiber
19-03-2009, 16:20
I would like to bring up the topic of the ternary operator. For those of you who do not know, in C you can use a?b:c; and have it as a completely valid statement so for example:

int foo(int bar)
{
return bar>0?1:-1;
}


The above is valid code and will return -1 if bar is negative and 1 otherwise. This is pretty clean code and, assuming you know the operator, is easy to read. Just curious what people think about it since we are talking about making code easier. I know that most of my college professors, though knowing the operator, do not like me using it.

nathanww
19-03-2009, 17:22
ternary operator=blech. The problem with it is even if you know what it does(which not everyone does), I prefer syntax that actually reflects the logic of the process(like a standard if/else)

As for whitespace--I am known among some people for writing "MLA code"--basically, I code the same way that I would right an essay, with indents, paragraphs, etc.

kyungjin
29-03-2009, 17:02
Why wouldn't you use white space?Ditto that. Was wondering why there wasn't a poll option for that...