How to make fewer errors at the stage of code writing

Part N1: http://www.viva64.com/en/a/0070/

I've arrived at the source code of a widely know instant messenger Miranda IM. Together with various plugins, this is a rather large project whose size is about 950 thousand code lines in C and C++. And like any other considerable project with a long development history, it has rather many errors and misprints.


Part N2: http://www.viva64.com/en/a/0072/

This is the second article on avoiding certain errors at the early stage of code writing. In the previous post, we have already advised you to avoid a large number of calculations in one expression. However, we should investigate this question in detail. Let's see what's dangerous about complex expressions and how we can avoid many logical errors.

Examples of bugs:
- Newton Game Dynamics
- Chromium
- IPP Samples
- Return to Castle Wolfenstein
- DOSBox
I'm not so sure about those articles, I can't say I agree with all points.

The best advice I've read on this matter is in Steve Macquire's Writing Solid Code.
http://www.amazon.com/Writing-Solid-Code-Microsoft-Programming/dp/1556155514
I disagree with not using memset to write shorter code. For example, a Win32 PIXELFORMATDESCRIPTOR has like what, 20 fields or so? And I set most of those to 0 anyways. I personally think using memset actually reduces the amount of possible errors that I could make here, and greatly improves the readability.
hanst99 + 1 this is a perfect example of what memset is meant for. In fact one of about 50 in the Win32 API.

As for the second point in the first article, you should just READ THE WARNINGS. If the author had tried to make a point about the dangers of Type Casting then this section might have gone somewhere but instead they use a lot of words and examples just to say "Quit Being Lazy".

I agree with point 3, although function attributes go a long way in preventing a lot of this 'confusion' the author mentions, there is no benefit to compact code. The compiler is going to unroll and optimize everything with or without your crazy pointer to pointer crap so save yourself and others the headache.

Point 4 is moot, you should never have to use Copy\Paste in C++. This is what Templates, Functions and Recursion are for.

Why does it seem that point 5 contridicts point 4 also?

Point 6 goes all over the place to justify using another tool to check for syntax errors. I'm not sure I get what they are trying to say.
Topic archived. No new replies allowed.