Headlines | Linux | Apps | Coding | BSD | Admin | News
Information for Linux System Administration 

C++ style: How to write clear code


This article is a sample chapter from the book Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions.
Remove gratuitous complexity. This function adores gratuitous local variables! It contains three examples. First, the variable iDst is initialized to last-first and then used only once; why not just write last-first where it's used and get rid of clutter? Second, the vector iterator vit is created where a subscript was already available and could have been used just as well, and the code would have been clearer. Third, the local variable it gets initialized to the value of a function parameter, after which the function parameter is never used; my personal preference in that case is just to use the function parameter (even if you change its value—that's okay!) instead of introducing another name.
 read more | mail this link | score:6221 | -Ray, April 18, 2005
More Programming articles...

Abstract Art in Tallahassee

Selected articles

Space Tyrant: A threaded C game project: First Code

MiniLesson: An introduction to Linux in ten commands A simple directory shadowing script for Linux

The Real Microsoft Monopoly

Programming Language Tradeoffs: 3GL vs 4GL

Download: Linux 3D Client for Starship Traders


Firefox sidebar

Site map

Site info

News feed


(to post)


Articles are owned by their authors.   © 2000-2012 Ray Yeargin