🔒 Locked
If(...) return inside void functions/methods
Advertisement
Original Post
I think you should ask a more specific question.
I think it looks like Santa Claus after being hit by a freight train.
I also think I have no idea what you are trying to ask. Are you asking if this is a good practice? If it affects performance? Whether or not it's a magical incantation that will make you rich and famous if you chant it backwards 3 times?
I also think I have no idea what you are trying to ask. Are you asking if this is a good practice? If it affects performance? Whether or not it's a magical incantation that will make you rich and famous if you chant it backwards 3 times?
Quote:
Original post by xissburg
I want advice about performance and coding style and whatever.
Then mention that in your question. The given code gives no description of what you were trying to ask, neither did your post. It's pretty hard to judge code without a context. Having that said, it's still hard to judge style and performance (performance should be measured anyway, not judged) based on so little code.
For example, a slow, unoptimized function that is only called a few times is much less of a problem than a slow, unoptimized function that is called thousands of times per frame. And something that feels slow may not be the actual bottleneck.
Google for "multiple return statements".
It depends. There are pro and contra arguments for single as well as multiple return statements. At the end of the day, they are all completely irrelevant, and merely serve as entertainment for bored coders and managers which like to run code metric tools.
Also: I claim that only correct value for tab is exactly 5 spaces.
It depends. There are pro and contra arguments for single as well as multiple return statements. At the end of the day, they are all completely irrelevant, and merely serve as entertainment for bored coders and managers which like to run code metric tools.
Also: I claim that only correct value for tab is exactly 5 spaces.
Because anything else would be wrong.
I mean, 4 factors in to 2 ... and 2! How confusing.
5 is pure. 5 is prime. 5 is the one true tab width.
(The previous poster is trying to indicate that what you are asking about is a religious issue -- one for which there are many answers, all of which differ only by the chosen dogma of the particular programmer.)
I mean, 4 factors in to 2 ... and 2! How confusing.
5 is pure. 5 is prime. 5 is the one true tab width.
(The previous poster is trying to indicate that what you are asking about is a religious issue -- one for which there are many answers, all of which differ only by the chosen dogma of the particular programmer.)
Quote:
Original post by NotAYakk
5 is pure. 5 is prime. 5 is the one true tab width.
Duh, 7 is prime, too, and will give you a longer nonrepeating sequence of tabs and spaces if you like to mix both in your indentation style, as the ghodz of programming dictated. If they did not intend this, they would not have given you both a tab key and a space bar.
It has its uses. Using your extremely simple example, I would have done:
However, if there are conditions that would cause a function to not want to exectute (bad input parameters, given parameters result in meaningless work done, etc) and it doesn't read well to do what I showed above, I'll make a check at the top of the function like you wrote and expliticly terminate the function by returning.
Your example is too simplistic to provide proper comments on.
void f(int x){ if (x <= 10) { // Do stuff. }}However, if there are conditions that would cause a function to not want to exectute (bad input parameters, given parameters result in meaningless work done, etc) and it doesn't read well to do what I showed above, I'll make a check at the top of the function like you wrote and expliticly terminate the function by returning.
Your example is too simplistic to provide proper comments on.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement