Jump to content

Coding Methods

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
What is the correct way to program. In certain languages you should post the { on a new line like

if (a == b)
{

And then in others you post on the same line

if (a == b) {

I prefer the method above. I try to leave a comment above anything major such as

// This determines ......
if (a == b) {

and of course an explanation above every function. If I have a nest IF/FOR/function statment I try to comment the ending }


// Main Function

void main() {

 

  // The Dermines .....

   if (a == b) {

       code.....

   } // End If


}



What standard do you guys use?

#2
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests
I use similar although I put the bracket { on a new line like
if (a == b)
{

I think it looks cleaner.

#3
sigs

sigs

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
i would prefer starting the new command in a new line. its always better to do so as far as i think.

#4
moonrise

moonrise

    Learning Programmer

  • Members
  • PipPipPip
  • 40 posts
i also use to put in a new line only

#5
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
As everyone should know by now, the K&R style of putting the brace at the end of the line is The One True Brace Style. ;)
However, VS.NET does (by default) force you to use the inferior BSD/Allman style of taking an entire line for a single brace.
That's why I prefer VB.NET. :D

#6
Crane

Crane

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 398 posts

brackett said:

As everyone should know by now, the K&R style of putting the brace at the end of the line is The One True Brace Style. ;)
However, VS.NET does (by default) force you to use the inferior BSD/Allman style of taking an entire line for a single brace.
That's why I prefer VB.NET. :D

I've never heard of the names for either style. Where did you learn about these? The admin needs to make a sticky about the two different styles.

"The One True Brace Style" - lol :)

#7
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts

Crane said:

I've never heard of the names for either style. Where did you learn about these? The admin needs to make a sticky about the two different styles.

"The One True Brace Style" - lol :)

I think I first came across the naming convention on somebody's C# blog that linked to the Wikipedia entry. Before that, I just defended the K&R style as being classic and wasting less lines - it also maps nicely to my preferred syntax - VB.NET. Then again, most of my C code is done in vi, so fitting as much as possible on a screen is pretty helpful.

#8
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
Interesting. I've never heard of either style being named. I'm going to dig up some information on them.

#9
Frantic

Frantic

    Learning Programmer

  • Members
  • PipPipPip
  • 91 posts
I always put my {on the same line, its much easier to read.

I end it though on a line of its own.

#10
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
I have never heard names for them. I use "The One True Brace" style (where it is on a seperate line).

#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I always put my { on a new line. I think it's partially a holdover from when I programmed in Pascal and had the keywords Begin and End on seperate lines.

I recently read The Elements of C++ Style and it says to just pick one and be consistent. If you're programming with other people, you should all be doing the same thing.