: Since we are now on the sensitive topic of coding style, it is worth
: mentioning that there are no absolute truths. However, the vast
: majority of programmers dislike code with multiple operators on one
: line as in the first example, as well as code written without any
: blank lines.
:
: Personally I dislike assignment inside the loop condition, or inside
: an if() statement. Because strictly, if() and while() should only
: evaluate boolean expressions and nothing else. Null termination and
: "false" both have the integer value 0, so the code will of course
: work, even though I wouldn't have written it like that. Avoiding
: assignment in conditions also eliminates any unintentional mix up
: between = and ==.
:
: I would have written the function like this:
:
:
: bool isStringHex (char* sz)
: {
: bool result = true;
:
: while(*sz != '\0')
: {
: if( !isxdigit(*sz) )
: {
: result = false;
: break;
: }
:
: sz++;
: }
:
: return result;
: }:
I agree about the assignment in statements, but only if there is only assignment. I often do that, but always together with logical operator.