loading...

re: Do You Struggle Naming Your Classes Well? VIEW POST

FULL DISCUSSION
 

Great article, especially the sample methods of finding names!

Having lately realized how much time can be lost on figuring out the 'right' name, of something that is mostly bound to change a bit again anyway (especially when more than one person is involved) I really like a thought that Martin Fowler casually put in the first chapter of Refactoring:

When you can't immediately think of a good name, start off with anything. Name it sandwich. As you talk and think about it and start writing code, you'll realize what it does precisely and have probably started using a name that fits in your head.

Might not be applicable for something like DDD, but so far I found the notion to be true and quite helpful!

 

Thanks! That's some good advice 🙂

 

I also like Robert C. Martin's constant suggesting to refactor for good names in "Clean Code" which has a similar feel to Fowler's. At one point (I wish I could find the exact quote again!) he recommends writing out a full, longer 'rule breaking' chunk of code in a method such as Fowler's sandwich, then going back over it and pulling out all the pieces that perform different jobs - if those pieces were written right, they should tell you their own names. Then you can rename or choose to remove sandwich altogether if it was only a placeholder.

 
Code of Conduct Report abuse