Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Name Variables Intelligently
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Mon Nov 01, 2004 6:41 pm   Post subject: Name Variables Intelligently

So I was walking through Chapters this morning, and perusing the programming section, and I noticed a disturbing pattern in several of the books that I've seen elsewhere. Still, this was from people who should know better, and claim to!

Things like:

code:
ResultSet resultSet;


code:
ResultSet rs;


code:
JPanel panel;


Does anyone else see what's wrong with the above?

As programmers, our goal, aside from getting things done, is to make our lives as easy as possible. High-level programming languages exist to make code meaningful to us, not the computer. The computer doesn't care what you call things, and it'd be happy if you fed it pure machine code.

But machine code is hard to write, so we created assembly, and Fortran, and Algol, and Pascal, and C, and then right on up to things like Java and Ruby. We did it because we wanted to humanize programming as much as possible.

One of the goals of this endeavor is to make code readable. The meaning of the code should be as apparent as possible on reading through it. This doesn't necessarily mean we should know how it's doing what it's doing, but we should understand why the program was written.

There are a lot of ways for a computer to get any particular programming task done, but there's only ever one reason for you to write the program. You can ask for help from your peers, but if they don't understand why you are doing what you're doing, and what the goal of the program is, there's a very slim chance they'll be able to help you, especially as the programs you write get more complex.

So, if you find yourself coding, and using variable names that simply describe what something is mechanically, then go back and try to give it a more meaningful name.

They key is not whether or not you can read your code today or tomorrow and know it, but whether someone else can, and whether you can in a month or two.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: