Alexandre Julliard wrote:
None of these are showstoppers, but it needs a *really* good reason to overcome all of them. So far I haven't heard anything convincing enough.
THE thing that makes me miss C++ the most is exception handling. C offers you, basically, three options:
1. Having to perform an "if" every other line and perform a *shudder* goto in case of error. 2. Have nested "if"s seven levels deep. 3. return from the middle of the function. 4. Worst yet, write insecure code.
1. produces the longest code. It is also the ugliest one, structured programming wise. 2. has solved the ugliness, at the expense of code readability. For performance reasons you have to place the branch most likely to happen as the "then" part of the if, leaving the error handling to the "else" part. This means that you have an operation, long long list of what to do in case it succeeds (this list includes nested "if"s, mind you), and then an "else" and a sigle line of error handling. These last lines are all bunched together for each nesting level, and by the time you read them you no longer have the opening condition on screen. 3. This one produces a very neat solution, except that it requires performing the shutdown procedure over and over again. With multiple resources allocated, the shutdown also gets progressively longer. 4. This is the simplest one, and very easy to understand. It is also very common. In a nutshell - this means that you don't check the results of the operations you perform, and therefor you don't clutter your code with error handling. I think I don't have to elaborate why this is bad.
Exceptions, on the other hand, give a clean solution to the entire problem. The source code looks almost like option 4 - on error checks are performed. The resulting machine language, however, looks almost like 1 - all resource cleanups in one place, and you jump there if necessary.
If the discussion goes forward, I can give an example of rewriting my latest patch to wineboot (currently using approach 1) with the other four approaches (2, 3, 4 and exceptions).
Shachar