Programming peeve of the Day
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
if (condition)
{
return;
}// Do something else
what about this annoys you?
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
-
if (condition)
{
return;
}// Do something else
what about this annoys you?
Your rewrite is how it should be done. Now get off my lawn.
cheers Chris Maunder
-
if (condition)
{
return;
}// Do something else
what about this annoys you?
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
-
Obviously it should have been:
if (!condition)
{
// Do something else
}
else
{
return;
}:cool:
- I would love to change the world, but they won’t give me the source code.
-
I would never do it the same, but I can understand it as a hint and that is ok. Of course
if (condition) return;
// Do otherwhisewould be more appropriate On the other hand: Is it really worth to discuss such little things?
Member 15092515 wrote:
On the other hand: Is it really worth to discuss such little things?
You're absolutely correct. Let's discuss this, instead: if (condition) { return; } else { // Do something else }
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
Member 15092515 wrote:
On the other hand: Is it really worth to discuss such little things?
You're absolutely correct. Let's discuss this, instead: if (condition) { return; } else { // Do something else }
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
Your rewrite is how it should be done. Now get off my lawn.
cheers Chris Maunder
Is snot.
if ( !condition )
{
// Do something else
}return ;
-
Your rewrite is how it should be done. Now get off my lawn.
cheers Chris Maunder
Chris Maunder wrote:
Your rewrite is how it should be done.
Why? It's not as clear as to what the code will do. Plus, returning from inside an if is bad form.
-
Obviously it should have been:
if (!condition)
{
// Do something else
}
else
{
return;
}:cool:
- I would love to change the world, but they won’t give me the source code.
Got it before I did! :)
The less you need, the more you have. JaxCoder.com
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
when you refactor some code and are too afraid to remove else clauses.
I'd rather be phishing!
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
I like single exit points... That code would drive me nuts too...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013 -
Chris Maunder wrote:
Your rewrite is how it should be done.
Why? It's not as clear as to what the code will do. Plus, returning from inside an if is bad form.
What's wrong with returning from inside an
if
? The rule about only returning at the end of a function leads to convoluted code where a flag is repeatedly used to bypass stuff just to reach the end of the function. Pure dross.Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
No religion in the lounge! ;p
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
-
Is snot.
if ( !condition )
{
// Do something else
}return ;
I believe to be totally proper it should be;
if ( !condition )
{
// Do something else
return;
}return ;
The less you need, the more you have. JaxCoder.com
-
No religion in the lounge! ;p
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
-
I believe to be totally proper it should be;
if ( !condition )
{
// Do something else
return;
}return ;
The less you need, the more you have. JaxCoder.com
If I had a lawn... :mad:
-
What's wrong with returning from inside an
if
? The rule about only returning at the end of a function leads to convoluted code where a flag is repeatedly used to bypass stuff just to reach the end of the function. Pure dross.Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.Greg Utas wrote:
The rule about only returning at the end of a function leads to convoluted code
As opposed to it not being clear when and where something can be returned.
-
If I had a lawn... :mad:
We have a saying here in the south; Hold my beer[^].
The less you need, the more you have. JaxCoder.com