Who writes Microsoft support articles? Can they always trust?

Here is an example of the type of article I'm talking about:

http://support.microsoft.com/kb/319401

I assume that these articles are written by people who work for Microsoft, and that the code in the articles will always be strong and will never contain malicious code. I just want to make sure I can explain to my boss that this is a good place to copy code (I was told to never copy code from the Internet, but it seems like a safe source).

+7
source share
8 answers

I would believe that they will not be evil, but they are not always good. (MSDN samples are sometimes quite terrible.)

For example, here is some code in the example you gave:

compareResult = ObjectCompare.Compare (listviewX.SubItems[ColumnToSort].Text, listviewY.SubItems[ColumnToSort].Text); // Calculate correct return value based on object comparison if (OrderOfSort == SortOrder.Ascending) { // Ascending sort is selected, return normal result of compare operation return compareResult; } else if (OrderOfSort == SortOrder.Descending) { // Descending sort is selected, return negative result of compare operation return (-compareResult); } else { // Return '0' to indicate they are equal return 0; } 

Now there are two problems:

  • Why is it considered that it has a comparator without sorting? This must be a constructor parameter, confirmed at the point of construction of the IMO.
  • You should not simply deny the result of a single comparison in order to perform a “reverse comparison”. This breaks if the result of the first comparison is int.MinValue - because -int.MinValue == int.MinValue . It is better to change the arguments used to perform the initial comparison.

There are other things that I would touch on in this code, but these two should be enough to express my point of view.

I sincerely agree with other answers, including: - Check copyright / license, etc. Any code you want to use. - Make sure you understand everything you want to use.

+8
source

Perhaps your boss would not mind if you only copied the code into a test project that you use to verify and understand the code. Then you can use what you learned to write production code.

And although I don’t think that someone outside of Microsoft knows the names of the people who write these support articles, they come from the same provider as your toolchain, so if you do not trust the support articles, then you cannot trust the tools you bought.

+5
source

Microsoft Knowledgebase articles show safe (as in the case of not malicious, but not necessarily secure) code, but usually this example provides the easiest use case. There is a good chance that you will have to adjust the code a bit to make it work the way you want.

You should also pay attention to the date of the articles. For example, the article you are linking to is almost three years old. There is definitely a better way to deal with this situation now.

+4
source

Remember that most articles in articles will help you understand the concepts. They are not "ready for production." Explore concepts and implement your own.

+3
source

Have you been told not to copy code from the Internet due to rights issues? If so, you do not need to worry about this Microsoft code.

I would advise you not to use any code that you do not understand. If you cannot tell whether the code is malicious or not to use it.

+2
source

MSDN and kb support articles are written by MS staff who are part of this UX (user experience) team. These are people who usually have experience in the field of technical writing, but not necessarily the developers themselves (although some of them). Very often, the UX team works with product developers to make sure their code samples are correct. However, this collaboration in my experience is one of the lowest priorities that a typical MS developer has and can be ignored, and therefore it can sometimes lead to poor code output.

With that said, I completely agree with Karl Norum's comment. Copying a code that you do not understand is at your own risk. Make sure you understand any code that you place in your product!

+1
source

I always found top-quality Microsoft articles (unfortunately, not their products).

However, there is always the danger of a site spoofing.

0
source

Explain that you carefully read the article to understand the information there, and just copy the code that you understand.

If you do not understand the code, then even if the code is correct, it may not do what you really need to do, so your program will be wrong.

You will also have complex debugging and code support if there are parts that you do not understand.

0
source

All Articles