Loading ...
Sorry, an error occurred while loading the content.

Re: [XP] How to name variables

Expand Messages
  • Michael Feathers
    ... From: Phlip ... Phlip, that s a cool technique. Here is a similar one: Use Names to Guide Splits I was once working on a class
    Message 1 of 62 , Dec 1, 2001
    • 0 Attachment
      ----- Original Message -----
      From: "Phlip" <pplumlee@...>
      > If I get it wrong, I go to the object's source and change the name.

      Phlip, that's a cool technique. Here is a similar one:


      Use Names to Guide Splits

      I was once working on a class that was used to provide synchronized access
      to a set of objects across multiple threads. Unfortunately, the code was
      messy and hard to understand. I decided to refactor it a bit before adding
      anything else.

      In the add method of the collection there was a chunk of code which dealt
      with synchronization work. As I looked at it, I really couldn't think of a
      good short name for what the code was really doing. The words that leapt
      into my mind were "register this thread's use of safe collections." Rather
      than lose this insight, I immediately extracted the method and gave it the
      name: registerThisThreadsUseOfSafeCollections.

      I knew that the name would not last long, but it reflected my understanding
      of the code. The next thing I noticed was that there was a noun in the name:
      Thread. I looked around and discovered that there was no Thread class in the
      system, although we were using the thread API. After creating the class and
      moving the method, the code became clearer.

      Sometimes the best thing that you can do is type a method name which
      describes exactly what you want. If you are pairing, the squished method
      name form of your intention (registerThisThreadsUseOfSafeCollections) gives
      you something that you can both grapple with and simplify. More importantly,
      it records your unedited thoughts about what you are really trying to
      accomplish. When the name is there on the screen, you can explore the
      concepts that you are using to think about the problem. Are they the same
      concepts that you have in the code? If not, why not?
    • Phlip
      ... The algorithm is a playful example. The real issue here is that hard-to-remember names, or hard-to-reconstruct names, are a DesignSpell. -- Phlip
      Message 62 of 62 , Dec 12, 2001
      • 0 Attachment
        > How do you know that algorithm will converge?

        > > I have memory issues. So suppose I type the name of an
        > > object. Then I type a
        > > dot. (I can usually remember the procedure this far.) But
        > > then I need to ...
        > > "remember" ... the method name the object should call.

        The "algorithm" is a playful example. The real issue here is that
        hard-to-remember names, or hard-to-reconstruct names, are a DesignSpell.

        --
        Phlip phlip_cpp@...
        http://www.greencheese.org/PeaceAndCalm
        -- "In my experience, the customer doesn't know what he wants
        until you don't give it to him." --David Brady --
      Your message has been successfully submitted and would be delivered to recipients shortly.