Writing Effective Methods in Java                Parag Shah      http://www.diycomputerscience.com
Always check method parameters for validity
WHY ?Because we should always fail fast !
An example
What will happen if we do not ?We may get an Exception which is unrelatedWe may get an incorrect resultWe may create an ob...
What should be checked ?ConstructorsPublic, protected, package methods
When not to check ?If the check is very expensive  a method which expects a sorted listIf the check will be done implicitl...
Upcoming SlideShare
Loading in...5
×

Check methods params_for_validity

347

Published on

This presentation explains how and why we should check method parameters for validity as a good programming practice in Java.

Published in: Technology, Economy & Finance
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
347
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Check methods params_for_validity

  1. 1. Writing Effective Methods in Java Parag Shah http://www.diycomputerscience.com
  2. 2. Always check method parameters for validity
  3. 3. WHY ?Because we should always fail fast !
  4. 4. An example
  5. 5. What will happen if we do not ?We may get an Exception which is unrelatedWe may get an incorrect resultWe may create an object which will fail at a totally different and unrelated time
  6. 6. What should be checked ?ConstructorsPublic, protected, package methods
  7. 7. When not to check ?If the check is very expensive a method which expects a sorted listIf the check will be done implicitly in the computation sorting automatically checks for comparable instancesPossible to omit checks in private methods
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×