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

Buy Large Wall Art on Canvas

Selected articles

Testing the Digital Ocean $5 Cloud Servers with an MMORPG

VPS: Xen vs. OpenVZ

Linux vs. Windows: Why Linux will win

Hacker Haiku

The Real Microsoft Monopoly

The life cycle of a programmer


Firefox sidebar

Site map

Site info

News feed


(to post)


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