coding

Place to talk about all that new hardware and decaying software you have.

Moderator: General Mods

Post Reply

So?

1
16
47%
2
18
53%
 
Total votes: 34

zoink
Rookie
Posts: 42
Joined: Mon Apr 25, 2005 7:02 pm

coding

Post by zoink »

in the light of useless polls.

what do you prefer?

1:

Code: Select all

int main(){
}
or
2:

Code: Select all

int main()
{
}
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

I used to do 1:, but 2 makes lots of sense when you need to check scope and errors.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
MisterJones
Trooper
Posts: 387
Joined: Fri Jul 30, 2004 6:25 am
Location: Mexico
Contact:

Post by MisterJones »

2. (IIRC, 1 is also known as West coast, and 2 as East coast. Source)

Because I can find the opening bracket by just looking above (assuming proper indentation). And folding feature in editors seem to work better with it.
_-|-_
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

I use a personal hybrid system based on '2':

Mode A =

Code: Select all

void func()
{
  <code block>
}
Openings and closings on the same column = clean, fast, efficient.

Mode B =

Code: Select all

if (test) { <single line> }
When both test conditions and single line is short enough to pull that in 80 columns. Same goes with else, while, for, do{}while... as long as total is under 80.

Mode C =

Code: Select all

while (huge_test || line && (here > kthx))
{ <or maybe that single line is a bit fat> }
When the previous mode doesn't work, fall back on that one

When Mode C fails, fall back on mode A. Indent by 2 for each {}.

Real sample using everything:

Code: Select all

  do
  {
    if (formula[i] == last) { times++; }
    else
    {
      sprintf(workbuf, "%s%u*%u", (*buffer) ? " + " : "", bases[last], times);
      if (times == 1) { workbuf[strcspn(workbuf, "*")] = 0; }
      last = formula[i];
      times = 1;
      strcat(buffer, workbuf);
    }
  } while (formula[i++]);

  total -= RANGE_MIN;

  if ((!strlen(best[total])) || (strlen(buffer) <= strlen(best[total])))
  { memcpy(best[total], buffer, 1024); }
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
byuu

Post by byuu »

One, but with a space before the bracket.

Code: Select all

void func() {
  ftw();
}
No sense wasting an extra line, indentation reveals scope just fine.
MisterJones
Trooper
Posts: 387
Joined: Fri Jul 30, 2004 6:25 am
Location: Mexico
Contact:

Post by MisterJones »

byuu wrote: No sense wasting an extra line
Which IIRC is just 2 bytes, if that.

Grin - In a way I am like that. However, for an if statement that includes an else, I go 2.

Single line code chunks I use the most at functions that just return a value. IE:

Code: Select all

getName() { return name; }
_-|-_
byuu

Post by byuu »

I said "no sense wasting an extra line", and not "no sense wasting another two bytes of disk space". With my text editor, I see about 25-30 lines onscreen at once. With my functions, generally 5-8 of those lines contain opening brackets. Therefore, I can see more of my code at one time, which for large functions, is a good thing (tm).
whicker
Trooper
Posts: 479
Joined: Sat Nov 27, 2004 4:33 am

Post by whicker »

Code: Select all

//code comment here
do {

} while TRUE;

//comment for the next block of code
if (0 > 1) {
    //meh
    meh(1);
} else {
    //not so meh
    neh(0);
};
SquareHead
Veteran
Posts: 970
Joined: Fri Jan 21, 2005 11:15 am
Location: Montana, United States

Post by SquareHead »

I was taught to keep it easy to read as in #2.
spoon0042
Rookie
Posts: 46
Joined: Mon Jun 12, 2006 9:52 pm

Post by spoon0042 »

Voted 1 since that's what I use for most things, except main() for some reason. (At least I think so, I can't actually find any code that I've written lately.)
creaothceann
Seen it all
Posts: 2302
Joined: Mon Jan 03, 2005 5:04 pm
Location: Germany
Contact:

Post by creaothceann »

#1 for my Pascal code. If I'd program in C-style languages I'd probably use #2.

Generally I try to save as much vertical space as possible, which for example means no blank lines in functions, and comments to the right side whenever possible.

Sample: link
vSNES | Delphi 10 BPLs
bsnes launcher with recent files list
OutrightOwnage
Rookie
Posts: 11
Joined: Sun Jul 30, 2006 3:50 am

Post by OutrightOwnage »

i use 2, for everything.

like:

Code: Select all

if( x == 3 )
{
	//do something
}
else if( x == 4 )
{
	//do something else
}
else
{
	//shouldn't get here - it means somethings screwy elsewhere
}
ok, spaces or tabs for indentation?

i use tabs. i see flamewars over 2 or 4 or omg 8 spaces. wtf? if you use tabs, any decent text editor can show them _whatever size you want_.

i used to be kind of wishy-washy until i tried learning python. i switched text editors at some point, i forget from what to what, and one of them tried to guess my indent levels, and like somehow screwed up the indentation levels. took me like 20 minutes to convert everything to tabs.
blackmyst
Zealot
Posts: 1161
Joined: Sun Sep 26, 2004 8:36 pm
Location: Place.

Post by blackmyst »

2, because it feels better. Idunno. Byuu's reason is good though.
[size=75][b]Procrastination.[/b]
Hard Work Often Pays Off After Time, but Laziness Always Pays Off Now.[/size]
MisterJones
Trooper
Posts: 387
Joined: Fri Jul 30, 2004 6:25 am
Location: Mexico
Contact:

Post by MisterJones »

byuu wrote:I said "no sense wasting an extra line", and not "no sense wasting another two bytes of disk space". With my text editor, I see about 25-30 lines onscreen at once. With my functions, generally 5-8 of those lines contain opening brackets. Therefore, I can see more of my code at one time, which for large functions, is a good thing (tm).
Code folding is a good IDE feature you might want to use further, if you haven't already.
_-|-_
creaothceann
Seen it all
Posts: 2302
Joined: Mon Jan 03, 2005 5:04 pm
Location: Germany
Contact:

Post by creaothceann »

Tabs, default size of 8 chars. No, I haven't run out of horz. space yet.

<rant>
The problem with tabs is that they are inserted into the files just like you entered them. Editors should just use the TAB key to goto the next column, and insert tabs when the file is saved.
</rant>

Btw. are there editors that display the columns? Haven't ecountered one yet, afaik.
vSNES | Delphi 10 BPLs
bsnes launcher with recent files list
MisterJones
Trooper
Posts: 387
Joined: Fri Jul 30, 2004 6:25 am
Location: Mexico
Contact:

Post by MisterJones »

creaothceann wrote:Tabs, default size of 8 chars. No, I haven't run out of horz. space yet.
That would be a killer for me. 4 spaces tops. Much more comnfortable for my reading. Same goes for xHTML/xml.
creaothceann wrote:<rant>
The problem with tabs is that they are inserted into the files just like you entered them. Editors should just use the TAB key to goto the next column, and insert tabs when the file is saved.
</rant>
I think you want soft tabs or something. Crimson editor lets you convert between spaces and tabs at any time.
Btw. are there editors that display the columns? Haven't ecountered one yet, afaik.
Define display. if by that you just mean a place where the column number is displayed, any decent editor should havce one. If you mean a "show column number", I don't think it exists, probably because of vwfs.
_-|-_
OutrightOwnage
Rookie
Posts: 11
Joined: Sun Jul 30, 2006 3:50 am

Post by OutrightOwnage »

creaothceann wrote:Tabs, default size of 8 chars. No, I haven't run out of horz. space yet.

<rant>
The problem with tabs is that they are inserted into the files just like you entered them. Editors should just use the TAB key to goto the next column, and insert tabs when the file is saved.
</rant>

Btw. are there editors that display the columns? Haven't ecountered one yet, afaik.
editors that save tabs as spaces suck major ass. get you a better editor ma friend. and codeblocks has a show indentation option that puts vertical lines where columns are.
Lord Alpha
Lurker
Posts: 165
Joined: Wed Jul 28, 2004 3:15 am
Location: The Land of Insanity
Contact:

Post by Lord Alpha »

I'm a C n00b so I use 1... I think.

Something like this:

Code: Select all

void foo () {
    if (bar) {
        //do stuff
    } else {
        //do other stuff
    }
}
It is better to be silent and thought a fool then to open your mouth and remove all doubt

I am Zophar, Master of Sh*t!

[url=http://archlyn.bravejournal.com]View my blog[/url]
creaothceann
Seen it all
Posts: 2302
Joined: Mon Jan 03, 2005 5:04 pm
Location: Germany
Contact:

Post by creaothceann »

MisterJones wrote:
creaothceann wrote:<rant>
The problem with tabs is that they are inserted into the files just like you entered them. Editors should just use the TAB key to goto the next column, and insert tabs when the file is saved.
</rant>
I think you want soft tabs or something. Crimson editor lets you convert between spaces and tabs at any time.
Alright, I'll check it out.
MisterJones wrote:
Btw. are there editors that display the columns? Haven't ecountered one yet, afaik.
Define display. If by that you just mean a place where the column number is displayed, any decent editor should havce one. If you mean a "show column number", I don't think it exists, probably because of vwfs.
No, not the column number. I mean the columns, as in colored vertical bars behind the code (or single colored lines between the columns).
OutrightOwnage wrote:editors that save tabs as spaces suck major ass. get you a better editor ma friend. and codeblocks has a show indentation option that puts vertical lines where columns are.
I can save tabs as spaces. The problem is, during loading a file, converting from spaces to tabs. And I want them because tabs drastically speed up the cursor scrolling and help with the code formatting.
vSNES | Delphi 10 BPLs
bsnes launcher with recent files list
MisterJones
Trooper
Posts: 387
Joined: Fri Jul 30, 2004 6:25 am
Location: Mexico
Contact:

Post by MisterJones »

creaothceann wrote: No, not the column number. I mean the columns, as in colored vertical bars behind the code (or single colored lines between the columns).
I think no editor has support for that.
creaothceann wrote:And I want them because tabs drastically speed up the cursor scrolling and help with the code formatting.
While the second point is valid, by ctrl scrolling (ctrl+left or right) your first point is moot :P
_-|-_
creaothceann
Seen it all
Posts: 2302
Joined: Mon Jan 03, 2005 5:04 pm
Location: Germany
Contact:

Post by creaothceann »

Ctrl+Left/Right works on per-word, so it depends on what is already on the line. I'm just not used to that. :wink:
vSNES | Delphi 10 BPLs
bsnes launcher with recent files list
Post Reply