JanetKay’s firm had a variety of work to do, and thus did not have the required employees to do all of it. It did not make sense to rent any new full-time staff, so that they resorted to bringing in just a few extremely paid consultants, particularly those that specialised in a particular drawback: vendor-bought {hardware}. Speaking to a bit of ware.
The {hardware} in query was a scientific one which communicated over a serial line. This machine supplied a variety of information that represented decimal values, however the information was not encoded as IEEE float. As a substitute, they used two integers—one for the information, and one representing the decimal quantity.
So, for instance, “555.55” could be displayed as “55555 2”.
Now, in embedded units, this isn’t too unusual. It is totally doable that the embedded CPU does not even help true floating level operations, and they also determined to work round it.
When speaking over the serial line, the machine didn’t ship information encoded in binary, nonetheless—it did all the things as textual content. This was arguably useful as a result of it meant {that a} technician might speak to the machine instantly on a terminal emulator, nevertheless it meant that any software program speaking to the machine needed to parse the information. .
Which brings us to code written by extremely paid consultants. This code must take two 16-bit integers and convert them to a decimal worth. Let’s examine how they did it.
public double ConvertIntToDecimal(string Worth, string decimalCount)
{
double End result;
var decimals = UInt16.Parse(decimalCount);
var Val = UInt16.Parse(Worth);
if (decimals > 0)
{
var divider = Math.Pow(10, decimals);
End result = ((float)Val) / divider;
}
else
{
End result = Val;
}
return End result;
}
We begin with feedback which might be utterly mistaken, which is all the time a superb begin. The entire thing has delightfully haphazard capitalization—a mixture of PascalCase
And camelCase
.
In fundamental logic, we parse the enter values, and if there are any decimal locations, we do one thing to create our floating level worth. Do the mathematics. We get the enjoyable bonus of casting. float
After we deal with our end result. double
however at the very least it is a widening inconsistency, I believe.
As a holistic strategy to the issue, it isn’t a prepare wreck, however one. Crucial factor That our extremely paid consultants forgot. Our HPC, keep in mind, was an skilled on this specific instrument, or at the very least that was their declare. And whereas their mistake is a straightforward mistake to make throughout coding, it must also be a straightforward mistake to catch throughout testing.
What was the error?
The worth is commonly unfavourable, and they’re utilizing UInt16
To parse the enter. Which signifies that this operate throws an exception too typically. Actually 5 minutes of testing would have modified it. Janet had a pile of pattern information, recorded from the machine, that she used for testing. Virtually all of its take a look at instances will set off a bug in some unspecified time in the future.
It appears that evidently at this level, HPC by no means really examined the code. They wrote it. They dedicated it. He collected his verify and left. Janet was in all probability the primary particular person to really run the code in any respect.
Lastly, hiring HPC prices some huge cash, and Possibly Saved just a few days of labor over the course of months. It is onerous to say, as a result of it might have created extra work, as a result of what HPC did needed to be debugged and infrequently rewritten.
The “good” information is that they’ve one other job, so administration is making an attempt to convey the consultants again for an additional spherical.
(advert) Plan your .NET 9 migration with confidence
Your .NET 9 journey is greater than only a resolution. Keep away from Migraine Migraines with the recommendation on this free information. Obtain the free information now!