Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   "White space" (http://www.chiefdelphi.com/forums/showthread.php?t=75948)

Alan Anderson 18-03-2009 16:01

Re: "White space"
 
Quote:

Originally Posted by basicxman (Post 837826)
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

Re: "White space"
 
Quote:

Originally Posted by Alan Anderson (Post 837862)
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

Re: "White space"
 
Quote:

Originally Posted by EricVanWyk (Post 837863)
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

Re: "White space"
 
I love white space. I do stuff like this:
Code:

function(
        int    parameter 1 , //comment
        int    parameter 2 , //comment
...
        word    parameter20 ) //more comment

Unfortunately the other programmers would do stuff like:
Code:

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

Re: "White space"
 
Quote:

Originally Posted by Alan Anderson (Post 837862)
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

Re: "White space"
 
You are missing an option on that poll:

"I can't even read my own code"

basicxman 19-03-2009 00:18

Re: "White space"
 
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

Code:

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

Re: "White space"
 
Quote:

Originally Posted by Lord_Jeremy (Post 837887)
I love white space. I do stuff like this:
Code:

function(
        int    parameter 1 , //comment
        int    parameter 2 , //comment
...
        word    parameter20 ) //more comment

Unfortunately the other programmers would do stuff like:
Code:

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

Re: "White space"
 
Quote:

Originally Posted by EricH (Post 838091)
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

Re: "White space"
 
Quote:

Originally Posted by Lord_Jeremy (Post 838260)
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

Re: "White space"
 
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:
Code:

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

Re: "White space"
 
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

Re: "White space"
 
Quote:

Originally Posted by virtuald (Post 837606)
Why wouldn't you use white space?

Ditto that. Was wondering why there wasn't a poll option for that...


All times are GMT -5. The time now is 13:55.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi