When designing an interface that allows callers to request an object from some data storage, ensure that your interface accepts unsigned integers rather than signed ones. If you use a signed integer then you need to have a guard clause to reject a negative parameter. However, if you
ensure your identifier type accurately models the data it represents. Then your guard clause is implicitly implemented by your parameter. This means you can drop the explicit guard clause from your code. Cleaner, faster, better code. Everyone is a winner.
Apologies for the image of code. Google Blogger doesn't really allow anything except poorly formatted text.
Note: Obviously this does not hold true if your information model allows negative identifiers.
No comments:
Post a Comment