[tz] proposed changes for Win32 and a improved mktime() algorithm
Kees.Dekker at infor.com
Wed May 10 15:24:09 UTC 2017
>Yes, here's an example of the problem:
> bool ok = complicated condition;
> int value;
> if (ok)
> value = complicated expression;
> complicated actions;
> if (ok)
> return value;
>An inferior compiler might complain that 'value' might be used
>uninitialized. One can pacify such a compiler by changing line 2 to 'int
>value = 0;', and you're correct that this typically won't slow the code
>down significantly. However, such a change obfuscates the source code,
>as the reader is left wondering why the unnecessary initialization is
>present. Instead, it's better to disable or ignore the bogus warnings,
>or get a better compiler. After all, there's nothing wrong with this
>code, and your compiler is supposed to be your servant not your master.
I agree with this example, but also disagree to a little extend:
1. although a compiler is indeed inferior, it is not easy (or even impossible) to switch to another compiler. You are IMO focusing too much on gcc.
2. Adding int value = 0 (or any initializing value what is wanted) does not reduce the readability of the code. If it does, I can’t imagine how.
3. Initialization gives an indication about how the developer things. E.g. if the initial value is an error, then you can easily see 'this function returns x upon error'.
Initialization then does not obfuscate code, but improve readability. Note that much other languages (Java/C++) always initialize types to defaults.
4. I've seen too many issues with uninitialized code in C, that I lean towards 'better safe than sorry' and always initialize any value.
Figuring out errors that are related to uninitialized code are very hard to find (debugging problems is almost always a hard job).
5. The compiler acts as servant to notify (probably sometimes with false alarms) potential issues. Indeed, dome compilers are too pedantic. But that
Is the freedom (isn't it?) of the owner of the compiler. It is usually out of the scope of a developer to define that (so many man, so many minds).
6. In most cases, real code is (much) more complex. In terms of costs and time is adding a good value for initialization is cheaper, compared to the single CPU needed for init.
Anyhow, as you are the maintainer of the TZ code, it is up to you, but is saves us time if we can use the unmodified code...
I guess that most users are not using visual studio (or something else than gcc), so it may also help others if these changes are accepted.
(I still did not check the patches, so I don't yet know what part was accepted. Have a nice day, I will leave for today).
More information about the tz