[C] The usage of ? and : when cleaning up recursive code

In summary: I would've written some different code then, possibly with block statements, but that's redundant and off topic.As for semantic clarity, if we both understand the same thing, then who cares anyway right?
  • #36
For all those talking about 1 instead of 1.0, don't forget about type promotions as mentioned earlier.
 
Technology news on Phys.org
  • #37
mafagafo said:
See my version. What you pointed out was "corrected" there.

Returning 1 instead of 1.0 is UGLY, not WRONG. (#22 explains why)

My apologies, I never saw your corrected version. In any event ugly or not, you must return the data type indicated. If you want to return some sort of error then it is common in some languages such as Java to return a NaN to indicate some error or to throw an exception to be caught by the application program.

Please be aware, that many of us here have years of experience in programming and look at things far differently from you.

The idea of writing things more compactly in the C or Java world never goes over so well. We are more interested in program maintainability and hard to read expressions compactly designed to eliminate intermediate results is considered bad style for two reasons:

- one is the next programmer may not be as familiar with the expression and

- two if it needs to be debugged the programmer doing it will curse and convert it to intermediate results to see exactly what is going on.

So have some compassion for your fellow programmers and write code stressing clarity over compactness, simplicity of complexity and with useful comments where needed.

Also take advantage of the latest programming tools like NetBeans, Eclipse or IntelliJ IDEs. They have many features that will save you time such as code refactoring, semantic understanding of what you're writing, and immediate error message feedback
 
  • #38
Why the lecture fella?
You thought:
1) I was OP?
2) I write OS code with 300 characters per line?

"In any event ugly or not, you must return the data type indicated."
HE DOES RETURN A DOUBLE.
 
  • #39
mafagafo said:
Why the lecture fella?
You thought:
1) I was OP?
2) I write OS code with 300 characters per line?

"In any event ugly or not, you must return the data type indicated."
HE DOES RETURN A DOUBLE.

My apologies again.
 
  • #40
Closed for moderation
 

Similar threads

Replies
1
Views
2K
Replies
22
Views
3K
Replies
36
Views
4K
Replies
1
Views
1K
Replies
11
Views
1K
Replies
6
Views
10K
Replies
1
Views
1K
Back
Top