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

C++ style: How to write clear code

Up
vote
Down

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:6528 | -Ray, April 18, 2005
More Programming articles...

Abstract Art on Acrylic Panels

coding headlines

No Starch Press has published my Perl One-Liners book!

 

Firefox sidebar

Site map

Site info

News feed

Features

Login
(to post)

Search

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