<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Programming</title>
        <link>http://ayende.com/Blog/category/496.aspx</link>
        <description>Programming</description>
        <language>en-US</language>
        <copyright>Ayende Rahien</copyright>
        <managingEditor>Ayende@ayende.com</managingEditor>
        <generator>Subtext Version 2.0.0.0</generator>
        <item>
            <title>My Erlang Religious Moment</title>
            <link>http://ayende.com/Blog/archive/2010/03/20/my-erlang-religious-moment.aspx</link>
            <description>&lt;p&gt;It is not often that a piece of code cause me to have a religious moment, but this one managed to:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/MyErlangReligiousMoment_68F9/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/MyErlangReligiousMoment_68F9/image_thumb.png" width="615" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11361.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/03/20/my-erlang-religious-moment.aspx</guid>
            <pubDate>Sat, 20 Mar 2010 10:00:00 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/11361.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2010/03/20/my-erlang-religious-moment.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11361.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Challenge: What does this code do?</title>
            <link>http://ayende.com/Blog/archive/2010/03/19/challenge-what-does-this-code-do-again.aspx</link>
            <description>&lt;p&gt;What language is it? What is it doing? Why?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ChallengeWhatdoesthiscodedo_D508/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ChallengeWhatdoesthiscodedo_D508/image_thumb_1.png" width="1133" height="649" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11360.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/03/19/challenge-what-does-this-code-do-again.aspx</guid>
            <pubDate>Fri, 19 Mar 2010 10:00:00 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/11360.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2010/03/19/challenge-what-does-this-code-do-again.aspx#feedback</comments>
            <slash:comments>17</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11360.aspx</wfw:commentRss>
        </item>
        <item>
            <title>You can&amp;rsquo;t learn the basics from the pros</title>
            <link>http://ayende.com/Blog/archive/2010/03/12/you-canrsquot-learn-the-basics-from-the-pros.aspx</link>
            <description>&lt;p&gt;There was a question recently in the NHibernate mailing list from a guy wanting to learn how to write database agnostic code from the NHibernate source code.&lt;/p&gt;  &lt;p&gt;While I suppose that this is possible, I can’t really think of a worst way to learn how to write database agnostic code than reading an OR/M code. The reason for that is quiet simple, an OR/M isn’t just about one thing, it is about doing a lot of things together and bringing them together into a single whole. Yes, most OR/M are database agnostic, but trying to figure out the principles of that from the code base is going to be very hard. &lt;/p&gt;  &lt;p&gt;That leads to an even more interesting problem, it is &lt;em&gt;very&lt;/em&gt; hard for a beginner to actually learn something useful from a professional. That is true in any field, of course. In software, the problem is that most pros would simply skip whole steps that beginners are thought to be crucial. It isn’t from neglect, it is because they &lt;em&gt;are&lt;/em&gt; going through those steps, but not in a conscious level.&lt;/p&gt;  &lt;p&gt;Very often, I’ll come up with a design, and when it is only when I need to justify it to someone else that I actually realize the finer points of what have actually gone through my own head (another reason that having a blog is useful).&lt;/p&gt;  &lt;p&gt;I think that there is a reason that we have names like code smells, you can immediately sense a problem in a smelly codebase, although it may take you a while to actually articulate it.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11345.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/03/12/you-canrsquot-learn-the-basics-from-the-pros.aspx</guid>
            <pubDate>Fri, 12 Mar 2010 10:00:00 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/11345.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2010/03/12/you-canrsquot-learn-the-basics-from-the-pros.aspx#feedback</comments>
            <slash:comments>10</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11345.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Getting code ready for production</title>
            <link>http://ayende.com/Blog/archive/2010/03/06/getting-code-ready-for-production.aspx</link>
            <description>&lt;p&gt;I am currently doing the production-ready pass through the Rhino DivanDB code base, and I thought that this change was interesting enough to post about:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute()
{
    &lt;span class="kwrd"&gt;while&lt;/span&gt;(context.DoWork)
    {
        &lt;span class="kwrd"&gt;bool&lt;/span&gt; foundWork = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        transactionalStorage.Batch(actions =&amp;gt;
        {
           var task = actions.GetFirstTask();
           &lt;span class="kwrd"&gt;if&lt;/span&gt;(task == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
           {
               actions.Commit(); 
               &lt;span class="kwrd"&gt;return&lt;/span&gt;;
           }
           foundWork = &lt;span class="kwrd"&gt;true&lt;/span&gt;;

           task.Execute(context);

           actions.CompleteCurrentTask();

           actions.Commit();
        });
        &lt;span class="kwrd"&gt;if&lt;/span&gt;(foundWork == &lt;span class="kwrd"&gt;false&lt;/span&gt;)
            context.WaitForWork();
    }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;This is “just get things working” phase. When getting a piece of code ready for production, I am looking for several things:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If this is running in production, and I get the log file, will I be able to understand what is going on?&lt;/li&gt;

  &lt;li&gt;Should this code handle any exceptions?&lt;/li&gt;

  &lt;li&gt;What happens if I send values from a previous version? From a future version?&lt;/li&gt;

  &lt;li&gt;Am I doing unbounded operations?&lt;/li&gt;

  &lt;li&gt;For error handling, can I avoid any memory allocations?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result for this piece of code was:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute()
{
    &lt;span class="kwrd"&gt;while&lt;/span&gt;(context.DoWork)
    {
        &lt;span class="kwrd"&gt;bool&lt;/span&gt; foundWork = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        transactionalStorage.Batch(actions =&amp;gt;
        {
            var taskAsJson = actions.GetFirstTask();
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (taskAsJson == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                actions.Commit();
                &lt;span class="kwrd"&gt;return&lt;/span&gt;;
            }
            log.DebugFormat(&lt;span class="str"&gt;"Executing {0}"&lt;/span&gt;, taskAsJson);
            foundWork = &lt;span class="kwrd"&gt;true&lt;/span&gt;;

            Task task;
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                task = Task.ToTask(taskAsJson);
                &lt;span class="kwrd"&gt;try&lt;/span&gt;
                {
                    task.Execute(context);
                }
                &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception e)
                {
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (log.IsWarnEnabled)
                    {
                        log.Warn(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Task {0} has failed and was deleted without completing any work"&lt;/span&gt;, taskAsJson), e);
                    }
                }
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception e)
            {
                log.Error(&lt;span class="str"&gt;"Could not create instance of a task from "&lt;/span&gt; + taskAsJson, e);
            }

            actions.CompleteCurrentTask();
            actions.Commit();
        });
        &lt;span class="kwrd"&gt;if&lt;/span&gt;(foundWork == &lt;span class="kwrd"&gt;false&lt;/span&gt;)
            context.WaitForWork();
    }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;The code size blows up &lt;em&gt;really&lt;/em&gt; quickly.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11339.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/03/06/getting-code-ready-for-production.aspx</guid>
            <pubDate>Sat, 06 Mar 2010 10:00:00 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/11339.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2010/03/06/getting-code-ready-for-production.aspx#feedback</comments>
            <slash:comments>24</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11339.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Nice process, but what about the engineering bits?</title>
            <link>http://ayende.com/Blog/archive/2010/02/20/nice-process-but-what-about-the-engineering-bits.aspx</link>
            <description>&lt;p&gt;Software processes has always been a popular topic of discussion in our industry. Those can get quite heated, with advocates of the “stable / stale” Waterfall method pointing fingers toward “rapid / rabid” Agile methods, with the CMMI people throwing documents around and Lean people standing on the sidelines muttering about Waste.&lt;/p&gt;  &lt;p&gt;This isn’t a post about a specific software process, I’ll defer that to another day. Instead, I want to focus on a flaw in the basic building blocks in many* software building processes. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;&lt;em&gt;They ignore the actual building the software&lt;/em&gt;.&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;That may sound ridiculous on the face of it, after all, how can a &lt;em&gt;software &lt;/em&gt;process ignore the act of building software. But take a look at the following diagrams:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://upload.wikimedia.org/wikipedia/en/thumb/e/e2/Waterfall_model.svg/350px-Waterfall_model.svg.png" /&gt;&lt;img src="http://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/ScrumLargeLabelled.png/400px-ScrumLargeLabelled.png" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Ilikeyourprocessbutwheredothesoftwarebit_A926/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Ilikeyourprocessbutwheredothesoftwarebit_A926/image_thumb.png" width="642" height="438" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p /&gt; &lt;p&gt;If you’ll pay attention, you’ll notice that those processes talk about everything &lt;em&gt;except&lt;/em&gt; how to actually build software. They talk about people, about requirements, about managing customers, about a whole &lt;em&gt;lot of things&lt;/em&gt;, but &lt;strong&gt;not &lt;/strong&gt;about the part where you have people sitting down and writing code. In most of those, in fact, that part is usually defined as one of those:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Ilikeyourprocessbutwheredothesoftwarebit_A926/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Ilikeyourprocessbutwheredothesoftwarebit_A926/image_thumb_3.png" width="410" height="202" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p /&gt;  &lt;p&gt;Why is that a problem? After all, isn’t there a big distinction between software &lt;em&gt;engineering&lt;/em&gt; (we know what to do, now let us do it) and &lt;em&gt;project management &lt;/em&gt;(getting to know what we need to do, and verifying that we did it right). Those processes deal primarily with project management and leave the engineering part to be defined in a way that fit that particular project. Surely that is better, right? In theory, it might be. But there is a big problem when you have a software process that ignore the software engineering aspects of building software.&lt;/p&gt;  &lt;p&gt;The problem is that that in many cases, there are hidden assumptions that are going to hammer you down the road if you use a certain process with engineering practices that doesn’t fit it. Take a look at the following chart, showing a team velocity over time, does this look familiar?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Ilikeyourprocessbutwheredothesoftwarebit_A926/image_16.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Ilikeyourprocessbutwheredothesoftwarebit_A926/image_thumb_7.png" width="483" height="291" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The term I heard used for this is Scrum Wall, but I have seen similar results in other processes as well. The best description for that &lt;a href="http://allankelly.blogspot.com/2009/07/scrum-wall-another-agile-failure-mode.html"&gt;is Allan Kelly’s&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;You hit the &lt;strong&gt;Scrum wall&lt;/strong&gt; when you adopt Scrum and everything goes well, then, after a few Sprints things don’t work any more - to use an English expression, &lt;em&gt;they go pear shaped. &lt;/em&gt;You can’t keep your commitments, you can’t release software, your customers get annoyed and angry, it looks like Scrum is broken. &lt;/p&gt;    &lt;p&gt;This is what happens when you adopt Scrum without technical practices such as Test Driven Development, continuous integration and refectoring. When teams adopt the Scrum process, they go faster, show progress, things look good... and then the quality becomes a problem. Now the team are fighting through quick sand.&lt;/p&gt;    &lt;p&gt;The code quality is poor and developers are expected to continue to make progress. Maybe the Scrum Master/Project Manager reverts to past behavior and demands overtime and weekend working. Maybe the team start busting a gut to keep their commitments. Either way the team is heading for burn-out.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The major issue is in focusing so much effort and time on project management with what amounts to willful ignorance of the technical and engineering practices will inevitably leads to disaster. The process of building software is intractably linked to the engineering practices involved in building the software. Moreover, some technical practices are actively harmful in some scenarios and life savers in others.&lt;/p&gt;  &lt;p&gt;Many Agile and post-Agile processes focus on short cycles, each of them producing something with a distinct value to the customer. That may be an iteration, a commit or a feature, where the goal is to increase the velocity over time so we can provide as much value to the customer in as short a time as possible. What those processes &lt;em&gt;ignore&lt;/em&gt; are things like technical debt, large scale refactoring and non functional efforts. Oh, you see those things mentioned on the edge, but they aren’t something that is dealt with heads on, as a core issue to consider.&lt;/p&gt;  &lt;p&gt;There is a bit more to that, actually. The software engineering practices and the project management strategies are linked and of paramount importance when the time comes to decide how the software should actually be built. No, this is not tautology. We just need to take into account Conway’s law and expand on it a bit.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Any organization that designs a system will inevitably produce a design whose structure is a copy of the organization's communication structure.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Part of the design process of a project should include design the team(s) structure, the project management strategy and the software engineering practices in order to align the end result with what is desired. Ignoring this leads to imbalance in the project, and if that imbalance is big enough, and goes on for long enough, the project is going to rip itself apart.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;* Nitpicker corner: I said &lt;em&gt;many&lt;/em&gt;, not all. Don’t bother to list me software process that deals with it. I had a reason to explicitly list the processes that I did.&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://ayende.com/Blog/aggbug/11322.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/02/20/nice-process-but-what-about-the-engineering-bits.aspx</guid>
            <pubDate>Sat, 20 Feb 2010 01:23:00 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/11322.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2010/02/20/nice-process-but-what-about-the-engineering-bits.aspx#feedback</comments>
            <slash:comments>31</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11322.aspx</wfw:commentRss>
        </item>
        <item>
            <title>WPF WebBrowser and JavaScript interaction</title>
            <link>http://ayende.com/Blog/archive/2010/01/15/wpf-webbrowser-and-javascript-interaction.aspx</link>
            <description>&lt;p&gt;I found myself needing to interact with JavaScript API in a WebBrowser hosted in a WPF application. That turned out to be quite a challenge to figure out, but I prevailed :-)&lt;/p&gt;  &lt;p&gt;Given the following XAML:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="WpfApplication1.Window1"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
    &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;="Window1"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;WebBrowser&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Browser"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;You can interact with the JavaScript API using this code:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Window1 : Window
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Window1()
    {
        InitializeComponent();
        Browser.LoadCompleted += BrowserOnLoadCompleted;
        Browser.Navigate(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;"http://example.com"&lt;/span&gt;));
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BrowserOnLoadCompleted(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, NavigationEventArgs navigationEventArgs)
    {
        var doc = (HTMLDocument)Browser.Document;
        var head = doc.getElementsByTagName(&lt;span class="str"&gt;"head"&lt;/span&gt;).Cast&amp;lt;HTMLHeadElement&amp;gt;().First();
        var script = (IHTMLScriptElement)doc.createElement(&lt;span class="str"&gt;"script"&lt;/span&gt;);
        script.text = &lt;span class="str"&gt;"alert('hi');"&lt;/span&gt;;
        head.appendChild((IHTMLDOMNode)script);
        script.text = &lt;span class="str"&gt;"alert('bye');"&lt;/span&gt;;
    }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.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; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;This allow you to inject JavaScript commands to the browser by manipulation the script.text property. It isn’t generally useful, I’ll admit, but for my scenario, it seems to be doing the job.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11281.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/01/15/wpf-webbrowser-and-javascript-interaction.aspx</guid>
            <pubDate>Fri, 15 Jan 2010 10:00:00 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2010/01/15/wpf-webbrowser-and-javascript-interaction.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11281.aspx</wfw:commentRss>
        </item>
        <item>
            <title>My Java Experience</title>
            <link>http://ayende.com/Blog/archive/2010/01/14/my-java-experience.aspx</link>
            <description>&lt;p&gt;As I &lt;a href="http://ayende.com/Blog/archive/2009/11/23/how-would-you-learn-a-new-platform.aspx"&gt;mentioned before&lt;/a&gt;, I am actively trying to find what I &lt;em&gt;don’t&lt;/em&gt; know, and plug it. As part of that endeavor, I spent the last week learning Java EE. I decided that in the interest of saving time I am going to invest some money and I took a week long course in it. That allowed me to kill several birds in a single stone, I got to experience Java in an environment that had an instructor that I could call on for help, it allowed me to learn Java EE and it allowed to me experience how people using &lt;a href="http://HibernateProfiler.com"&gt;Hibernate Profiler&lt;/a&gt; feel like.&lt;/p&gt;  &lt;p&gt;Now that it is over, I can say that the course has met my expectations to a T. But that isn’t the point of this post. I wanted to talk about what I learned and my experience.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Nitpicker corner: please note that I am talking &lt;em&gt;only &lt;/em&gt;about Java EE and EJB 3.0. I am well aware of the existence of frameworks that build on top of that (and earlier versions), but right now I intend to discuss Naked Java EE.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;From language perspective, working with Java was &lt;em&gt;incredibly &lt;/em&gt;frustrating. I had not really realized how much I come to rely on such things as object initializers, the &lt;em&gt;var&lt;/em&gt; keyword or null coalescing operators. &lt;/p&gt;  &lt;p&gt;As a platform, I have a much better understanding for how the Java EE eco system developed. Basically, it works like this (the concepts does not translate exactly, mind you):&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="742"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;Java EE&lt;/td&gt;        &lt;td valign="top" width="540"&gt;.NET&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;Servlet&lt;/td&gt;        &lt;td valign="top" width="540"&gt;Http Handler – but with singleton semantics &amp;amp; with threading issues.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;JSP&lt;/td&gt;        &lt;td valign="top" width="540"&gt;ASPX – but without any code behind.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;Listener&lt;/td&gt;        &lt;td valign="top" width="540"&gt;Http Module&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;One of the things that really drove me crazy is the notion of making everything a singleton. I wonder if there was a time where object creation in Java was very expensive, that might result in this design. The problem in making everything a singleton is that it become shared state, which means that you need to handle concurrency yourself. &lt;em&gt;This is a bad thing&lt;/em&gt;. In fact, I would go further and say that &lt;em&gt;any framework that requires users to handle concurrency for standard scenarios is flawed&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;When I learned that you had to wire each independent servlet in the web.xml, I was quite shocked. The sheer friction that this is going to add to a project is mind numbing. Imagine the camera unzooming, and the full picture showing up. There are usually very few servlets in an application, often only one. They handle the request by sending the data to an EJB to handle the business end and a JSP to handle the HTML generation end. If it sounds a lot like MVC, it should. The interesting bit is that I don’t think that all the Java MVC frameworks came out because of anything unique in the Java sphere. They came out of sheer self defense out of the amount of toil &amp;amp; trouble that you have to go through using what the bare bones Java EE gave you.&lt;/p&gt;  &lt;p&gt;Moving on to what I would call the controller side of things, we have EJBs, Enterprise Java Beans. There are Session Beans and Message Driven Beans. The MDB reminded me quite strongly of a very basic service bus. Considering something like Rhino ServiceBus or NServiceBus, it looks very similar in concept and execution, but without a lot of the things that the those two do for you. Session Beans are supposed to handle requests, they are divided into stateful and stateless beans. In general, I seems that you would generally use the stateless beans. &lt;/p&gt;  &lt;p&gt;A stateless bean is a class implementing a specific interface, and that is where a lot of the interesting things are happening, dependency injection, automatic transaction management, session management, etc. It is interesting to note that with .NET we have gotten to the same result, but without having the overreaching presence of the container everywhere. I really like the fact that there is no attempt to disguise how they are doing things, the Java’s language decision to make everything virtual by default has really paid off in here.&lt;/p&gt;  &lt;p&gt;Still, I can’t say that I like the default architecture, it seems very inflexible. I do like the ideas of full blown servers that you can just deploy a file into. It is a very nice concept, but it has some sever downsides, the time that it takes to do a modify-deploy-test cycle is significantly larger than what I noticed on the .NET side of things. And keep in mind that I am talking about projects that had about 5 classes in them all told.&lt;/p&gt;  &lt;p&gt;During the course, the instructor said something that I found very insightful, “the tooling help you deal with… [wiring the xml, inheriting from the appropriate interfaces, etc]”. I found this very telling, because up until then I was quite puzzled by the behavior of all the standard wizards in Eclipse. They seem to violate the KISS principle, especially after getting used to the Yes, Dear experience when using R# on VS. It was only after I realized just how much work those poor wizards had to do for me that I understood what was going on.&lt;/p&gt;  &lt;p&gt;After the course, I took a look at some of the MVC frameworks in the Java market. Just reading the tutorials is fascinating, from a code archaeology perspective. You can clearly see that Struts came early on, since while I am sure it is an improvement over Naked Jave EE, the amount of XML you have to deal with is &lt;em&gt;not&lt;/em&gt; funny.&lt;/p&gt;  &lt;p&gt;All in all, I find myself unimpressed by the amount of work that was shuffled to the tools, it doesn’t seem right. And it seems like a justification of a bad practice. When I consider my own design principles (Zero Friction!) in light of this, I am much happier that I am mainly working in the .NET world. But I think that having this understanding is going to be very helpful moving forward.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11280.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/01/14/my-java-experience.aspx</guid>
            <pubDate>Thu, 14 Jan 2010 10:00:00 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2010/01/14/my-java-experience.aspx#feedback</comments>
            <slash:comments>39</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11280.aspx</wfw:commentRss>
        </item>
        <item>
            <title>As to the methods there may be a million, but principles are few</title>
            <link>http://ayende.com/Blog/archive/2010/01/11/as-to-the-methods-there-may-be-a-million-but.aspx</link>
            <description>&lt;p&gt;I run across the &lt;a href="http://devlicio.us/blogs/tim_barcz/archive/2009/12/14/ralph-waldo-emerson-would-ve-been-a-great-developer.aspx?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed:+Devlicious+(Devlicio.us)&amp;amp;utm_content=Google+Reader"&gt;following quote&lt;/a&gt; a while ago, and I found it quite interesting.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;“As to the methods there may be a million and then some, but principles are few. The man who grasps principles can successfully select his own methods. The man who tries methods, ignoring principles, is sure to have trouble.”&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;- Ralph Waldo Emerson (1803-1882)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I have been programming, in one form or another, for about fifteen years, but I can put my finger on the precise moment in which I moved from a mere dabbler to a professional. That was in 1999, and I decided that I had enough of toying with Pascal, VB6 &amp;amp; Java Applets. It was the height of the bubble, and I wanted to learn just enough to be able to get a job doing something that I enjoyed. I had about a year opened to me, and I registered myself to a C/C++ course in a local college.&lt;/p&gt;  &lt;p&gt;In hindsight, that was one of the best things that I have ever done. That course taught me C and pointers, and then C++ and OO. I also introduced me to concepts that I have been using ever since. Admittedly, I don’t want to look at any of my code from that time period, but that is probably a good thing :-) The most important part of the course was that it taught me how computers work, by introducing C first and forcing me to write my own implementation of any system call that I wanted to make. &lt;/p&gt;  &lt;p&gt;I studied programming in High School as well, and I distinctly remember being utterly and completely baffled by strange things like dynamic memory and pointers. I mean, why don’t you just allocate a bigger array. During that course I actually grasped pointers for the first time, and even looking back over the last couple of weeks, a &lt;em&gt;lot&lt;/em&gt; of my performance work recently is directly based on things that I learned there.&lt;/p&gt;  &lt;p&gt;After completing that course, I got several books to help me understand the fundamentals better. &lt;a href="http://www.amazon.com/Operating-Systems-Design-Implementation-3rd/dp/0131429388/ref=sr_1_8?ie=UTF8&amp;amp;s=books&amp;amp;qid=1262153174&amp;amp;sr=8-8"&gt;Operating Systems Design and Implementation&lt;/a&gt;, &lt;a href="http://www.amazon.com/Modern-Operating-Systems-Andrew-Tanenbaum/dp/0136006639/ref=sr_1_4?ie=UTF8&amp;amp;s=books&amp;amp;qid=1262153174&amp;amp;sr=8-4"&gt;Modern Operating Systems&lt;/a&gt; and &lt;a href="http://www.amazon.com/Operating-System-Concepts-Abraham-Silberschatz/dp/0471694665/ref=sr_1_6?ie=UTF8&amp;amp;s=books&amp;amp;qid=1262153174&amp;amp;sr=8-6"&gt;Operating System Concepts&lt;/a&gt; to understand how an operating system works, not just a single program. &lt;a href="http://www.amazon.com/Win32-System-Programming-Johnson-Hart/dp/0201634651/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1262153343&amp;amp;sr=8-1"&gt;Win32 System Programming&lt;/a&gt;, which I read mainly to understand the environment in which I was working and &lt;a href="http://www.amazon.com/Windows-Sockets-Network-Programming-paperback/dp/0768682320/ref=sr_1_2?ie=UTF8&amp;amp;s=books&amp;amp;qid=1262153451&amp;amp;sr=1-2"&gt;Windows Sockets Network Programming&lt;/a&gt;, from which I learned the basic concepts of networking.&lt;/p&gt;  &lt;p&gt;The common thread throughout all of them is that initially I focused on understanding the technical environment in which I was working, getting to understand how things are working at a very low level. And while it may appear that understand those low level details would be nice in terms of general education but have little relevance to where I am spending most of my time, that is quite inaccurate. The recently built serialization system built for the profiler was heavily influenced from my reading of the OS books, for example.&lt;/p&gt;  &lt;p&gt;For that matter, other good books are &lt;a href="http://www.amazon.com/Practical-System-Design-Dominic-Giampaolo/dp/1558604979/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1262153691&amp;amp;sr=8-1"&gt;Practical File System Design&lt;/a&gt;, talking about the BeOS file system, which I found utterly fascinating or &lt;a href="http://www.amazon.com/Virtual-Machine-Design-Implementation-Blunden/dp/1556229038/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1262153703&amp;amp;sr=8-1"&gt;Virtual Machine Design and Implementation C/C++&lt;/a&gt; which is a &lt;em&gt;horrible&lt;/em&gt; book, but one that gave me the confidence to do a lot of things, since I saw how trivially simple it was to build such things.&lt;/p&gt;  &lt;p&gt;Coming back to the quote in the beginning of this post, understanding the underlying principles has allowed me to do approach a new technology with the confidence that I understand how it must work, because I understand the environment in which it works. Oh, there are a lot of details that you need to get, but once you have the conceptual model of a technology in mind, it is so much easier to get to grips with it.&lt;/p&gt;  &lt;p&gt;Interestingly enough, I only got to software design books at a much later stage, and even today, I find the low level details quite fascinating, when I can get new material in a subject that is interesting to me.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11269.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/01/11/as-to-the-methods-there-may-be-a-million-but.aspx</guid>
            <pubDate>Mon, 11 Jan 2010 10:00:00 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2010/01/11/as-to-the-methods-there-may-be-a-million-but.aspx#feedback</comments>
            <slash:comments>19</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11269.aspx</wfw:commentRss>
        </item>
        <item>
            <title>The problem with compression &amp;amp; streaming</title>
            <link>http://ayende.com/Blog/archive/2010/01/10/the-problem-with-compression-amp-streaming.aspx</link>
            <description>&lt;p&gt;I spent some time today trying to optimize the amount of data the profiler is sending on the wire. My first thought was that I could simply wrap the output stream with a compressing stream and use that, indeed, in my initial testing, it proved to be quite simple to do and reduced the amount of data being sent by a factor of 5. I played around a bit more and discovered that different compression implementation can bring me up to a factor of 50!&lt;/p&gt;  &lt;p&gt;Unfortunately, I did all my initial testing on &lt;em&gt;files, &lt;/em&gt;and while the profiler is able to read files just fine, it is most commonly used for live profiling, to see what is going on in the application &lt;em&gt;right now&lt;/em&gt;. The problem here is that adding compression is a truly marvelous way to screw that up. Basically, I want to compress live data, and most compression libraries are not up for &lt;em&gt;that &lt;/em&gt;task. It gets a bit more complex when you realize that what I actually wanted was a way to get compression to work on relatively small data chunks.&lt;/p&gt;  &lt;p&gt;When you think how most compression algorithm works (there is a dictionary in there &lt;em&gt;somewhere&lt;/em&gt;), you realize what the problem is. You need to keep updating the dictionary while you are compressing the stream, and at the same time, you need the dictionary to uncompress things. That make it… difficult to handle things. I thought about compressing small chunks (say, every 256Kb), but then I run into problems of figuring out when exactly I am supposed to be flushing them, how to handle partial messages, and more.&lt;/p&gt;  &lt;p&gt;In the end, I decided that while it was a very interesting trial run, this is not something that is likely to show good ROI.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11273.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/01/10/the-problem-with-compression-amp-streaming.aspx</guid>
            <pubDate>Sun, 10 Jan 2010 10:00:00 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2010/01/10/the-problem-with-compression-amp-streaming.aspx#feedback</comments>
            <slash:comments>12</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11273.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Production profiling security considerations</title>
            <link>http://ayende.com/Blog/archive/2010/01/04/production-profiling-security-considerations.aspx</link>
            <description>&lt;p&gt;I am currently in the process of building support for the production profiling. The technical part (how to reduce the footprint of the profiler when &lt;em&gt;not&lt;/em&gt; profiling) is pretty easy, and I spiked it out in a matter of a few hours. The non technical part has been driving me mad for days.&lt;/p&gt;  &lt;p&gt;One of the &lt;em&gt;major &lt;/em&gt;issues that I have to deal with with regards to production profiling is the issue of security. There are actually multiple levels to this issue. The most obvious one is that we want to secure &lt;em&gt;who&lt;/em&gt; can start profiling. Initially I thought that providing a password and limiting IP range that can connect to the profiling endpoint would be enough, but I quickly realized that I am being overly naive.&lt;/p&gt;  &lt;p&gt;The idea that someone can just hook into all the communication that goes on with the database is something that will give any security analyst heart palpitations. Not only do I need to secure access to the endpoint, I also need to ensure that no one can sniff this traffic, as it might very well include sensitive information. Beyond that, just to make sure that the aforementioned security analyst doesn’t show up at my door armed &amp;amp; pissed, it is important that only the system administrator (and &lt;em&gt;not&lt;/em&gt; the developers) can turn that on.&lt;/p&gt;  &lt;p&gt;That one isn’t so much to catch maliciousness, as much as to prevent people from deploying to production with their debug configuration enabled, but will also stop malicious acts of trying to open up holes in the application.&lt;/p&gt;  &lt;p&gt;After some investigation, I decided that I probably want to use SSL (and the SslStream implementation in the BCL) to do that. This has several advantages, it means that the network traffic is encrypted and I can ignore that aspect. It also means that I can take advantage on mutual authentication to ensure that the client is really authorized to do connect to me. Finally, I can also require that the certificate will be installed on the server machine, thus meeting the requirement of the system administrator having to take an explicit step to allow it.&lt;/p&gt;  &lt;p&gt;From design perspective, it looks nice, so the next question was to write some code to spike it. I should preface everything that follows with the admission that I have only rudimentary knowledge of the actual details of SSL and certificates. But basically, what I thought was to have the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Server certificate – self signed, server auth, bound to a particular hostname, not CA.&lt;/li&gt;    &lt;li&gt;Client certificate – self signed, client auth, bound to a particular hostname, not CA.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The client certificate would need to be added as a trusted root on the server. That would allow mutual authentication between the two parties. The server will reject unknown certs or ones that do not bind to the same hostname as the server cert. I am not sure if I should require that the server cert would have to be installed on the client machine, but I am leaning on not requiring that.&lt;/p&gt;  &lt;p&gt;Thoughts? Anything else that I might need to think about? Is this scheme really secure? Is it going to cause the ops people to go mad?&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/11274.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2010/01/04/production-profiling-security-considerations.aspx</guid>
            <pubDate>Mon, 04 Jan 2010 19:06:00 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2010/01/04/production-profiling-security-considerations.aspx#feedback</comments>
            <slash:comments>36</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/11274.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>