Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who Writes Microsoft Support Articles? Can They Always Be Trusted? [closed]

Tags:

c#

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

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

I assume these articles are written by people who work for Microsoft and that the code in the articles will always be rock solid and never contain any malicious code. I just want to make sure I can explain to my boss that this is an ok place to copy code from (I've been told never to copy code from the internet, but this seems like a safe source).

like image 827
sooprise Avatar asked Apr 07 '11 15:04

sooprise


People also ask

What is a Microsoft trusted document?

What are trusted documents? Trusted documents are files that have been marked as trusted by enabling active content in them. Active content (macros, ActiveX controls, data connections, and so on) opens without the Message Bar warning after you mark the file as trusted.

Does Microsoft provide technical support?

If you need immediate technical support for your business, Professional Support is available as a single pay-per-incident (PPI) or a 5-pack of incidents. Microsoft experts help you troubleshoot a specific problem, error message or functionality that isn't working as expected.

How do I turn off the security warning in Microsoft Office?

Click Options. Click Trust Center, and then click Trust Center Settings. Click Privacy Options. Under Privacy Options, select or clear Check Microsoft Office documents that are from or link to suspicious Web sites check box.

How do I get access to trusted?

On the File tab, click Options. In the Access Options dialog box, on the left, click Trust Center. On the right, under Microsoft Office Access Trust Center, click Trust Center Settings. In the left pane of the Trust Center dialog box, click Trusted Locations.


2 Answers

I would trust them not to be malicious, but they're not always good code. (MSDN samples are sometimes pretty awful.)

For example, here's some code in the sample 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 issues here:

  • Why is it deemed valid to have a comparer with no sort order? This should be a constructor parameter, validated at the point of construction IMO.
  • You should not just negate the result of one comparison to perform a "reverse comparison". That breaks if the result of the first comparison is int.MinValue - because -int.MinValue == int.MinValue. It's better to reverse the arguments used to perform the original comparison.

There are other things I'd take issue with in this code, but these two should be enough to make my point.

I heartily agree with the other answers too, in terms of: - Check the copyright / licence etc of any code you want to use - Make sure you understand anything you want to use

like image 81
Jon Skeet Avatar answered Sep 21 '22 20:09

Jon Skeet


Your boss probably wouldn't mind if you only copied the code into a test project that you use to test and understand the code. You can then use what you've learned to write the production code.

And while I don't think anyone outside of Microsoft knows the names of the people who write those support articles, they come from the same vendor that your toolchain does, so if you don't trust the support articles, then you can't trust the tools you've bought either.

like image 45
Chris Wenham Avatar answered Sep 19 '22 20:09

Chris Wenham