<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Cos' Adventures</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/cosmin/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/cosmin/feed.xml</link>
    <description>Cosmin Nicolaescu&amp;#039;s Blog</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:20:47 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Singleton</title>
      <link>https://docs.microsoft.com/archive/blogs/cosmin/singleton</link>
      <pubDate>Thu, 10 Sep 2009 01:19:50 GMT</pubDate>
      <dc:creator><![CDATA[cosn]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cosmin/2009/09/10/singleton/</guid>
      <description><![CDATA[The Singleton design pattern is seemingly one of the most simple patterns out there, yet on several...]]></description>
      <content:encoded><![CDATA[<p>The <a href="https://en.wikipedia.org/wiki/Singleton_pattern" target="_blank">Singleton</a> design pattern is seemingly one of the most simple patterns out there, yet on several channels (forums, discussion lists etc.) people seem to be asking what the best way to do it is.</p> <p>A quick search for <a href="https://www.bing.com/search?q=singleton+implementations&amp;form=QBLH&amp;qs=n" target="_blank">singleton implementations</a> yields some very useful results, and given the simplicity of the pattern the language should not be a barrier for anyone. Some of the implementations out there are truly naive, and it shows something extremely common: even the simplest piece of code can have so much depth that people can easily make the wrong choice.</p> <p>The simplest implementation is the following:</p><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Singleton
{
    <span class="kwrd">private</span> <span class="kwrd">static</span> Singleton instance;

    <span class="kwrd">private</span> Singleton() {}

    <span class="kwrd">public</span> <span class="kwrd">static</span> Singleton Instance
    {
        get
        {
            <span class="kwrd">if</span> (instance == <span class="kwrd">null</span>)
            {
                instance = <span class="kwrd">new</span> Singleton();
            }

            <span class="kwrd">return</span> instance;
        }
    }
}</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>Is there something wrong with this? Well, the answer is no. If you write this on a college exam, you will most likely get all the points. The catch is that you can’t have multiple threads calling Singleton.Instance, or you risk having multiple Singletons out there, which kind of defeats the purpose of the whole pattern :) </p>
<p>While in general I’m a fan of keeping things as simple as possible, in today’s day and age where almost all computers have at least two cores, there’s really no excuse of designing things for just one thread. So let’s make this solution a thread-safe one:</p><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Singleton
{
    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">volatile</span> Singleton instance;
    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">readonly</span> <span class="kwrd">object</span> mutex = <span class="kwrd">new</span> <span class="kwrd">object</span>();

    <span class="kwrd">private</span> Singleton() {}

    <span class="kwrd">public</span> <span class="kwrd">static</span> Singleton Instance
    {
        get
        {
            <span class="kwrd">if</span> (instance == <span class="kwrd">null</span>)
            {
                <span class="kwrd">lock</span> (mutex)
                {
                    <span class="kwrd">if</span> (instance == <span class="kwrd">null</span>)
                    {
                        instance = <span class="kwrd">new</span> Singleton();
                    }
                }
            }

            <span class="kwrd">return</span> instance;
        }
    }
}</pre>
<p>For those who are scratching their head about the double-check, just think about what happens if two threads access the first check at the same time, and that should give you the answer ;)</p>
<p>Now this solution will always work, regardless if you have just one thread or thousands accessing Singleton.Instance. The only argument for this code is that it’s not as simple as the first option, and that’s very true. So let’s look at this third solution, which should address this concern while keeping everything we have so far: a multi-threaded Singleton implementation:</p><pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Singleton
{
    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">readonly</span> Singleton instance;

    <span class="kwrd">static</span> Singleton()
    {
        instance = <span class="kwrd">new</span> Singleton();
    }

    <span class="kwrd">private</span> Singleton() {}

    <span class="kwrd">public</span> <span class="kwrd">static</span> Singleton Instance
    {
        get
        {
            <span class="kwrd">return</span> instance;
        }
    }
}</pre>
<p>This is a bit specific to .NET, but it works like this: a static constructor is <em>guaranteed </em>to be called only once per AppDomain, and only when it’s needed (a static member is called or an instance of that object is created). So we can safely get rid of our lock and the checks, and rely on the CLR doing the right thing. So we now have a thread-safe, relatively pretty implementation for the Singleton pattern. The only change we can do to this is add <a href="https://en.wikipedia.org/wiki/Lazy_loading" target="_blank">lazy loading</a>, which may slightly improve performance if you have other static methods, but chances are that’s not going to be your bottleneck so don’t waste your time.</p>
<p>All-in-all, I think this is a great example of the power of how very subtle changes drastically change the look or behavior of a piece of software. It also forces people to think a lot more than they probably thought they would need to, which will hopefully make it habitual :)</p>
<p>-Cos</p>]]></content:encoded>
    </item>
    <item>
      <title>Copy + Pasting in Unit Tests</title>
      <link>https://docs.microsoft.com/archive/blogs/cosmin/copy-pasting-in-unit-tests</link>
      <pubDate>Wed, 26 Aug 2009 18:44:24 GMT</pubDate>
      <dc:creator><![CDATA[cosn]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cosmin/2009/08/26/copy-pasting-in-unit-tests/</guid>
      <description><![CDATA[Some people love designing. Others love writing the code. While it’s true that some like testing and...]]></description>
      <content:encoded><![CDATA[<p>Some people love designing. Others love writing the code. While it’s true that some like testing and breaking software, I haven’t met a lot of people who enjoy writing <strong>unit tests</strong>. There’s something about them – getting 100% code coverage even though you know you’ll never encounter some situations, the repetitiveness of the set-up or the hassles you have to go through when dealing with external dependencies (such as files) – that make developers in particularly want to get done with their unit tests as soon as possible.</p> <p>The result of that is, among other things, that we get sloppy and start taking shortcuts; one of them involves copy + pasting code from the code you’re actually testing.</p> <p>For example, let’s say you have a program, which based on some input, will perform some action. It can be as simple as:</p> <div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">public</span> <span class="kwrd">int</span> ConvertStatus(<span class="kwrd">string</span> status)</pre><pre><span class="lnum">   2:  </span>{</pre><pre class="alt"><span class="lnum">   3:  </span>        <span class="kwrd">switch</span>(status)</pre><pre><span class="lnum">   4:  </span>        {</pre><pre class="alt"><span class="lnum">   5:  </span>                <span class="kwrd">case</span> <span class="str">"status - valid"</span>:</pre><pre><span class="lnum">   6:  </span>                      <span class="kwrd">return</span> 123;</pre><pre class="alt"><span class="lnum">   7:  </span>                <span class="kwrd">case</span> <span class="str">"status – invalid"</span>:</pre><pre><span class="lnum">   8:  </span>                      <span class="kwrd">return</span> 456;</pre><pre class="alt"><span class="lnum">   9:  </span>         }</pre><pre><span class="lnum">  10:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">  11:  </span>         <span class="kwrd">return</span> 0;</pre><pre><span class="lnum">  12:  </span>}</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>Unit testing this method is relatively straightforward: pass in the first status and make sure the return code is “123”, pass in the other status and make sure the return code is “456”, pass in a different value, and make sure the return code is “0” (my college courses also tell me to pass in null and empty string and make sure the return code is “0”). What some developers will end up doing is look at the code, copy the statuses and check the return value. All tests pass, the little green check mark is there, and we’re good to go.</p>
<p>So what’s wrong with that? Does the unit test actually test the code? Yes. Do the tests cover all the possible cases? Yes. When you actually run this code in the real world, is it going to perform as <em>designed</em>? Maybe. Let’s look at why.</p>
<p>In a larger organization (where larger is defined as not you and your buddy), there’s usually a delegation of duties, and different individuals will provide input in the process. At Microsoft, usually all engineering work is split between three roles: Program Manager, Developer and Tester. It is the PM who defines the requirements, the dev who designs, codes and unit tests the software, and the tester who will ensure the software developed meets the requirements defined. In our example below, the statuses can be defined either by the PM or the dev, and will be in a document (Functional Specification or Design Document). This ensures that everyone (including people outside the triad mentioned above) can easily read the document and understand what’s being delivered, rather than having to read code. So let’s assume that the PM wrote the statues, and when the dev went to code it, copied the text into their code. Then they wrote the unit test in the manner described above, and decided they’re code complete. However, when the tester runs their automated tests, it fails miserably. The dev’s first reaction is “no way, your test must be invalid; I wrote unit tests, and they passed fine”. How can this be?</p>
<p>As I discovered recently while doing a code review, word processors have a nifty way of changing your characters. For example, if you type “word1”, space, “-“, space, “word2”, the “-“ will actually become “–”. In a document, that actually does look better, but in actual code, nobody could care less. </p>
<p>So what happened above is exactly that: in the second status, instead of having a regular “-“, we ended up with a “–” (copy this text in a hex editor, or change the encoding to UTF-8 and you’ll notice). In order to make sure we don’t have any typos, the developer copied and pasted the text from the Functional Specification into their code. Afterwards, that same text was copied into the unit tests, thus ensuring everything passes. The tester however typed it by hand, and now we broke. </p>
<p>So what? If the system has that status everywhere, what’s the problem? Well, the other developer who wrote the component which stores the status in the database didn’t actually copy + paste the values, for one. Or this method can be part of a public API, and you have no idea who’s calling it. Chances are, 99% of your users won’t put the text in a document first and then copy + paste the value, but rather type it by hand.</p>
<p>So after this long story, the morale is pretty clear – don’t copy + paste things from a text document, just write it by hand. Actually, there can be problems with that too – and the most <em>obivous </em>is a typo. You copy + paste the typo in your unit tests, things pass again, yet you’ve got the same problem. This is how you end up with some APIs that have typos in them, and cannot be fixed due to backwards compatibility. </p>
<p>Whether you copy the text from a document, or you type it by hand in your code, you should <strong>always</strong> write your unit tests from scratch. Anytime you use Ctrl-C, Ctrl-V in a unit tests you risk masking a bug. Other than increasing your time, actually typing your unit tests can lead to one of three things:</p>
<ol>
<li>You do a good job, and the tests that pass are actually proper 
<li>You write the proper test, and discover a bug in the code. 
<li>You make a mistake in the test, and it will fail. You will take a look and fix the mistake (either in the code or the test)</li></ol>
<p>Finding these types of bugs is usually a pain. Even when you have an error, it’s hard to spot because our brain masks this and interprets the correct thing. Unit tests are the best, and in the end fastest way to find these issues early and isolate the problem easily. </p>]]></content:encoded>
    </item>
    <item>
      <title>Hello Win7.c</title>
      <link>https://docs.microsoft.com/archive/blogs/cosmin/hello-win7-c</link>
      <pubDate>Mon, 02 Feb 2009 20:13:08 GMT</pubDate>
      <dc:creator><![CDATA[cosn]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cosmin/2009/02/02/hello-win7-c/</guid>
      <description><![CDATA[This marks my first post from a Windows 7 machine. I am *highly* impressed so far. The full...]]></description>
      <content:encoded><![CDATA[<p>This marks my first post from a Windows 7 machine. I am *highly* impressed so far. The full reinstallation of my machine, which included a fresh install of Windows 7 and all my applications (around 30) took less than 8 hours.</p> <p>The actual Windows installation took under 1 hour (I'd say in the 40 minute range), and went very smoothly. There were 2 devices (webcam – has always been flaky on this laptop – and fingerprint reader) which were not detected out-of-the-box but Windows picked them up in the first update.</p> <p>Skype was the only software which had some compatibility issues and in the new Action Center I was provided with a link to the beta which works fine.</p> <p>The interface is very snappy and I really enjoy the new features. There are also some <a href="https://brandonlive.com/2009/01/10/windows-7-beta-hotkey-cheat-sheet/">neat shortcuts</a> which make life a lot better.</p> <p>Also used the <em>Send Feedback</em> feature a couple of times already. Perhaps they should leave it there after they ship too :)</p> <p>Overall, kudos to the Win 7 team so far. I’m really looking forward to the RC and RTM! On a scale from 1-10, I give it a 9.5, which is great considering it’s a beta software.</p>]]></content:encoded>
    </item>
    <item>
      <title>The DATAbase is part of the DATA layer, so it should be used for … DATA</title>
      <link>https://docs.microsoft.com/archive/blogs/cosmin/the-database-is-part-of-the-data-layer-so-it-should-be-used-for-data</link>
      <pubDate>Sun, 04 Jan 2009 21:27:07 GMT</pubDate>
      <dc:creator><![CDATA[cosn]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cosmin/2009/01/04/the-database-is-part-of-the-data-layer-so-it-should-be-used-for-data/</guid>
      <description><![CDATA[I was talking to a friend the other day, and he’s learning some Silverlight (which, as a side note...]]></description>
      <content:encoded><![CDATA[<p>I was talking to a friend the other day, and he’s learning some Silverlight (which, as a side note is *really* neat). One of the things he’s doing is building an HTML control, so I asked the obvious questions – why? Well as it turns out, he needs to get some HTML and display it to the user. There’s no Silverlight control which does this (and I don’t think there should be either), and there’s a good reason for it.</p> <p>The conversation continued, and I soon learned that the database contains HTML, and the UI just gets the appropriate value and displays it. Needless to say, I HATE that. There’s a reason we have different layers, and we should use them appropriately. I’ve seen this happen several times, and it never ends up well.</p> <p>So why do people do it? Well, there’s some <strong>immediate</strong> advantages to it:</p> <ol> <li>There’s no recompile necessary for changes: there’s a bug, just have an ALTER statement ready with your fix, or just DROP and add the fixed version.</li> <li>Shortcuts – if you have some complex data which you need to store, it sure as heck <strong>seems</strong> easier to store the HTML blob needed, rather than serialize/deserialize things.</li> <li>Personnel – if you have some SQL-heavy developers in your team, their first instinct is to put it in the database. If you ask a brain surgeon about a medical mystery, he’ll probably see brain damage. If you ask an oncologist, he’ll see cancer. It’s just human nature.</li></ol> <p>So at this point some of you might ask yourselves, <em>so what’s the problem</em>? Well, there are several issues with using your data layer for more than data:</p> <ol> <li>It doesn’t “scale” – you are now limited to SQL, and for all the power that it provides, there’s LOTS of stuff missing because it’s not what it was intended to do – want to do any advanced XML stuff? need to call a web service? how about some localization?</li> <li>It’s not strongly-typed – just because you have basic types, tables and columns, it’s not the same thing. Going back to the example at hand – you can store WHATEVER you want in those columns, it’s just ntext or nvarchar. Which brings me to the last point</li> <li>It’s not secure – so assume my friends writes his Silverlight HTML control, and is now able to get the html blob from the database and just display it, so links work and all. There is absolutely NO way (short of parsing the content – and at that point you have more work to do than you signed up in the first place) to know what that HTML contains. Can you spell Cross Site Scripting vulnerabilities?</li></ol> <p>I was briefly working on a project a few months ago which was VERY data-heavy (let’s just say that having html in some columns was the LEAST of my worries), and I had to debug a very simple UI issue (hyperlink wasn’t pointing to the right thing). Instead of being a simple fix in a resource file, it resulted in a 2-hour investigation which resulted in editing a stored procedure to fix this.</p> <p>So as a last word of advice – please, please, please stop abusing you database and use it for what it’s meant – storing your data. Do it in a smart manner (normalize your data, use indexes, use stored procedures instead of dynamic sql etc.) and get the most out of it. But do <strong>not</strong> store everything in there just to save some code higher in the stack. Else, you’ll have major headaches down the road, and pulling stuff out of the database is not as easy as you’d imagine.</p>]]></content:encoded>
    </item>
    <item>
      <title>UTF-8 strings in C#</title>
      <link>https://docs.microsoft.com/archive/blogs/cosmin/utf-8-strings-in-c</link>
      <pubDate>Fri, 26 Dec 2008 20:54:08 GMT</pubDate>
      <dc:creator><![CDATA[cosn]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cosmin/2008/12/26/utf-8-strings-in-c/</guid>
      <description><![CDATA[I was doing a code review a few days ago on a web service library. There was a message which was...]]></description>
      <content:encoded><![CDATA[<p>I was doing a code review a few days ago on a web service library. There was a message which was supposed to be stored in UTF-8, since the service is internationalized. The code looked similarly to this:</p> <div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">string</span> someRandomText;</pre><pre><span class="lnum">   2:  </span>UTF8Encoding encoder = <span class="kwrd">new</span> UTF8Encoding();</pre><pre class="alt"><span class="lnum">   3:  </span><span class="kwrd">byte</span>[] bytes = Encoding.UTF8.GetBytes(someRandomText);</pre><pre><span class="lnum">   4:  </span><span class="kwrd">string</span> utf8ReturnString = encoder.GetString(bytes);</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>I actually didn’t noticed this on my first glance, but then I actually went back and thought about it. Can you figure it out? I’ll give you a few seconds … If you actually do <a target="_blank" href="https://www.google.com/search?hl=en&amp;q=c%23+string+to+utf-8&amp;btnG=Google+Search&amp;meta=">a</a> <a target="_blank" href="https://search.live.com/results.aspx?q=c%23+string+to+utf-8&amp;go=&amp;form=QBLH">search</a>, you’ll <a target="_blank" href="https://www.chilkatsoft.com/p/p_320.asp">find</a> something pretty similar. Given how it’s the top post for both search engines, I figured it’s worth talking about and analyzing this really simple code. </p>
<p>So what do we have here? Line 1 is just to demonstrate this. Assume <em>someRandomText</em> contains some .. err .. random text :) Assume it contains a bunch of characters, not just your usual ASCII text. Line 2 simply initializes the encoder. So far so good. Even line 3 is perfectly OK. You can just <a target="_blank" href="https://msdn.microsoft.com/en-us/library/ds4kkd55(VS.80).aspx">convert</a> the string into a byte array. As you probably suspected, line 4 is the culprit here.</p>
<p>I guess it’s only fair give a little history of how strings are stored in C#. The short answer is UTF-16. Normally, this is perfectly fine, and for most application, UTF-16 should be the default encoding. However, for web services, UTF-8 is the usual encoding. XML is usually encoded in UTF-8, and since web services work over SOAP, it’s only natural to encode the text similarly.</p>
<p>Now, back to our little problem. Do you notice what’s going on here? The schema would look something like:</p>
<p>string (UTF-16) –&gt; bytes[] (UTF-8) –&gt; string (UTF-16)</p>
<p>So we’re really not doing anything. You might as well have just returned <em>someRandomText</em> and save some processor cycles.</p>
<p>If you really want to encode things properly, you’ll have to walk the byte array and extract the characters from there in hex format. A little bit more work, but at least it will do what you wanted it to do :)</p>
<p>-Cos</p>]]></content:encoded>
    </item>
    <item>
      <title>Platforms vs. Frameworks</title>
      <link>https://docs.microsoft.com/archive/blogs/cosmin/platforms-vs-frameworks</link>
      <pubDate>Wed, 22 Oct 2008 17:06:00 GMT</pubDate>
      <dc:creator><![CDATA[cosn]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cosmin/2008/10/22/platforms-vs-frameworks/</guid>
      <description><![CDATA[First of all, apologies for not having any activity lately. I pretty much blame the lack of Internet...]]></description>
      <content:encoded><![CDATA[<P>First of all, apologies for not having any activity lately. I pretty much blame the lack of Internet at home, a situation now remedied.</P>
<P>Since I mentioned that my work is for an online platform, I had some people come ask me what the difference between&nbsp;a platform and a framework are. Based on my current experience, I'm going to give a simple explanation. Others might have contradictory experiences, so feel free to share.</P>
<UL>
<LI>A framework&nbsp;is a set of <A title=APIs target=_blank href="https://en.wikipedia.org/wiki/Api" mce_href="https://en.wikipedia.org/wiki/Api">APIs</A>&nbsp;which allow the consumer (3rd party developer most of the times) to perform some actions.</LI>
<LI>A platform is a set of services and APIs which allow the consumer (3rd party company most of the time) to perform some actions.</LI></UL>
<P>You can now see why we have the confusion. Until the emergence of the Internet, a platform was pretty synonymous with a framework. Now, platforms usually represent some web services, and at times frameworks (or <A title=SDKs target=_blank href="https://en.wikipedia.org/wiki/SDK" mce_href="https://en.wikipedia.org/wiki/SDK">SDKs</A>, if you wanted to have more complicated buzzwords). Let's take a look at 2 examples, one for consumers and one for businesses:</P>
<OL>
<LI><A title=XNA target=_blank href="https://msdn.microsoft.com/en-us/xna/default.aspx" mce_href="https://msdn.microsoft.com/en-us/xna/default.aspx">XNA</A>&nbsp;- consumer platform enabling hobbyists develop and publish video games. On one hand, it has a bunch of services, which allow developers to interact with it (Blog, Creators Club etc), and on the other it has a full framework which hides the complexity of DirectX development rather nicely.</LI>
<LI><A title=OCP target=_blank href="https://www.microsoft.com/online" mce_href="https://www.microsoft.com/online">OCP</A>&nbsp;- a commercial platform enabling businesses integrate, sell, advertise and bill their services online. Our current architecture is comprised of several web services which perform different duties. Companies can plug into our environment and start using the web service APIs. There are some high level APIs, for general abstract things (eg. billing a customer), and lots of lower level APIs which the web services use to talk to each other and perform their duties. Currently there is no public framework in place, and I'm not sure given the current model one would be needed.</LI>
<LI><A title=Facebook target=_blank href="https://www.facebook.com/" mce_href="https://www.facebook.com">Facebook</A>&nbsp;- everybody knows that Facebook is a social site, but for developers it is a platform - it has a set of public APIs which developers can call to get different information and provide whatever they seem worthy to their customers (and if you didn't notice the tons of apps for Facebook it means you're not using it often enough)</LI></OL>
<P>When&nbsp;I refer to a <STRONG>framework</STRONG>, I usually expect to download some DLLs, and be able to reference them in my code. <A title=.NET target=_blank href="https://www.microsoft.com/net/" mce_href="https://www.microsoft.com/net/">.NET</A>&nbsp;is a perfect example of a framework. While the complexity of .NET is significantly higher (it's also a runtime, among other things), it is a set of DLLs which can be referenced within a 3rd party's code.</P>
<P>As I initially said, there's a pretty thin line between a framework and a platform, but one that will probably become more clear in the future, when I expect services to become more relevant and common.</P>
<P>-Cos</P>]]></content:encoded>
    </item>
    <item>
      <title>First post ... sort of</title>
      <link>https://docs.microsoft.com/archive/blogs/cosmin/first-post-sort-of</link>
      <pubDate>Wed, 01 Oct 2008 00:47:46 GMT</pubDate>
      <dc:creator><![CDATA[cosn]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/cosmin/2008/10/01/first-post-sort-of/</guid>
      <description><![CDATA[For those of you who know me, you probably have read my previous posts. For everyone else, feel free...]]></description>
      <content:encoded><![CDATA[<p>For those of you who know me, you probably have read my <a target="_blank" href="https://cosnicolaescu.spaces.live.com/default.aspx">previous posts</a>. For everyone else, feel free to browse through my Live Spaces page.</p>  <p>I hope to have some time soon to post some fresh content here.</p>  <p>-Cos</p>]]></content:encoded>
    </item>
  </channel>
</rss>