Quote:
Originally Posted by Dragonshadow
Can someone give me one example of where making code readable reduces efficiency? >.>
|
In the case of idiomatic C (C that uses syntax abuse in order to function correctly)
Code:
while(*(string1++) = *(string2++));
Would be re-written to be readable as
Code:
//Iterators for strings
int Iterator1 = 0;
int Iterator2 = 0;
//Copy from Source string to Destination String
while(Destination[Iterator1] != '\0')
{
Destination[Iterator1] = Source[Iterator2];
Iterator1++;
Iterator2++;
}
//This code takes longer to write over-all, requires ints and a larger memory footprint, but is more readable
Pointer and bitwise logic will make things more unreadable. SM thankfully shields people from pointers.
Code:
int G, J;
int *L, *X; //Pointers; * is not 'multiply' but 'dereferencing'
L = G, X = J;
*L = *X = 2;
*L = (*L| (2 == (*L | *X))); //Fairly useless code, but some code can be written as confusingly
L = L ^ X;
X = L ^ X;
L = L ^ X;
//This is a swapping operation... but what has it swapped? The addresses or the variables?
If I was to simplify the code to make it readable I'd need to declare separate variables (as well named bools), instead of using bitwise operations, using standard C ops that are better recognised (or explaining each operation process throughout). If you have trouble following this code then you got problems; this is the basics.