Recent Changes - Search:

edit SideBar


Learning at least one new thing every day. 20060508

  • To Keep In Mind: Knowledge consists of what we know, what we can forget, and what we can look up. All of which is dependent on what we presently think we will need.

Navigation Aid

Currently considering:

Programming By Intention

When we program by intention

  • We reflect on what we intend to do
  • We write the simple method first
  • We simply say that we're going to create the array of strings by first creating an ArrayList
  • Further that we intend to copy it into an array of Strings
  • We write the short version of the method
  • Then we write the two sub-methods


Clarity is key in Programming by Intention -- a central idea in XP.

  • It means making your intent clear when you write code.
  • Have you ever had to work on a piece of code and found that it was hard to understand?
  • Maybe the logic was convoluted, the identifiers meaningless, or worse, misleading.
  • You say there was documentation?
  • Was it readable?
  • Did it make sense?
  • Was it up to date with the code?
  • Are you sure?
  • How do you know?


  • We don't have to remember so much. As soon as we know what we intend to do, we write it down.
  • We just refine it until the code is there.
  • The Code Emerges Well Factored? without not needing as much refactoring as by other methods.
  • We get better code in less time!"

''Summarized from:


Intentions can be revealed in Naming Conventions?


By names I mean the identifiers we choose to name the various classes, variables, methods, etc., that we create as we work. We need to choose names that are semantically transparent, that is, they say what they mean and mean what they say.

There are several conventions that we can use when choosing names:


  • Use nouns or noun phrases for class names.
  • Name classes for what they represent or what they do:

Interface Name Convention?

  • Use either adjectives or generic nouns and noun phrases for interfaces.
  • Interfaces are a bit different.
  • If an adjective is used for an interface name it usually ends with -able, for example, Runnable, Serializable.
    • My advice is to avoid conventions that prepend or append "I" to the name when possible. Sometimes there isn't a good name for an interface other than "interface to something."
      • In that case, ISomething is acceptable.

Method Name Convention?

  • Use verbs and verb phrases for method names.
  • Methods do something, so using verbs to name them makes sense. Examples include add and fetchReview.
  • Avoid Redundancy?
    • Don't put redundant information in method names.
    • If you need a method to add an instance of X, call the method add rather than addX since the parameter will be an X.
      • This has the benefit that if later refactoring changes the type of the argument (even simple renaming of the class),
        • then the method name is out of sync with its argument.
        • The innocent redundancy has now become misleading and confusing.
      • Another benefit is that you gain clarity if you need to support adding of different types by the ability to overload the method name.

There are always exceptions..

Accessor Or Mutator Convention?

  • Use accepted conventions for accessors and mutators.
  • Many languages have generally accepted conventions for how to retrieve and modify instance variables.
    • For instance, if you are working in Java, to retrieve/modify a variable named are advised to use the Java Beans conventions of getX and setX
    • To access a boolean variable, use isX in both Java and Smalltalk.
    • An alternative in some cases is to use the form isX() where X refers to an optional part of the object

Computed Properties and Instance Variables

  • this applies to computed properties as well as actual instance variables,
    • for example, when a circular queue class needs a method to query whether it is full
      • we suggest isFull.
  • Sometimes it is clearer to drop the get prefix.
    • For example, I tend to use size rather than getSize to fetch the size of a composite object.
      • This is often the case when the value you are asking for is a property of the object as opposed to one of its attributes.
  • conforming to the convention used in the Java class libraries, it is a good idea to use the naming idioms of the environment you are working in because it is what others reading your code will be familiar with.

Variable Name Convention

  • Use nouns and noun phrases for variable names.
    • Variables hold things,
    • so nouns make sense, for example, rating, movies, connectionToReviewServer.

Choose Names Carefully

  • but don't spend too much time at it


Category Home Page?

Edit - History - Print - Recent Changes - Search
Page last modified on May 03, 2020, at 09:06 PM