DEV Community

Discussion on: Writing Good Method & Variable Names

Collapse
 
programazing profile image
Christopher C. Johnson

Loved this, thank you!

I've been ranting about a method I found in one of our old libraries for the last couple of weeks.

GetIdById(), really? What the heck is that supposed to even do?

After digging into it and figuring out what it did I eventually renamed it to GetPatientIdByChartId()

Collapse
 
timothymcgrath profile image
Timothy McGrath

Ha. I wish it had just contained

return id;

Collapse
 
rachelsoderberg profile image
Rachel Soderberg

Your rename makes a lot more sense than the original. "GetIdById" sounds like the code equivalent of trying to divide something by zero if you ask me!

Collapse
 
fpuffer profile image
Frank Puffer • Edited

You write that it is a method, not a standalone function. So it belongs to an object, probably an object of type Patient. So what about calling it GetIdByChartId()? It makes no sense to put information into a name that is obvious from the context.

Collapse
 
programazing profile image
Christopher C. Johnson

Because it was a standalone function. I tend to use method and function interchangeably when I really shouldn't.