Learn to Program
Chapter 4
Variables and Assignment
Since the book does a pretty good job of explaining variables, I'm only going to mention two things:
- Keep your naming conventions obvious
- Consider using camel case
Naming conventions are the most important. If you have a variable that is going to hold a first name, call it firstname
. Don't call it name1
because that leaves room for interpretation. If you leave a larger program alone for a few weeks/months/years and have to comeback to it, you don't want to second guess what all your variables mean.
Camel case, I think—and so do many others—is the easiest way to name variables. Underscores are fine, but if you have a long variable, such as database_connection_through_hyper-text_transfer_protocol_servlet
, it can get confusing. A better way is to keep the first word lowercase and capitilize all the remaining words and use well know acronyms: dbConnHTTPServlet
. It's still a little confusing, but a lot easier on the eyes and fingers.
For now, all you'll have to worry about are things like firstName, favNumber, and so on.