C/C++ personal coding standards

For general rambling.
Post Reply
Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

C/C++ personal coding standards

Post by Jonathan »

In my job, I write a lot of code in C (or languages with C-like syntax) that isn't reviewed and is solely maintained by me. There aren't a lot of style guidelines for this code. How do you personally write your C, outside of (or maybe in spite of) style guidelines?

For my part, I label anything with a FIXME comment that might have a remote chance of requiring later attention. I probably also copy and paste too much. Stupid functions.

bob
Poser
Posts: 344
Joined: Fri Jul 18, 2003 1:26 am
Location: p-town, pa
Contact:

Post by bob »

I use INCOMPLETE as my marker comment. Many programmers use TODO.

As an overall goal for code cleanliness, which I apply to all of the languages I use, I try to be very good about making classes do exactly what you would expect them to do based on the name, and have the interface you would expect. A lot of that is grammar, using certain verbs to indicate what a function will do.

A point to apply to any artists you may work with: don't ever let them name something "final". For some reason, artists like to do this a lot, and then you show them what's wrong that makes it not so final, and you start ending up with filenames like "final thing 2", "new final thing", and whatever the hell comes after that. I've started making my artists name things by date when there are lots of iterations.

George
Veteran Doodler
Posts: 1267
Joined: Sun Jul 18, 2004 12:26 am
Location: Arlington, VA

Post by George »

I prefer TODO in code, but for some reason in Word documents I use a red TBD instead.

I find my standards are still evolving. After playing with C# for several months, my C++ style has become a lot more objecty. I still prefer an ordered heirarchy (according to some that's a relic of structured programming) since it makes the design easier to visual and follow for me.

Unfortunately, I work with people that don't understand any object oriented concepts other than "stick functions in structures and call them methods". They like polymorphism, but they don't understand that the semantic definitions of the methods have to be the same. So they put every method of every child class in the parent, then stub them out in the child classes they don't need them in. That way, they can call anything they want without casting. I hope I don't ever have to maintain their code; it's a given that someone is going to try to substitute a class and crash the system.

They also banned namespaces. They don't want to have to type anything extra. The current naming convention is that they call their stuff whatever they want, and I have to name my similar things by adding prefixes.
I feel like I just beat a kitten to death... with a bag of puppies.

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

I use TODO, and HACK since Visual Studio actually recognize those words and will put them into your task list.

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

In some objecty (or procedurey) languages, I break things down into steps and then fill in the steps. In C, though, I throw everything into one huge file/function. Kinda like image manipulation classwork, now that I think about it. I am so lazy.

Post Reply