Are KB articles allowed to have poorly written code? (KB: 320348)
If you take a look at KB article 320348 you might think it was the holy grail if you were trying to figure out how to compare binary files using the .NET Framework. However, the code isn't really written all that well and to the less astute programmer, it might go straight into production use without so much as a code change to make sure the routine worked properly. So what am I worried about from this function?
1. Not checking the null string case. You really shouldn't pass a null string into a FileStream. Just not good coding practice.
2. Not checking for file existence before creating the FileStreams. “Try“ing for exceptional programming they are (without the try).
3. Not putting the FileStream's into a using statement or something that protects their closure if something goes wrong:
(for instance, if FileStream1 exists and FileStream2 throws an exception FileStream1 stays open a while.)
I can live with the rest of the code, it doesn't seem all that bad. But the question remains. Should KB articles that attempt to create non-existent technology do so with the mindset of LCS (least cost solution) or should they adopt a best practices approach? Should the code be usable out of the box, or should it simply be a technology sample that needs to be cleansed by the proper authorities before being used in an actual application? I welcome any comments, negative or positive, since I'm really curious what other people think.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;320348