Search code examples
javanaming-conventionsreadability

Simple yet reoccurring naming problem


Let's say we have a method:

  public String wishes(Date birthday) { 
          String birthayDateString = convertToString(birthay);

  ...

  }

I wonder what's the best name to give to the string called now "birthayDateString". This string represents date converted to text. I can't name it "birthay" beause this name is alredy used. Does nameing it "birthdayString" or "birthdayDateString" violate some naming convention good practice rules?


Solution

  • That actually looks fine.

    I personally would prefer birthdayStr - shorter and to the point - making it both meaningful and yet concise.

    Yielding:

      public String wishes(Date birthday) { 
          String birthdayStr = convertToString(birthday);
          // whatever
      }