I have a custom designated initialiser like this:
- (id)initWithLocation:(CLLocation *)location
{
if (location == nil)
{
return nil;
}
self = [super init];
if (self)
{
self.location = location;
}
return self;
}
My colleagues sometimes ask me to wrap everything (apart from the return), that follows after first curly brace pair, in an else clause:
- (id)initWithLocation:(CLLocation *)location
{
if (location == nil)
{
return nil;
}
else
{
self = [super init];
if (self)
{
self.location = location;
}
return self;
}
}
But I am not sure. What is the point? The first if condition is a quick death check. If the parameter is not provided, no instance is provided. This serves as enforcement for providing a parameter. else seems superficial here as it is implied in the flow of the code.
What would be the advantage having it?
- The code is extremely trivial. What could be clarified here is beyond my understanding.
- The possible modification I ask about (and which constitutes the merrit of my question) has NOTHING TO DO with where I possibly would handle what is returned. My question is about logical flow of code.
- The second explicit example in CodeCaster's revision ruins my question as he put the return into ELSE in spite of my stating in the original question that it is not part of ELSE.
- I get downvote because other people can't read code/change the question with faulty revisions.
– Earl Grey Nov 19 '13 at 12:13selftonilher eanyway. Please remember that if the question was clear, nobody would be asking for clarification, so show what you actually mean! :) – CodeCaster Nov 19 '13 at 14:59