There are only two hard problems in Computer Science: cache invalidation and naming things.

Phil Karlton

Chapter 4
Name Things Right

In Norwegian, the term for “moose” is “elg.” When the first northern settlers from Europe came to North America and saw this huge elg-like animal in the forest, they decided: “Okay, that’s gonna be the elg here” (or elk, as it’s spelled in English). Turns out, they were completely wrong. The settlers happened to meet a wapiti first—a totally different kind of deer. There is a close relative to the European “elg” in North America, but it’s the moose. Up to the present day, this little naming error leads to profound confusion between North American and European friends of the wilderness, and it leads to a discussion on etymology at the start of every “elg tour” in Scandinavia.

Assigning good names can be very hard. Even experts have a difficult time coming up with a good name on the first try. The European settlers had a concept for moose, but they still managed to assign it to the wrong animal.

Naming’s even harder for your code. Code doesn’t have horns or other properties that most people would recognize. It’s abstract, and most of the time, it’s also completely new and very domain-specific.

That’s why good naming is more important in programming. We have to name a whole lot of stuff: packages, classes, methods, fields, parameters, and local variables. And these elements often represent something unknown or hard to grasp. This makes it very difficult to find a good name, especially in the beginning. Later, after using an element a lot, you may find it easier to come up with a better name because you’ll be able to relate to the concept easily.

The comparisons in this section help you find better names for your code elements. We’ll show you why the Java conventions matter when it comes to naming, why you should be concise when naming methods, and how to avoid meaningless or single letter names.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.152.136