Comments on: id Software C++ Coding Conventions https://www.geeks3d.com/20081111/id-software-c-coding-conventions/ Graphics Cards and GPUs News, Graphics Programming, Home of FurMark Fri, 11 Oct 2013 00:33:26 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: Andreas https://www.geeks3d.com/20081111/id-software-c-coding-conventions/#comment-33260 Fri, 11 Oct 2013 00:33:26 +0000 http://www.geeks3d.com/?p=2035#comment-33260 Guys, it’s not about the particular choice of conventions id uses. The point is to have such a paper, and make it available to every developer.

]]>
By: Jason McGuiness https://www.geeks3d.com/20081111/id-software-c-coding-conventions/#comment-4391 Tue, 02 Dec 2008 16:18:05 +0000 http://www.geeks3d.com/?p=2035#comment-4391 Might I suggest a more modern, and comprehensive work upon which one may base their coding standards? (That is also peer-reviewed.) My suggestion is:

“C++ Coding Standards” by H. Sutter et al, Addison-Wesley, Feb 2005.

]]>
By: Philip Spencer https://www.geeks3d.com/20081111/id-software-c-coding-conventions/#comment-4388 Tue, 02 Dec 2008 10:31:26 +0000 http://www.geeks3d.com/?p=2035#comment-4388 Nice to see someone’s best practice recommendations. I’ve been coding in flavours of C for over 20 years, and would support ID’s layout choice regarding braces:
if ( x ) {
blah valh;
} else {
vlah balh;
}

for two primary reasons:

1: Safety in code maintenance. Many times I have seen the alternate format accidentally split, changing the code flow but not generating compile warnings:
if ( x )
{
blah blah;
}
else
line added during maintenance;
{
blah blah;
}

or the simple case
if ( x )
line added during maintenance;
{
blah blah;
}

The most common instance is the accidental
for ( ix = 0; ix < END_IX; ix++ );
{
copy[ix] = original[ix];
}

Legal code and hard to spot, but not what is intended.

2: Compact presentation. Either on an old-fashioned glass teletype screen, or in a typical small window in a GUI environment, one is often performing keyhole surgery on the source code, and this format maximises the quantity of functional code visible.

I also like the way that the closing brace matches the start conditional (or function, or loop control, etc), and the clearer indentation (IMHO).

]]>
By: JeGX https://www.geeks3d.com/20081111/id-software-c-coding-conventions/#comment-3694 Wed, 12 Nov 2008 07:41:34 +0000 http://www.geeks3d.com/?p=2035#comment-3694 Totally OK with you. Thanks for your contribution saew, interesting reading 😉

The convention

if ( x ) {
blah valh
}else {
}

is awful and I prefer a more compact manner like this:
if (x)
{
doSomething1();
doSomething2();
}
else
{
doSomething3();
doSomething4();
}

or

if (x)
doSomething1();
else
doSomething2();

But I appreciate the fact id Software has a coding convention paper and this is a good example to follow with of course, each one with his own conventions!

]]>
By: saew https://www.geeks3d.com/20081111/id-software-c-coding-conventions/#comment-3668 Tue, 11 Nov 2008 18:53:06 +0000 http://www.geeks3d.com/?p=2035#comment-3668 I think ID has very few experience with C++. They used C a loooong time and they started to program their games using C++ just a few years ( for Quake Wars I think ).

I’m programming C++ for 10 years and that doc clearly shows some immature decisions, for example:

if ( x ) {
blah valh
}else {
}

that’s ugly notation that does not help at all the code readability and neither correct code identation. It’s way better this other one:

if ( x )
{
//blah blah
}
else
{
//blah blah
}

( which is called ANSI C++ style brackets btw ).

Other thing I don’t like is that pseudo-hungary notation with the _t at the end

struct myStruct_t

almost all the code editors in the world ( VS, NetBeans, Eclipse, SlickEdit, etc etc ) can tell you if a data structure is a struct, a class, an integer, etc in the debug watch, class navigators, etc… actually, I think there is no need at all to use hungary notation and neither that 80-era _t thing.

They’s are using “float” also which is terribly bad. A good practise is to re-map floating point types to custom typedefs or classes, so you can alter the type them easy. For example, imagine you’re developing a mobile game and that platform does not suppport floats… with custom classes or a typedef you can use fixed fp precision or whatever…

]]>
By: JeGX https://www.geeks3d.com/20081111/id-software-c-coding-conventions/#comment-3652 Tue, 11 Nov 2008 09:59:25 +0000 http://www.geeks3d.com/?p=2035#comment-3652 Cool 😉 I’m glad this find is useful.

]]>
By: Hightree https://www.geeks3d.com/20081111/id-software-c-coding-conventions/#comment-3650 Tue, 11 Nov 2008 09:49:12 +0000 http://www.geeks3d.com/?p=2035#comment-3650 Thanks a bundle !
This will make a great template for our own coding conventions doc.

]]>