userNum? numUser? Why not encourage using global variables? Please read Code Complete 2

The Chinese title of this book is "Code Complete 2", which discusses how to write highly readable code. The vocabulary in the original edition is not difficult; it's recommended to try reading the original.

Naming

Instead of using userNum to represent a user's ID and numUser to represent the number of users, a better approach is: userIndex to represent a user's ID, and userCount to represent the number of users

Variable scope

Design

If your boss asks why you haven't started writing code yet, open the code from past projects and pretend you're writing code; in fact you're doing design.

Abstract Data Type

Hide internal design (you've heard this many times, but it's easy to forget when actually doing it)

Suppose you have a very large insurance rate table that needs to be placed on disk, so you write: `RateFile.Read()`. If in the future you choose for some reason to store the table in memory, "File" would be odd. You should write: `rateTable.Read()`. Callers don't need to know whether the insurance rate table is stored on disk or in memory.

Last updated