Content deleted Content added
Phil Boswell (talk | contribs) →Formatting of C examples: I think the whole problem is caused by formatting the C example in the same fashion as the Python version. Try re-writing the C version in a single line |
Phil Boswell (talk | contribs) →Formatting of C examples: example |
||
Line 128:
::Sorry for the removal of the braces in the first place. I made the change facetiously to try to raise the point that it was a poor example since it was valid without the braces. When I first read the comparison of Python code and C code, it did not clearly communicate to me the difference between the two, because I (as a seasoned C programmer) immediately saw that I could remove those braces. Without the knowledge that Python is indentation based, I (as having no prior knowledge of Python) was momentarily confused since it would be natural to assume (to a C programmer) that perhaps it didn't require braces since it only consisted of one statement. Of course, having read the rest of the text, I realised the point that was being attempted to be made, but isn't the intention of the example to make it obvious? I think that, although the page is about Python, since the comparison is with C, the example should be clear to C programmers what the intented point was. — The anon that made the change 11:23, 22 Sep 2004 (UTC)
:I think the whole problem is caused by formatting the C example in the same fashion as the Python version. If you re-write the C version in a single line, converting all whitespace to single spaces, you might get the idea across better. HTH HAND --[[User:Phil Boswell|Phil]] | [[User talk:Phil Boswell|Talk]] 12:33, Sep 22, 2004 (UTC)
===Example ===
I have not made this change in the main article in order that someone more familiar with Python can confirm the correctness of the example. --[[User:Phil Boswell|Phil]] | [[User talk:Phil Boswell|Talk]] 12:48, Sep 22, 2004 (UTC)
;Factorial function in C:
int factorial(int x) {
if (x == 0) {
return 1;
} else {
return x * factorial(x-1);
}
}
is syntactically equivalent to:
int factorial(int x) { if (x == 0) { return 1; } else { return x * factorial(x-1); } }
;Factorial function in Python:
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x-1)
is '''not''' equivalent to:
def factorial(x): if x == 0: return 1 else: return x * factorial(x-1)
|