Recently I was discussing get functions, for bools mainly. I actually got in an argument with this person on how you should return a boolean value, and a bit into how you should return value in general.
I say if you want to return, say a bool named isFat, you should approach it like this.
1 2 3 4 5 6 7 8
|
Foo::isFat()
{
if(Foo::_isFat==true)
{
return true;
}
return false;
}
|
They said, and I quote, "Why? That's just stupid extra work, with a bool you can just return it and it will equal true or false."
To them the proper way is
1 2 3 4
|
Foo::isFat()
{
return Foo:_isFat;
}
|
Note, this isn't a get function though as in get the variable and access it, I tried explaining this. If all you want to know is whether or not Foo is fat, then why the hell would you return the variable, even if it's not a reference? Do it my way you know it's just returning a literal value, and that's all it's good for. Their method could have it's purpose misunderstood and applied improperly. They're convinced though that just because their way takes a few less lines, it's the "better" way.
So as you can see we weren't even really arguing about a get function, however
that seems to be what they thought.
Then we argue a bit about get functions in general. Apparently they think that you should always just return that variable (sometimes you should return it of course) and it doesn't matter you can't actually change it unless you're returning a reference or pointer. Really does this person have no sense of safety? I'm not you're doing bad programming if you just return it, sometimes you just need to do that, it all depends on the situation. Obviously you can't always make a return statement based on a conditional branch. If you have a program calculating where the moon will be at a given time, then obviously you have a huge series of values passing around and you just have to. You still can apply safety barriers though. I.e if you don't need to worry about keeping a reference to what a function returns, then why not just return a copy that will be removed from that stack once it's finished?
I'm not saying what they think is right is always wrong, sometimes that's what you need to do, but I'm highly irritated by how they seemingly won't acknowledge other more proper ways for different scenarios.