Wednesday, May 21, 2008

Method naming conventions

This is just another rehash of what you've probably read many other places.

Start the method with a verb and end it with a noun. You want to make the method name be like what it does.

Bad method names.

Good method names

I ran across a method today that threw me. An object was declared off of my screen and set to
employee = getEmployee()

I was looking for a property of the employee object so I went digging for it, however, the object appeared to be a string. I went looking and yep, it was.

String employee; was declared off the screen above and the method returned the EmployeeName. Inside the getEmployee method it actually retrieved an employee object then returned just the name.

A few refactors later and everything was all better.


Anonymous said...

why did you delete my comment? I concurred with you. if you continue to edit comments, i'll leave none.

Steven Rigney said...

The only comments that I delete are personal attacks against me, I will leave anything else that is constructive even if it disagrees with everything I say. I have not deleted any comments from this post, if you commented here then it may have been a quirk of blogger that it did not post.