Log in

View Full Version : coding standards


Eglin
11-12-2003, 03:21 AM
I'm just getting to know your codebase, and I find the lack of coding standards to be a bit overwhelming. I guess this is just symptomatic of having a lot of cooks in one kitchen. It feels like the early Java API, where you could clearly tell which routines were written by which authors because the interfaces were so wildly different! hehe... I noticed that at least one major developer is intimately familiar w/ STL (the single biggest source of my rejuvenated love for c++), while others are ingrained in basic c.

Sorry if my post seems inflammatory... At any rate, I thought I'd mention that I found the i/o functions (and the makeanylengthstring) to be dangerous. Instead of c++ style i/o where the object to be output is asked to serialize itself into a stream or the really new style i/o where you use output iterators to walk structures, most i/o uses the va_args stuff that died back with the stdio stuff a decade ago. The problem with the va_args stuff is that it totally disables c's very refined type-checking. As an example of why this could be problematic, consider the following snippet:

std::string msg = "teststring";
c->Message(0, "test: %s", msg);

This, of course, isn't correct code. However, it is a very easy mistake to make. By bypassing the type-checking of parameter passing, we have also taken away the compiler's ability to warn us of this error. So, by using msg (like we're used to w/ most library i/o routines) instead of msg.c_str(), we've introduced a runtime error that could easily bring down the entire system. Also a very insidious error to track down.

Not really sure what I hoped to accomplish by posting this (maybe just a gotcha! warning). I certainly don't mean to talk trash about your codebase (or I wouldn

Trumpcard
11-12-2003, 03:44 AM
No, I think its great to share things like this..

The code started from a much earlier project, and there were no well defined coding standards in the beginning.. (Most of the coders havent been pro. coders)

What I've found useful for projects is a coding guru that does code reviews and helps the project adhere to well defined standards. People fix what they can here and there.

Any tips, tricks or suggestions are greatly appreciated.

And I know what you mean about Java.. I work in the java code world, and its amazing how many hands I have to slap for people bringing over bad coding practices from C++ into Java.. Ones that really piss me off are these..

for (int x=0;x<array.size();x++)

catch {}

and

people that think vectors should be used anywhere.. In multithreaded apps vectors can be the devil since they're synchronized...