Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prefix "Is" in Method Name for Verification Methods

I've been reading Code Complete lately, based off of many references here and also by a friend, and had a naming question for the community. Should the prefix "Is" be used on boolean methods that determine whether an event was successful? Here is a code example of two different naming schemes I tried:

migrationSuccessful = CopyData();
if (VerifyCopyData())
   migrationSuccessful = CleanupData();

versus:

migrationSuccessful = CopyData();
if (IsDataCopied())
   migrationSuccessful = CleanupData();

Notice the difference between VerifyCopyData and IsDataCopied. To me IsDataCopied is more meaningful and makes the code flow in a more descriptive pattern.

Thanks for your thoughts!

EDIT: Based on some of the comments, I thought I'd clarify what the IsDataCopied method does. It loops through several directories and files and makes sure the source and destination directory/files match.

like image 1000
Blake Blackwell Avatar asked Nov 17 '09 17:11

Blake Blackwell


2 Answers

I agree with you. To me, IsDataCopied is much more readable.

More generally, VerifyCopyData is, to me, ambiguous as to whether it is strictly a validation method or whether is actually does something. IsDataCopied is very clear that it only checks to see if the data is copied.

like image 88
Matthew Jones Avatar answered Jan 01 '23 22:01

Matthew Jones


I agree with Matthew Jones that is it preferable to name the method IsDataCopied. I would like to add though, that when naming code elements related to other code elements I generally find it better to put the Is inside the the name instead of at the front because it will be closer in Intellisense to the element it is related to (and thus easier to find). For example, in Winforms, Form has a Handle and IsHandleCreated property. If IsHandleCreated was named HandleIsCreated, it would be close to the Handle property and easier to find (not buried way down in Intellisense).

like image 32
Zach Johnson Avatar answered Jan 01 '23 22:01

Zach Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!