February 25, 2005

A discussion on Compiling

There was a brief entry at Slashdot about Optimizing Compilers:
I have been coding in C for a while (10 yrs or so) and tend to use short code snippets. As a simple example, take 'if (!ptr)' instead of 'if (ptr==NULL)'. The reason someone might use the former code snippet is because they believe it would result in smaller machine code if the compiler does not do optimizations or is not smart enough to optimize the particular code snippet. IMHO the latter code snippet is clearer than the former, and I would use it in my code if I know for sure that the compiler will optimize it and produce machine code equivalent to the former code snippet. The previous example was easy. What about code that is more complex? Now that compilers have matured over years and have had many improvements, I ask the Slashdot crowd, what they believe the compiler can be trusted to optimize and what must be hand optimized?
The comments to this are flowing fast and thick and wonderful. I can bash out C if needed but I know that I am not a good programmer. I have had the wonderful pleasure to know some great programmers and I stand totally in awe of them. (They have shown respect for my hardware mojo so this is not entirely a one-sided relationship...) That said; a good program can be "read" and the question being talked about is what target audience do you write for: the person who will have to maintain your code after you are no longer with responsible for it or the compiler that will take your code and turn it into the Application that your employer sells to its customers.
Do you write for slower user performance and greater maintainability or... Posted by DaveH at February 25, 2005 11:52 PM