I’m in Chicago this week. My hotel phone number is +1-630-916-9000, room 102.
Archive for September 2001
Safe C++
I posted the following message to comp.lang.c++.moderated today. Any takers?
| One problem that C++ has is that it lets you corrupt memory. This is the biggest reason why C and its derivatives have a bad name.
Expert C++ programmers have learned to avoid dangerous constructs and thus manage to avoid most of these problems. But most folks out there don’t have neither the knowledge nor discipline to do that, and they regularly shoot themselves in the foot. Is there any interest in making a variant of C++ called “Safe C++”? Such a language would preserve C++’s expressiveness while avoiding C++’s bad sides. The diffs from standard C++ would be:
Disclaimer: The above list may have some holes. This is a half-baked idea. |
Making C++ Safe
Reproducibility is the key to to successful bug fixing.
Now, there’s a lot of things that kill reproducibility: Threads. Different computer settings. Operating system differences. Network conditions. But C and C++ add a problem of their own to this palette: memory corruption. It’s easy to corrupt the heap and the stack by using pointers and arrays. And once that happens the bugs start cropping up randomly and killing all the fun.
How can you avoid memory errors? You can’t avoid them altogether in C++ because of the way the language is designed. But you can come real close:
- Use an automatic garbage collector. There’s a commercial one from Geodesic, there’s a free one by Hans Boehm, and I understand that Visual Studio.NET is going to have one although it will limit the language somewhat.
- Use STLPort. Iterators are frequently only disguised pointers but STLPort checks them for validity in Debug mode.
- Don’t use pointer arithmetic at all. Use STL containers and checked iterators.
- Don’t use native arrays. Use STL vector or roll your own bounds-checked class if your arrays are of fixed size and the performance is absolutely critical.
Do those four things described above and you will avoid all the usual headaches associated with C programming.
Paintball
I played a game of paintball with some of my friends yesterday. Wow! It’s fun! Kinda like playing Quake in the real world.
The biggest problem was that it started raining just about the time we were scheduled to start. This made our goggles fog and dampened the enjoyment of the game. The rain stopped after a while and then the real fun started. I want to get one of those big faceplates that cops use when breaking up demonstrations. That would give good visibility while protecting the face. It’s probably expensive, though, as professional equipment always is.
