Method declarations are like units of communication between developers. They convey intent and actions.
For the beginner or uninitiated, a method declaration is everything that makes up a method, except for its implementation. That means the access modifier, return type, method name, and parameter list.
This method below looks simple enough. There’s not a whole lot to it.
The method above is potentially lying to us in ways that can crash your or others’ application.
You typically find these kinds of method declarations in repository classes. I think any developer will understand the method declaration above. It’ll return an instance of the Person
class with a social security number that matches the method parameter. Nothing out of the ordinary, really.
Even though this example is somewhat contrived, there’re some learnings we can gain from examining the issues with this simple method, anyway.
I’m sure any experienced developer is aware of all the false indications this method is giving us. Inexperienced developers likely don’t think about or catch the two potential lies this method is telling us.
So, let me break it down for anyone not familiar with the issues.
#javascript