Counting Bugs in Windows Calculator
habr.com
habr.com
This is not a bug. Look how the `BooleanNegationConverter` is used:
<RadioButton x:Name="fullKeypad"
...
IsChecked="{x:Bind Model.IsBitFlipChecked, Converter={StaticResource BooleanNegationConverter}, Mode=TwoWay}"/>
<RadioButton x:Name="bitFlip"
...
IsChecked="{x:Bind Model.IsBitFlipChecked, Mode=TwoWay}"/>
Two radio buttons bound to the same boolean value, one with the negation converter. If `fullKeypad` is checked, `IsBitFlipChecked` should be set to false. If `IsBitFlipChecked` is set to true, `fullKeypad.IsChecked` should be set to false. The converter needs to do the same operation in both directions.However since the method bodies are identical, IMO one should have the full implementation and then the other should just call the first. Still not a bug, just a code smell.
Clang: https://www.viva64.com/en/b/0108/ , https://www.viva64.com/en/b/0155/ , https://www.viva64.com/en/b/0446/
isActive = ((ratio > threshold) || (ActiveIfEqual && (ratio == threshold)));
is called out as bad code by the blogger; this feels very much like a false positive, given that we're checking an inequality already; just effectively changing it from > to >=
A good example of not just blindly following the linter...
When you want to check whether A >= B (where A and B are numbers represented as floats), you would probably want to use the check A >= B - epsilon.
A relevant question is what epsilon should be.
So I'm not sure you can argue against a piece of code on the basis of likelihood.
TEST_METHOD(TestSwitchAndReselectCurrentlyActiveValueDoesNothing)
{
// *snip*
vm.Value2Active = true;
// Establish base condition
VERIFY_ARE_EQUAL((UINT)1, mock->m_switchActiveCallCount);
VERIFY_ARE_EQUAL((UINT)1, mock->m_sendCommandCallCount);
VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount);
vm.Value2Active = true;
VERIFY_ARE_EQUAL((UINT)1, mock->m_switchActiveCallCount);
VERIFY_ARE_EQUAL((UINT)1, mock->m_sendCommandCallCount);
VERIFY_ARE_EQUAL((UINT)1, mock->m_setCurUnitTypesCallCount);
}
> [...] The analyzer has detected two identical code fragments executing immediately one after the other. It looks like this code was written using the copy-paste technique and the programmer forgot to modify the copies.Here Value2Active is a C++/CX property rigged to a PropertyChanged event [1] with a macro:
public ref class UnitConverterViewModel sealed: public Windows::UI::Xaml::Data::INotifyPropertyChanged
{
// other members omitted
OBSERVABLE_OBJECT();
OBSERVABLE_PROPERTY_RW(bool, Value2Active);
};
Can you be sure that this actually does not have a side effect? I bet not. Indeed, the intention of the original test is clear: a property, once set ("Switch") to a particular value, should not update other states even when set ("Reselect") to that same value---as it will really trigger a side effect! This idempotency guarantee is an important interface contract worth testing, no matter what a linter and clueless blog author says.[1] https://github.com/Microsoft/calculator/blob/master/docs/App...
Although considering this application Calculator could be one of the most-used programs on Windows, and they left that many errors in. It's scary to think how many errors could be in other parts of the system...
I'd seriously doubt that. I'm sure browsers and word processors are used far more often, and that's not even including programs that run every time the computer boots!
Physical calculators are for classrooms.
- Reach goal.
- Simple curve fitting
- Drawing charts in general (even with matplotlib categorical bat charts are a world of pain and then they tell you to learn Altair or something.
- Tables with conditional formatting
- ...
The right answer is probably to use the right tool for the job, be it xcas, octave or python. Microsoft's calculator is probably better suited for unit conversion, for instance, although units(1) would be a contender :)
How many of those errors are visible to end users in a way that actually matters? A 'suspicious' floating point conversion in a display aspect ratio check? A memory leak in a program that's almost entirely interactively driven? I don't see anything else terribly huge on the list either.
Software errors have an impact to the user and a cost to fix. These don't seem like errors where the ROI on the fix was likely to be positive, so maybe it's reasonable they were left in.
You should also consider the errors that Microsoft _removed_ from the calculator before passing too much judgement on their software development process. After all, this is the same company that replaced IEEE754 floating point in calculator with an arbitrary precision library. (At considerably more expense than any of the bug fixes indicaetd by the attached article)
https://blogs.msdn.microsoft.com/oldnewthing/20040525-00/?p=...
As far as I remember, and it has been a while (and is virtually undocumented), with ETW the convention is to not call the EndX method when an error occurs as EndX is basically synonymous with `return`. This might have been carried over.
Either way, I'm sure there are false positives, as always with static analysis.
https://github.com/Microsoft/calculator/search?q=1995&unscop...
Turned out that it was due to something profile related: re-registering the Windows App Store fixed the issue. Yes, that's right, a dependency on the app store can prevent you from running Calculator.
Aside from the obvious answer of them using C++ based upon "using something you know and that works", why shouldn't they have used C++? (Genuinely wanting to know/understand.)
It would seem like a monolithic task to rearchitecture the entire app versus just dropping the code-behind into a new UI wrapper, yeah? I'm not excusing it, to be sure, just explaining the potential ROI perspective they might've had when they stuck with C++.
[0] - https://en.wikipedia.org/wiki/Windows_Calculator#History
[1] - https://en.wikipedia.org/wiki/Windows_Calculator#Windows_10
- https://blogs.msdn.microsoft.com/oldnewthing/20040525-00/?p=...
- https://blogs.msdn.microsoft.com/oldnewthing/20160628-00/?p=...
- https://blogs.msdn.microsoft.com/oldnewthing/20180704-00/?p=...
This might also explain the choice of C++. Rather than rewriting their calculation engine in another language (it works, so a rewrite is rarely a good idea), UWP (not WPF; XAML is merely an XML dialect for object graphs and works pretty much anywhere if you want it to) allows you to write the UI in C++ (C++/CX to be precise) as well, and the UI code is for the most part not that complicated that C++ is a major impediment. That, and of course, most developers for Windows applications at Microsoft are familiar and well-versed in C++. Rewriting it in JavaScript or C# may take longer.
This is very true. If we look at Exchange, as an example, most of it was ported to .NET between E12 (2007) and E14 (2010) but Information Store wasn't able to be fully ported to C# until E15 (2013)[0,1].
[0] - https://docs.microsoft.com/en-us/exchange/managed-store-exch...
[1] - https://en.wikipedia.org/wiki/History_of_Microsoft_Exchange_...
The first step toward full C++/WinRT support within Visual Studio and the eventual retirement of C++/CX happened today with the availability of build 17025 of the Windows SDK Insider Preview.
https://moderncpp.com/2017/11/01/cppwinrt-in-the-windows-sdk...
I didn't say they shouldn't, I just thought it was interesting to see.