![](_gb_images/_gb_sitenav_spacer.gif) |
![](_gb_images/_gb_clear.gif) |
Coding Habits
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Grizzled Veteran
Join Date: Jun 2001
Status:
Offline
|
|
When I'm writing code, I find it helpful to play something instumental in iTunes like movie scores or some non-English moody music like Enya or Adiemus. I also tend to log off iChat and quit Mail so nothing interrupt my flow. And quit any non-essential apps, except for Photoshop...you never know when you'll need to manipulate an image :-P
And by the way, creating functions like this
{
![](http://www.command-tab.com/images/spacer.gif) is the right way
}
not{
![](http://www.command-tab.com/images/spacer.gif) this
}
What kinds of things to you guys/gals do when coding? :-P
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Registered User
Join Date: Feb 2003
Status:
Offline
|
|
I love dead silence, maybe a faint radio more as subtle noise in the next room, thats it or I get distracted.
As for formating style see your language specification, which usually clearly states how to do it. I however find version one is more popular style, but it takes some getting used to and it takes up less vertical space.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
Ahh someone else who likes spacing things out!
I like to have chat open and mail open and the net open and maybe the tv going. Well the tv can be interrupting sometimes... Oh and I like it when noone is around too!
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
I agree with your function syntax. If-Else blocks should be created similarly. Braces should always be on their own lines!
Oh, and
Code:
if (bracesAreLikeThis)
{
die();
}
else
{
fork();
}
is the worst! ![Big Grin](http://forums.macnn.com/images/smilies/oldschool/biggrin.gif)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Here's my preferred syntax:
Code:
private static Hashtable getHash(File[] list)
{
Hashtable hash = new Hashtable();
if (list == null)
{
return hash;
}
for (int index = 0; index < list.length; index++)
{
if ( ! list[index].equals("") )
{
File real_file = list[index];
hash.put(real_file.getName(), real_file);
}
}
return hash;
}
As to noise and whatnot, I work in a cube farm, so quiet is not an option. I just get into a zone and ignore my surroundings. When I'm at home, I generally code in bed with the lights off while my wife sleeps next to me.
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status:
Offline
|
|
aaahhhh!
Pet peeves:
1 declaring variables in the for loop, anywhere in the for loop. In any loop for that matter.
2 using i++ instead of ++i when you not using pre incremented value.
(
Last edited by BLAZE_MkIV; Mar 1, 2004 at 02:14 PM.
)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
Originally posted by BLAZE_MkIV:
Pet peeves:
2 using i++ instead of ++i when you not using per incremented value.
You're weird.
If you aren't using the pre-incremented value, it doesn't matter if you use i++ or ++i. Why would one of those bother you over another?
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status:
Offline
|
|
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
Ok, so I see your point when you are incrementing a custom Fraction object that you create in C++. I could have told you as much, before.
However, I'm not at all convinced that ++i is faster than i++ when i is a primitive integer. Sure, theoretically you might have to allocate a little more memory for what you are returning. However, a compiler worth anything should see that in
for (int i = 0; i < NUM; i++)
the value returned by i++ is never actually used. Thus, a decent compiler should change it to:
for (int i = 0; i < NUM; i = i + 1)
negating the problem alltogether.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status:
Offline
|
|
Its about habbits, if you get in the habit of doing it that way and you eventually use a non simple type you get to eat a allocation, 2 copy contructors and a deallocation.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
Bah, I'm too lazy to code an increment operator on a non-simple datatype, let alone use one.
![Big Grin](http://forums.macnn.com/images/smilies/oldschool/biggrin.gif)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
Originally posted by Arkham_c:
When I'm at home, I generally code in bed with the lights off while my wife sleeps next to me.
Glad I'm not the only person who does this.
I use the same syntax as you, too, even down to the spacing in the if() statement that contains a leading bang (!).
Wow, that was a pretty geeky sentence...
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
Originally posted by smeger:
Glad I'm not the only person who does this. ![Smilie](http://forums.macnn.com/images/smilies/oldschool/smile.gif)
I use the same syntax as you, too, even down to the spacing in the if() statement that contains a leading bang (!).
Wow, that was a pretty geeky sentence...
Geeky maybe so... but then does it really matter? ![Big Grin](http://forums.macnn.com/images/smilies/oldschool/biggrin.gif)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
Pet peeves:
1 declaring variables in the for loop, anywhere in the for loop. In any loop for that matter.
What is wrong with that? What if you only need the variable in the loop?
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status:
Offline
|
|
if its just the incrementer in a for loop, it not technically wrong but i find it to look messy, and annoying to move if it turns out i need it, oh and the debugger looses access to it when the loop exits.
If you declare variables in the loop depending on the compiler they may end up being pushed and popped off the stack everytime through.
All that and I like my local variables grouped at the top of the function so I don't have to hunt them down, big fan of copy and paste with long variable names.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Junior Member
Join Date: Sep 2003
Location: Nowhere, Missouri
Status:
Offline
|
|
I like listening to some beaty music (Green Day, t.A.T.u, etc.), laying in bed with my iBook. Mail, iChat, and Safari are a must. I can't do this alone!
I prefer the braces be like this:
{
doStuff
}
Incrementals go outside the for loop.
Anything else you need/want to know?
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
hayesk
|
|
Originally posted by Turias:
I agree with your function syntax. If-Else blocks should be created similarly. Braces should always be on their own lines! ![Smilie](http://forums.macnn.com/images/smilies/oldschool/smile.gif)
Agreed. Unfortunately, some languages (TCL *cough* *cough*) stupidly require the { to be on the same line. But that language is dying.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Registered User
Join Date: Sep 2002
Location: New York City
Status:
Offline
|
|
In college I prefered a rum+coke, rave music playing, and other people around me doing their own thing while I program.
Now, I find that I program best when I have a white-board within arms reach, some background sound (people talking/music/etc.), and email and phone turned off.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Clinically Insane
Join Date: Jun 2000
Location: Union County, NJ
Status:
Offline
|
|
People that put their braces at the end of the line rather than marking the block on the next line where it should be should all be FIRED.
If you're going to mark the end of the block with a brace on its own line do the same at the beginning.
Mike
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Dedicated MacNNer
Join Date: Aug 2001
Location: Seattle, WA
Status:
Offline
|
|
Fine, since everyone else is doing it, here's my general style:
Code:
bool a_function(type *somePtr)
{
int someArg, anotherArg;
bool something = false;
if (something)
one_line_of_code(someArg, &anotherArg);
else {
two_lines_of_code();
should_be_in_braces(true);
}
return true;
}
I code best at night, in a dimly-lit environment. Music sometimes helps, although it doesn't really matter what kind since I like most things.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status:
Offline
|
|
I have noticed that no one has made much of a reference to object oriented programming...
I am a big fan of Objective-C++.
I prefer C++ for strict mathematical objects that could really use operator overloading (like vectors and matrices). However, I prefer Objective-C for more abstract controller type objects:
Code:
- (IBAction)doSomeMath:(id)sender
{
lavector aCppVector(1,2,3);
lavector *converted = new lavector;
lamatrix aCppMatrix(3,3);
aCppMatrix.makeRotate(pi/2,0,0);
*converted = aCppMatrix*aCppVector;
[vectorController postAnswer: converted];
}
|
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Banned
Join Date: Apr 2002
Location: -
Status:
Offline
|
|
I never go
[anObject doSomething: arg];
I always go
[anObject doSomething:arg];
and
if ()
not
if()
for()
while()
space is good, like Angus_D once told me
what else.
yeah, model object members vars are underscored
int _count
and private methods or ugly hacks are underscored...
- (void)_doThreadedChangeStatus ![Frown](http://forums.macnn.com/images/smilies/oldschool/frown.gif) id)arg;
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Professional Poster
Join Date: May 2001
Location: North Dakota, USA
Status:
Offline
|
|
My roommate blasts super fast, super-bass techno music when he codes, or, in fact, when he's doing anything. He is notoriously known, pretty much around the entire campus, as the guy who wears headphones (and a black trenchcoat...) everywhere. Yeah... mm-hmm... (he's not my roommate next year)
I need very quiet, calm music in the background... anything on http://www.monkeyradio.org works just fine, so that includes Thievery Corporation, Tosca, Kruder & Dorfmeister, Q-Burns, Weather Report, Miles, etc. Listening to my roommate's techno music so much when I've been trying to concentrate has almost made me not able to work with music in the background, though... quite annoying.
And I have a penchant for if else's like this:
if( exp )
{
mystuff
} else {
morestuff
}
It helps me keep the else's together with the original if ... otherwise they seem to get kind of out of hand.
Originally posted by Arkham_c:
When I'm at home, I generally code in bed with the lights off while my wife sleeps next to me.
What an understanding woman... clickitty click click click tap tapitty tap tap.... ugh.
You're a lucky man ![Wink](http://forums.macnn.com/images/smilies/oldschool/wink.gif)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status:
Offline
|
|
Though I'd normally listen to pretty intense death metal, when I'm coding I like to listen to more melodic, slow, jazz fusion/progressive stuff like Opeth, Gordian Knot, or even some Enya. I like lots of lights on and I usually like to be alone in my room, yet have my roommates home so I can go yell obscenities or throw miscellaneous food items from our freezer. I'm always more comfortable with no shirt or socks on also.
Also, there's nothing wrong with space when you're coding, I use plenty of white space to separate code segments and use newlines liberally for loops and if/elses.
![Smilie](http://forums.macnn.com/images/smilies/oldschool/smile.gif)
|
"In Nomine Patris, Et Fili, Et Spiritus Sancti"
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Grizzled Veteran
Join Date: Jun 2001
Status:
Offline
|
|
Just found some Sibelius on iTMS.....it's great for coding or general computin' :-P
6 bucks, too...for like 60 minutes of music! can't beat it.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Forum Regular
Join Date: Nov 2002
Location: PVD/MSP
Status:
Offline
|
|
For me, I only need a quiet calm atmosphere when I'm planning my implementation. When I get down to coding I like loaded and faster stuff. It helps me keep up the pace. Examples include Yeah Yeah Yeahs, The White Stripes, Interpol, The Breeders. Even TV on (as long as it is a good show). I need to be in a well lit area.
I use blank lines often to group related code blocks.
I'm not huge into extra spaces on a single line, so:
if(i=0;i<size;++i){
}
I also like to be connected to the internet when I'm coding. It is nice to take a break on slashdot, macnn, etc, while figuring stuff out.
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
hayesk
|
|
Originally posted by Tim2 at Omni:
Fine, since everyone else is doing it, here's my general style:
Code:
bool a_function(type *somePtr)
{
int someArg, anotherArg;
bool something = false;
if (something)
one_line_of_code(someArg, &anotherArg);
else {
two_lines_of_code();
should_be_in_braces(true);
}
return true;
}
Yuck! I hate no braces around single lines because I don't want to forget them later when adding more lines. I also always put opening braces not on their own line to make them easier to line them up with the closing brace - they're always in the same column. Here's my style:
Code:
void MyFunctionWithStartingCapitalInTheName(Whatever *thing)
{
if (test)
{
SingleLinesInBracesToo();
}
else
{
// putting opening brace on single line makes it easy to line up with closing brace
if(test2)
{
varablesStartWithLowerCase = 0;
FunctionsStartWithUpperCase();
}
}
}
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Grizzled Veteran
Join Date: Jun 2001
Status:
Offline
|
|
Originally posted by hayesk:
Code:
void MyFunctionWithStartingCapitalInTheName(Whatever *thing)
{
if (test)
{
SingleLinesInBracesToo();
}
else
{
// putting opening brace on single line makes it easy to line up with closing brace
if(test2)
{
varablesStartWithLowerCase = 0;
FunctionsStartWithUpperCase();
}
}
}
The man with the plan!! ![thumbs up](http://forums.macnn.com/images/smilies/up.gif)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
|
|
|
![](_gb_images/_img_misc/_gb_mb_previousthread-off.gif)
|
|
![](_gb_images/_gb_clear.gif) |
Forum Rules
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_sitenav_spacer.gif) |