Cover of Code Complete by Steve McConnell - Business and Economics Book

From "Code Complete"

Author: Steve McConnell
Publisher: Pearson Education
Year: 2004
Category: Computers

🎧 Free Preview Complete

You've listened to your free 10-minute preview.
Sign up free to continue listening to the full summary.

🎧 Listen to Summary

Free 10-min Preview
0:00
Speed:
10:00 free remaining
Chapter 3: Variables
Key Insight 3 from this chapter

Effective Variable Declarations and Data Literacy

Key Insight

Creating effective data necessitates a strong understanding of various data types, which forms a core component of a programmer's skill set. A 'Data Literacy Test' helps assess this knowledge by presenting terms such as 'abstract data type', 'array', 'boolean variable', 'pointer', 'string', 'tree', and 'typedef'. Participants score 1 for familiar terms and 0.5 for unsure ones, with scores interpreted ranging from 0 (beginner, requiring further study) to 25-29 (expert, suggesting an ability to write a book). Notably, scores of 30 or higher are deemed 'pompous fraud' due to the inclusion of made-up terms like 'elongated stream', designed to test 'Intellectual Honesty'.

Streamlining variable declarations, though seemingly minor, significantly impacts project efficiency and reduces frustration. A major hazard discussed is 'implicit declarations', a feature in some languages (e.g., Microsoft Visual Basic without `Option Explicit`) where variables are automatically declared upon first use. This can lead to insidious errors, such as mistyping `acctNo` for `acctNum`, where both variables are implicitly created and used, making debugging difficult. Explicit declaration, conversely, requires two mistakes (using an undeclared variable and then declaring it separately) for such a problem to occur, virtually eliminating the 'synonymous-variables' issue.

To mitigate the risks of implicit declarations, programmers should disable them when possible (e.g., using `Option Explicit` in Visual Basic). A consistent practice is to explicitly declare all new variables as they are typed, even if the language doesn't enforce it. Establishing clear naming conventions for common suffixes or types can prevent confusion between similar variable names. Additionally, utilizing compiler cross-reference lists or utility programs is beneficial, as these tools can list all variables in a routine, helping to spot similar names like `acctNum` and `acctNo`, and identifying declared but unused variables, thereby promoting more careful data handling.

📚 Continue Your Learning Journey — No Payment Required

Access the complete Code Complete summary with audio narration, key takeaways, and actionable insights from Steve McConnell.