Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Semantically speaking, does it make a difference which one of these styles you use when writing code, or will the processor parse it the same way. If there is a difference, which one is faster?
int function(bool) {
...
return 0
}
or
int function(bool)
{
...
return 0
}
Both are correct, choose one style and stick with it.
But don't use both styles in same project.
Both styles are commonly in use. When I began programming I used the latter, it made it easier to determine that the block was closed. Now I use the former because it uses less vertical space. Both are fine.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is there is any specific reason behind undefined behavior in C and C++?
Why are some features left undefined?
For some part at least, it was to allow a more efficient implementation.
A simple example: Function parameters. Their evaluation order in unspecifed, because some architectures could work better depending on how they made the calculations or the calling convention (registers, stack, etc.)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Simple question about formatting code (in my case C++).
If I have a line of code, say:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace + IDontActuallyUseVariablesThisLong
Should I split it like:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace +
IDontActuallyUseVariablesThisLong
or:
SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace
+ IDontActuallyUseVariablesThisLong
Another example:
foo = bar->baz;
// Should it be:
foo = bar->
baz;
//Or:
foo = bar
->baz;
Do people have a preference when it comes to this? Is it on a case-by-case basis? They both seem equally clear (or unclear) to me, so I was wondering if there are any standard ways of doing it.
Yes, people have preferences about this.
No, there's no standard or consensus agreement. I'm not aware of any especially strong arguments for either side, either.
So like any coding style issue, you can stick with whatever other people who edit the same code have been doing, or just pick one you like.
(I wouldn't even complain about being inconsistent on this issue.)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm making a small game and I don't know whether I should have the majority of the statements in the main function or instead just put them as void functions in my player object (I'm not really returning anything other than boolean values throughout each iteration).
In general, you should aim for your main() to be a bridge between the execution environment (the OS) and the system that you implement. This means that main should "crack" the command-line parameters, and then promptly pass control to the method that instantiates top-level objects and runs your system.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What are the advantages of C++ over the others languages in working with videodata and videodevices (developing object detection program). Thank you.
for object detection, you could use python, matlab, java and c++. You have to use c++ if you need substantially speed improvement (C++ is the fastest in most of the cases). You could also use OpenCv easily with c++ for face and object detection.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Are there alternatives that would be more preferred?
Short-circuit evaluation is a crucial feature of most modern programming languages and there's no reason to avoid relying on it. Without it pointer-related tests would be (unnecessarily) much more complicated and less readable.
Of course it's good design, everyone knows to expect it and it beats using nested conditionals.