views:

79

answers:

3

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?

+2  A: 

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
  }
Yuval A
A: 

No, I don't think you're violating any "best practice" standards. In cases like those, I often use variable names like birthdayText or birthdayStr.

In general, though, I try to make variable names as meaningful as possible—I don't just automatically tack on "Str" or "Text" if there's a naming collision. But in this case, it's just the string representation of the date, so I'd say it's meaningful enough.

htw
A: 

Call it whatever you want.

The variable name will only be in scope for the current method block (which should be reasonably small if you have your code properly broken up/encapsulated).

Personally I'd go with birthdayStr just for clarity in that particular method.]

I'd also Upper case those MethodNames to Wishes and ConvertToString

Eoin Campbell
why upper-case? Standard Java convention is camelCase for method names
Yuval A
This is Java, though—the convention in Java is to use camelCase. PascalCase is mostly a C# convention.
htw