Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Coding Habits

Coding Habits
Thread Tools
macgyvr64
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Mar 1, 2004, 03:17 AM
 
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
{
is the right way
}

not{
this
}



What kinds of things to you guys/gals do when coding? :-P
     
depolitic
Registered User
Join Date: Feb 2003
Status: Offline
Reply With Quote
Mar 1, 2004, 05:04 AM
 
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.
     
djohnson
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Mar 1, 2004, 10:29 AM
 
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!
     
Turias
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Mar 1, 2004, 11:38 AM
 
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!
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Mar 1, 2004, 12:30 PM
 
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
     
BLAZE_MkIV
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status: Offline
Reply With Quote
Mar 1, 2004, 02:07 PM
 
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. )
     
Turias
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Mar 1, 2004, 02:14 PM
 
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?
     
BLAZE_MkIV
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status: Offline
Reply With Quote
Mar 1, 2004, 02:17 PM
 
Compare the two and tell me which is faster?

http://cplus.about.com/library/weekly/aa101302f.htm
     
Turias
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Mar 1, 2004, 02:25 PM
 
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.
     
BLAZE_MkIV
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status: Offline
Reply With Quote
Mar 1, 2004, 02:30 PM
 
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.
     
Turias
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Mar 1, 2004, 02:34 PM
 
Bah, I'm too lazy to code an increment operator on a non-simple datatype, let alone use one.

     
smeger
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Mar 1, 2004, 08:45 PM
 
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.
     
djohnson
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Mar 1, 2004, 08:46 PM
 
Originally posted by smeger:
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...
Geeky maybe so... but then does it really matter?
     
macrophyllum
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Mar 2, 2004, 01:17 AM
 
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?
     
BLAZE_MkIV
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status: Offline
Reply With Quote
Mar 2, 2004, 03:53 PM
 
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.
     
Arclite
Junior Member
Join Date: Sep 2003
Location: Nowhere, Missouri
Status: Offline
Reply With Quote
Mar 3, 2004, 11:43 PM
 
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?
     
hayesk
Guest
Status:
Reply With Quote
Mar 5, 2004, 02:12 PM
 
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!
Agreed. Unfortunately, some languages (TCL *cough* *cough*) stupidly require the { to be on the same line. But that language is dying.
     
bens1901
Registered User
Join Date: Sep 2002
Location: New York City
Status: Offline
Reply With Quote
Mar 13, 2004, 06:14 PM
 
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.
     
starman
Clinically Insane
Join Date: Jun 2000
Location: Union County, NJ
Status: Offline
Reply With Quote
Mar 13, 2004, 06:26 PM
 
Originally posted by macgyvr64:
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
{
is the right way
}

not{
this
}



What kinds of things to you guys/gals do when coding? :-P
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

Home - Twitter - Sig Wall-Retired - Flickr
     
Tim2 at Omni
Dedicated MacNNer
Join Date: Aug 2001
Location: Seattle, WA
Status: Offline
Reply With Quote
Mar 13, 2004, 06:34 PM
 
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.
Tim Omernick
Engineer, The Omni Group
     
Detrius
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Mar 14, 2004, 12:15 AM
 
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
     
ambush
Banned
Join Date: Apr 2002
Location: -
Status: Offline
Reply With Quote
Mar 14, 2004, 09:12 PM
 
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)_doThreadedChangeStatusid)arg;
     
funkboy
Professional Poster
Join Date: May 2001
Location: North Dakota, USA
Status: Offline
Reply With Quote
Mar 15, 2004, 02:19 PM
 
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
     
[APi]TheMan
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Mar 15, 2004, 09:07 PM
 
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.

"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
macgyvr64  (op)
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Mar 16, 2004, 06:10 AM
 
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.
     
off/lang
Forum Regular
Join Date: Nov 2002
Location: PVD/MSP
Status: Offline
Reply With Quote
Mar 16, 2004, 11:46 AM
 
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.
dearinter.net consensus life coaching.
     
hayesk
Guest
Status:
Reply With Quote
Mar 17, 2004, 03:06 PM
 
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(); } } }
     
macgyvr64  (op)
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Mar 17, 2004, 05:14 PM
 
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!!
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:36 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,