Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Poll for c/c++ users - what styling do you prefer

Author
Message
IanG
20
Years of Service
User Offline
Joined: 25th Sep 2004
Location: Cyberspace
Posted: 20th Apr 2005 04:17
Do you prefer

style 1:


or

style 2:


thanks

*code borrowed from http://forum.thegamecreators.com/?m=forum_view&t=52194&b=20

Used to be Phoenix_insane registered in september 2003 despite what the date says to the left <--
PC - amd athlon 2.0ghz, 512mb, GeForce FX 5200 128mb, 200gb, xp pro sp2
billy the kid
19
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 20th Apr 2005 04:36
2

Ok now I dont mind the caps lock rule for letters. However when I just type "2" and I get the caps lock rule error, something is wrong. And I dont mean a bug, I mean you should be able to put just numbers without getting the caps lock rule error.
Antdizzle
20
Years of Service
User Offline
Joined: 6th Mar 2004
Location: Las Vegas
Posted: 20th Apr 2005 04:39
I prefer number one.
DBAlex
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: United Kingdom
Posted: 20th Apr 2005 04:41
I prefer number 1...I prefer my code not spaced out...




AMD 64 3000 + 512mb RAM + 80GB HD + Radeon 9600se 128mb
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 20th Apr 2005 04:43
I prefer #1.
And I believe you meant <= instead of ==. As it is, it won't print anything.

billy, what capslock rule are you talking about?

AphoticVM status: 30% (Yes, that number just went down.) AphoticBasic status: 10%
billy the kid
19
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 20th Apr 2005 04:46 Edited at: 20th Apr 2005 04:48
Try just posting with a number like "245" or with a word in all caps like "DUDE".

EDIT:
From my limited experience in industry, style 2 is the norm cause it is easier to read. However Im sure there are lots of professional programmers who like style 1 or prefer some other style.
Jimmy
21
Years of Service
User Offline
Joined: 20th Aug 2003
Location: Back in the USA
Posted: 20th Apr 2005 04:47
hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 20th Apr 2005 04:56
Number 2. It's much easier for me to read.

The Nerd
20
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Denmark
Posted: 20th Apr 2005 04:59
i like number 2 the best

*************
*panzergames*
http://www.panzergames.tekhawk.com
IanG
20
Years of Service
User Offline
Joined: 25th Sep 2004
Location: Cyberspace
Posted: 20th Apr 2005 05:02
I must admit that i am a 2 fan - spacing doesn't cost anything so you might as well use it

Used to be Phoenix_insane registered in september 2003 despite what the date says to the left <--
PC - amd athlon 2.0ghz, 512mb, GeForce FX 5200 128mb, 200gb, xp pro sp2
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 20th Apr 2005 05:05
I prefer style 2, however I do like things relatively compact while being easy to read. I would probably have it like this:



Then again I'm not sure.


"Lets migrate like bricks" - Me
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 20th Apr 2005 05:28
Style 2 for me...

Jimmy
21
Years of Service
User Offline
Joined: 20th Aug 2003
Location: Back in the USA
Posted: 20th Apr 2005 06:55
I like #1 because each block starts with one line and ends with one line. It's brilliant.

bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 20th Apr 2005 07:22
style 2 myself


Yarr join teh New and Improved LoGD!
Ace Of Spades
19
Years of Service
User Offline
Joined: 6th Mar 2005
Location: Across the ocean
Posted: 20th Apr 2005 08:57
When I am developing it myself, i prefer number one as it is a milisecond faster to type, but when i am reading someone else's code i prefer number two.
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 20th Apr 2005 09:36
Style 2,

But I like Benjamin's better.

Crazy Donut Productions
Current Project: A Redneck game
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Apr 2005 11:11
Benjamin's style, or simply style 2.

@Benjamin,
I used to have teachers yell at me for doing statements like that. And other students couldn't comprehend that its the number of commands in a block, not line count, that determine whether you needs brackets or not.

PETA - People for the Eating of Tasty Animals
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 20th Apr 2005 11:29
Quote: "I used to have teachers yell at me for doing statements like that"

I can understand that. I guess the reason its considered bad is because sometimes you might go back to that part of code, add more stuff, and not realise that the extra code will be ran without condition of a statement.

Personally, if I know for sure that I will be adding more code, I use brackets, but if its just one line of code, I leave the brackets out.

As for placement of brackets, style 2 is what I usually use, however for smaller structures (ones that contain about 3 lines of code or less) I prefer style 1 for some reason.


"Lets migrate like bricks" - Me
Sol462
20
Years of Service
User Offline
Joined: 12th Sep 2004
Location: playing with the spazookeedoo
Posted: 20th Apr 2005 13:15
Style 2, but for functions that just return a value I'll mix the 1 aspect with it.

BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 20th Apr 2005 15:10
For return values only I do this:

int function()
{return (42);}

Crazy Donut Productions
Current Project: A Redneck game
billy the kid
19
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 20th Apr 2005 15:37
strange!!!
EddieB
20
Years of Service
User Offline
Joined: 29th Sep 2004
Location: United Kingdom
Posted: 20th Apr 2005 15:49
Style 2 ( I need my space )

[href]http:www.graphics-monkey.co.uk[href]
"Him? A guru? Rich is the guru, David T is just good"
Jeku
Moderator
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 20th Apr 2005 18:37
I like style 1 for Java, C#, and C, but style 2 for C++...

Most company's coding standards will be style 2, however...


--[GameBasic - Coming Soon]-- ^^^ banner generously designed by TheBigBabou
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 20th Apr 2005 18:42 Edited at: 20th Apr 2005 18:43
I personally use the first one, but Uni coding standards require me to use the 2nd, actually, the Uni wants everything spaced out completely:



Quite over the top.


"Computers are useless, they can only give you answers."
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Apr 2005 21:57
I prefer Exeats 'over the top' example for new code. I use whatever is there already for existing code.

Ultimately, life's too short to worry about it too much

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
IanG
20
Years of Service
User Offline
Joined: 25th Sep 2004
Location: Cyberspace
Posted: 21st Apr 2005 01:27
in 99% of the time i will use brackets for single line ifs - just so i can come back and add more code without worrying to put in the brackets

Used to be Phoenix_insane registered in september 2003 despite what the date says to the left <--
PC - amd athlon 2.0ghz, 512mb, GeForce FX 5200 128mb, 200gb, xp pro sp2
Jeku
Moderator
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 21st Apr 2005 06:58
Quote: "Quite over the top."


Really? Well that's the way I do it 'normally'. I just have one exception--- my for loops are squished. But EVERYTHING else is spaced out for good reason.


--[GameBasic - Coming Soon]-- ^^^ banner generously designed by TheBigBabou
Neofish
20
Years of Service
User Offline
Joined: 7th Apr 2004
Location: A swimming pool of coke
Posted: 21st Apr 2005 07:06
2, my style varies though:

int function(int moo) { return moo; }

and again if it was a long function:

int function(int moo)
{
// lots of crap goes here

return moo;
}

"OC192...that's like the speed of light"
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 21st Apr 2005 10:52
Now that I think of it, I've made programs with the intention of being hard to read. So my teacher couldn't tell why it was that whatever she typed into the linux console showed up as an *. Even after I handed her the source code to the... bacteria.



I love the way C/C++ is so flexible.

AphoticVM status: 30% (Yes, that number just went down.) AphoticBasic status: 10%
Ace Of Spades
19
Years of Service
User Offline
Joined: 6th Mar 2005
Location: Across the ocean
Posted: 21st Apr 2005 10:55
Quote: "#include <iostream.h>
#include <windows.h>
int main(){for(
int year=0;year
== 99; year++){
for(intmonth=0;
month==11;month
++){for(int hour
=0;hour==23;hour
++){for(int min=
0;min==60;min++)
{Sleep(1000);cout
<<year<<":"; cout
<<month<<":";cout
<<hour<<":"; cout
<<min;}}}}}"



AHHHHHH!!!!!!

Digitalmodr
Coder_David
[Apolloed ]
Hoopkid ups
19
Years of Service
User Offline
Joined: 24th Nov 2004
Location:
Posted: 21st Apr 2005 12:34
I prefer this method:

GothOtaku
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location: Amherst, MA, USA
Posted: 21st Apr 2005 13:32
#1, I'm all about the 1TBS.

The One True Brace Style must be preserved! Death to the Infidels!
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 21st Apr 2005 13:38


That's how I do it:/


Yarr join teh New and Improved LoGD!
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 21st Apr 2005 14:08
How about this?

#include<iostream>
#include "specialdefine.cpp"
using namespace std;

WAKEUP
numbaneine num;
heyyou "Enter a number: ";
getoverhere num;
GETOUT



Inside "specialdefine.cpp"...


Crazy Donut Productions
Current Project: A Redneck game
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 21st Apr 2005 14:11
brilliant coding!!


Yarr join teh New and Improved LoGD!
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 21st Apr 2005 14:17
Quote: "Really? Well that's the way I do it 'normally'."


In my opinion it is, I'd much rather use:



Both the 'For' / 'If' keywords as well as the tabbing signify a new code block so there's no need to use another line on the '{' character. Actually, I wouldn't mind spacing out the for loops that much but using 3 lines for "} else {" is just ridiculous in my opinion. It takes too long to scroll through code that way.


"Computers are useless, they can only give you answers."
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 21st Apr 2005 14:23
I'm a little confused on your message there Jerico...?

Crazy Donut Productions
Current Project: A Redneck game
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 21st Apr 2005 14:46
Quote: "I'm a little confused on your message there Jerico...?"


Your quite rightly simplified C++ with that tip..

I'm off to go program an OS now that I can use regular english in C


Yarr join teh New and Improved LoGD!
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 21st Apr 2005 14:50
Ah I gotcha now, thought you were talking about just the i/o part...confuddled my mind (need coffee).

My college instructor showed me that and I instantly began to plot how I would make life miserable for my high school programming teacher.

Crazy Donut Productions
Current Project: A Redneck game
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 21st Apr 2005 15:08
Quote: "My college instructor showed me that and I instantly began to plot how I would make life miserable for my high school programming teacher."


Dumb teacher? If it were me I'd flat out fail you


Yarr join teh New and Improved LoGD!
Mnemonix
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 21st Apr 2005 22:08
No. 2 for me. I especially dislike Benjamins style(No Offence) because its lead to me having particular difficults making changes to code, but maybe thats just me.

Try out the controller:-
http://controller.logicstudios.net
IanG
20
Years of Service
User Offline
Joined: 25th Sep 2004
Location: Cyberspace
Posted: 22nd Apr 2005 01:01
to me code should always be easy to read - thats why my code has more comments about what the function does and how it does it than the code - that way i can tell what i am doing when i return to it months down the line

Used to be Phoenix_insane registered in september 2003 despite what the date says to the left <--
PC - amd athlon 2.0ghz, 512mb, GeForce FX 5200 128mb, 200gb, xp pro sp2
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 22nd Apr 2005 15:58
I've no doubt o'that Jerico . This guy tries to, but I just keep getting everything right (to his dismay). We have to write our algorithm and code down on a special form (even for something like printing out integers from a file), and show it to him and we're not supposed to code it until he signs us off. Naturally we code it first anyway and I am truly amused when I compile it fine, and then he tells me I'm wrong.

Crazy Donut Productions
Current Project: A Redneck game
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Apr 2005 16:01


PETA - People for the Eating of Tasty Animals
EddieB
20
Years of Service
User Offline
Joined: 29th Sep 2004
Location: United Kingdom
Posted: 22nd Apr 2005 16:11
How Sad....

[href]http:www.graphics-monkey.co.uk[href]
"Him? A guru? Rich is the guru, David T is just good"
IanG
20
Years of Service
User Offline
Joined: 25th Sep 2004
Location: Cyberspace
Posted: 23rd Apr 2005 04:21
but funny

Used to be Phoenix_insane registered in september 2003 despite what the date says to the left <--
PC - amd athlon 2.0ghz, 512mb, GeForce FX 5200 128mb, 200gb, xp pro sp2
Three Score
20
Years of Service
User Offline
Joined: 18th Jun 2004
Location: behind you
Posted: 25th Apr 2005 08:04
i like #1
although i would most likely if i was making something based on source i would use #2 for ease of reading

X-Patch x-patch.exe(gui):75% make.exe:5% x-patch.dll(runtime dll):0% developed on win xp home sp2
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 25th Apr 2005 08:43
#2

#1 bugs the crap out of me, anyone who codes using 1's standards, should die

[url="http://www.spreadfirefox.com/?q=affiliates&amp;id=0&amp;t=54"][/url]
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 25th Apr 2005 11:06 Edited at: 25th Apr 2005 11:08
Quote: "although i would most likely if i was making something based on source i would use #2 for ease of reading"

Generally code is source

Quote: "because its lead to me having particular difficults making changes to code, but maybe thats just me."

Haha, prawned.


"Lets migrate like bricks" - Me
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 25th Apr 2005 16:16
int x
while(x=1)
{
cout << "I pity Mr. T!\n...prawned???";
}

Crazy Donut Productions
Current Project: A Redneck game

Login to post a reply

Server time is: 2024-11-15 01:07:27
Your offset time is: 2024-11-15 01:07:27