<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Useless Inc. - Development</title>
    <link>http://www.tomergabel.com/</link>
    <description>Tomer Gabel's annoying spot on the 'net</description>
    <language>en-us</language>
    <copyright>Tomer Gabel</copyright>
    <lastBuildDate>Mon, 11 Feb 2013 14:33:11 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>tomer@tomergabel.com</managingEditor>
    <webMaster>tomer@tomergabel.com</webMaster>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=851a7271-9bda-403c-a72f-8b13ec552271</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,851a7271-9bda-403c-a72f-8b13ec552271.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This is the second post of a two-parter. Please read <a href="http://www.tomergabel.com/Scala210MigrationCaseStudyPartI.aspx">part
1</a> for context and additional information.
</p>
        <p>
          <span style="text-decoration: underline;">3rd Party Libraries</span>
        </p>
        <p>
As mentioned in part 1, Scala is not binary backwards-compatible between major releases.
Although code compiled with 2.10 <em>may</em> work properly with libraries compiled
against 2.9.x, this is hardly recommended and may result in a lot of subtle error
conditions at runtime that are hard to track down. As a result, the recommended practice
is to upgrade <em>all</em> Scala dependencies to versions compiled against 2.10. Fortunately
the Scala ecosystem is very active, so most common libraries had 2.10 builds on announcement
day, but you are still likely to encounter libraries that need to be upgraded because:
</p>
        <ul>
          <li>
They're lagging behind the Scala release schedule and simply haven't released 2.10-compatible
binaries (fortunately, this seems to be extremely rare; in practice all our dependencies
were otherwise resolved);</li>
          <li>
The specific version you're using does not have a 2.10-compatible release and likely
never will (Squeryl 0.9.5-2);</li>
          <li>
A 2.10-compatible official release is out but hasn't yet been published to the central
repository (Scalatra 2.0.5).</li>
        </ul>
        <p>
My experience shows that with a bit of dilligence, practically all our (myriad) dependencies
were fairly easy to migrate to 2.10. In most cases this simply entails switching to
the appropriate artifact ID suffix (_2.10 instead of _2.9.2, see part 1 for associated
rant), in other cases I had to upgrade to a later official release and in rare cases
I had to dig in and replace a dependency with an appropriate fork or snapshot version.
Here is a list of migration notes for some of our dependencies:
</p>
        <table border="1" cellpadding="5">
          <thead>
            <tr>
              <td>
                <strong>Library</strong>
              </td>
              <td>
                <strong>Previous</strong>
              </td>
              <td>
                <strong>New version</strong>
              </td>
              <td>
                <strong>Comments</strong>
              </td>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>
                <a href="https://github.com/jorgeortiz85/scala-time">Scala-Time</a>
              </td>
              <td>
0.6</td>
              <td>
nscala-time 0.2 
</td>
              <td>
The original library appears to be abandoned and <a href="https://github.com/nscala-time/nscala-time">was
forked</a> on GitHub.<br />
The package changed from <span style="font-family: 'courier new', courier;">org.scala-tools.time</span> to <span style="font-family: 'courier new', courier;">com.github.nscala-time.time</span><span style="font-size: 14px;"></span></td>
            </tr>
            <tr>
              <td>
                <a href="http://scalamock.org/">ScalaMock</a>
              </td>
              <td>
2.4</td>
              <td>
3.0.1</td>
              <td>
The 3.x series runs natively on Scala 2.10 without proxy factories and the like. Syntax
is a bit odd but works like a charm.<br />
The ScalaTest integration is compiled against ScalaTest 2.0-M5b, which forced us to
upgrade. 
</td>
            </tr>
            <tr>
              <td>
                <a href="http://scalatest.org/">ScalaTest</a>
              </td>
              <td>
1.8</td>
              <td>
2.0-M5b 
</td>
              <td>
Minor API changes: <span style="font-family: 'courier new', courier;">Spec</span><span style="font-family: 'courier new', courier;">→</span><span style="font-family: 'courier new', courier;">FunSpec</span>,
parameters changed in <span style="font-family: 'courier new', courier;">Suite.run()</span></td>
            </tr>
            <tr>
              <td>
                <a href="http://squeryl.org/">Squeryl</a>
              </td>
              <td>
0.9.5-2 
</td>
              <td>
0.9.5-6 
</td>
              <td>
              </td>
            </tr>
            <tr>
              <td>
                <a href="http://software.clapper.org/argot/">Argot</a>
              </td>
              <td>
0.4 
</td>
              <td>
1.0.0 
</td>
              <td>
              </td>
            </tr>
            <tr>
              <td>
                <a href="https://github.com/scala-incubator/scala-io">Scala I/O</a>
              </td>
              <td>
0.4.1-seq 
</td>
              <td>
0.4.2 
</td>
              <td>
              </td>
            </tr>
            <tr>
              <td>
                <a href="https://github.com/lift/framework/tree/master/core/json">Lift JSON</a> (+<a href="https://github.com/lift/framework/tree/master/core/json-ext">ext</a>)</td>
              <td>
2.4 
</td>
              <td>
2.5-M4 
</td>
              <td>
              </td>
            </tr>
            <tr>
              <td>
                <a href="https://github.com/lift/modules/tree/master/facebook">Lift Facebook</a>
              </td>
              <td>
2.4 
</td>
              <td>
2.5-SNAPSHOT 
</td>
              <td>
Had to exclude <span style="font-family: 'courier new', courier;">net.liftweb:lift-webkit_2.10</span> to
avoid dependency conflicts</td>
            </tr>
            <tr>
              <td>
                <a href="http://akka.io/">Akka</a>
              </td>
              <td>
2.0.4 
</td>
              <td>
2.1 
</td>
              <td>
Scheduling now requires an implicit <span style="font-family: 'courier new', courier;">ExecutionContext</span>.
See <a href="http://doc.akka.io/docs/akka/2.1.0/project/migration-guide-2.0.x-2.1.x.html">migration
guide</a> for details. 
</td>
            </tr>
            <tr>
              <td>
                <a href="http://www.scalatra.org/">Scalatra</a>
              </td>
              <td>
2.0.4 
</td>
              <td>
2.0.5-SNAPSHOT 
</td>
              <td>
Official <a href="http://www.scalatra.org/2013/02/06/scalatra2-2-released.html">2.0.5
is out</a>, but has not yet shown up on the central repository, so I ended up going
with the (frozen) 2.0.5 snapshot artifacts</td>
            </tr>
            <tr>
              <td>
                <a href="http://www.scalatra.org/">Scalatra</a>
              </td>
              <td>
2.1.1 
</td>
              <td>
2.2.0 
</td>
              <td>
scalatra-akka module <a href="http://notes.implicit.ly/post/42420935465/scalatra-2-2-0">has
been folded back</a> into the core artifact as of 2.2.0.</td>
            </tr>
            <tr>
              <td>
                <a href="https://www.assembla.com/spaces/scala-graph/wiki">Graph for Scala</a>
              </td>
              <td>
1.5.1</td>
              <td>
1.6.1 
</td>
              <td>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
        </p>
        <p>
          <span style="text-decoration: underline;">Scala Library Changes</span>
        </p>
        <p>
The Scala class library itself has a number of changes you ought to be aware of before
migrating to 2.10. The really big change is that Scala actors are deprecated in favor
of Akka. You can still use them by importing the <span style="font-family: 'courier new', courier;">scala-actors</span> artifact
from the Scala 2.10 distribution, but it is recommended to migrate fully to the new
actor system as this is also likely to be obsoleted by 2.10.1. The gentle folk at
Typesafe have provided a very comprehensive <a href="http://docs.scala-lang.org/overviews/core/actors-migration-guide.html">migration
guide</a> to assist your efforts. 
</p>
        <p>
The less prevasive API changes we ran into include:
</p>
        <ul>
          <li>
            <span style="font-family: 'courier new', courier;">List.elements </span>is deprecated
in favor of <span style="font-family: 'courier new', courier;">List.iterator</span>;</li>
          <li>
            <span style="font-family: 'courier new', courier;">TraversableOnce.toIndexedSeq</span> no
longer takes a type argument. This was actually quite pervasive in our codebase, causing
plenty of compilation errors, and is easily worked around by removing the type parameter
(which is extraneous to begin with);</li>
          <li>
Scala actors' <span style="font-family: 'courier new', courier;">Actor.receive</span> method
is now public (previously protected). This had to be rectified in pretty much all
of our existing actors by removing the <span style="font-family: 'courier new', courier;">protected</span> modifer;</li>
          <li>
Occasional subtle API changes requiring minor code fixes. For example, see this <a href="http://stackoverflow.com/questions/9487425/enumeration-and-mapping-with-scala-2-10">question
on StackOverflow</a>.</li>
        </ul>
        <p>
          <br />
          <span style="text-decoration: underline;">Summary</span>
        </p>
        <p>
Opinions differ among members of our team - some predicted that the migration process
will be much more complex whereas personally, given the relatively high level of maturity
I've come to depend on in the 2.9 series, the migration process actually ended up
being significantly harder than I anticipated. Particularly disconcerting were the
occasional compiler failures which took a lot of time to track down. Practically speaking,
though, the whole migration process took less than 3 days (including documentation),
did not involve additional teammates, and all problems were either resolved or worked
around rather quickly. The Typesafe compiler team has been very helpful in analyzing
and resolving the single bona-fide compiler bug we've run into, and the community
as a whole (on Stack Overflow, Google Groups and elsewhere) was also extremely supportive
and helpful.
</p>
        <p>
On the whole, am I happy with the process? So-so. There is nothing here an experienced
Scala developer should have serious trouble with, but it will take a lot more stability
and predictability for Scala to gain mainstream acceptance in the industry, and that
includes a much easier and more robust migration path to upcoming releases (yes, that
includes migrating from 2.10 to 2.11 when it comes along). That being said, Scala
has been a terrific language to work with in the last couple of years, and the new
features in 2.10 (particularly reflection, macros and string interpolation) should
make this an extremely worthwhile upgrade. We still have a lot of regression testing
to do on the new version, and if anything interesting pops up I'll be sure to post
about it separately (or bitch about it on <a href="http://twitter.com/@tomerg">Twitter</a>...)
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=851a7271-9bda-403c-a72f-8b13ec552271" />
      </body>
      <title>Scala 2.10: Migration Case Study - part II</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,851a7271-9bda-403c-a72f-8b13ec552271.aspx</guid>
      <link>http://www.tomergabel.com/Scala210MigrationCaseStudyPartII.aspx</link>
      <pubDate>Mon, 11 Feb 2013 14:33:11 GMT</pubDate>
      <description>&lt;p&gt;
This is the second post of a two-parter. Please read &lt;a href="http://www.tomergabel.com/Scala210MigrationCaseStudyPartI.aspx"&gt;part
1&lt;/a&gt; for context and additional information.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="text-decoration: underline;"&gt;3rd Party Libraries&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
As mentioned in part 1, Scala is not binary backwards-compatible between major releases.
Although code compiled with 2.10 &lt;em&gt;may&lt;/em&gt; work properly with libraries compiled
against 2.9.x, this is hardly recommended and may result in a lot of subtle error
conditions at runtime that are hard to track down. As a result, the recommended practice
is to upgrade &lt;em&gt;all&lt;/em&gt; Scala dependencies to versions compiled against 2.10. Fortunately
the Scala ecosystem is very active, so most common libraries had 2.10 builds on announcement
day, but you are still likely to encounter libraries that need to be upgraded because:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
They're lagging behind the Scala release schedule and simply haven't released 2.10-compatible
binaries (fortunately, this seems to be extremely rare; in practice all our dependencies
were otherwise resolved);&lt;/li&gt;
&lt;li&gt;
The specific version you're using does not have a 2.10-compatible release and likely
never will (Squeryl 0.9.5-2);&lt;/li&gt;
&lt;li&gt;
A 2.10-compatible official release is out but hasn't yet been published to the central
repository (Scalatra 2.0.5).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
My experience shows that with a bit of dilligence, practically all our (myriad) dependencies
were fairly easy to migrate to 2.10. In most cases this simply entails switching to
the appropriate artifact ID suffix (_2.10 instead of _2.9.2, see part 1 for associated
rant), in other cases I had to upgrade to a later official release and in rare cases
I had to dig in and replace a dependency with an appropriate fork or snapshot version.
Here is a list of migration notes for some of our dependencies:
&lt;/p&gt;
&lt;table border="1" cellpadding="5"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Library&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Previous&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;New version&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Comments&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/jorgeortiz85/scala-time"&gt;Scala-Time&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
0.6&lt;/td&gt;
&lt;td&gt;
nscala-time 0.2 
&lt;/td&gt;
&lt;td&gt;
The original library appears to be abandoned and &lt;a href="https://github.com/nscala-time/nscala-time"&gt;was
forked&lt;/a&gt; on GitHub.&lt;br /&gt;
The package changed from &lt;span style="font-family: 'courier new', courier;"&gt;org.scala-tools.time&lt;/span&gt; to &lt;span style="font-family: 'courier new', courier;"&gt;com.github.nscala-time.time&lt;/span&gt;&lt;span style="font-size: 14px;"&gt; &lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://scalamock.org/"&gt;ScalaMock&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
2.4&lt;/td&gt;
&lt;td&gt;
3.0.1&lt;/td&gt;
&lt;td&gt;
The 3.x series runs natively on Scala 2.10 without proxy factories and the like. Syntax
is a bit odd but works like a charm.&lt;br /&gt;
The ScalaTest integration is compiled against ScalaTest 2.0-M5b, which forced us to
upgrade. 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://scalatest.org/"&gt;ScalaTest&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
1.8&lt;/td&gt;
&lt;td&gt;
2.0-M5b 
&lt;/td&gt;
&lt;td&gt;
Minor API changes: &lt;span style="font-family: 'courier new', courier;"&gt;Spec&lt;/span&gt;&lt;span style="font-family: 'courier new', courier;"&gt;→&lt;/span&gt;&lt;span style="font-family: 'courier new', courier;"&gt;FunSpec&lt;/span&gt;,
parameters changed in &lt;span style="font-family: 'courier new', courier;"&gt;Suite.run()&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://squeryl.org/"&gt;Squeryl&lt;/a&gt; 
&lt;/td&gt;
&lt;td&gt;
0.9.5-2 
&lt;/td&gt;
&lt;td&gt;
0.9.5-6 
&lt;/td&gt;
&lt;td&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://software.clapper.org/argot/"&gt;Argot&lt;/a&gt; 
&lt;/td&gt;
&lt;td&gt;
0.4 
&lt;/td&gt;
&lt;td&gt;
1.0.0 
&lt;/td&gt;
&lt;td&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/scala-incubator/scala-io"&gt;Scala I/O&lt;/a&gt; 
&lt;/td&gt;
&lt;td&gt;
0.4.1-seq 
&lt;/td&gt;
&lt;td&gt;
0.4.2 
&lt;/td&gt;
&lt;td&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/lift/framework/tree/master/core/json"&gt;Lift JSON&lt;/a&gt; (+&lt;a href="https://github.com/lift/framework/tree/master/core/json-ext"&gt;ext&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;
2.4 
&lt;/td&gt;
&lt;td&gt;
2.5-M4 
&lt;/td&gt;
&lt;td&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/lift/modules/tree/master/facebook"&gt;Lift Facebook&lt;/a&gt; 
&lt;/td&gt;
&lt;td&gt;
2.4 
&lt;/td&gt;
&lt;td&gt;
2.5-SNAPSHOT 
&lt;/td&gt;
&lt;td&gt;
Had to exclude &lt;span style="font-family: 'courier new', courier;"&gt;net.liftweb:lift-webkit_2.10&lt;/span&gt; to
avoid dependency conflicts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://akka.io/"&gt;Akka&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
2.0.4 
&lt;/td&gt;
&lt;td&gt;
2.1 
&lt;/td&gt;
&lt;td&gt;
Scheduling now requires an implicit &lt;span style="font-family: 'courier new', courier;"&gt;ExecutionContext&lt;/span&gt;.
See &lt;a href="http://doc.akka.io/docs/akka/2.1.0/project/migration-guide-2.0.x-2.1.x.html"&gt;migration
guide&lt;/a&gt; for details. 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.scalatra.org/"&gt;Scalatra&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
2.0.4 
&lt;/td&gt;
&lt;td&gt;
2.0.5-SNAPSHOT 
&lt;/td&gt;
&lt;td&gt;
Official &lt;a href="http://www.scalatra.org/2013/02/06/scalatra2-2-released.html"&gt;2.0.5
is out&lt;/a&gt;, but has not yet shown up on the central repository, so I ended up going
with the (frozen) 2.0.5 snapshot artifacts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="http://www.scalatra.org/"&gt;Scalatra&lt;/a&gt; 
&lt;/td&gt;
&lt;td&gt;
2.1.1 
&lt;/td&gt;
&lt;td&gt;
2.2.0 
&lt;/td&gt;
&lt;td&gt;
scalatra-akka module &lt;a href="http://notes.implicit.ly/post/42420935465/scalatra-2-2-0"&gt;has
been folded back&lt;/a&gt; into the core artifact as of 2.2.0.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.assembla.com/spaces/scala-graph/wiki"&gt;Graph for Scala&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
1.5.1&lt;/td&gt;
&lt;td&gt;
1.6.1 
&lt;/td&gt;
&lt;td&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="text-decoration: underline;"&gt;Scala Library Changes&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
The Scala class library itself has a number of changes you ought to be aware of before
migrating to 2.10. The really big change is that Scala actors are deprecated in favor
of Akka. You can still use them by importing the &lt;span style="font-family: 'courier new', courier;"&gt;scala-actors&lt;/span&gt; artifact
from the Scala 2.10 distribution, but it is recommended to migrate fully to the new
actor system as this is also likely to be obsoleted by 2.10.1. The gentle folk at
Typesafe have provided a very comprehensive &lt;a href="http://docs.scala-lang.org/overviews/core/actors-migration-guide.html"&gt;migration
guide&lt;/a&gt; to assist your efforts. 
&lt;/p&gt;
&lt;p&gt;
The less prevasive API changes we ran into include:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;span style="font-family: 'courier new', courier;"&gt;List.elements &lt;/span&gt;is deprecated
in favor of &lt;span style="font-family: 'courier new', courier;"&gt;List.iterator&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;span style="font-family: 'courier new', courier;"&gt;TraversableOnce.toIndexedSeq&lt;/span&gt; no
longer takes a type argument. This was actually quite pervasive in our codebase, causing
plenty of compilation errors, and is easily worked around by removing the type parameter
(which is extraneous to begin with);&lt;/li&gt;
&lt;li&gt;
Scala actors' &lt;span style="font-family: 'courier new', courier;"&gt;Actor.receive&lt;/span&gt; method
is now public (previously protected). This had to be rectified in pretty much all
of our existing actors by removing the &lt;span style="font-family: 'courier new', courier;"&gt;protected&lt;/span&gt; modifer;&lt;/li&gt;
&lt;li&gt;
Occasional subtle API changes requiring minor code fixes. For example, see this &lt;a href="http://stackoverflow.com/questions/9487425/enumeration-and-mapping-with-scala-2-10"&gt;question
on StackOverflow&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;br /&gt;
&lt;span style="text-decoration: underline;"&gt;Summary&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Opinions differ among members of our team - some predicted that the migration process
will be much more complex whereas personally, given the relatively high level of maturity
I've come to depend on in the 2.9 series, the migration process actually ended up
being significantly harder than I anticipated. Particularly disconcerting were the
occasional compiler failures which took a lot of time to track down. Practically speaking,
though, the whole migration process took less than 3 days (including documentation),
did not involve additional teammates, and all problems were either resolved or worked
around rather quickly. The Typesafe compiler team has been very helpful in analyzing
and resolving the single bona-fide compiler bug we've run into, and the community
as a whole (on Stack Overflow, Google Groups and elsewhere) was also extremely supportive
and helpful.
&lt;/p&gt;
&lt;p&gt;
On the whole, am I happy with the process? So-so. There is nothing here an experienced
Scala developer should have serious trouble with, but it will take a lot more stability
and predictability for Scala to gain mainstream acceptance in the industry, and that
includes a much easier and more robust migration path to upcoming releases (yes, that
includes migrating from 2.10 to 2.11 when it comes along). That being said, Scala
has been a terrific language to work with in the last couple of years, and the new
features in 2.10 (particularly reflection, macros and string interpolation) should
make this an extremely worthwhile upgrade. We still have a lot of regression testing
to do on the new version, and if anything interesting pops up I'll be sure to post
about it separately (or bitch about it on &lt;a href="http://twitter.com/@tomerg"&gt;Twitter&lt;/a&gt;...)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=851a7271-9bda-403c-a72f-8b13ec552271" /&gt;</description>
      <category>Development</category>
      <category>Development/Scala</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=63886411-d1b2-42f7-ae3e-833d2026be73</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,63886411-d1b2-42f7-ae3e-833d2026be73.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just spent a few days migrating our codebase from Scala 2.9.2 to <a href="http://www.scala-lang.org/node/27499">Scala
2.10</a>. A quick search found very little in the way of migration guides and studies,
so it seemed appropriate to document my experiences and offer what tips I managed
to collect on the way.
</p>
        <p>
          <span style="text-decoration: underline;">General Observations</span>
        </p>
        <p>
This process should not be undertaken lightly, and its implementation inevitably depends
on your resources and team composition. The group (or person) charged with migrating
the codebase should, at the very least, consist of an experienced Scala developer
not afraid to get his or her hands dirty.
</p>
        <p>
The migration is not an entirely smooth process - there are plenty of (fortunately
fairly minor) breaking changes in the Scala APIs, and since Scala does not yet feature
binary backwards compatibility between major versions (2.9→2.10→2.11...), so expect
some inevitable library upgrades and the potential complexities inherent in any such
update. The specific issues I encountered are documented in their respective sections
below.
</p>
        <p>
Unfortunately there is not much I can offer in the way of preparation; these are the
obvious steps:
</p>
        <ul>
          <li>
            <a href="http://www.scala-lang.org/node/27499">Familiarize yourself</a> with Scala
2.10. Make sure you know what you’re getting in exchange for investing time and effort
on the migration process and early-bird issues;</li>
          <li>
Work in an isolated branch and pull changes from the master branch often;</li>
          <li>
Commit early, commit often. Try to keep your commits small and well-documented, so
you have good revert checkpoints for when things go wrong;</li>
          <li>
Keep the affected code to a minimum. The fewer changes, the easier it will be to isolate
problems down the road.</li>
        </ul>
        <p>
If you’ve read so far and still can’t wait for 2.10.1, I hope the next few sections
will save you some time and pain.
</p>
        <p>
          <span style="text-decoration: underline;">Toolchain</span>
        </p>
        <p>
To start things off I switched the build to use Scala 2.10. Our project runs on Maven
in lieu of SBT (topic for another post), and we use David Bernard’s excellent <a href="http://davidb.github.com/scala-maven-plugin/">scala-maven-plugin</a>,
which deduces the Scala version from the scala-library dependency.
</p>
        <p>
The convention for the Scala version suffix has changed between 2.9 and 2.10: for
example, <tt>argot<em>2.9.2</em></tt><em> is now <tt>argot</tt></em><tt>2.10</tt> -
no revision for the 2.10 series. This rendered the suffix macro we employ useless,
because annoyingly the Scala <em>libraries</em>themselves (e.g. scalap or scala-compiler)
actually use the full version number, so we ended up needing <em>two</em> macros (a
“raw” Scala version and a suffix).
</p>
        <p>
Fortunately, at least as far as Maven is concerned the rest was smooth sailing. I
next turned my attention to IntelliJ IDEA - I wanted to make sure an existing workspace
can be reused with the migrated codebase, otherwise my entire team will have to undergo
the inconvenience of starting from scratch on a clean working copy. Fortunately the
process turned out to be quite painless (on IDEA 12.0.3 with Scala plugin build 0.7.121),
with the following caveats:
</p>
        <ul>
          <li>
Code analysis appears to miss some cases of stricter compilation compared to 2.9.x
(see below);</li>
          <li>
Code analysis occasionally identifies relative import statements as erroneous (e.g. <tt>import
util.Random</tt>);</li>
          <li>
Project FSC settings had to be manually changed to use the 2.10 compiler bundle (it
remained on the default 2.9.2). This proved to be a moot point, because:</li>
          <li>
The much-touted IDEA <a href="http://blog.jetbrains.com/scala/2012/12/28/a-new-way-to-compile/">external
build mode</a> finally works consistently for the first time (and it uses the significantly
better SBT compiler)!</li>
          <li>
On the negative side, IDEA does not seem to handle compiler failures (as opposed to
compilation errors) gracefully, missing a lot of detail in the output. As I ran into
quite a few of these (details below), I ended up doing most of the compilation tests
with Maven directly.</li>
        </ul>
        <p>
Beyond setting up a build job for the new branch, Jenkins posed no issues.<br />
To summarize, from a toolchain standpoint, this was actually a fairly smooth process.
</p>
        <p>
          <span style="text-decoration: underline;">Language/Compiler</span>
        </p>
        <p>
I was surprised and somewhat disheartened to find that, after some initial compilation
attempts, it became evident that I missed <em>every single mark</em> in my code risk
predictions. Where I expected most language-level headaches I encountered none, and
seemingly simple and risk-free code ended up taking most of the time working on this
process.
</p>
        <p>
First off, the Scala 2.10 compiler is <em>much stricter</em> than the earlier 2.9.x
series. It has a few new heuristics that ended up triggering very often on our codebase;
some are simply the result of messy code or design, but most are new best practices
adopted by the compiler team at Typesafe:
</p>
        <ul>
          <li>
            <tt>“warning: This catches all Throwables. If this is really intended, use `case _
: Throwable` to clear this warning.”</tt>
            <br class="kix-line-break" />
We wrap-and-throw or swallow a lot of exceptions, and for brevity’s sake often use
the shorter <tt>catch { case _ =&gt; }</tt>. A catch block is analogous to a partial
function from Throwable, and there are undoubtedly cases where the distinction matters.
We’ll clean these up iteratively by qualifying that we’re only catching Exceptions.<br /><br class="kix-line-break" /></li>
          <li>
            <tt>“non-variable type argument B[T] in type A[B[T]] is unchecked since it is eliminated
by erasure”</tt>
            <br class="kix-line-break" />
The 2.10 compiler is actually quite helpful in warning you when generic code may not
behave as expected. This is just one example of such a warning.<br /><br class="kix-line-break" /></li>
          <li>
            <tt>“error: overloaded method methodName needs result type”</tt>
            <br class="kix-line-break" />
The 2.10 compiler <em>requires</em> you to specify result types on most (all?) types
of method overloading. Not much work here.</li>
          <li>
Case classes can no longer derive from other case classes, which makes a whole lot
of sense if you consider the typesystem; 2.9.x had a whole variety of bugs and edge-cases
relating to case class inheritance and companion objects, including some unwieldy
constructor syntax. 2.10 simply does away with the complexity and potential ambiguity,
which will break existing code. Since such class hierarchies are inherently problematic,
I see this as an opportunity to refactor them properly; <a href="http://www.scala-lang.org/node/112">extractor
objects</a> were often useful for that task.<br /><br class="kix-line-break" /></li>
          <li>
In one case we ran into stricter cyclic dependency analysis on the part of 2.10 -
an object extended a class and passed a member of another object as a constructor
parameter. The second object referenced the first, which compiled fine under 2.9.2
but resulted in a cyclic dependency error with 2.10. As the original design was hard
to understand I refactored the code to be a bit simpler, which resolved the problem
satisfactorily.<br /><br class="kix-line-break" /></li>
          <li>
Manifests are deprecated in favor of TypeTags and the new reflection library built
into 2.10 (certainly one if its most anticipated and celebrated features), but are
still functional. We haven’t migrated to the new APIs yet, and that process will likely
deserve a post all on its own; read this <a href="http://stackoverflow.com/a/12232195/11558">excellent
answer</a> on Stack Overflow for an introduction to TypeTags.<br class="kix-line-break" /></li>
        </ul>
        <p>
Beyond these and the occasional minor syntax change, the 2.10 compiler proved a somewhat
difficult beast to tame:
</p>
        <ul>
          <li>
Ran into crazily-detailed compiler failures that clearly (though long-windedly) indicated
that I need to manually add <tt>scala-reflect</tt> to the classpath;<br /><br class="kix-line-break" /></li>
          <li>
Missing or conflicting dependencies, typically due to mishandling POMs, resulted in
what I ended up dubbing the <em>Spontaneous Compiler Combustion phenomenon</em>: a
cryptic compilation failure, complete with what appears to be an AST dump and full-blown
debug information. Tracking the occasional familiar type name in the compiler log
can be helpful in tracking down the dependency at fault (this was the case in all
but one of the occurrences), but the error itself is completely inscrutable.<br /><br class="kix-line-break" /></li>
          <li>
The one case was, unfortunately, a proper compiler bug logged as <a href="https://issues.scala-lang.org/browse/SI-7091">SI-7109</a>,
which has to do with consuming a package-protected (or -private) trait/class from
another trait/class with the same accessibility. Jason Zaugg of Typesafe (<a href="https://twitter.com/retronym">@retronym</a>)
was extremely helpful in analysing the compiler output and producing a reproduction
case, which I haven’t been able to do on my own. Until a fix is included and released,
I’ve worked around this by temporarily commenting out the problematic qualifiers.<br class="kix-line-break" /><br /></li>
          <li>
            <b>Update (2013-02-12)</b>: Ran into another compiler bug that causes a runtime <tt>ClassFormatError</tt>.
We've managed to identify, reproduce and work around the problem; see <a href="https://issues.scala-lang.org/browse/SI-7120">SI-7120</a> on
the Typesafe JIRA.<br class="kix-line-break" /></li>
        </ul>
        <p>
Lastly, it’s worth noting that the 2.10 compiler is significantly heavier than the
older 2.9.x series: it appears to require 50-100% more permgen space, and compile
times are up x2 on average and <strong>up to x10</strong> on a clean, fresh build.
This seems consistent on both my laptop and the build server, which use different
CPUs and OS. A quick check (<tt>top</tt> and <tt>jstat -gcutil</tt>) showed the compiler
process to be single-threaded and CPU-bound, as it consistently utilizes 100% of a
single core. GC activity was low to the point of negligible, so it appears the new
compiler is actually a step back in terms of compilation throughput. I hope subsequent
2.10.x releases focus primarily on compilation stability and performance.
</p>
        <p>
        </p>
        <p>
That’s it for today; next post <span style="text-decoration: line-through;">will be
up in a day or two</span><a href="http://www.tomergabel.com/Scala210MigrationCaseStudyPartII.aspx">is
up</a> and focuses on the Scala library, dependencies and miscellanea.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=63886411-d1b2-42f7-ae3e-833d2026be73" />
      </body>
      <title>Scala 2.10: Migration Case Study - part I</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,63886411-d1b2-42f7-ae3e-833d2026be73.aspx</guid>
      <link>http://www.tomergabel.com/Scala210MigrationCaseStudyPartI.aspx</link>
      <pubDate>Mon, 11 Feb 2013 00:57:09 GMT</pubDate>
      <description>&lt;p&gt;
I just spent a few days migrating our codebase from Scala 2.9.2 to &lt;a href="http://www.scala-lang.org/node/27499"&gt;Scala
2.10&lt;/a&gt;. A quick search found very little in the way of migration guides and studies,
so it seemed appropriate to document my experiences and offer what tips I managed
to collect on the way.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="text-decoration: underline;"&gt;General Observations&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
This process should not be undertaken lightly, and its implementation inevitably depends
on your resources and team composition. The group (or person) charged with migrating
the codebase should, at the very least, consist of an experienced Scala developer
not afraid to get his or her hands dirty.
&lt;/p&gt;
&lt;p&gt;
The migration is not an entirely smooth process - there are plenty of (fortunately
fairly minor) breaking changes in the Scala APIs, and since Scala does not yet feature
binary backwards compatibility between major versions (2.9→2.10→2.11...), so expect
some inevitable library upgrades and the potential complexities inherent in any such
update. The specific issues I encountered are documented in their respective sections
below.
&lt;/p&gt;
&lt;p&gt;
Unfortunately there is not much I can offer in the way of preparation; these are the
obvious steps:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.scala-lang.org/node/27499"&gt;Familiarize yourself&lt;/a&gt; with Scala
2.10. Make sure you know what you’re getting in exchange for investing time and effort
on the migration process and early-bird issues;&lt;/li&gt;
&lt;li&gt;
Work in an isolated branch and pull changes from the master branch often;&lt;/li&gt;
&lt;li&gt;
Commit early, commit often. Try to keep your commits small and well-documented, so
you have good revert checkpoints for when things go wrong;&lt;/li&gt;
&lt;li&gt;
Keep the affected code to a minimum. The fewer changes, the easier it will be to isolate
problems down the road.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
If you’ve read so far and still can’t wait for 2.10.1, I hope the next few sections
will save you some time and pain.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="text-decoration: underline;"&gt;Toolchain&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
To start things off I switched the build to use Scala 2.10. Our project runs on Maven
in lieu of SBT (topic for another post), and we use David Bernard’s excellent &lt;a href="http://davidb.github.com/scala-maven-plugin/"&gt;scala-maven-plugin&lt;/a&gt;,
which deduces the Scala version from the scala-library dependency.
&lt;/p&gt;
&lt;p&gt;
The convention for the Scala version suffix has changed between 2.9 and 2.10: for
example, &lt;tt&gt;argot&lt;em&gt;2.9.2&lt;/em&gt;&lt;/tt&gt;&lt;em&gt; is now &lt;tt&gt;argot&lt;/tt&gt;&lt;/em&gt;&lt;tt&gt;2.10&lt;/tt&gt; -
no revision for the 2.10 series. This rendered the suffix macro we employ useless,
because annoyingly the Scala &lt;em&gt;libraries&lt;/em&gt;themselves (e.g. scalap or scala-compiler)
actually use the full version number, so we ended up needing &lt;em&gt;two&lt;/em&gt; macros (a
“raw” Scala version and a suffix).
&lt;/p&gt;
&lt;p&gt;
Fortunately, at least as far as Maven is concerned the rest was smooth sailing. I
next turned my attention to IntelliJ IDEA - I wanted to make sure an existing workspace
can be reused with the migrated codebase, otherwise my entire team will have to undergo
the inconvenience of starting from scratch on a clean working copy. Fortunately the
process turned out to be quite painless (on IDEA 12.0.3 with Scala plugin build 0.7.121),
with the following caveats:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Code analysis appears to miss some cases of stricter compilation compared to 2.9.x
(see below);&lt;/li&gt;
&lt;li&gt;
Code analysis occasionally identifies relative import statements as erroneous (e.g. &lt;tt&gt;import
util.Random&lt;/tt&gt;);&lt;/li&gt;
&lt;li&gt;
Project FSC settings had to be manually changed to use the 2.10 compiler bundle (it
remained on the default 2.9.2). This proved to be a moot point, because:&lt;/li&gt;
&lt;li&gt;
The much-touted IDEA &lt;a href="http://blog.jetbrains.com/scala/2012/12/28/a-new-way-to-compile/"&gt;external
build mode&lt;/a&gt; finally works consistently for the first time (and it uses the significantly
better SBT compiler)!&lt;/li&gt;
&lt;li&gt;
On the negative side, IDEA does not seem to handle compiler failures (as opposed to
compilation errors) gracefully, missing a lot of detail in the output. As I ran into
quite a few of these (details below), I ended up doing most of the compilation tests
with Maven directly.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Beyond setting up a build job for the new branch, Jenkins posed no issues.&lt;br /&gt;
To summarize, from a toolchain standpoint, this was actually a fairly smooth process.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="text-decoration: underline;"&gt;Language/Compiler&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
I was surprised and somewhat disheartened to find that, after some initial compilation
attempts, it became evident that I missed &lt;em&gt;every single mark&lt;/em&gt; in my code risk
predictions. Where I expected most language-level headaches I encountered none, and
seemingly simple and risk-free code ended up taking most of the time working on this
process.
&lt;/p&gt;
&lt;p&gt;
First off, the Scala 2.10 compiler is &lt;em&gt;much stricter&lt;/em&gt; than the earlier 2.9.x
series. It has a few new heuristics that ended up triggering very often on our codebase;
some are simply the result of messy code or design, but most are new best practices
adopted by the compiler team at Typesafe:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;tt&gt;“warning: This catches all Throwables. If this is really intended, use `case _
: Throwable` to clear this warning.”&lt;/tt&gt;
&lt;br class="kix-line-break" /&gt;
We wrap-and-throw or swallow a lot of exceptions, and for brevity’s sake often use
the shorter &lt;tt&gt;catch { case _ =&gt; }&lt;/tt&gt;. A catch block is analogous to a partial
function from Throwable, and there are undoubtedly cases where the distinction matters.
We’ll clean these up iteratively by qualifying that we’re only catching Exceptions.&lt;br /&gt;
&lt;br class="kix-line-break" /&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;tt&gt;“non-variable type argument B[T] in type A[B[T]] is unchecked since it is eliminated
by erasure”&lt;/tt&gt;
&lt;br class="kix-line-break" /&gt;
The 2.10 compiler is actually quite helpful in warning you when generic code may not
behave as expected. This is just one example of such a warning.&lt;br /&gt;
&lt;br class="kix-line-break" /&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;tt&gt;“error: overloaded method methodName needs result type”&lt;/tt&gt;
&lt;br class="kix-line-break" /&gt;
The 2.10 compiler &lt;em&gt;requires&lt;/em&gt; you to specify result types on most (all?) types
of method overloading. Not much work here.&lt;/li&gt;
&lt;li&gt;
Case classes can no longer derive from other case classes, which makes a whole lot
of sense if you consider the typesystem; 2.9.x had a whole variety of bugs and edge-cases
relating to case class inheritance and companion objects, including some unwieldy
constructor syntax. 2.10 simply does away with the complexity and potential ambiguity,
which will break existing code. Since such class hierarchies are inherently problematic,
I see this as an opportunity to refactor them properly; &lt;a href="http://www.scala-lang.org/node/112"&gt;extractor
objects&lt;/a&gt; were often useful for that task.&lt;br /&gt;
&lt;br class="kix-line-break" /&gt;
&lt;/li&gt;
&lt;li&gt;
In one case we ran into stricter cyclic dependency analysis on the part of 2.10 -
an object extended a class and passed a member of another object as a constructor
parameter. The second object referenced the first, which compiled fine under 2.9.2
but resulted in a cyclic dependency error with 2.10. As the original design was hard
to understand I refactored the code to be a bit simpler, which resolved the problem
satisfactorily.&lt;br /&gt;
&lt;br class="kix-line-break" /&gt;
&lt;/li&gt;
&lt;li&gt;
Manifests are deprecated in favor of TypeTags and the new reflection library built
into 2.10 (certainly one if its most anticipated and celebrated features), but are
still functional. We haven’t migrated to the new APIs yet, and that process will likely
deserve a post all on its own; read this &lt;a href="http://stackoverflow.com/a/12232195/11558"&gt;excellent
answer&lt;/a&gt; on Stack Overflow for an introduction to TypeTags.&lt;br class="kix-line-break" /&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Beyond these and the occasional minor syntax change, the 2.10 compiler proved a somewhat
difficult beast to tame:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Ran into crazily-detailed compiler failures that clearly (though long-windedly) indicated
that I need to manually add &lt;tt&gt;scala-reflect&lt;/tt&gt; to the classpath;&lt;br /&gt;
&lt;br class="kix-line-break" /&gt;
&lt;/li&gt;
&lt;li&gt;
Missing or conflicting dependencies, typically due to mishandling POMs, resulted in
what I ended up dubbing the &lt;em&gt;Spontaneous Compiler Combustion phenomenon&lt;/em&gt;: a
cryptic compilation failure, complete with what appears to be an AST dump and full-blown
debug information. Tracking the occasional familiar type name in the compiler log
can be helpful in tracking down the dependency at fault (this was the case in all
but one of the occurrences), but the error itself is completely inscrutable.&lt;br /&gt;
&lt;br class="kix-line-break" /&gt;
&lt;/li&gt;
&lt;li&gt;
The one case was, unfortunately, a proper compiler bug logged as &lt;a href="https://issues.scala-lang.org/browse/SI-7091"&gt;SI-7109&lt;/a&gt;,
which has to do with consuming a package-protected (or -private) trait/class from
another trait/class with the same accessibility. Jason Zaugg of Typesafe (&lt;a href="https://twitter.com/retronym"&gt;@retronym&lt;/a&gt;)
was extremely helpful in analysing the compiler output and producing a reproduction
case, which I haven’t been able to do on my own. Until a fix is included and released,
I’ve worked around this by temporarily commenting out the problematic qualifiers.&lt;br class="kix-line-break" /&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;b&gt;Update (2013-02-12)&lt;/b&gt;: Ran into another compiler bug that causes a runtime &lt;tt&gt;ClassFormatError&lt;/tt&gt;.
We've managed to identify, reproduce and work around the problem; see &lt;a href="https://issues.scala-lang.org/browse/SI-7120"&gt;SI-7120&lt;/a&gt; on
the Typesafe JIRA.&lt;br class="kix-line-break" /&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Lastly, it’s worth noting that the 2.10 compiler is significantly heavier than the
older 2.9.x series: it appears to require 50-100% more permgen space, and compile
times are up x2 on average and &lt;strong&gt;up to x10&lt;/strong&gt; on a clean, fresh build.
This seems consistent on both my laptop and the build server, which use different
CPUs and OS. A quick check (&lt;tt&gt;top&lt;/tt&gt; and &lt;tt&gt;jstat -gcutil&lt;/tt&gt;) showed the compiler
process to be single-threaded and CPU-bound, as it consistently utilizes 100% of a
single core. GC activity was low to the point of negligible, so it appears the new
compiler is actually a step back in terms of compilation throughput. I hope subsequent
2.10.x releases focus primarily on compilation stability and performance.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
That’s it for today; next post &lt;span style="text-decoration: line-through;"&gt;will be
up in a day or two&lt;/span&gt; &lt;a href="http://www.tomergabel.com/Scala210MigrationCaseStudyPartII.aspx"&gt;is
up&lt;/a&gt; and focuses on the Scala library, dependencies and miscellanea.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=63886411-d1b2-42f7-ae3e-833d2026be73" /&gt;</description>
      <category>Development</category>
      <category>Development/Scala</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=b8d6056d-cdf8-49a7-ac8c-d4424a965720</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,b8d6056d-cdf8-49a7-ac8c-d4424a965720.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This post attempts to summarize and clarify a lecture given at the <a href="https://www.facebook.com/botzia">Botzia</a> (Israeli
Java user group) meeting on May 3rd, 2012. You can view the presentation in its entirety
on SlideShare:
</p>
        <p style="text-align: center;">
          <iframe src="http://www.slideshare.net/slideshow/embed_code/12803578" style="border: 1px solid #CCC; border-width: 1px 1px 0; margin-bottom: 5px;" width="512" height="421" scrolling="no" marginwidth="0" marginheight="0" frameborder="0">
          </iframe>
        </p>
        <div style="margin-bottom: 5px; text-align: center;">
          <strong>
            <a title="Scala in practice" href="http://www.slideshare.net/holograph/scala-in-practice-12803578" target="_blank">Scala
in practice</a>
          </strong> from <strong><a href="http://www.slideshare.net/holograph" target="_blank">Tomer
Gabel</a></strong></div>
        <h3>What is Scala?
</h3>
        <p>
          <a href="http://www.scala-lang.org/">Scala</a> is a modern, statically-typed language
designed to run on the Java platform. It's commonly perceived as an "evolutionary
Java" and with good reason: Scala adds powerful features while significantly reducing
Java's verbosity. It is a highly practical language in that it offers a very straightforward
migration path for developers on existing platforms: Java developers will feel right
at home with Scala, and a .NET developers will not have to give up on a lot of the
advantages C# has over Java.
</p>
        <p>
For organizations with a preexisting codebase Scala offers an excellent balance between
power and feature set, as well as perfect interoperability with existing Java code:
although you certainly don't <em>have </em>to, you can freely use familiar libraries
without a hitch, call into existing code and, for the most part, use your existing
tool-chain with little or no impact.
</p>
        <h3>Why did we pick Scala?
</h3>
        <p>
As mentioned above, Scala offers a very compelling migration path from an existing
Java codebase. When we were setting up the new R&amp;D center at <a href="http://www.newbrandanalytics.com">newBrandAnalytics</a>,
we were already serving paying customers via a complex codebase. A complete rewrite
was out of the question as we had contractual obligations, and we had to keep improving
the existing product in order to maintain the competitive edge; it became very clear
that we needed to maintain the existing codebase and refactor it incrementally.
</p>
        <p>
An additional data point was that our core team members were highly experienced with
Java development and quite comfortable with the platform; we also had a distinct preference
for statically typed languages, which ruled several alternatives (particularly Clojure)
right out. Scala seemed like a great compromise in that it allowed us to maintain
and extend the existing codebase while enjoying advanced language features and improved
veracity at little or no risk to the product itself.
</p>
        <h3>How should I "sell" Scala to my boss?
</h3>
        <p>
          <strong>"Safe" choice with proven track record: </strong>Scala is not an entirely
new language, and has reached a maturity tipping point at 2.8; over the last two years
the language has been gaining significant momentum, and has a number of strong advocates
and success stories, including Twitter, Foursquare, LinkedIn and a <a href="http://www.quora.com/Startups/What-startups-or-tech-companies-are-using-Scala">whole
host of others</a>.
</p>
        <p>
          <strong>Scala as a better Java:</strong> You don't have to go all-in on Scala's advanced
feature set, but can instead think of Scala as an improved Java with type inference,
closures, advanced collection framework, traits and pattern matching; these features
alone will increase your developers' happiness by an order of magnitude, and productivity
will see a corresponding improvement. 
</p>
        <p>
          <strong>Less code ⇒ less bugs</strong>: Scala code is far more concise than corresponding
Java code, an helps the developer focus on the "what" instead of the "how". The resulting
code is usually much shorter, clearer and simpler, which in turn helps lower bug count.
</p>
        <p>
          <strong>Helps hire better engineers:</strong> Great engineers not only love working
with the latest technologies, but also love practical, incremental improvements to
well-respected technologies. Merely saying "we use Scala" will help attract the sort
of seasoned, reliable and professional engineers that you most want to hire.
</p>
        <h3>Where does Scala put you at risk?
</h3>
        <p>
          <strong>Learning curve:</strong> Although Scala largely derives from Java, it's a
whole new language with a lot of features that takes time to master. Don't expect
your developers to be productive from day one; instead, provide opportunities for
experimentation and encourage iterative development (and yes, give your developers
time and mandate to throw away badly written early code and redo their work if necessary).
There is actually a lot of material on Scala and an active and vibrant community;
specifically, your developers can easily find help (and answers) on <a href="http://www.stackoverflow.com">StackOverflow</a>.
</p>
        <p>
          <strong>Rough edges: </strong>Scala is fairly new, and consequently a lot of things
that you take for granted with Java are not as mature or robust with Scala. IDE support
is a moving target: Eclipse and IntelliJ IDEA both have actively developed Scala plugins
and both have occasional issues (spurious error highlighting, lackluster performance,
wonky debuggers). The common build tools support Scala, but don't play as nicely;
for example, only the native build tool (sbt) support incremental compilation. Even
the compiler itself is not entirely bug-free, although these are getting very rare
indeed. Bottom line: expect occasional problems, and be patient while working around
them; even better, <strong>encourage your engineers to participate in the community</strong>,
file bugs and even offer patches where possible.
</p>
        <p>
          <strong>Production characteristics:</strong> While it runs on the JVM, Scala is <em>not</em> Java;
there are subtle differences that you should be aware of when maintaining large-scale
or highly-available software. Scala generates a great deal of synthetic code, which
puts additional pressure on the PermGen space; synthetic stack frames may also exhibit
significantly increased stack usage. Scala also creates a lot of intermediate objects
at runtime, which results in added eden generation churn. You may want to profile
your applications and tune the GC accordingly.
</p>
        <h3>What's the bottom line?
</h3>
        <p>
          <img style="display: block; margin-left: auto; margin-right: auto;" title="codebase-evolution.png" src="http://www.tomergabel.com/content/binary/codebase-evolution.png" alt="Codebase evolution" width="600" height="450" border="0" />
        </p>
        <p>
Scala is fantastic. Our team at newBrandAnalytics is remarkably happier with Scala
despite the occasional hitches, and I doubt any of us will consider going back to
Java given the option. As long as you keep in mind that <em>on the bleeding edge you
may get cut</em>, I definitely recommend taking the plunge, with contractors and die-hard
traditional enterprises the possible exceptions.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b8d6056d-cdf8-49a7-ac8c-d4424a965720" />
      </body>
      <title>Scala In Practice: A Case Study</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,b8d6056d-cdf8-49a7-ac8c-d4424a965720.aspx</guid>
      <link>http://www.tomergabel.com/ScalaInPracticeACaseStudy.aspx</link>
      <pubDate>Thu, 02 Aug 2012 07:20:42 GMT</pubDate>
      <description>&lt;p&gt;
This post attempts to summarize and clarify a lecture given at the &lt;a href="https://www.facebook.com/botzia"&gt;Botzia&lt;/a&gt; (Israeli
Java user group) meeting on May 3rd, 2012. You can view the presentation in its entirety
on SlideShare:
&lt;/p&gt;
&lt;p style="text-align: center;"&gt;
&lt;iframe src="http://www.slideshare.net/slideshow/embed_code/12803578" style="border: 1px solid #CCC; border-width: 1px 1px 0; margin-bottom: 5px;" width="512" height="421" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;div style="margin-bottom: 5px; text-align: center;"&gt;&lt;strong&gt; &lt;a title="Scala in practice" href="http://www.slideshare.net/holograph/scala-in-practice-12803578" target="_blank"&gt;Scala
in practice&lt;/a&gt; &lt;/strong&gt; from &lt;strong&gt;&lt;a href="http://www.slideshare.net/holograph" target="_blank"&gt;Tomer
Gabel&lt;/a&gt;&lt;/strong&gt;
&lt;/div&gt;
&lt;h3&gt;What is Scala?
&lt;/h3&gt;
&lt;p&gt;
&lt;a href="http://www.scala-lang.org/"&gt;Scala&lt;/a&gt; is a modern, statically-typed language
designed to run on the Java platform. It's commonly perceived as an "evolutionary
Java" and with good reason: Scala adds powerful features while significantly reducing
Java's verbosity. It is a highly practical language in that it offers a very straightforward
migration path for developers on existing platforms: Java developers will feel right
at home with Scala, and a .NET developers will not have to give up on a lot of the
advantages C# has over Java.
&lt;/p&gt;
&lt;p&gt;
For organizations with a preexisting codebase Scala offers an excellent balance between
power and feature set, as well as perfect interoperability with existing Java code:
although you certainly don't &lt;em&gt;have &lt;/em&gt;to, you can freely use familiar libraries
without a hitch, call into existing code and, for the most part, use your existing
tool-chain with little or no impact.
&lt;/p&gt;
&lt;h3&gt;Why did we pick Scala?
&lt;/h3&gt;
&lt;p&gt;
As mentioned above, Scala offers a very compelling migration path from an existing
Java codebase. When we were setting up the new R&amp;amp;D center at &lt;a href="http://www.newbrandanalytics.com"&gt;newBrandAnalytics&lt;/a&gt;,
we were already serving paying customers via a complex codebase. A complete rewrite
was out of the question as we had contractual obligations, and we had to keep improving
the existing product in order to maintain the competitive edge; it became very clear
that we needed to maintain the existing codebase and refactor it incrementally.
&lt;/p&gt;
&lt;p&gt;
An additional data point was that our core team members were highly experienced with
Java development and quite comfortable with the platform; we also had a distinct preference
for statically typed languages, which ruled several alternatives (particularly Clojure)
right out. Scala seemed like a great compromise in that it allowed us to maintain
and extend the existing codebase while enjoying advanced language features and improved
veracity at little or no risk to the product itself.
&lt;/p&gt;
&lt;h3&gt;How should I "sell" Scala to my boss?
&lt;/h3&gt;
&lt;p&gt;
&lt;strong&gt;"Safe" choice with proven track record: &lt;/strong&gt;Scala is not an entirely
new language, and has reached a maturity tipping point at 2.8; over the last two years
the language has been gaining significant momentum, and has a number of strong advocates
and success stories, including Twitter, Foursquare, LinkedIn and a &lt;a href="http://www.quora.com/Startups/What-startups-or-tech-companies-are-using-Scala"&gt;whole
host of others&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Scala as a better Java:&lt;/strong&gt; You don't have to go all-in on Scala's advanced
feature set, but can instead think of Scala as an improved Java with type inference,
closures, advanced collection framework, traits and pattern matching; these features
alone will increase your developers' happiness by an order of magnitude, and productivity
will see a corresponding improvement. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Less code ⇒ less bugs&lt;/strong&gt;: Scala code is far more concise than corresponding
Java code, an helps the developer focus on the "what" instead of the "how". The resulting
code is usually much shorter, clearer and simpler, which in turn helps lower bug count.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Helps hire better engineers:&lt;/strong&gt; Great engineers not only love working
with the latest technologies, but also love practical, incremental improvements to
well-respected technologies. Merely saying "we use Scala" will help attract the sort
of seasoned, reliable and professional engineers that you most want to hire.
&lt;/p&gt;
&lt;h3&gt;Where does Scala put you at risk?
&lt;/h3&gt;
&lt;p&gt;
&lt;strong&gt;Learning curve:&lt;/strong&gt; Although Scala largely derives from Java, it's a
whole new language with a lot of features that takes time to master. Don't expect
your developers to be productive from day one; instead, provide opportunities for
experimentation and encourage iterative development (and yes, give your developers
time and mandate to throw away badly written early code and redo their work if necessary).
There is actually a lot of material on Scala and an active and vibrant community;
specifically, your developers can easily find help (and answers) on &lt;a href="http://www.stackoverflow.com"&gt;StackOverflow&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Rough edges: &lt;/strong&gt;Scala is fairly new, and consequently a lot of things
that you take for granted with Java are not as mature or robust with Scala. IDE support
is a moving target: Eclipse and IntelliJ IDEA both have actively developed Scala plugins
and both have occasional issues (spurious error highlighting, lackluster performance,
wonky debuggers). The common build tools support Scala, but don't play as nicely;
for example, only the native build tool (sbt) support incremental compilation. Even
the compiler itself is not entirely bug-free, although these are getting very rare
indeed. Bottom line: expect occasional problems, and be patient while working around
them; even better, &lt;strong&gt;encourage your engineers to participate in the community&lt;/strong&gt;,
file bugs and even offer patches where possible.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Production characteristics:&lt;/strong&gt; While it runs on the JVM, Scala is &lt;em&gt;not&lt;/em&gt; Java;
there are subtle differences that you should be aware of when maintaining large-scale
or highly-available software. Scala generates a great deal of synthetic code, which
puts additional pressure on the PermGen space; synthetic stack frames may also exhibit
significantly increased stack usage. Scala also creates a lot of intermediate objects
at runtime, which results in added eden generation churn. You may want to profile
your applications and tune the GC accordingly.
&lt;/p&gt;
&lt;h3&gt;What's the bottom line?
&lt;/h3&gt;
&lt;p&gt;
&lt;img style="display: block; margin-left: auto; margin-right: auto;" title="codebase-evolution.png" src="http://www.tomergabel.com/content/binary/codebase-evolution.png" alt="Codebase evolution" width="600" height="450" border="0" /&gt;
&lt;/p&gt;
&lt;p&gt;
Scala is fantastic. Our team at newBrandAnalytics is remarkably happier with Scala
despite the occasional hitches, and I doubt any of us will consider going back to
Java given the option. As long as you keep in mind that &lt;em&gt;on the bleeding edge you
may get cut&lt;/em&gt;, I definitely recommend taking the plunge, with contractors and die-hard
traditional enterprises the possible exceptions.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b8d6056d-cdf8-49a7-ac8c-d4424a965720" /&gt;</description>
      <category>Development</category>
      <category>Development/Java</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=93d13e31-691e-410c-842d-8c1379e8bfdd</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,93d13e31-691e-410c-842d-8c1379e8bfdd.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <title>DevOps: Organically grown, no preservatives</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,93d13e31-691e-410c-842d-8c1379e8bfdd.aspx</guid>
      <link>http://www.tomergabel.com/DevOpsOrganicallyGrownNoPreservatives.aspx</link>
      <pubDate>Mon, 11 Oct 2010 17:55:29 GMT</pubDate>
      <description>&lt;p&gt;
(Cross-posted on the &lt;a href="http://blog.delver.com/index.php/2010/10/11/devops-at-delver/"&gt;Delver
Blog&lt;/a&gt;)
&lt;/p&gt;
&lt;p&gt;
A little while ago I posted a job opening for the &lt;a href="http://www.tomergabel.com/SwitchingR%c3%b4les.aspx" target="_blank"&gt;application
engineer&lt;/a&gt; position at Delver, and one of the replies caught my interest: “so it’s
a DevOps position?” A Google search later and I was astounded to find what I tried
to explain has since grown into a &lt;a href="http://en.wikipedia.org/wiki/DevOps" target="_blank"&gt;fully&lt;/a&gt; &lt;a href="http://www.jedi.be/blog/2010/02/12/what-is-this-devops-thing-anyway/" target="_blank"&gt;fledged&lt;/a&gt; &lt;a href="http://www.devopsdays.org/" target="_blank"&gt;industry&lt;/a&gt; &lt;a href="http://agileoperations.net/index.php?/archives/24-Devops.html" target="_blank"&gt;trend&lt;/a&gt;&lt;?xml:namespace prefix = o /&gt;.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
I’ve learned to be mistrustful of such trends; in my experience they tend to inflate
and deflate regularly, and if you try to keep abreast of all the proposed improvements
to the development process you’re going to drown in overhead. Still, a critical percentage
of these trends have a valid rationale driving them: unit testing, concurrency constructs,
event-driven application servers, RESTful interfaces – all of these have very solid
theoretical and/or practical reasoning and have had significant impact on the software
development field. An additional commonality is: each took several years to gain acceptance
in leading R&amp;amp;D teams, and several more to become ingrained methodology. The key
word here is &lt;em&gt;risk management&lt;/em&gt;, which is typically avoided or ignored altogether
by the common developer.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
Don’t get me wrong: I come from a purely R&amp;amp;D background, and have shared that
trait for years. What started me on a different line of thinking was the distinct
pleasure of being woken up, once too often, by some poor NOC operator in the middle
of the night, and getting mad enough to do something about it. Like most R&amp;amp;D personnel
I was largely oblivious to the pains of deployment, availability, scaling, production
troubleshooting and customer support, and had to learn my lessons the hard way. I
believe most R&amp;amp;D people aren’t more minded of the pains inherent in each of these
domains because of the simplest of reasons: they’ve never been challenged to do so.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
This is where “DevOps” comes in.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
An application engineer (app engineer or “devops guy” if you will) has two primary
objectives:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;ul type="disc"&gt;
&lt;li style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in" class="MsoNormal"&gt;
&lt;span style="mso-fareast-font-family: 'Times New Roman'"&gt;Guide the R&amp;amp;D team in
risk assessment. Having a software-savvy operations team member participating in design
reviews is a huge boon to risk management; a better app engineer will want to participate
in the &lt;em&gt;design process itself,&lt;/em&gt; not necessarily designing the actual feature&lt;sup&gt;†&lt;/sup&gt;,
but even a quick overview of the proposed design is usually enough to provide operational
feedback. This, without fail, results in a better design: clearer error-handling semantics,
better monitoring and configuration facilities, high availability baked into the design,
and induction into the deployment/administration toolchain concurrently with development
efforts. This in turn leads to much better overall estimates and reduced failure rate. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in" class="MsoNormal"&gt;
&lt;span style="mso-fareast-font-family: 'Times New Roman'"&gt;Keep the system up and running!
This entails more than just observing the monitoring system (in my opinion, the less
time you spend that way the less you are likely to have to, ad vitam aut culpam).
The application engineer is in the relatively unique position of being both the &lt;em&gt;consumer&lt;/em&gt; and &lt;em&gt;producer&lt;/em&gt; of
his or her own tools; this is where the wheat is separated from the chaff: a great
app engineer will forever strive to improve and automate every nonfunctional aspect
of the system, diligently working towards that asymptotic 100% uptime&lt;sup&gt;‡&lt;/sup&gt;.
DevOps personnel are &lt;em&gt;the &lt;/em&gt;go-to people for getting systems off the ground;
they’ll sketch the solution out, provide short- and long-term plans for deployment,
monitoring and administration solutions both system-wide and component-specific. They’ll
devise automatic tools to identify problems and anomalies, they’ll work ever-more-specific
endpoints into their monitoring system, and they’ll be happy doing it because contrary
to nearly any other position in the industry &lt;em&gt;their interests and the business’s
inherently converge.&lt;/em&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Both DevOps and management would like nothing more than a clean, orderly universe
in which systems do not fail, no data is ever lost and the system performs optimally
on as little hardware as possible. Management’s business is budget and revenue; app
engineers simply do not want to be woken up in the middle of the night.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
Next up: Growing a DevOps organization, stay tuned!&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;sup&gt;†&lt;/sup&gt; While not mandatory by any means, some design cycles can significantly
benefit from an operational perspective; examples include static content management
for websites; high availability for various system components; and any subsystem with
external dependencies.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;sup&gt;‡&lt;/sup&gt; A DevOps position is inherently multidisciplinary; for example, R&amp;amp;D
background can significantly assist in troubleshooting. design reviews and in rolling
your own tools. Strong system analysis skills, however, may be even more important,
as they enable the two most important functions of the application engineer: spotting
subtle holes in the design phase, and under-fire troubleshooting (which often requires
the elusive ability to rapidly - but accurately - jump to conclusions).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=93d13e31-691e-410c-842d-8c1379e8bfdd" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=7a6c8b16-6220-478d-84ce-4b423d0de0bf</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,7a6c8b16-6220-478d-84ce-4b423d0de0bf.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <title>Switching rôles</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,7a6c8b16-6220-478d-84ce-4b423d0de0bf.aspx</guid>
      <link>http://www.tomergabel.com/SwitchingR%c3%b4les.aspx</link>
      <pubDate>Sun, 13 Dec 2009 12:54:30 GMT</pubDate>
      <description>&lt;p&gt;
When a company is acquired by another, some sort of restructuring is inevitable. As &lt;a href="http://www.tomergabel.com/LifeIsFullOfSurprises.aspx"&gt;Delver’s
acquisition&lt;/a&gt; by Sears Holdings became reality, it was also obvious that significant
changes were required to how we operate. The first and most pronounced of these changes
was that our social (or socially-connected, if you’re picky) search engine, the &lt;a href="http://www.readwriteweb.com/archives/delver_reinvents_search.php"&gt;first
product of its kind&lt;/a&gt; – we have enough ego to kick ourselves hard now that &lt;a href="http://mashable.com/2009/10/26/social-search-launch/"&gt;Google’s
version&lt;/a&gt; is out – was scrapped, and the entire team was put to work on a new product
for Sears Holdings. This, of course, meant restructuring the R&amp;D team.
&lt;/p&gt;
&lt;p&gt;
One of our tenants at Delver was that everything is open to interpretation, critique
and improvement. As an R&amp;D team we were always relentlessly self-improving; I believe
my two years at Delver were perhaps the best I have ever experienced professionally.
I’m happy to say that this approach still prevails under Sears Holdings, and we’ve
taken the first few months under the new management for some serious introspection,
trying to learn everything we can from the mistakes we made while still working under
the Delver banner. I believe the organization has improved across the board with these
sessions, resulting in significant improvements to everything from recruiting, HR
and managerial processes to source control, configuration and release management.
But as a developer I felt I was hitting a professional plateau.
&lt;/p&gt;
&lt;p&gt;
As the new product’s specs took shape I was initially meant to take charge of the
search engine implementation, continuing my original position at Delver. After nearly
two years of working on search it became obvious to me that it is a very broad and
nontrivial domain, and that to do a good job I will have to truly specialize in search.
While I knew I did not want to continue working on the search engine, I also knew
that the other developer positions would not satisfy me. While the product was being
specified I kept busy with tasks that were not directly related with the product itself:
setting up an integration testing framework (not trivial with a system comprising
both Java and .NET components, and which integrates a significant number of 3rd party
products), defining various development processes like version and branch guidelines,
and finally implementing a &lt;a href="http://code.google.com/p/ant-intellij-tasks/"&gt;proper
Java build system&lt;/a&gt; that still drives our builds today. The common ground here is
that, for the most part, the greatest enjoyment was derived from doing stuff that’s
“horizontal”, that crosses components and teams and sort of binds the entire development
effort together. With this in mind I approached my bosses at Sears and, after prolonged
discussions, we came up with the title of &lt;a href="http://www.slideshare.net/holograph/application-engineer-introductory-presentation"&gt;&lt;em&gt;Application
Engineer&lt;/em&gt;&lt;/a&gt;:
&lt;/p&gt;
&lt;center&gt;
&lt;div style="text-align: center; width: 425px" id="__ss_2708205"&gt;
&lt;p align="center"&gt;
&lt;object style="margin:0px" width="425" height="355"&gt;
&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=applicationengineer-091213064141-phpapp01&amp;rel=0&amp;stripped_title=application-engineer-introductory-presentation" /&gt;
&lt;param name="allowFullScreen" value="true" /&gt;
&lt;param name="allowScriptAccess" value="always" /&gt;&lt;embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=applicationengineer-091213064141-phpapp01&amp;rel=0&amp;stripped_title=application-engineer-introductory-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/center&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
An application engineer, in Sears parlance at any rate, bridges the gap between R&amp;D
and IT (or rather, the support, deployment and administrative teams). Essentially,
where R&amp;D (and QA) ends, the app engineer’s role begins: the app engineer is directly
responsible for the smooth operation of the production system. This means that the
app engineer must not only be fully versed in the system architecture and inner workings,
but must also be an active participant in defining it. Wherever there is an overlap
between R&amp;D and IT is where you will find the app engineer: front-end server farms,
logging and profiling requirements, log aggregation and reporting, system monitoring
(which suddenly not only includes health, but applicative counters that must be correctly
specified and monitored), deployment and troubleshooting processes etc. Having been
assigned this role for the past few months I’ve reached the conclusion that an app
engineer is a cross between IT-oriented system architect and system administrator,
walking a fine line between a developer and a system adminstrator. I certainly hope
I don’t fall off!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=7a6c8b16-6220-478d-84ce-4b423d0de0bf" /&gt;</description>
      <category>Development</category>
      <category>Personal</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=b849579e-4637-4051-ba21-f87975905ca0</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,b849579e-4637-4051-ba21-f87975905ca0.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>Download </em>
          <a href="http://ant-intellij-tasks.googlecode.com/files/ant-intellij-tasks-1.0-b1.zip">
            <em>ant-intellij-tasks-1.0-b1.zip</em>
          </a>
          <em>
          </em>
        </p>
        <p>
A great but oft-ignored feature of Visual Studio 2005 and up is the inherent consolidation
of an important developer tool: the build system. With a Visual Studio solution you
can simply run MSBuild and you get accurate, automated builds. This is an invaluable
capability: continuous integration is ridiculously easy to set up, as are nightly
builds and automated deployment tools.
</p>
        <p>
Since I started working for Delver (<a href="http://www.tomergabel.com/LifeIsFullOfSurprises.aspx">now
Sears</a>) I’ve been switching back and forth between C# (2.0 and later 3.0) and Java
1.6, and though the ecosystems share many similarities there are also several glaring
differences. The first of these differences is that, in the Java world, it is perfectly
acceptable – even traditional – to maintain a dual project structure, one using the
IDE (usually Eclipse or IntelliJ IDEA) and one using one of the build tools (commonly
Ant or Maven). The build scripts need to be continuously synchronized with the project
structure, and output parity between the two separate build systems is almost unheard-of.
</p>
        <p>
Because I had been a complete Java newbie when I started, I had never had the time
to really sit down and set up a continuous integration server for our Java codebase,
a mistake I did not intent to repeat when Sears took over. The first item on my agenda
was to do away with the dual project structure; we originally used Eclipse, so I built
a custom Ant script (my first, actually) around <a href="http://ant4eclipse.sourceforge.net/">ant4eclipse</a> and
managed to come up with a semi-satisfactory solution. This also gave us invaluable
insight when it was time to revisit our IDE choice; the lackluster project structure
offered by Eclipse, along with firm positive comments on IntelliJ IDEA from several
team members, tipped the balance and led us to switch to the alternative IDE, while
also creating the necessity for a revamped build system can that work on top of the
IntelliJ IDEA project structure.
</p>
        <p>
Out of necessity, a project was born. <a href="http://code.google.com/p/ant-intellij-tasks/">ant-intellij-tasks</a> is
the result of several months of all-night itch-scratching on my part. While not directly
affiliated with the company, we’ve been dogfooding the project at Sears for over a
month now, and while there are certainly rough edges it finally seems stable enough
for release! From the project website:
</p>
        <blockquote style="padding-bottom: 5px; padding-left: 5px; padding-right: 5px; background: #ccc; padding-top: 5px">
          <p>
            <a href="http://code.google.com/p/ant-intellij-tasks">ant-intellij-tasks</a> is a
self-contained build system for IntelliJ IDEA projects based around <a href="http://ant.apache.org/">Apache
Ant</a>. In essence, ant-intellij-tasks comprises three components: 
</p>
          <ol>
            <li>
An Ant task library that can extract and resolve the IntelliJ IDEA project and module
files (.ipr and .iml respectively), and provides a set of tasks and conditions around
the project structure; 
</li>
            <li>
A common build script which provides the four major build targets for modules: clean,
build, test and package (see <a href="http://code.google.com/p/ant-intellij-tasks/#Quickstart_Guide">the
quickstart guide</a>); 
</li>
            <li>
A master build script which extends these targets to the entire project. 
</li>
          </ol>
          <p>
The build system is designed to be extensible (e.g. by adding targets), customizable
(e.g. by overriding a target's behavior for a specific module) and self contained
in that it's a drop-in solution that should not require any significant modifications
to the code base. 
</p>
          <p>
          </p>
          <p>
This project is fully open source (distributed under an Apache license) and hosted
at Google Code. Please report any bugs or issues on the project <a href="http://code.google.com/p/ant-intellij-tasks/issues/list">issue
tracker</a>. 
</p>
          <p>
          </p>
          <p>
ant-intellij-tasks makes use of, and redistributes, the <a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> task
library. 
</p>
        </blockquote>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b849579e-4637-4051-ba21-f87975905ca0" />
      </body>
      <title>Announcing ant-intellij-tasks</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,b849579e-4637-4051-ba21-f87975905ca0.aspx</guid>
      <link>http://www.tomergabel.com/AnnouncingAntintellijtasks.aspx</link>
      <pubDate>Wed, 30 Sep 2009 06:18:58 GMT</pubDate>
      <description>&lt;p&gt;
&lt;em&gt;Download &lt;/em&gt;&lt;a href="http://ant-intellij-tasks.googlecode.com/files/ant-intellij-tasks-1.0-b1.zip"&gt;&lt;em&gt;ant-intellij-tasks-1.0-b1.zip&lt;/em&gt;&lt;/a&gt;&lt;em&gt; &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
A great but oft-ignored feature of Visual Studio 2005 and up is the inherent consolidation
of an important developer tool: the build system. With a Visual Studio solution you
can simply run MSBuild and you get accurate, automated builds. This is an invaluable
capability: continuous integration is ridiculously easy to set up, as are nightly
builds and automated deployment tools.
&lt;/p&gt;
&lt;p&gt;
Since I started working for Delver (&lt;a href="http://www.tomergabel.com/LifeIsFullOfSurprises.aspx"&gt;now
Sears&lt;/a&gt;) I’ve been switching back and forth between C# (2.0 and later 3.0) and Java
1.6, and though the ecosystems share many similarities there are also several glaring
differences. The first of these differences is that, in the Java world, it is perfectly
acceptable – even traditional – to maintain a dual project structure, one using the
IDE (usually Eclipse or IntelliJ IDEA) and one using one of the build tools (commonly
Ant or Maven). The build scripts need to be continuously synchronized with the project
structure, and output parity between the two separate build systems is almost unheard-of.
&lt;/p&gt;
&lt;p&gt;
Because I had been a complete Java newbie when I started, I had never had the time
to really sit down and set up a continuous integration server for our Java codebase,
a mistake I did not intent to repeat when Sears took over. The first item on my agenda
was to do away with the dual project structure; we originally used Eclipse, so I built
a custom Ant script (my first, actually) around &lt;a href="http://ant4eclipse.sourceforge.net/"&gt;ant4eclipse&lt;/a&gt; and
managed to come up with a semi-satisfactory solution. This also gave us invaluable
insight when it was time to revisit our IDE choice; the lackluster project structure
offered by Eclipse, along with firm positive comments on IntelliJ IDEA from several
team members, tipped the balance and led us to switch to the alternative IDE, while
also creating the necessity for a revamped build system can that work on top of the
IntelliJ IDEA project structure.
&lt;/p&gt;
&lt;p&gt;
Out of necessity, a project was born. &lt;a href="http://code.google.com/p/ant-intellij-tasks/"&gt;ant-intellij-tasks&lt;/a&gt; is
the result of several months of all-night itch-scratching on my part. While not directly
affiliated with the company, we’ve been dogfooding the project at Sears for over a
month now, and while there are certainly rough edges it finally seems stable enough
for release! From the project website:
&lt;/p&gt;
&lt;blockquote style="padding-bottom: 5px; padding-left: 5px; padding-right: 5px; background: #ccc; padding-top: 5px"&gt; 
&lt;p&gt;
&lt;a href="http://code.google.com/p/ant-intellij-tasks"&gt;ant-intellij-tasks&lt;/a&gt; is a
self-contained build system for IntelliJ IDEA projects based around &gt;&lt;a href="http://ant.apache.org/"&gt;Apache
Ant&lt;/a&gt;. In essence, ant-intellij-tasks comprises three components: 
&lt;ol&gt;
&lt;li&gt;
An Ant task library that can extract and resolve the IntelliJ IDEA project and module
files (.ipr and .iml respectively), and provides a set of tasks and conditions around
the project structure; 
&lt;li&gt;
A common build script which provides the four major build targets for modules: clean,
build, test and package (see &lt;a href="http://code.google.com/p/ant-intellij-tasks/#Quickstart_Guide"&gt;the
quickstart guide&lt;/a&gt;); 
&lt;li&gt;
A master build script which extends these targets to the entire project. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The build system is designed to be extensible (e.g. by adding targets), customizable
(e.g. by overriding a target's behavior for a specific module) and self contained
in that it's a drop-in solution that should not require any significant modifications
to the code base. 
&lt;p&gt;
&lt;p&gt;
This project is fully open source (distributed under an Apache license) and hosted
at Google Code. Please report any bugs or issues on the project &lt;a href="http://code.google.com/p/ant-intellij-tasks/issues/list"&gt;issue
tracker&lt;/a&gt;. 
&lt;p&gt;
&lt;p&gt;
ant-intellij-tasks makes use of, and redistributes, the &lt;a href="http://ant-contrib.sourceforge.net/"&gt;ant-contrib&lt;/a&gt; task
library. 
&lt;/p&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b849579e-4637-4051-ba21-f87975905ca0" /&gt;</description>
      <category>Development</category>
      <category>Development/Java</category>
      <category>Software</category>
      <category>ant-intellij-tasks</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=6a6c2dc7-df2a-4bec-8a2b-0e7d1e652d3f</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,6a6c2dc7-df2a-4bec-8a2b-0e7d1e652d3f.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Apparently Java has quite a few known but practically undocumented issues with its
handling of UNC paths under Windows. I’ve specifically encountered <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086147">this
bug</a> albeit in a slightly different scenario:
</p>
        <div>
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">@Test<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> test() <span style="color: #0000ff">throws</span> URISyntaxException
{<br /><span style="color: #0000ff">final</span> URI uri = <span style="color: #0000ff">new</span> URI( <span style="color: #006080">"file://c:/temp/test/ham.and.eggs"</span> );<br /><span style="color: #0000ff">new</span> File( uri ); <span style="color: #008000">//
IllegalArgumentException thrown here</span><br />
}</pre>
        </div>
        <div>
          <br />
Apparently the two slashes after file: are misinterpreted as the authority part of
the URI; <a href="http://stackoverflow.com/questions/1131273/java-file-touri-tourl-on-windows-file/1131465#1131465">this
thread</a> on StackOverflow may give a few starting points if want to delve deeper.
It seems Java implements an older RFC for URIs which has slightly different tokenization
rules.
</div>
        <div> 
</div>
        <div>At any rate, so far the only sensible solution I’ve managed to come with is to
manually remove or add (depending on your tastes…) a slash:
</div>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <p>
              <span style="color: #008000">/**</span>
              <br />
              <span style="color: #008000"> * Resolves the specified URI, and returns the file </span>
              <br />
              <span style="color: #008000"> * represented by the URI.</span>
              <br />
              <span style="color: #008000"> *</span>
              <br />
              <span style="color: #008000"> * @param uri The URI for which to return an absolute
path.</span>
              <br />
              <span style="color: #008000"> * @return The {@link File} instance represented by the</span>
              <br />
              <span style="color: #008000"> * specified URI.</span>
              <br />
              <span style="color: #008000"> * @throws IllegalArgumentException &lt;ul&gt;&lt;li&gt;The
URI cannot </span>
              <br />
              <span style="color: #008000"> * be null.&lt;/li&gt;&lt;li&gt;Wrong URI scheme for
path resolution;</span>
              <br />
              <span style="color: #008000"> * only file:// URIs are supported.&lt;/li&gt;&lt;/ul&gt;</span>
              <br />
              <span style="color: #008000"> */</span>
              <br />
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">static</span> File
getFile( URI uri )<br /><span style="color: #0000ff">throws</span> IllegalArgumentException {<br /><span style="color: #0000ff">if</span> ( uri == null )<br /><span style="color: #0000ff">throw</span><span style="color: #0000ff">new</span> IllegalArgumentException(<br /><span style="color: #006080">"The URI cannot be null."</span> );
</p>
            <p>
              <br />
              <br />
              <span style="color: #0000ff">if</span> ( !<span style="color: #006080">"file"</span>.equals(
uri.getScheme() ) )<br /><span style="color: #0000ff">throw</span><span style="color: #0000ff">new</span> IllegalArgumentException( <span style="color: #006080">"Wrong
URI "</span> + 
<br /><span style="color: #006080">"scheme for path resolution, expected \"file\" "</span> +<br /><span style="color: #006080">"and got \""</span> + uri.getScheme() + <span style="color: #006080">"\""</span> );
</p>
            <p>
              <br />
              <span style="color: #008000">// Workaround for the following bug: </span>
              <br />
              <span style="color: #008000">// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086147</span>
              <br />
              <span style="color: #008000">// Remove extra slashes after the scheme part.</span>
              <br />
              <span style="color: #0000ff">if</span> ( uri.getAuthority() != null )<br /><span style="color: #0000ff">try</span> {<br />
uri = <span style="color: #0000ff">new</span> URI( uri.toString().replace( 
<br /><span style="color: #006080">"file://"</span>, <span style="color: #006080">"file:/"</span> )
);<br />
} <span style="color: #0000ff">catch</span> ( URISyntaxException e ) {<br /><span style="color: #0000ff">throw</span><span style="color: #0000ff">new</span> IllegalArgumentException( <span style="color: #006080">"The
specified "</span> +<br /><span style="color: #006080">"URI contains an authority, but could not be "</span> +<br /><span style="color: #006080">"normalized."</span>, e );<br />
}
</p>
            <p>
              <br />
              <br />
              <span style="color: #0000ff">return</span>
              <span style="color: #0000ff">new</span> File(
uri );<br />
}<br /></p>
          </pre>
          <br />
        </div>
        <div> 
</div>
        <div>This is definitely a workaround, but according to newsgroup and forum posts these
bugs have been around forever. If anyone has a more elegant solution I’d love to know.
</div>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=6a6c2dc7-df2a-4bec-8a2b-0e7d1e652d3f" />
      </body>
      <title>Java mishandles UNC paths on Windows</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,6a6c2dc7-df2a-4bec-8a2b-0e7d1e652d3f.aspx</guid>
      <link>http://www.tomergabel.com/JavaMishandlesUNCPathsOnWindows.aspx</link>
      <pubDate>Mon, 03 Aug 2009 05:00:20 GMT</pubDate>
      <description>&lt;p&gt;
Apparently Java has quite a few known but practically undocumented issues with its
handling of UNC paths under Windows. I’ve specifically encountered &lt;a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086147"&gt;this
bug&lt;/a&gt; albeit in a slightly different scenario:
&lt;/p&gt;
&lt;div&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;@Test&lt;br&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; test() &lt;span style="color: #0000ff"&gt;throws&lt;/span&gt; URISyntaxException
{&lt;br&gt;
&lt;span style="color: #0000ff"&gt;final&lt;/span&gt; URI uri = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; URI( &lt;span style="color: #006080"&gt;"file://c:/temp/test/ham.and.eggs"&lt;/span&gt; );&lt;br&gt;
&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; File( uri ); &lt;span style="color: #008000"&gt;//
IllegalArgumentException thrown here&lt;/span&gt;
&lt;br&gt;
}&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br&gt;
Apparently the two slashes after file: are misinterpreted as the authority part of
the URI; &lt;a href="http://stackoverflow.com/questions/1131273/java-file-touri-tourl-on-windows-file/1131465#1131465"&gt;this
thread&lt;/a&gt; on StackOverflow may give a few starting points if want to delve deeper.
It seems Java implements an older RFC for URIs which has slightly different tokenization
rules.
&lt;/div&gt;
&lt;div&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div&gt;At any rate, so far the only sensible solution I’ve managed to come with is to
manually remove or add (depending on your tastes…) a slash:
&lt;/div&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
&lt;p&gt;
&lt;span style="color: #008000"&gt;/**&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; * Resolves the specified URI, and returns the file &lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; * represented by the URI.&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; *&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; * @param uri The URI for which to return an absolute
path.&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; * @return The {@link File} instance represented by the&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; * specified URI.&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; * @throws IllegalArgumentException &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;The
URI cannot &lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; * be null.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Wrong URI scheme for
path resolution;&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; * only file:// URIs are supported.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt; */&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; File
getFile( URI uri )&lt;br&gt;
&lt;span style="color: #0000ff"&gt;throws&lt;/span&gt; IllegalArgumentException {&lt;br&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( uri == null )&lt;br&gt;
&lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; IllegalArgumentException(&lt;br&gt;
&lt;span style="color: #006080"&gt;"The URI cannot be null."&lt;/span&gt; );
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( !&lt;span style="color: #006080"&gt;"file"&lt;/span&gt;.equals(
uri.getScheme() ) )&lt;br&gt;
&lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; IllegalArgumentException( &lt;span style="color: #006080"&gt;"Wrong
URI "&lt;/span&gt; + 
&lt;br&gt;
&lt;span style="color: #006080"&gt;"scheme for path resolution, expected \"file\" "&lt;/span&gt; +&lt;br&gt;
&lt;span style="color: #006080"&gt;"and got \""&lt;/span&gt; + uri.getScheme() + &lt;span style="color: #006080"&gt;"\""&lt;/span&gt; );
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt;// Workaround for the following bug: &lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt;// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086147&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #008000"&gt;// Remove extra slashes after the scheme part.&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( uri.getAuthority() != null )&lt;br&gt;
&lt;span style="color: #0000ff"&gt;try&lt;/span&gt; {&lt;br&gt;
uri = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; URI( uri.toString().replace( 
&lt;br&gt;
&lt;span style="color: #006080"&gt;"file://"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"file:/"&lt;/span&gt; )
);&lt;br&gt;
} &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; ( URISyntaxException e ) {&lt;br&gt;
&lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; IllegalArgumentException( &lt;span style="color: #006080"&gt;"The
specified "&lt;/span&gt; +&lt;br&gt;
&lt;span style="color: #006080"&gt;"URI contains an authority, but could not be "&lt;/span&gt; +&lt;br&gt;
&lt;span style="color: #006080"&gt;"normalized."&lt;/span&gt;, e );&lt;br&gt;
}
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; File(
uri );&lt;br&gt;
}&lt;br&gt;
&lt;/p&gt;
&lt;/pre&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;div&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div&gt;This is definitely a workaround, but according to newsgroup and forum posts these
bugs have been around forever. If anyone has a more elegant solution I’d love to know.
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=6a6c2dc7-df2a-4bec-8a2b-0e7d1e652d3f" /&gt;</description>
      <category>Development</category>
      <category>Development/Java</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=4672705f-4f41-49e2-94b3-8ef57cf25536</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,4672705f-4f41-49e2-94b3-8ef57cf25536.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It seems nothing to do with maintaining this website is as easy or as simple as it
should be. Whenever I switch hosts it’s an uphill struggle to get the site up and
running again; whenever I upgrade <a href="http://www.dasblog.info/">dasBlog</a> to
a newer version I have to learn a lot about how it works, how ASP.NET works, how IIS
is configured etc. It’s enough to make me seriously consider hosting my blog elsewhere
and/or moving to another blogging platform, but the truth is I love dasBlog so much
I simply forget how complex and volatile it can be and have to go through the same
frustrating process whenever something changes.
</p>
        <p>
The way I update my site is usually this:
</p>
        <ol>
          <li>
Ensure I have an up-to-date local mirror of the website. dasBlog keeps all of its
data in XML files, so backing up the website is simply a question of <tt><a href="http://www.gnu.org/software/wget/">wget</a> –-passive-ftp
–m ftp://user:password@website.com</tt>; I have a daily scheduled task to take care
of this. 
</li>
          <li>
Copy the latest mirrored version to a working directory; set the directory up as an
IIS website/virtual directory. 
</li>
          <li>
Test the new working copy to make sure it works. 
</li>
          <li>
Perform whatever modifications are required. 
</li>
          <li>
Test again to make sure that the website works with multiple browsers (this time I
tested with <a href="http://www.google.com/chrome">Chrome</a> 2.0.170.0, <a href="http://www.mozilla.com/firefox/">Firefox</a> 3.1
Beta 3 and <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">IE</a> 8) 
</li>
          <li>
Upload the website over FTP using the <a href="http://filezilla-project.org/">FileZilla</a> client.
I always verify that the relevant configuration files and binaries are overwritten
and nothing else.</li>
        </ol>
        <p>
This process generally allows me to test upgrades before uploading them to the “production”
website, as well as provides an easy rollback path if something goes wrong. Thing
is, something <em>always</em> goes wrong. In this case, although nothing’s changed
in the site configuration I started getting <tt>SecurityException</tt>s just after
the upgrade:
</p>
        <blockquote>
          <p>
            <tt>Request for the permission of type 'System.Security.Permissions.SecurityPermission,
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.</tt>
          </p>
        </blockquote>
        <p>
This is one of the least informative error messages I have ever seen. All it tells
me is that a request for some permission is denied; it doesn’t say what permission
was requested, nor by whom (the stack trace seemed to indicate the permission was
asserted from within <tt>System.Diagnostics.Trace</tt>, which doesn’t make much sense).
A quick web search brought me to <a href="http://bencoffman.com/blog/CommentView,guid,06e3fffc-b763-434e-ba10-6c44939c90ed.aspx">this
page</a>, which deals specifically with installing dasBlog on a <a href="http://www.godaddy.com">GoDaddy</a>-hosted
website. Because GoDaddy runs ASP.NET applications under a <a href="http://help.godaddy.com/article/1039">modified
medium trust</a> that allows file-system access only to the virtual directory hierarchy,
the site recommends adding a virtual directory for each of dasBlog’s writable directories
(content, siteconfig, logs); I tried this out and the problem was not resolved.
</p>
        <p>
At this point I was getting desperate, and was willing to try just about anything
to get the site up and running again. Eventually I ran a diff between the site backup
and the newly modified version, and found a new <tt>openidConsumerTrace.txt</tt> file
in the site root. I’ve never seen that one before; where'd it come from? A quick search
showed the following section in the <tt>web.config</tt> file:
</p>
        <div>
          <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">system.diagnostics</span>
            <span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">assert</span>
            <span style="color: #ff0000">assertuienabled</span>
            <span style="color: #0000ff">="false"</span>
            <span style="color: #0000ff">/&gt;</span>
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">switches</span>
            <span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">add</span>
            <span style="color: #ff0000">name</span>
            <span style="color: #0000ff">="OpenID"</span>
            <span style="color: #ff0000">value</span>
            <span style="color: #0000ff">="4"</span>
            <span style="color: #0000ff">/&gt;</span>
            <span style="color: #0000ff">&lt;/</span>
            <span style="color: #800000">switches</span>
            <span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">trace</span>
            <span style="color: #ff0000">autoflush</span>
            <span style="color: #0000ff">="true"</span>
            <span style="color: #ff0000">indentsize</span>
            <span style="color: #0000ff">="4"</span>
            <span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">listeners</span>
            <span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">add</span>
            <span style="color: #ff0000">name</span>
            <span style="color: #0000ff">="fileLogger"</span>
            <span style="color: #ff0000">type</span>
            <span style="color: #0000ff">="System.Diagnostics.TextWriterTraceListener"</span>
            <span style="color: #ff0000">initializeData</span>
            <span style="color: #0000ff">="openidConsumerTrace.txt"</span>
            <span style="color: #ff0000">traceOutputOptions</span>
            <span style="color: #0000ff">="None"</span>
            <span style="color: #0000ff">/&gt;</span>
            <span style="color: #0000ff">&lt;/</span>
            <span style="color: #800000">listeners</span>
            <span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;/</span>
            <span style="color: #800000">trace</span>
            <span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;/</span>
            <span style="color: #800000">system.diagnostics</span>
            <span style="color: #0000ff">&gt;</span>
          </pre>
        </div>
        <p>
A-ha! So the OpenID activity trace log is written to the virtual root, which is not
writable (I set the ACLs to only allow writes to the above three directories). I tried
changing the trace file path to <tt>~/logs/openidConsumerTrace.txt</tt> (which is
a virtual directory and has the appropriate write ACL), but this did not resolve the
problem. At this point I was ready to roll back to the previous version and work on
switching to another (perhaps hosted) blogging platform, and in my despair I simply
commented out the whole <tt>system.diagnostics section</tt>; oddly enough, this resolved
the problem…
</p>
        <p>
Now I know dasBlog is free and there’s little or no point complaining, so I hope this
post helps someone handle the problem. And if anyone from the dasBlog team is reading
this… please be a little more careful with undocumented dependencies?
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=4672705f-4f41-49e2-94b3-8ef57cf25536" />
      </body>
      <title>dasBlog 2.3 update woes: Dealing with SecurityException</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,4672705f-4f41-49e2-94b3-8ef57cf25536.aspx</guid>
      <link>http://www.tomergabel.com/dasBlog23UpdateWoesDealingWithSecurityException.aspx</link>
      <pubDate>Thu, 26 Mar 2009 13:32:08 GMT</pubDate>
      <description>&lt;p&gt;
It seems nothing to do with maintaining this website is as easy or as simple as it
should be. Whenever I switch hosts it’s an uphill struggle to get the site up and
running again; whenever I upgrade &lt;a href="http://www.dasblog.info/"&gt;dasBlog&lt;/a&gt; to
a newer version I have to learn a lot about how it works, how ASP.NET works, how IIS
is configured etc. It’s enough to make me seriously consider hosting my blog elsewhere
and/or moving to another blogging platform, but the truth is I love dasBlog so much
I simply forget how complex and volatile it can be and have to go through the same
frustrating process whenever something changes.
&lt;/p&gt;
&lt;p&gt;
The way I update my site is usually this:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Ensure I have an up-to-date local mirror of the website. dasBlog keeps all of its
data in XML files, so backing up the website is simply a question of &lt;tt&gt;&lt;a href="http://www.gnu.org/software/wget/"&gt;wget&lt;/a&gt; –-passive-ftp
–m ftp://user:password@website.com&lt;/tt&gt;; I have a daily scheduled task to take care
of this. 
&lt;li&gt;
Copy the latest mirrored version to a working directory; set the directory up as an
IIS website/virtual directory. 
&lt;li&gt;
Test the new working copy to make sure it works. 
&lt;li&gt;
Perform whatever modifications are required. 
&lt;li&gt;
Test again to make sure that the website works with multiple browsers (this time I
tested with &lt;a href="http://www.google.com/chrome"&gt;Chrome&lt;/a&gt; 2.0.170.0, &lt;a href="http://www.mozilla.com/firefox/"&gt;Firefox&lt;/a&gt; 3.1
Beta 3 and &lt;a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx"&gt;IE&lt;/a&gt; 8) 
&lt;li&gt;
Upload the website over FTP using the &lt;a href="http://filezilla-project.org/"&gt;FileZilla&lt;/a&gt; client.
I always verify that the relevant configuration files and binaries are overwritten
and nothing else.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
This process generally allows me to test upgrades before uploading them to the “production”
website, as well as provides an easy rollback path if something goes wrong. Thing
is, something &lt;em&gt;always&lt;/em&gt; goes wrong. In this case, although nothing’s changed
in the site configuration I started getting &lt;tt&gt;SecurityException&lt;/tt&gt;s just after
the upgrade:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;tt&gt;Request for the permission of type 'System.Security.Permissions.SecurityPermission,
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.&lt;/tt&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
This is one of the least informative error messages I have ever seen. All it tells
me is that a request for some permission is denied; it doesn’t say what permission
was requested, nor by whom (the stack trace seemed to indicate the permission was
asserted from within &lt;tt&gt;System.Diagnostics.Trace&lt;/tt&gt;, which doesn’t make much sense).
A quick web search brought me to &lt;a href="http://bencoffman.com/blog/CommentView,guid,06e3fffc-b763-434e-ba10-6c44939c90ed.aspx"&gt;this
page&lt;/a&gt;, which deals specifically with installing dasBlog on a &lt;a href="http://www.godaddy.com"&gt;GoDaddy&lt;/a&gt;-hosted
website. Because GoDaddy runs ASP.NET applications under a &lt;a href="http://help.godaddy.com/article/1039"&gt;modified
medium trust&lt;/a&gt; that allows file-system access only to the virtual directory hierarchy,
the site recommends adding a virtual directory for each of dasBlog’s writable directories
(content, siteconfig, logs); I tried this out and the problem was not resolved.
&lt;/p&gt;
&lt;p&gt;
At this point I was getting desperate, and was willing to try just about anything
to get the site up and running again. Eventually I ran a diff between the site backup
and the newly modified version, and found a new &lt;tt&gt;openidConsumerTrace.txt&lt;/tt&gt; file
in the site root. I’ve never seen that one before; where'd it come from? A quick search
showed the following section in the &lt;tt&gt;web.config&lt;/tt&gt; file:
&lt;/p&gt;
&lt;div&gt;&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;system.diagnostics&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;assert&lt;/span&gt; &lt;span style="color: #ff0000"&gt;assertuienabled&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="false"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;switches&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="OpenID"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="4"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;switches&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;trace&lt;/span&gt; &lt;span style="color: #ff0000"&gt;autoflush&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="true"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;indentsize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="4"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;listeners&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="fileLogger"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="System.Diagnostics.TextWriterTraceListener"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;initializeData&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="openidConsumerTrace.txt"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;traceOutputOptions&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="None"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;listeners&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;trace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;system.diagnostics&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
A-ha! So the OpenID activity trace log is written to the virtual root, which is not
writable (I set the ACLs to only allow writes to the above three directories). I tried
changing the trace file path to &lt;tt&gt;~/logs/openidConsumerTrace.txt&lt;/tt&gt; (which is
a virtual directory and has the appropriate write ACL), but this did not resolve the
problem. At this point I was ready to roll back to the previous version and work on
switching to another (perhaps hosted) blogging platform, and in my despair I simply
commented out the whole &lt;tt&gt;system.diagnostics section&lt;/tt&gt;; oddly enough, this resolved
the problem…
&lt;/p&gt;
&lt;p&gt;
Now I know dasBlog is free and there’s little or no point complaining, so I hope this
post helps someone handle the problem. And if anyone from the dasBlog team is reading
this… please be a little more careful with undocumented dependencies?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=4672705f-4f41-49e2-94b3-8ef57cf25536" /&gt;</description>
      <category>Development</category>
      <category>Software</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=1db72c20-3c25-42ad-93c4-b0551a0fed4e</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,1db72c20-3c25-42ad-93c4-b0551a0fed4e.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <u>Update</u> (8 May 2009): Eli Ofek pointed out in the comments a little-known but
effective tool called the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=80CF81F7-D710-47E3-8B95-5A6555A230C2&amp;displaylang=en">Managed
Stack Explorer</a>. Although it features a basic GUI, it can effectively be a .NET
equivalent of jstack if you add to the path; then it’s just a question of typing <tt>mse
/s /p <i>&lt;pid&gt;</i></tt>. It’s a little slower than jstack but <strong>worlds
better </strong>than the alternative suggested below.
</p>
        <p>
I’ve been working mostly with Java over the last year, and the .NET code I write is
usually limited to interface code between our .NET-based and Java-based components.
A long while away from production-grade code on Windows means I need to brush up on
my production debugging skills.
</p>
        <p>
On today’s menu: thread dumps, or per-thread stack traces if you will. With Java code
(at least starting with Java 5) this is as easy as <tt>jstack <i>&lt;pid&gt;</i></tt>;
with .NET it turns out to be quite a bit more complicated:
</p>
        <ol>
          <li>
Download and install the appropriate <a href="http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx">Debugging
Tools for Windows</a> version for your architecture (x86/x64/Itanium) 
</li>
          <li>
If you need information about Windows function calls (e.g. you want to trace into
kernel calls), download and install the appropriate <a href="http://www.microsoft.com/whdc/DevTools/Debugging/symbolpkg.mspx">symbols</a>.
This isn't strictly necessary if you just want a thread dump of your own code. 
</li>
          <li>
If you need line numbers or any other detailed information, make sure to place your
assemblies' PDB files where the debugger can find them (normally you just put them
next to your actual assemblies). 
</li>
          <li>
Start-&gt;Programs-&gt;Debugging Tools for Windows [x64]-&gt;windbg 
</li>
          <li>
Attach the debugger to your running process using the menu 
</li>
          <li>
Load the SOS extension with "<tt>.loadby sos mscorwks</tt>" for .NET 2.0 ("<tt>.load
sos</tt>" for .NET 1.0/1.1) 
</li>
          <li>
Take a thread dump using "<tt>!eestack</tt>" 
</li>
          <li>
Detach using "<tt>.detach</tt>"</li>
        </ol>
        <p>
Quite a bit of work for something as trivial as a thread dump. I hope .NET diagnostic
and debugging tools improve with time (Process Explorer is definitely a step in the
right direction).
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=1db72c20-3c25-42ad-93c4-b0551a0fed4e" />
      </body>
      <title>.NET production debugging 101</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,1db72c20-3c25-42ad-93c4-b0551a0fed4e.aspx</guid>
      <link>http://www.tomergabel.com/NETProductionDebugging101.aspx</link>
      <pubDate>Thu, 19 Mar 2009 15:16:24 GMT</pubDate>
      <description>&lt;p&gt;
&lt;u&gt;Update&lt;/u&gt; (8 May 2009): Eli Ofek pointed out in the comments a little-known but
effective tool called the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=80CF81F7-D710-47E3-8B95-5A6555A230C2&amp;amp;displaylang=en"&gt;Managed
Stack Explorer&lt;/a&gt;. Although it features a basic GUI, it can effectively be a .NET
equivalent of jstack if you add to the path; then it’s just a question of typing &lt;tt&gt;mse
/s /p &lt;i&gt;&amp;lt;pid&amp;gt;&lt;/i&gt;&lt;/tt&gt;. It’s a little slower than jstack but &lt;strong&gt;worlds
better &lt;/strong&gt;than the alternative suggested below.
&lt;/p&gt;
&lt;p&gt;
I’ve been working mostly with Java over the last year, and the .NET code I write is
usually limited to interface code between our .NET-based and Java-based components.
A long while away from production-grade code on Windows means I need to brush up on
my production debugging skills.
&lt;/p&gt;
&lt;p&gt;
On today’s menu: thread dumps, or per-thread stack traces if you will. With Java code
(at least starting with Java 5) this is as easy as &lt;tt&gt;jstack &lt;i&gt;&amp;lt;pid&amp;gt;&lt;/i&gt;&lt;/tt&gt;;
with .NET it turns out to be quite a bit more complicated:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Download and install the appropriate &lt;a href="http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx"&gt;Debugging
Tools for Windows&lt;/a&gt; version for your architecture (x86/x64/Itanium) 
&lt;li&gt;
If you need information about Windows function calls (e.g. you want to trace into
kernel calls), download and install the appropriate &lt;a href="http://www.microsoft.com/whdc/DevTools/Debugging/symbolpkg.mspx"&gt;symbols&lt;/a&gt;.
This isn't strictly necessary if you just want a thread dump of your own code. 
&lt;li&gt;
If you need line numbers or any other detailed information, make sure to place your
assemblies' PDB files where the debugger can find them (normally you just put them
next to your actual assemblies). 
&lt;li&gt;
Start-&amp;gt;Programs-&amp;gt;Debugging Tools for Windows [x64]-&amp;gt;windbg 
&lt;li&gt;
Attach the debugger to your running process using the menu 
&lt;li&gt;
Load the SOS extension with "&lt;tt&gt;.loadby sos mscorwks&lt;/tt&gt;" for .NET 2.0 ("&lt;tt&gt;.load
sos&lt;/tt&gt;" for .NET 1.0/1.1) 
&lt;li&gt;
Take a thread dump using "&lt;tt&gt;!eestack&lt;/tt&gt;" 
&lt;li&gt;
Detach using "&lt;tt&gt;.detach&lt;/tt&gt;"&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Quite a bit of work for something as trivial as a thread dump. I hope .NET diagnostic
and debugging tools improve with time (Process Explorer is definitely a step in the
right direction).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=1db72c20-3c25-42ad-93c4-b0551a0fed4e" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=918cc1bd-e8bb-4952-a4e8-f7c06280c577</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,918cc1bd-e8bb-4952-a4e8-f7c06280c577.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p align="center">
          <a href="http://www.tomergabel.com/content/binary/WindowsLiveWriter/Andisntitironic_9F28/highscal_irony_2.png">
            <img title="highscal_irony" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="346" alt="highscal_irony" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/Andisntitironic_9F28/highscal_irony_thumb.png" width="504" border="0" />
          </a>
        </p>
        <p>
Don’t ya think?
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=918cc1bd-e8bb-4952-a4e8-f7c06280c577" />
      </body>
      <title>And isn&amp;rsquo;t it ironic</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,918cc1bd-e8bb-4952-a4e8-f7c06280c577.aspx</guid>
      <link>http://www.tomergabel.com/AndIsnrsquotItIronic.aspx</link>
      <pubDate>Sun, 15 Mar 2009 09:19:18 GMT</pubDate>
      <description>&lt;p align="center"&gt;
&lt;a href="http://www.tomergabel.com/content/binary/WindowsLiveWriter/Andisntitironic_9F28/highscal_irony_2.png"&gt;&lt;img title="highscal_irony" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="346" alt="highscal_irony" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/Andisntitironic_9F28/highscal_irony_thumb.png" width="504" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Don’t ya think?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=918cc1bd-e8bb-4952-a4e8-f7c06280c577" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=994db352-2cac-413d-938f-4449a4e5b082</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,994db352-2cac-413d-938f-4449a4e5b082.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was making modifications to one of our components, and running all of the unit tests
revealed that <em>all</em> database-dependant integration tests were failing:
</p>
        <blockquote>
          <tt>
            <p>
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
</p>
            <p>
Last packet sent to the server was 0 ms ago.<br />
&lt;snip&gt; (cut for brevity’s sake)<br />
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)<br />
at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:729)<br />
at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:46)
</p>
          </tt>
        </blockquote>
        <p>
Strange error message, but as it turns out the inner exception was far more revealing:
</p>
        <blockquote>
          <p>
            <tt>java.net.ConnectException: Connection refused: connect</tt>
          </p>
        </blockquote>
        <p>
As can be expected, the local MySQL server was up and running, and I was able to connect
with the command line tool as well as with <a href="http://www.webyog.com/">SQLYog</a>,
so it was obviously not a problem with MySQL or the local firewall. Next up I tried
to telnet to the appropriate port (the easiest way I know to check port-level connectivity)
without success:
</p>
        <p>
          <a href="http://www.tomergabel.com/content/binary/WindowsLiveWriter/IPv6andlocalhostonWindows_B796/ipconflict_noconnect_2.png">
            <img title="Can't connect to localhost" style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" height="255" alt="Can't connect to localhost" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/IPv6andlocalhostonWindows_B796/ipconflict_noconnect_thumb.png" width="504" border="0" />
          </a>
        </p>
        <p>
I next tried to connect to the loopback IP (<tt>127.0.0.1</tt>), and experienced a
major WTF moment when the connection succeeded. I <a href="http://www.tomergabel.com/DevelopingOnWindowsServer2008.aspx">use
Windows Server 2008</a> and, as it turns out, it supports IPv6 out of the box. <tt>localhost</tt> has
a slightly different meaning under IPv6 (it maps to <tt>::1</tt>), and as I understand
it traditional IPv4 traffic is tunneled over the looback IPv6 connection; I’m not
yet familiar enough with IPv6 to draw any conclusions on why the above shouldn’t work,
but the bottom line is there are several ways of resolving the problem:
</p>
        <ol>
          <li>
Edit your <tt>hosts</tt> file (it’s hidden under Windows Server 2008, but you should
be able to Start-&gt;Run-&gt;notepad %SYSTEMROOT%\System32\Drivers\etc\hosts) and
change the mapping for localhost from “<tt>::1 localhost</tt>” to “<tt>127.0.0.1 localhost</tt>”.
This does resolve the problem, although I can’t say what impact this will have on
IPv6-enabled applications. 
</li>
          <li>
Set the TCP stack to prefer IPv4 to IPv6 when attempting to connect (it’s the reverse
by default). According to <a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/36f57ccf-7a76-4843-84bd-7bb945aad23f/">this
forum post</a>, this entails setting the registry value <tt>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters\DisabledComponents</tt> to
the DWORD value <tt>0x20</tt>. 
</li>
          <li>
Disable IPv6 altogether for your network connection: remove the IPv6 protocol from
your network connection component list. At this point in time IPv6 is still very rare
so I doubt this will cause any significant issues, but YMMV.</li>
        </ol>
        <p>
For me, changing the <tt>hosts</tt> file was the quickest solution because it works
and is easy to revert. I’ll have to keep a very careful eye on the behavior of my
machine though.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=994db352-2cac-413d-938f-4449a4e5b082" />
      </body>
      <title>IPv6 and localhost on Windows</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,994db352-2cac-413d-938f-4449a4e5b082.aspx</guid>
      <link>http://www.tomergabel.com/IPv6AndLocalhostOnWindows.aspx</link>
      <pubDate>Wed, 11 Mar 2009 11:02:08 GMT</pubDate>
      <description>&lt;p&gt;
I was making modifications to one of our components, and running all of the unit tests
revealed that &lt;em&gt;all&lt;/em&gt; database-dependant integration tests were failing:
&lt;/p&gt;
&lt;blockquote&gt;&lt;tt&gt; 
&lt;p&gt;
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
&lt;/p&gt;
&lt;p&gt;
Last packet sent to the server was 0 ms ago.&lt;br&gt;
&amp;lt;snip&amp;gt; (cut for brevity’s sake)&lt;br&gt;
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)&lt;br&gt;
at com.mysql.jdbc.ConnectionImpl.&amp;lt;init&amp;gt;(ConnectionImpl.java:729)&lt;br&gt;
at com.mysql.jdbc.JDBC4Connection.&amp;lt;init&amp;gt;(JDBC4Connection.java:46)
&lt;/p&gt;
&lt;/tt&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Strange error message, but as it turns out the inner exception was far more revealing:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;tt&gt;java.net.ConnectException: Connection refused: connect&lt;/tt&gt; 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
As can be expected, the local MySQL server was up and running, and I was able to connect
with the command line tool as well as with &lt;a href="http://www.webyog.com/"&gt;SQLYog&lt;/a&gt;,
so it was obviously not a problem with MySQL or the local firewall. Next up I tried
to telnet to the appropriate port (the easiest way I know to check port-level connectivity)
without success:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.tomergabel.com/content/binary/WindowsLiveWriter/IPv6andlocalhostonWindows_B796/ipconflict_noconnect_2.png"&gt;&lt;img title="Can't connect to localhost" style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" height="255" alt="Can't connect to localhost" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/IPv6andlocalhostonWindows_B796/ipconflict_noconnect_thumb.png" width="504" border="0"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
I next tried to connect to the loopback IP (&lt;tt&gt;127.0.0.1&lt;/tt&gt;), and experienced a
major WTF moment when the connection succeeded. I &lt;a href="http://www.tomergabel.com/DevelopingOnWindowsServer2008.aspx"&gt;use
Windows Server 2008&lt;/a&gt; and, as it turns out, it supports IPv6 out of the box. &lt;tt&gt;localhost&lt;/tt&gt; has
a slightly different meaning under IPv6 (it maps to &lt;tt&gt;::1&lt;/tt&gt;), and as I understand
it traditional IPv4 traffic is tunneled over the looback IPv6 connection; I’m not
yet familiar enough with IPv6 to draw any conclusions on why the above shouldn’t work,
but the bottom line is there are several ways of resolving the problem:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Edit your &lt;tt&gt;hosts&lt;/tt&gt; file (it’s hidden under Windows Server 2008, but you should
be able to Start-&amp;gt;Run-&amp;gt;notepad %SYSTEMROOT%\System32\Drivers\etc\hosts) and
change the mapping for localhost from “&lt;tt&gt;::1 localhost&lt;/tt&gt;” to “&lt;tt&gt;127.0.0.1 localhost&lt;/tt&gt;”.
This does resolve the problem, although I can’t say what impact this will have on
IPv6-enabled applications. 
&lt;li&gt;
Set the TCP stack to prefer IPv4 to IPv6 when attempting to connect (it’s the reverse
by default). According to &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/36f57ccf-7a76-4843-84bd-7bb945aad23f/"&gt;this
forum post&lt;/a&gt;, this entails setting the registry value &lt;tt&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters\DisabledComponents&lt;/tt&gt; to
the DWORD value &lt;tt&gt;0x20&lt;/tt&gt;. 
&lt;li&gt;
Disable IPv6 altogether for your network connection: remove the IPv6 protocol from
your network connection component list. At this point in time IPv6 is still very rare
so I doubt this will cause any significant issues, but YMMV.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
For me, changing the &lt;tt&gt;hosts&lt;/tt&gt; file was the quickest solution because it works
and is easy to revert. I’ll have to keep a very careful eye on the behavior of my
machine though.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=994db352-2cac-413d-938f-4449a4e5b082" /&gt;</description>
      <category>Development</category>
      <category>Software</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=b0897826-14a8-4bff-8475-00e61d62a06b</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,b0897826-14a8-4bff-8475-00e61d62a06b.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you've ever tried to develop using PHP on IIS7 (Vista), you'll find that errors
in your script result in the default IIS7 "friendly" HTTP 500 error page, which is
useless for debugging. This happens in both FastCGI and ISAPI modes.
</p>
        <p>
To save you hours of crawling through the 'net, the solution (found on <a href="http://www.phwinfo.com/forum/1342724-post4.html">this
forum post</a>) is very simple:
</p>
        <ul>
          <li>
Start a command prompt; 
</li>
          <li>
Copy-paste the following: <tt>%windir%\system32\inetsrv\appcmd.exe set config -Section:system.webServer/httpErrors
-errorMode:Detailed</tt></li>
          <li>
Run <tt>iireset</tt></li>
          <li>
Enjoy.</li>
        </ul>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b0897826-14a8-4bff-8475-00e61d62a06b" />
      </body>
      <title>Getting decent PHP errors with IIS7</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,b0897826-14a8-4bff-8475-00e61d62a06b.aspx</guid>
      <link>http://www.tomergabel.com/GettingDecentPHPErrorsWithIIS7.aspx</link>
      <pubDate>Mon, 02 Feb 2009 17:58:44 GMT</pubDate>
      <description>&lt;p&gt;
If you've ever tried to develop using PHP on IIS7 (Vista), you'll find that errors
in your script result in the default IIS7 "friendly" HTTP 500 error page, which is
useless for debugging. This happens in both FastCGI and ISAPI modes.
&lt;/p&gt;
&lt;p&gt;
To save you hours of crawling through the 'net, the solution (found on &lt;a href="http://www.phwinfo.com/forum/1342724-post4.html"&gt;this
forum post&lt;/a&gt;) is very simple:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Start a command prompt; 
&lt;li&gt;
Copy-paste the following: &lt;tt&gt;%windir%\system32\inetsrv\appcmd.exe set config -Section:system.webServer/httpErrors
-errorMode:Detailed&lt;/tt&gt; 
&lt;li&gt;
Run &lt;tt&gt;iireset&lt;/tt&gt; 
&lt;li&gt;
Enjoy.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b0897826-14a8-4bff-8475-00e61d62a06b" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=56f230f3-e6a0-4f0c-b3f8-e9cb80bdf995</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,56f230f3-e6a0-4f0c-b3f8-e9cb80bdf995.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <u>Update</u>: I was wrong, and private setters do not appear to work (strange, I’m
sure I verified this in my test code, but it didn’t work in practice). See below.
</p>
        <p>
It’s been ages since I used <tt>XmlSerializer</tt>, or even written meaningful amounts
of code in C# for that matter, which is why I was utterly stumped by this problem.
Try running this code:
</p>
        <blockquote>
          <pre class="code">[<span style="color: #2b91af">XmlRoot</span>( <span style="color: #a31515">"test" </span>)] <span style="color: blue">public
class </span><span style="color: #2b91af">Test </span>{ <span style="color: blue">private
readonly string </span>_string1; <span style="color: blue">private readonly string </span>_string2; <span style="color: blue">public </span>Test( <span style="color: blue">string </span>string1, <span style="color: blue">string </span>string2
) { _string1 = string1; _string2 = string2; } [<span style="color: #2b91af">XmlAttribute</span>( <span style="color: #a31515">"attr" </span>)] <span style="color: blue">public
string </span>String1 { <span style="color: blue">get </span>{ <span style="color: blue">return </span>_string1;
} } [<span style="color: #2b91af">XmlElement</span>( <span style="color: #a31515">"element" </span>)] <span style="color: blue">public
string </span>String2 { <span style="color: blue">get </span>{ <span style="color: blue">return </span>_string2;
} } }<br /><span style="color: gray">/// </span><span style="color: green">... </span><span style="color: #2b91af">XmlSerializer </span>xs
= <span style="color: blue">new </span><span style="color: #2b91af">XmlSerializer</span>( <span style="color: blue">typeof</span>( <span style="color: #2b91af">Test </span>), <span style="color: #a31515">"" </span>); <span style="color: #2b91af">XmlSerializerNamespaces </span>xsn
= <span style="color: blue">new </span><span style="color: #2b91af">XmlSerializerNamespaces</span>();
xsn.Add(<span style="color: #a31515">""</span>, <span style="color: #a31515">""</span>); <span style="color: green">//
Gets rid of redundant xmlns: attributes </span><span style="color: #2b91af">StringWriter </span>pw
= <span style="color: blue">new </span><span style="color: #2b91af">StringWriter</span>();
xs.Serialize( pw, <span style="color: blue">new </span><span style="color: #2b91af">Test</span>( <span style="color: #a31515">"1"</span>, <span style="color: #a31515">"2" </span>),
xsn ); <span style="color: #2b91af">Console</span>.WriteLine( pw.GetStringBuilder().ToString()
);</pre>
        </blockquote>
        <div>You’ll get an <tt>InvalidOperationException</tt> stating that “Test cannot be
serialized because it does not have a parameterless constructor.” A quick look at
the documentation (or a search which may lead you to <a href="http://stackoverflow.com/questions/267724/why-serializable-class-need-a-parameterless-constructor">this
post</a> on StackOverflow) will get you the answer: add a parameterless constructor
and mark it <tt>private</tt>. Run the test code again and this time no exception will
be thrown; however, you probably won’t be expecting this result:
</div>
        <blockquote>
          <div>
            <pre>
              <span style="color: #0000ff">&lt;?</span>
              <span style="color: #800000">xml</span>
              <span style="color: #ff0000">version</span>
              <span style="color: #0000ff">="1.0"</span>
              <span style="color: #ff0000">encoding</span>
              <span style="color: #0000ff">="utf-16"</span>?<span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">test</span><span style="color: #0000ff">/&gt;</span></pre>
          </div>
        </blockquote>
        <p>
The solution? Add a setter to each of your serializable properties. Don’t need a setter
because the class is immutable? <strike>Mark it as <tt>private</tt> and you’re good
to go.</strike> Tough – you’re going to need one anyway, <tt>private</tt>/<tt>internal</tt>/<tt>protected</tt> setters
don’t appear to work. If you must use <tt>XmlSerializer</tt> you should throw a <tt>NotImplementedException</tt> from
these setters, but in my opinion the resulting contract clutter implies you should
simply avoid <tt>XmlSerializer</tt> altogether.
</p>
        <p>
Although this behavior makes sense in light of how <tt>XmlSerializer</tt> can be used
for both serialization and de-serialization, what threw me off was that no exception
is thrown – the contract doesn’t require a setter property, and the serializer output
is corrupt. Beware!
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=56f230f3-e6a0-4f0c-b3f8-e9cb80bdf995" />
      </body>
      <title>XmlSerializer Voodoo</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,56f230f3-e6a0-4f0c-b3f8-e9cb80bdf995.aspx</guid>
      <link>http://www.tomergabel.com/XmlSerializerVoodoo.aspx</link>
      <pubDate>Sun, 18 Jan 2009 15:03:06 GMT</pubDate>
      <description>&lt;p&gt;
&lt;u&gt;Update&lt;/u&gt;: I was wrong, and private setters do not appear to work (strange, I’m
sure I verified this in my test code, but it didn’t work in practice). See below.
&lt;/p&gt;
&lt;p&gt;
It’s been ages since I used &lt;tt&gt;XmlSerializer&lt;/tt&gt;, or even written meaningful amounts
of code in C# for that matter, which is why I was utterly stumped by this problem.
Try running this code:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;XmlRoot&lt;/span&gt;( &lt;span style="color: #a31515"&gt;"test" &lt;/span&gt;)] &lt;span style="color: blue"&gt;public
class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Test &lt;/span&gt;{ &lt;span style="color: blue"&gt;private
readonly string &lt;/span&gt;_string1; &lt;span style="color: blue"&gt;private readonly string &lt;/span&gt;_string2; &lt;span style="color: blue"&gt;public &lt;/span&gt;Test( &lt;span style="color: blue"&gt;string &lt;/span&gt;string1, &lt;span style="color: blue"&gt;string &lt;/span&gt;string2
) { _string1 = string1; _string2 = string2; } [&lt;span style="color: #2b91af"&gt;XmlAttribute&lt;/span&gt;( &lt;span style="color: #a31515"&gt;"attr" &lt;/span&gt;)] &lt;span style="color: blue"&gt;public
string &lt;/span&gt;String1 { &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;_string1;
} } [&lt;span style="color: #2b91af"&gt;XmlElement&lt;/span&gt;( &lt;span style="color: #a31515"&gt;"element" &lt;/span&gt;)] &lt;span style="color: blue"&gt;public
string &lt;/span&gt;String2 { &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;_string2;
} } }&lt;br&gt;
&lt;span style="color: gray"&gt;/// &lt;/span&gt;&lt;span style="color: green"&gt;... &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlSerializer &lt;/span&gt;xs
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlSerializer&lt;/span&gt;( &lt;span style="color: blue"&gt;typeof&lt;/span&gt;( &lt;span style="color: #2b91af"&gt;Test &lt;/span&gt;), &lt;span style="color: #a31515"&gt;"" &lt;/span&gt;); &lt;span style="color: #2b91af"&gt;XmlSerializerNamespaces &lt;/span&gt;xsn
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlSerializerNamespaces&lt;/span&gt;();
xsn.Add(&lt;span style="color: #a31515"&gt;""&lt;/span&gt;, &lt;span style="color: #a31515"&gt;""&lt;/span&gt;); &lt;span style="color: green"&gt;//
Gets rid of redundant xmlns: attributes &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringWriter &lt;/span&gt;pw
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringWriter&lt;/span&gt;();
xs.Serialize( pw, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Test&lt;/span&gt;( &lt;span style="color: #a31515"&gt;"1"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"2" &lt;/span&gt;),
xsn ); &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine( pw.GetStringBuilder().ToString()
);&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;div&gt;You’ll get an &lt;tt&gt;InvalidOperationException&lt;/tt&gt; stating that “Test cannot be
serialized because it does not have a parameterless constructor.” A quick look at
the documentation (or a search which may lead you to &lt;a href="http://stackoverflow.com/questions/267724/why-serializable-class-need-a-parameterless-constructor"&gt;this
post&lt;/a&gt; on StackOverflow) will get you the answer: add a parameterless constructor
and mark it &lt;tt&gt;private&lt;/tt&gt;. Run the test code again and this time no exception will
be thrown; however, you probably won’t be expecting this result:
&lt;/div&gt;
&lt;blockquote&gt; 
&lt;div&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="1.0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="utf-16"&lt;/span&gt;?&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;test&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The solution? Add a setter to each of your serializable properties. Don’t need a setter
because the class is immutable? &lt;strike&gt;Mark it as &lt;tt&gt;private&lt;/tt&gt; and you’re good
to go.&lt;/strike&gt; Tough – you’re going to need one anyway, &lt;tt&gt;private&lt;/tt&gt;/&lt;tt&gt;internal&lt;/tt&gt;/&lt;tt&gt;protected&lt;/tt&gt; setters
don’t appear to work. If you must use &lt;tt&gt;XmlSerializer&lt;/tt&gt; you should throw a &lt;tt&gt;NotImplementedException&lt;/tt&gt; from
these setters, but in my opinion the resulting contract clutter implies you should
simply avoid &lt;tt&gt;XmlSerializer&lt;/tt&gt; altogether.
&lt;/p&gt;
&lt;p&gt;
Although this behavior makes sense in light of how &lt;tt&gt;XmlSerializer&lt;/tt&gt; can be used
for both serialization and de-serialization, what threw me off was that no exception
is thrown – the contract doesn’t require a setter property, and the serializer output
is corrupt. Beware!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=56f230f3-e6a0-4f0c-b3f8-e9cb80bdf995" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=8780ca97-eed3-49de-a307-ed8b493b4893</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,8780ca97-eed3-49de-a307-ed8b493b4893.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <span class="Apple-style-span" style="word-spacing: 0px; font: 14px/18px arial; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: collapse; text-align: left; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0">
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
(Cross-posted on <a href="http://stackoverflow.com/questions/56555/what-are-your-essential-phone-screen-questions#74882">Stack
Overflow</a>)
</p>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
            <u>Update (17-Sep-08)</u>: Corrected the answer to an integer arithmetic question
("rotate to the right" was obviously incorrect - I was careless when I wrote this.
Thanks, Kuperstein!) and some formatting adjustments.
</p>
          <h3>Preparation
</h3>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
I never interview the applicant on the first phone call. This doesn't give me the
time to go over the candidate's CV and consider if there are points I'd like to bring
up on the interview, such as specific work experience or glaringly missing skills.
Additionally, setting up a specific time for the phone interview allows the candidate
time to mentally prepare, drink a coffee and settle down in a quiet spot somewhere.
Just puts everyone at their ease.
</p>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
When first calling the candidate I always take the time to introduce the company I
work for, a synopsis of what we do and a general description of how the company operates.
I then proceed to inquire if the applicant sees this as a potentially interesting
place to work in and whether or not they have any questions; you'd be surprised at
the time this can save, for example it's not always obvious whether or not the applicant
is interested in working for a start-up company, or alternatively may not find the
problem domain engaging.
</p>
          <h3>Getting to Know The Candidate
</h3>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
To start the interview off, I usually skim over the candidate's CV and select two
or three interesting projects that the candidate was involved in. I ask the candidates
to describe their involvement (sometimes, but not often, going into a bit of detail
if the domain is familiar to me), their specific contribution to the project, whether
or not they had fun and why. This usually gives me a sense of what the candidates
are looking for; are they heavily into design? Are they enthusiastic about a specific
technology, and if so, do they have a sound reason for it? Were they frustrated by
administrative issues, did they try to improve their working environment?
</p>
          <h3 style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: bold; border-left-width: 0px; font-size: 110%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 5px; vertical-align: baseline; padding-top: 0px; font-family: 'Trebuchet MS', helvetica, sans-serif; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">Technical
Questions
</h3>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
Once those formalities and niceties are out of the way, I turn to my ever-growing
collection of interview questions and select a small subset to present to the candidate.
For example, a typical interview may include the following questions:
</p>
          <p>
            <u>Integer Arithmetic</u>
          </p>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
Does the candidate have a decent grasp of bits and bytes? I consider this a must-have;
a candidate that fails this part has no chance in hell of tackling even the most trivial
native code.
</p>
          <ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"Take an integer. How do you turn the 7th least significant bit off?" This question
alone removes about half of the applicants from the equation. Some people tell you
"you need to apply bitwise AND, but I can't remember the number you need to AND with"
-- this isn't what you're looking for. A good answer would be something like "x &amp;=
~(1 &lt;&lt; 6)". 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"How would you quickly divide an integer by eight (8)?" A good answer is, you shift
right by three. A better answer would be "is the integer signed or unsigned?", with
a bonus for Java developers who know the difference between &gt;&gt; and &gt;&gt;&gt;.</li>
          </ul>
          <p>
            <u>Pointers and Pointer Arithmetic</u>
          </p>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
This really depends on what your company does. Most developers today don't need to
know in practice the particulars of pointers and pointer arithmetic optimizations,
but if you're developing a highly scalable system and/or one with serious performance
considerations, this is a very good measure of how likely the candidate will be able
to tackle such challenges.
</p>
          <ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"How big is a pointer?" The only correct answer is, "depends on the architecture".
32-bit operating systems will have 32-bit pointers, 64-bit systems will have 64-bit
pointers. Anything that doesn't fall into these two categories is not relevant for
my purposes, and likely yours as well. If the candidate fails this question I usually
mark this section as "failed" and move on.</li>
          </ul>
          <p>
            <u>Floating Point Numbers</u>
          </p>
          <ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"What is NaN?" A programmer who can't answer this question has never really worked
with floating point numbers. 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"How are floating point numbers represented in a typical modern architecture?" Failing
this question is not a deal-breaker, but answering it correctly will score the candidate
a lot of points. "sign, exponent, mantissa/fraction/significand" is a sufficient answer.</li>
          </ul>
          <p>
            <u>Essential Data Structures and Algorithms</u>
          </p>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
This is the bread-and-butter of programming. A candidate should exhibit robust familiarity
with commonplace data structures (hashtables, linked lists, trees etc.) and algorithms
(sorting, graph traversal).
</p>
          <ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"Describe how quicksort works. Elaborate on its performance characteristics." Any
professional developer should be able to explain quicksort in a few minutes, know
its average- and worst-case complexity, and recognize pathological cases (typical
school-level quicksort implementations exhibit horrible performance on pre-sorted
data). 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"How are hashtables commonly implemented?" A candidate should be able to describe
the concept of a hashing function (uniform distribution) and how it relates to the
internal data structure (normally an array of buckets). 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"What backing data structure would you choose for a simple text editor?" The classic
answer is a<a style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; cursor: pointer; color: rgb(74,107,130); padding-top: 0px; background-color: transparent; border-right-width: 0px; text-decoration: none; -webkit-background-clip: initial; -webkit-background-origin: initial" href="http://en.wikipedia.org/wiki/Rope_(computer_science)" rel="nofollow"><font face="Arial">rope</font></a>,
but it's unlikely that a candidate will be familiar with this data structure. A more
likely response would be a "linked-list of strings", in which case you should ask
about the complexity of various editing operations (deleting a line, inserting a line,
deleting a character etc.) This question typically takes slightly longer to answer
but I've found that it gives me a good measure of the candidate's intuition in choosing/analyzing
data representations.</li>
          </ul>
          <p>
            <u>Threading and Sychronization</u>
          </p>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
This is fast becoming the most important subject with which to distinguish the truly
brilliant candidates from the merely competent; the ubiquity of multithreaded code
nowadays also means that these questions can be used to quickly weed out the unworthy
candidates.
</p>
          <ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"Describe one common way of synchronizing access to a shared resource." This is just
a starter question, and if the candidate takes more than a few seconds to come up
with an answer (mutex, semaphore, monitor or "synchronized" for Java developers, "lock"
for C# developers) it's usually a good sign that they don't have any reasonable experience
with multithreaded development. 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"You have a shared cache with a very good hit ratio. How would you synchronize access
to the cache with as little performance overhead as possible?" The answer is trivially
a read-write lock which can accomodate multiple readers and a single, exclusive writer.
Where appropriate, ask how the candidate would implement such a lock. 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"Describe a nontrivial problem that you've had with threaded code." Responses usually
fall into one of three categories: either (1) a reasonably experienced multithreaded
developer would never make the same mistakes, in which case the candidate obviously
isn't one; (2) a classic race-condition/deadlock/etc. scenario, which merely tells
you that the candidate has some experience with multithreaded code and appears capable
of tackling such challenges; or (3) rarely, a candidate may have a genuinely interesting
"war story," in which case you'll probably want to hire them right away.</li>
          </ul>
          <p>
            <u>Peripheral Technologies</u>
          </p>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
Approach this section with caution. A canditate that's familiar with a great deal
of today's hot technologies may prove completely incompetent, whereas it's quite possible
to find brilliant programmers that have never touched COM in their lives. I still
like to get a sense of how "in touch" the developer is with contemporary technologies;
familiarity with tools and technologies can definitely be a tie-breaker between two
promising candidates.
</p>
          <ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"Are you familiar with COM? Describe an interface which any COM object must implement
and its methods." Anyone who's even a bit familiar with Windows software development
should be able to answer this question fully. For those unfamiliar with COM, describe
it in a few words and ask the canditate to guess what the required methods of IUnknown
are. 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"What is a well-formed XML file? Give two examples of errors in an XML file which
would render it non-well-formed." XML is prevalent in almost every software development
domain. A candidate which cannot answer these questions (and doesn't have a very good
excuse) will not go past this interview. 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"What's XPath? Explain what a predicate is and how it's used." This is not most-have.
I'd expect serious developers to at least have an idea of what XPath is. The second
question is there to differentiate those who profess to know XPath from those who've
actually done work with XPath and/or XSLT. 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
"If you had to verify the input of an e-mail address field, how would you go about
it?" There are only two valid answers to this question: "I would use a regular expression,"
or "I'd like to use a regular expression, but I know that fully matching e-mails according
to the RFC is insanely complex, which is why I'd get a proven library to do it for
me." If the canditate is being a smart-ass you can always ask them about the performance
characteristics of commonplace regex engines (which have<span class="Apple-converted-space"> </span><a style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; cursor: pointer; color: rgb(74,107,130); padding-top: 0px; background-color: transparent; border-right-width: 0px; text-decoration: none; -webkit-background-clip: initial; -webkit-background-origin: initial" href="http://swtch.com/~rsc/regexp/regexp1.html" rel="nofollow"><font face="Arial">pathological
cases</font></a>). 
</li>
            <li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
I also like to just toss buzzwords (Ruby, Boo, JSON, Struts, J2EE, WCF) around and
examine the candidate's responses. It may also provide an interesting subject to ask
about in a personal interview later on.</li>
          </ul>
          <h3 style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: bold; border-left-width: 0px; font-size: 110%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 5px; vertical-align: baseline; padding-top: 0px; font-family: 'Trebuchet MS', helvetica, sans-serif; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">Concluding
the Interview
</h3>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
The previous section usually takes between 10 and 15 minutes. At this point I normally
ask the candidate if there are any questions they'd like answered, or anything I should
know before we conclude the interview. Once that'd done, I thank them for their time
and tell them (even if they've failed miserably) that I will call them back in a day
or two with an answer.
</p>
          <p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial">
Hope this helps, comments are welcome.
</p>
        </span>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=8780ca97-eed3-49de-a307-ed8b493b4893" />
      </body>
      <title>Conducting A Phone Interview</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,8780ca97-eed3-49de-a307-ed8b493b4893.aspx</guid>
      <link>http://www.tomergabel.com/ConductingAPhoneInterview.aspx</link>
      <pubDate>Tue, 16 Sep 2008 17:39:11 GMT</pubDate>
      <description>&lt;span class="Apple-style-span" style="word-spacing: 0px; font: 14px/18px arial; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: collapse; text-align: left; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0"&gt; 
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
(Cross-posted on &lt;a href="http://stackoverflow.com/questions/56555/what-are-your-essential-phone-screen-questions#74882"&gt;Stack
Overflow&lt;/a&gt;)
&lt;/p&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
&lt;u&gt;Update (17-Sep-08)&lt;/u&gt;: Corrected the answer to an integer arithmetic question
("rotate to the right" was obviously incorrect - I was careless when I wrote this.
Thanks, Kuperstein!) and some formatting adjustments.
&lt;/p&gt;
&lt;h3&gt;Preparation
&lt;/h3&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
I never interview the applicant on the first phone call. This doesn't give me the
time to go over the candidate's CV and consider if there are points I'd like to bring
up on the interview, such as specific work experience or glaringly missing skills.
Additionally, setting up a specific time for the phone interview allows the candidate
time to mentally prepare, drink a coffee and settle down in a quiet spot somewhere.
Just puts everyone at their ease.
&lt;/p&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
When first calling the candidate I always take the time to introduce the company I
work for, a synopsis of what we do and a general description of how the company operates.
I then proceed to inquire if the applicant sees this as a potentially interesting
place to work in and whether or not they have any questions; you'd be surprised at
the time this can save, for example it's not always obvious whether or not the applicant
is interested in working for a start-up company, or alternatively may not find the
problem domain engaging.
&lt;/p&gt;
&lt;h3&gt;Getting to Know The Candidate
&lt;/h3&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
To start the interview off, I usually skim over the candidate's CV and select two
or three interesting projects that the candidate was involved in. I ask the candidates
to describe their involvement (sometimes, but not often, going into a bit of detail
if the domain is familiar to me), their specific contribution to the project, whether
or not they had fun and why. This usually gives me a sense of what the candidates
are looking for; are they heavily into design? Are they enthusiastic about a specific
technology, and if so, do they have a sound reason for it? Were they frustrated by
administrative issues, did they try to improve their working environment?
&lt;/p&gt;
&lt;h3 style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: bold; border-left-width: 0px; font-size: 110%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 5px; vertical-align: baseline; padding-top: 0px; font-family: 'Trebuchet MS', helvetica, sans-serif; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;Technical
Questions
&lt;/h3&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
Once those formalities and niceties are out of the way, I turn to my ever-growing
collection of interview questions and select a small subset to present to the candidate.
For example, a typical interview may include the following questions:
&lt;/p&gt;
&lt;p&gt;
&lt;u&gt;Integer Arithmetic&lt;/u&gt;
&lt;/p&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
Does the candidate have a decent grasp of bits and bytes? I consider this a must-have;
a candidate that fails this part has no chance in hell of tackling even the most trivial
native code.
&lt;/p&gt;
&lt;ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"Take an integer. How do you turn the 7th least significant bit off?" This question
alone removes about half of the applicants from the equation. Some people tell you
"you need to apply bitwise AND, but I can't remember the number you need to AND with"
-- this isn't what you're looking for. A good answer would be something like "x &amp;amp;=
~(1 &amp;lt;&amp;lt; 6)". 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"How would you quickly divide an integer by eight (8)?" A good answer is, you shift
right by three. A better answer would be "is the integer signed or unsigned?", with
a bonus for Java developers who know the difference between &amp;gt;&amp;gt; and &amp;gt;&amp;gt;&amp;gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;u&gt;Pointers and Pointer Arithmetic&lt;/u&gt;
&lt;/p&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
This really depends on what your company does. Most developers today don't need to
know in practice the particulars of pointers and pointer arithmetic optimizations,
but if you're developing a highly scalable system and/or one with serious performance
considerations, this is a very good measure of how likely the candidate will be able
to tackle such challenges.
&lt;/p&gt;
&lt;ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"How big is a pointer?" The only correct answer is, "depends on the architecture".
32-bit operating systems will have 32-bit pointers, 64-bit systems will have 64-bit
pointers. Anything that doesn't fall into these two categories is not relevant for
my purposes, and likely yours as well. If the candidate fails this question I usually
mark this section as "failed" and move on.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;u&gt;Floating Point Numbers&lt;/u&gt;
&lt;/p&gt;
&lt;ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"What is NaN?" A programmer who can't answer this question has never really worked
with floating point numbers. 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"How are floating point numbers represented in a typical modern architecture?" Failing
this question is not a deal-breaker, but answering it correctly will score the candidate
a lot of points. "sign, exponent, mantissa/fraction/significand" is a sufficient answer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;u&gt;Essential Data Structures and Algorithms&lt;/u&gt;
&lt;/p&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
This is the bread-and-butter of programming. A candidate should exhibit robust familiarity
with commonplace data structures (hashtables, linked lists, trees etc.) and algorithms
(sorting, graph traversal).
&lt;/p&gt;
&lt;ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"Describe how quicksort works. Elaborate on its performance characteristics." Any
professional developer should be able to explain quicksort in a few minutes, know
its average- and worst-case complexity, and recognize pathological cases (typical
school-level quicksort implementations exhibit horrible performance on pre-sorted
data). 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"How are hashtables commonly implemented?" A candidate should be able to describe
the concept of a hashing function (uniform distribution) and how it relates to the
internal data structure (normally an array of buckets). 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"What backing data structure would you choose for a simple text editor?" The classic
answer is a&lt;a style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; cursor: pointer; color: rgb(74,107,130); padding-top: 0px; background-color: transparent; border-right-width: 0px; text-decoration: none; -webkit-background-clip: initial; -webkit-background-origin: initial" href="http://en.wikipedia.org/wiki/Rope_(computer_science)" rel="nofollow"&gt;&lt;font face="Arial"&gt;rope&lt;/font&gt;&lt;/a&gt;,
but it's unlikely that a candidate will be familiar with this data structure. A more
likely response would be a "linked-list of strings", in which case you should ask
about the complexity of various editing operations (deleting a line, inserting a line,
deleting a character etc.) This question typically takes slightly longer to answer
but I've found that it gives me a good measure of the candidate's intuition in choosing/analyzing
data representations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;u&gt;Threading and Sychronization&lt;/u&gt;
&lt;/p&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
This is fast becoming the most important subject with which to distinguish the truly
brilliant candidates from the merely competent; the ubiquity of multithreaded code
nowadays also means that these questions can be used to quickly weed out the unworthy
candidates.
&lt;/p&gt;
&lt;ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"Describe one common way of synchronizing access to a shared resource." This is just
a starter question, and if the candidate takes more than a few seconds to come up
with an answer (mutex, semaphore, monitor or "synchronized" for Java developers, "lock"
for C# developers) it's usually a good sign that they don't have any reasonable experience
with multithreaded development. 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"You have a shared cache with a very good hit ratio. How would you synchronize access
to the cache with as little performance overhead as possible?" The answer is trivially
a read-write lock which can accomodate multiple readers and a single, exclusive writer.
Where appropriate, ask how the candidate would implement such a lock. 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"Describe a nontrivial problem that you've had with threaded code." Responses usually
fall into one of three categories: either (1) a reasonably experienced multithreaded
developer would never make the same mistakes, in which case the candidate obviously
isn't one; (2) a classic race-condition/deadlock/etc. scenario, which merely tells
you that the candidate has some experience with multithreaded code and appears capable
of tackling such challenges; or (3) rarely, a candidate may have a genuinely interesting
"war story," in which case you'll probably want to hire them right away.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;u&gt;Peripheral Technologies&lt;/u&gt;
&lt;/p&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
Approach this section with caution. A canditate that's familiar with a great deal
of today's hot technologies may prove completely incompetent, whereas it's quite possible
to find brilliant programmers that have never touched COM in their lives. I still
like to get a sense of how "in touch" the developer is with contemporary technologies;
familiarity with tools and technologies can definitely be a tie-breaker between two
promising candidates.
&lt;/p&gt;
&lt;ul style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em 30px; vertical-align: baseline; padding-top: 0px; list-style-type: disc; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"Are you familiar with COM? Describe an interface which any COM object must implement
and its methods." Anyone who's even a bit familiar with Windows software development
should be able to answer this question fully. For those unfamiliar with COM, describe
it in a few words and ask the canditate to guess what the required methods of IUnknown
are. 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"What is a well-formed XML file? Give two examples of errors in an XML file which
would render it non-well-formed." XML is prevalent in almost every software development
domain. A candidate which cannot answer these questions (and doesn't have a very good
excuse) will not go past this interview. 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"What's XPath? Explain what a predicate is and how it's used." This is not most-have.
I'd expect serious developers to at least have an idea of what XPath is. The second
question is there to differentiate those who profess to know XPath from those who've
actually done work with XPath and/or XSLT. 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
"If you had to verify the input of an e-mail address field, how would you go about
it?" There are only two valid answers to this question: "I would use a regular expression,"
or "I'd like to use a regular expression, but I know that fully matching e-mails according
to the RFC is insanely complex, which is why I'd get a proven library to do it for
me." If the canditate is being a smart-ass you can always ask them about the performance
characteristics of commonplace regex engines (which have&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;a style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; cursor: pointer; color: rgb(74,107,130); padding-top: 0px; background-color: transparent; border-right-width: 0px; text-decoration: none; -webkit-background-clip: initial; -webkit-background-origin: initial" href="http://swtch.com/~rsc/regexp/regexp1.html" rel="nofollow"&gt;&lt;font face="Arial"&gt;pathological
cases&lt;/font&gt;&lt;/a&gt;). 
&lt;li style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
I also like to just toss buzzwords (Ruby, Boo, JSON, Struts, J2EE, WCF) around and
examine the candidate's responses. It may also provide an interesting subject to ask
about in a personal interview later on.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; font-weight: bold; border-left-width: 0px; font-size: 110%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 5px; vertical-align: baseline; padding-top: 0px; font-family: 'Trebuchet MS', helvetica, sans-serif; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;Concluding
the Interview
&lt;/h3&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
The previous section usually takes between 10 and 15 minutes. At this point I normally
ask the candidate if there are any questions they'd like answered, or anything I should
know before we conclude the interview. Once that'd done, I thank them for their time
and tell them (even if they've failed miserably) that I will call them back in a day
or two with an answer.
&lt;/p&gt;
&lt;p style="border-top-width: 0px; clear: both; padding-right: 0px; padding-left: 0px; border-left-width: 0px; font-size: 100%; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 1em; vertical-align: baseline; padding-top: 0px; background-color: transparent; border-right-width: 0px; -webkit-background-clip: initial; -webkit-background-origin: initial"&gt;
Hope this helps, comments are welcome.
&lt;/p&gt;
&lt;/span&gt;&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=8780ca97-eed3-49de-a307-ed8b493b4893" /&gt;</description>
      <category>Development</category>
      <category>Personal</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=eae0e740-85ac-40ce-b924-2c126bfa7471</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,eae0e740-85ac-40ce-b924-2c126bfa7471.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Because the Java language lacks delegates, anonymous classes are prevalent as a syntactic
replacement. Non-static nested classes are also often used in the language, a feature
which is conspicuously absent from C#, albeit far less necessary with that language.
</p>
        <p>
This brings me to the following language caveat. This may seem a contrived example,
but it's a simplification of an actual issue I've encountered in the last few days.
Suppose you have a generic base class, call it <tt>BaseClass&lt;U&gt;</tt>, which
you extend with an anonymous class. Lets also assume that the extended class spawns
a thread that needs to access the <tt>BaseClass&lt;U&gt;</tt> state:
</p>
        <blockquote>
          <pre>
            <span style="color: #0000ff">class</span> BaseClass&lt;U&gt; { <span style="color: #0000ff">void</span> getState()
{} } <span style="color: #0000ff">class</span> Test { <span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> test()
{ <span style="color: #0000ff">final</span> BaseClass&lt;String&gt; instance = <span style="color: #0000ff">new</span> BaseClass&lt;String&gt;()
{ <span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> invokeStatefulThread()
{ <span style="color: #008000">// Create our runnable</span><span style="color: #0000ff">final</span> Runnable
threadCode = <span style="color: #0000ff">new</span> Runnable() { <span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> run()
{ <span style="color: #008000">/* 1 */</span> getState(); <span style="color: #008000">/*
2 */</span><span style="color: #0000ff">this</span>.getState(); <span style="color: #008000">/*
3 */</span><span style="color: #0000ff">super</span>.getState(); <span style="color: #008000">/*
4 */</span> BaseClass.<span style="color: #0000ff">this</span>.getState(); <span style="color: #008000">/*
5 */</span> BaseClass&lt;String&gt;.<span style="color: #0000ff">this</span>.getState();
} }; <span style="color: #0000ff">new</span> Thread( threadCode ).start(); } }; instance.invokeStatefulThread();
} }</pre>
        </blockquote>
        <p>
I'll spare you the guessing game. Here's what happens with each of the five invocations
of <tt>getState()</tt>:
</p>
        <ol>
          <li>
Compiles and behaves as expected. 
</li>
          <li>
Obviously won't compile; <tt>this</tt> points to the <tt>Runnable</tt>. 
</li>
          <li>
Obviously won't compile; the superclass of a <tt>Runnable</tt> is <tt>Object</tt>. 
</li>
          <li>
Although this is the correct raw class, it won't compile because <tt>"No enclosing
instance of the type BaseClass&lt;U&gt; is accessible in scope"</tt>, even though
the raw type should still be accessible and <tt>U</tt> can be inferred. 
</li>
          <li>
Although this appears to be the correct fully-qualified form, this does not compile
with a <tt>"Syntax error on token(s), misplaced construct(s)"</tt> error.</li>
        </ol>
        <p>
The Java language specification section on "<a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.8.4">qualified <tt>this</tt></a>"
is very brief and does not mention generics at all (does "class name" include bounded
type parameters?). Oddly enough, moving the class declaration outside of the test
method actually lets 4 compile -- if there's a clue there, I haven't figured it out
yet.
</p>
        <p>
I still haven't found a syntactically-correct way to access <tt>BaseClass&lt;string&gt;.this</tt>,
other than placing it in a temporary variable outside of the <tt>Runnable</tt> declaration.
I searched yesterday for a couple of hours with no obvious solution in sight. Ideas
are more than welcome!...
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=eae0e740-85ac-40ce-b924-2c126bfa7471" />
      </body>
      <title>Java &amp;quot;qualified this&amp;quot; with generic enclosing types</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,eae0e740-85ac-40ce-b924-2c126bfa7471.aspx</guid>
      <link>http://www.tomergabel.com/JavaQuotqualifiedThisquotWithGenericEnclosingTypes.aspx</link>
      <pubDate>Tue, 22 Jul 2008 08:27:45 GMT</pubDate>
      <description>&lt;p&gt;
Because the Java language lacks delegates, anonymous classes are prevalent as a syntactic
replacement. Non-static nested classes are also often used in the language, a feature
which is conspicuously absent from C#, albeit far less necessary with that language.
&lt;/p&gt;
&lt;p&gt;
This brings me to the following language caveat. This may seem a contrived example,
but it's a simplification of an actual issue I've encountered in the last few days.
Suppose you have a generic base class, call it &lt;tt&gt;BaseClass&amp;lt;U&amp;gt;&lt;/tt&gt;, which
you extend with an anonymous class. Lets also assume that the extended class spawns
a thread that needs to access the &lt;tt&gt;BaseClass&amp;lt;U&amp;gt;&lt;/tt&gt; state:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BaseClass&amp;lt;U&amp;gt; { &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; getState()
{} } &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Test { &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; test()
{ &lt;span style="color: #0000ff"&gt;final&lt;/span&gt; BaseClass&amp;lt;String&amp;gt; instance = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; BaseClass&amp;lt;String&amp;gt;()
{ &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; invokeStatefulThread()
{ &lt;span style="color: #008000"&gt;// Create our runnable&lt;/span&gt; &lt;span style="color: #0000ff"&gt;final&lt;/span&gt; Runnable
threadCode = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Runnable() { &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; run()
{ &lt;span style="color: #008000"&gt;/* 1 */&lt;/span&gt; getState(); &lt;span style="color: #008000"&gt;/*
2 */&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.getState(); &lt;span style="color: #008000"&gt;/*
3 */&lt;/span&gt; &lt;span style="color: #0000ff"&gt;super&lt;/span&gt;.getState(); &lt;span style="color: #008000"&gt;/*
4 */&lt;/span&gt; BaseClass.&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.getState(); &lt;span style="color: #008000"&gt;/*
5 */&lt;/span&gt; BaseClass&amp;lt;String&amp;gt;.&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.getState();
} }; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thread( threadCode ).start(); } }; instance.invokeStatefulThread();
} }&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
I'll spare you the guessing game. Here's what happens with each of the five invocations
of &lt;tt&gt;getState()&lt;/tt&gt;:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Compiles and behaves as expected. 
&lt;li&gt;
Obviously won't compile; &lt;tt&gt;this&lt;/tt&gt; points to the &lt;tt&gt;Runnable&lt;/tt&gt;. 
&lt;li&gt;
Obviously won't compile; the superclass of a &lt;tt&gt;Runnable&lt;/tt&gt; is &lt;tt&gt;Object&lt;/tt&gt;. 
&lt;li&gt;
Although this is the correct raw class, it won't compile because &lt;tt&gt;"No enclosing
instance of the type BaseClass&amp;lt;U&amp;gt; is accessible in scope"&lt;/tt&gt;, even though
the raw type should still be accessible and &lt;tt&gt;U&lt;/tt&gt; can be inferred. 
&lt;li&gt;
Although this appears to be the correct fully-qualified form, this does not compile
with a &lt;tt&gt;"Syntax error on token(s), misplaced construct(s)"&lt;/tt&gt; error.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The Java language specification section on "&lt;a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.8.4"&gt;qualified &lt;tt&gt;this&lt;/tt&gt;&lt;/a&gt;"
is very brief and does not mention generics at all (does "class name" include bounded
type parameters?). Oddly enough, moving the class declaration outside of the test
method actually lets 4 compile -- if there's a clue there, I haven't figured it out
yet.
&lt;/p&gt;
&lt;p&gt;
I still haven't found a syntactically-correct way to access &lt;tt&gt;BaseClass&amp;lt;string&amp;gt;.this&lt;/tt&gt;,
other than placing it in a temporary variable outside of the &lt;tt&gt;Runnable&lt;/tt&gt; declaration.
I searched yesterday for a couple of hours with no obvious solution in sight. Ideas
are more than welcome!...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=eae0e740-85ac-40ce-b924-2c126bfa7471" /&gt;</description>
      <category>Development</category>
      <category>Development/Java</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=405afab6-978b-4a16-988d-c9e78156b57b</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,405afab6-978b-4a16-988d-c9e78156b57b.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Among a lot of other tools and technologies we use <a href="http://lucene.apache.org/">Lucene</a> here
at <a href="http://www.delver.com">Delver</a>. Lucene is a very mature, high-performance
and full-featured information retrieval library, which in simple terms means: it allows
you to add search functionality to your applications with ease. I could spend an entire
day talking about Lucene, but instead I'd like to show you how to write scripts for
Lucene with Python on Windows (and thus differs from <a href="http://sujitpal.blogspot.com/2007/06/pylucene-python-scripting-for-lucene.html">Sujit
Pal's excellent instructions</a> on the same subject matter).
</p>
        <p>
First, make sure you have your Python environment <a href="http://www.python.org/download/">all
set up</a> -- at the time of writing this I use the Python 2.5.1 Windows installer.
Next you'll need Python bindings for the library, so go and grab a copy of <a href="http://pylucene.osafoundation.org/">PyLucene</a>;
to make a long story short I suggest you use the JCC version for Windows which is
downloadable <a href="http://lists.osafoundation.org/pipermail/pylucene-dev/2008-February/002281.html">here</a>.
Grab it and install it, no fussing necessary. Finally you'll need the Java VM DLL
in your path, and this depends on which type of JRE you're using:
</p>
        <ul>
          <li>
If you're using the Java JDK, add the mental equivalent of <tt>C:\Program Files\Java\jdk1.6.0_03\jre\bin\client</tt> to
your path; 
</li>
          <li>
If you're using a JRE, add <tt>C:\Program Files\Java\jre1.6.0_03\bin\client</tt> to
your path.</li>
        </ul>
        <p>
(As an aside, you should probably be using <tt>%JAVA_HOME%</tt> and <tt>%JRE_HOME%</tt> and
indirecting through those.)
</p>
        <p>
Now you can quickly whip down scripts in Python, like this one which took about two
minutes to write:
</p>
        <blockquote>
          <pre>
            <font color="#008000">#!/usr/bin/python # # extract.py -- Extracts
term from an <span style="color: #0000ff">index</span> # Tomer Gabel, Delver, 2008
# # Usage: extract.py &lt;field_name&gt; &lt;index_url&gt; #</font>
            <span style="color: #0000ff">import</span>
            <span style="color: #0000ff">sys</span>
            <span style="color: #0000ff">import</span>
            <span style="color: #0000ff">string</span>
            <span style="color: #0000ff">import</span> lucene
from lucene <span style="color: #0000ff">import</span> IndexReader, StandardAnalyzer,
FSDirectory <span style="color: #0000ff">def</span> usage(): <span style="color: #0000ff">print</span> "<span style="color: #8b0000">Usage:\n</span>" <span style="color: #0000ff">print</span><span style="color: #0000ff">sys</span>.argv[
0 ] + "<span style="color: #8b0000"> &lt;field_name&gt; &lt;index_url&gt;</span>" <span style="color: #0000ff">sys</span>.<span style="color: #0000ff">exit</span>(
-1 ) <span style="color: #0000ff">def</span> main(): <span style="color: #0000ff">if</span> (
len( <span style="color: #0000ff">sys</span>.argv ) &lt; 3 ): usage() lucene.initVM(
lucene.CLASSPATH ) term = <span style="color: #0000ff">sys</span>.argv[ 1 ] index_location
= <span style="color: #0000ff">sys</span>.argv[ 2 ] reader = IndexReader.<span style="color: #0000ff">open</span>(
FSDirectory.getDirectory( index_location, False ) ) try: for i in range( reader.maxDoc()
): <span style="color: #0000ff">if</span> ( not reader.isDeleted( i ) ): doc = reader.document(
i ) <span style="color: #0000ff">print</span> doc.get( term ) finally: reader.<span style="color: #0000ff">close</span>()
main()</pre>
        </blockquote>
        <p>
Note the VM initialization line at the beginning -- for the JCC version of PyLucene
this is a must, but even like so using the library is extremely painless. Kudos to
the developers responsible!
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=405afab6-978b-4a16-988d-c9e78156b57b" />
      </body>
      <title>Scripting Lucene with Python</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,405afab6-978b-4a16-988d-c9e78156b57b.aspx</guid>
      <link>http://www.tomergabel.com/ScriptingLuceneWithPython.aspx</link>
      <pubDate>Sun, 24 Feb 2008 10:26:41 GMT</pubDate>
      <description>&lt;p&gt;
Among a lot of other tools and technologies we use &lt;a href="http://lucene.apache.org/"&gt;Lucene&lt;/a&gt; here
at &lt;a href="http://www.delver.com"&gt;Delver&lt;/a&gt;. Lucene is a very mature, high-performance
and full-featured information retrieval library, which in simple terms means: it allows
you to add search functionality to your applications with ease. I could spend an entire
day talking about Lucene, but instead I'd like to show you how to write scripts for
Lucene with Python on Windows (and thus differs from &lt;a href="http://sujitpal.blogspot.com/2007/06/pylucene-python-scripting-for-lucene.html"&gt;Sujit
Pal's excellent instructions&lt;/a&gt; on the same subject matter).
&lt;/p&gt;
&lt;p&gt;
First, make sure you have your Python environment &lt;a href="http://www.python.org/download/"&gt;all
set up&lt;/a&gt; -- at the time of writing this I use the Python 2.5.1 Windows installer.
Next you'll need Python bindings for the library, so go and grab a copy of &lt;a href="http://pylucene.osafoundation.org/"&gt;PyLucene&lt;/a&gt;;
to make a long story short I suggest you use the JCC version for Windows which is
downloadable &lt;a href="http://lists.osafoundation.org/pipermail/pylucene-dev/2008-February/002281.html"&gt;here&lt;/a&gt;.
Grab it and install it, no fussing necessary. Finally you'll need the Java VM DLL
in your path, and this depends on which type of JRE you're using:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
If you're using the Java JDK, add the mental equivalent of &lt;tt&gt;C:\Program Files\Java\jdk1.6.0_03\jre\bin\client&lt;/tt&gt; to
your path; 
&lt;li&gt;
If you're using a JRE, add &lt;tt&gt;C:\Program Files\Java\jre1.6.0_03\bin\client&lt;/tt&gt; to
your path.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
(As an aside, you should probably be using &lt;tt&gt;%JAVA_HOME%&lt;/tt&gt; and &lt;tt&gt;%JRE_HOME%&lt;/tt&gt; and
indirecting through those.)
&lt;/p&gt;
&lt;p&gt;
Now you can quickly whip down scripts in Python, like this one which took about two
minutes to write:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;font color="#008000"&gt;#!/usr/bin/python # # extract.py -- Extracts
term from an &lt;span style="color: #0000ff"&gt;index&lt;/span&gt; # Tomer Gabel, Delver, 2008
# # Usage: extract.py &amp;lt;field_name&amp;gt; &amp;lt;index_url&amp;gt; #&lt;/font&gt; &lt;span style="color: #0000ff"&gt;import&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sys&lt;/span&gt; &lt;span style="color: #0000ff"&gt;import&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; &lt;span style="color: #0000ff"&gt;import&lt;/span&gt; lucene
from lucene &lt;span style="color: #0000ff"&gt;import&lt;/span&gt; IndexReader, StandardAnalyzer,
FSDirectory &lt;span style="color: #0000ff"&gt;def&lt;/span&gt; usage(): &lt;span style="color: #0000ff"&gt;print&lt;/span&gt; "&lt;span style="color: #8b0000"&gt;Usage:\n&lt;/span&gt;" &lt;span style="color: #0000ff"&gt;print&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sys&lt;/span&gt;.argv[
0 ] + "&lt;span style="color: #8b0000"&gt; &amp;lt;field_name&amp;gt; &amp;lt;index_url&amp;gt;&lt;/span&gt;" &lt;span style="color: #0000ff"&gt;sys&lt;/span&gt;.&lt;span style="color: #0000ff"&gt;exit&lt;/span&gt;(
-1 ) &lt;span style="color: #0000ff"&gt;def&lt;/span&gt; main(): &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (
len( &lt;span style="color: #0000ff"&gt;sys&lt;/span&gt;.argv ) &amp;lt; 3 ): usage() lucene.initVM(
lucene.CLASSPATH ) term = &lt;span style="color: #0000ff"&gt;sys&lt;/span&gt;.argv[ 1 ] index_location
= &lt;span style="color: #0000ff"&gt;sys&lt;/span&gt;.argv[ 2 ] reader = IndexReader.&lt;span style="color: #0000ff"&gt;open&lt;/span&gt;(
FSDirectory.getDirectory( index_location, False ) ) try: for i in range( reader.maxDoc()
): &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( not reader.isDeleted( i ) ): doc = reader.document(
i ) &lt;span style="color: #0000ff"&gt;print&lt;/span&gt; doc.get( term ) finally: reader.&lt;span style="color: #0000ff"&gt;close&lt;/span&gt;()
main()&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Note the VM initialization line at the beginning -- for the JCC version of PyLucene
this is a must, but even like so using the library is extremely painless. Kudos to
the developers responsible!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=405afab6-978b-4a16-988d-c9e78156b57b" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=b657662e-31b1-4eb3-bfd4-2557b2ff78b0</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,b657662e-31b1-4eb3-bfd4-2557b2ff78b0.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The Java implementation for generics is radically different from the C# equivalent;
I won't reiterate issues that have been <a href="http://www.itu.dk/courses/PFOO/F2006/diku-javacsharpgenerics.pdf">thoroughly
discussed before</a>, but suffice to say that Java generics are implemented as a backwards-compatible
compiler extension that works on unmodified VMs.
</p>
        <p>
The implications of this are considerable, and I'd like to present one of them. Lets
fast forward a bit and consider a relatively new language feature in Java (introduced,
I believe, with J2SE 5.0): autoboxing. A thoroughly overdue language feature, autoboxing
allows the seamless transition from regular value types (e.g. the ubiquitous <span class="codetext">int</span>)
to object references (<span class="codetext">Integer</span>); before autoboxing you
couldn't simply add a value to an untyped ArrayList, you had to box (wrap) it in a
reference type:
</p>
        <blockquote>
          <pre>ArrayList list = <span style="color: #0000ff">new</span> ArrayList();
list.add( 3 ); <span style="color: #008000">// Compile-time error</span> list.add( <span style="color: #0000ff">new</span> Integer(
3 ) ); <span style="color: #008000">// OK</span></pre>
        </blockquote>
        <p>
Eventually Java caught up with C# (which introduced autoboxing in 2002), and with
a modern compiler the above code would be valid.
</p>
        <p>
With the introductions out of the way, here's a pop-quiz: what does the following
code print?
</p>
        <blockquote>
          <pre>HashMap&lt;Integer, Integer&gt; map = <span style="color: #0000ff">new</span> HashMap&lt;Integer,
Integer&gt;(); map.put( 4, 2 ); <span style="color: #0000ff">short</span> n = 4; System.out.println(
Integer.toString( map.get( n ) ) );</pre>
        </blockquote>
        <p>
As a long-time C# programmer I was completely befuddled when the code resulted in
a <span class="codetext">NullPointerException</span>. Huh? Exception? What? Why?
</p>
        <p>
It took me a while to figure it out: because Java generics are compile-time constructs
and are not directly supported by the VM, what actually happens is that the underlying
container class accepts regular <span class="codetext">Object</span> instances (reference
types); the compile-time check merely asserts that <span class="codetext">n</span> can
be promoted from <span class="codetext">short</span> to <span class="codetext">int</span>,
whereas the actual object passed to the container class (via autoboxing) is a <span class="codetext">Short</span>!
Since the container doesn't doesn't actually have a runtime generic <em>type</em> per
se, the collection merely looks up the reference object in the map, fails to find
it (I guess the <span class="codetext">Object.hashCode</span> implementation for value
types simply returns the reference value as the hash code as in C#) and returns <span class="codetext">null</span>.
Doh! <b>*slaps forehead*</b></p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b657662e-31b1-4eb3-bfd4-2557b2ff78b0" />
      </body>
      <title>Java language caveat: autoboxing and generics</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,b657662e-31b1-4eb3-bfd4-2557b2ff78b0.aspx</guid>
      <link>http://www.tomergabel.com/JavaLanguageCaveatAutoboxingAndGenerics.aspx</link>
      <pubDate>Sun, 06 Jan 2008 17:15:54 GMT</pubDate>
      <description>&lt;p&gt;
The Java implementation for generics is radically different from the C# equivalent;
I won't reiterate issues that have been &lt;a href="http://www.itu.dk/courses/PFOO/F2006/diku-javacsharpgenerics.pdf"&gt;thoroughly
discussed before&lt;/a&gt;, but suffice to say that Java generics are implemented as a backwards-compatible
compiler extension that works on unmodified VMs.
&lt;/p&gt;
&lt;p&gt;
The implications of this are considerable, and I'd like to present one of them. Lets
fast forward a bit and consider a relatively new language feature in Java (introduced,
I believe, with J2SE 5.0): autoboxing. A thoroughly overdue language feature, autoboxing
allows the seamless transition from regular value types (e.g. the ubiquitous &lt;span class="codetext"&gt;int&lt;/span&gt;)
to object references (&lt;span class="codetext"&gt;Integer&lt;/span&gt;); before autoboxing you
couldn't simply add a value to an untyped ArrayList, you had to box (wrap) it in a
reference type:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;ArrayList list = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArrayList();
list.add( 3 ); &lt;span style="color: #008000"&gt;// Compile-time error&lt;/span&gt; list.add( &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Integer(
3 ) ); &lt;span style="color: #008000"&gt;// OK&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Eventually Java caught up with C# (which introduced autoboxing in 2002), and with
a modern compiler the above code would be valid.
&lt;/p&gt;
&lt;p&gt;
With the introductions out of the way, here's a pop-quiz: what does the following
code print?
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;HashMap&amp;lt;Integer, Integer&amp;gt; map = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HashMap&amp;lt;Integer,
Integer&amp;gt;(); map.put( 4, 2 ); &lt;span style="color: #0000ff"&gt;short&lt;/span&gt; n = 4; System.out.println(
Integer.toString( map.get( n ) ) );&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
As a long-time C# programmer I was completely befuddled when the code resulted in
a &lt;span class="codetext"&gt;NullPointerException&lt;/span&gt;. Huh? Exception? What? Why?
&lt;/p&gt;
&lt;p&gt;
It took me a while to figure it out: because Java generics are compile-time constructs
and are not directly supported by the VM, what actually happens is that the underlying
container class accepts regular &lt;span class="codetext"&gt;Object&lt;/span&gt; instances (reference
types); the compile-time check merely asserts that &lt;span class="codetext"&gt;n&lt;/span&gt; can
be promoted from &lt;span class="codetext"&gt;short&lt;/span&gt; to &lt;span class="codetext"&gt;int&lt;/span&gt;,
whereas the actual object passed to the container class (via autoboxing) is a &lt;span class="codetext"&gt;Short&lt;/span&gt;!
Since the container doesn't doesn't actually have a runtime generic &lt;em&gt;type&lt;/em&gt; per
se, the collection merely looks up the reference object in the map, fails to find
it (I guess the &lt;span class="codetext"&gt;Object.hashCode&lt;/span&gt; implementation for value
types simply returns the reference value as the hash code as in C#) and returns &lt;span class="codetext"&gt;null&lt;/span&gt;.
Doh! &lt;b&gt;*slaps forehead*&lt;/b&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b657662e-31b1-4eb3-bfd4-2557b2ff78b0" /&gt;</description>
      <category>Development</category>
      <category>Development/Java</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=b66898eb-7c2d-41c2-9ed5-3dab91422eaf</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,b66898eb-7c2d-41c2-9ed5-3dab91422eaf.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A few ReSharper tips for your viewing pleasure (according to rumors it can extend
your penis too!):
</p>
        <p>
          <strong>Alt+Shift+L locates the current file in the Solution Explorer </strong>(at
least with the IDEA-style keyboard bindings we all know and love). This is particularly
useful for extremely file-heavy solutions where you often want to Get Latest (or Undo
Check Out) the current file.
</p>
        <p>
          <u>Note</u>: you can get this behavior automatically through Tools-&gt;Options-&gt;Projects
and Solutions-&gt;Track Active Item in Solution Explorer, but in my opinion it's annoying
as hell.
</p>
        <p>
          <strong>Easier unit testing</strong>: you can bind shortcuts to run or debug unit
tests by context. Context means that the behavior is exactly as expected: using the
shortcut with the cursor on a test will run just that test, using it on a class will
run it as a whole fixture, and using it on a directory in the Solution Explorer will
run all tests that reside in that directory. This is easily accomplished by going
to the Tools-&gt;Options-&gt;Keyboard menu and binding:
</p>
        <ul>
          <li>
            <strong>ReSharper.ReSharper_UnitTest_ContextDebug</strong> to whichever shortcut you
wish for debugging purposes (my favourite is <strong>Ctrl+T</strong>, <strong>Ctrl+D</strong>) 
</li>
          <li>
            <strong>ReSharper.ReSharper_UnitTest_ContextRun</strong> to whichever shortcut you'd
like to use in order to just run tests (my favourite is <strong>Ctrl+T</strong>, <strong>Ctrl+T</strong>)</li>
        </ul>
        <p>
          <u>Note</u>: You can get the same behavior with the ubiquitous <a href="http://www.testdriven.net/">TestDriven.net</a>,
but it makes no sense to me to pay twice for the same functionality.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b66898eb-7c2d-41c2-9ed5-3dab91422eaf" />
      </body>
      <title>Improve Your Life With ReSharper</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,b66898eb-7c2d-41c2-9ed5-3dab91422eaf.aspx</guid>
      <link>http://www.tomergabel.com/ImproveYourLifeWithReSharper.aspx</link>
      <pubDate>Wed, 02 Jan 2008 16:07:15 GMT</pubDate>
      <description>&lt;p&gt;
A few ReSharper tips for your viewing pleasure (according to rumors it can extend
your penis too!):
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Alt+Shift+L locates the current file in the Solution Explorer &lt;/strong&gt;(at
least with the IDEA-style keyboard bindings we all know and love). This is particularly
useful for extremely file-heavy solutions where you often want to Get Latest (or Undo
Check Out) the current file.
&lt;/p&gt;
&lt;p&gt;
&lt;u&gt;Note&lt;/u&gt;: you can get this behavior automatically through Tools-&amp;gt;Options-&amp;gt;Projects
and Solutions-&amp;gt;Track Active Item in Solution Explorer, but in my opinion it's annoying
as hell.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Easier unit testing&lt;/strong&gt;: you can bind shortcuts to run or debug unit
tests by context. Context means that the behavior is exactly as expected: using the
shortcut with the cursor on a test will run just that test, using it on a class will
run it as a whole fixture, and using it on a directory in the Solution Explorer will
run all tests that reside in that directory. This is easily accomplished by going
to the Tools-&amp;gt;Options-&amp;gt;Keyboard menu and binding:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ReSharper.ReSharper_UnitTest_ContextDebug&lt;/strong&gt; to whichever shortcut you
wish for debugging purposes (my favourite is &lt;strong&gt;Ctrl+T&lt;/strong&gt;, &lt;strong&gt;Ctrl+D&lt;/strong&gt;) 
&lt;li&gt;
&lt;strong&gt;ReSharper.ReSharper_UnitTest_ContextRun&lt;/strong&gt; to whichever shortcut you'd
like to use in order to just run tests (my favourite is &lt;strong&gt;Ctrl+T&lt;/strong&gt;, &lt;strong&gt;Ctrl+T&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;u&gt;Note&lt;/u&gt;: You can get the same behavior with the ubiquitous &lt;a href="http://www.testdriven.net/"&gt;TestDriven.net&lt;/a&gt;,
but it makes no sense to me to pay twice for the same functionality.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=b66898eb-7c2d-41c2-9ed5-3dab91422eaf" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=f204d6c8-6299-46c2-afc9-390ab6685e4e</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,f204d6c8-6299-46c2-afc9-390ab6685e4e.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Quick link: <a href="http://www.tomergabel.com/content/binary/LightweightWebServer.zip">download</a></p>
        <p>
In my work at <a href="http://www.semingo.com">Semingo</a> I often encounter situations
where it's impossible to unit- or integration-test a component without accessing the
web. This happens in one of two cases: either the component itself is web-centric
and makes no sense in any other context, or I simply require an actual web server
to test the components against.
</p>
        <p>
Since I firmly believe that tests should be self-contained and rely on external resources
as little as possible, a belief which also extends to integration tests, I wrote a
quick-and-dirty pluggable web server based on the .NET <span class="codetext">HttpListener</span> class.
The unit-tests for the class itself serve best to demonstrate how it's used; for instance,
the built-in <span class="codetext">HttpNotFoundHandler</span> returns 404 on all
requests:
</p>
        <pre>    [Test]
    [ExpectedException( <span style="color: #0000ff">typeof</span>(
WebException ) )] [Description( "<span style="color: #8b0000">Instantiates an HTTP
server that returns 404 on all " +<br />
"</span><span style="color: #8b0000">requests, and validates that behavior.</span>"
)] <span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> VerifyThatHttpNotFoundHandlerBehavesAsExpected()
{ <span style="color: #0000ff">using</span> ( LightweightWebServer webserver = 
<br /><span style="color: #0000ff"> new</span> LightweightWebServer( LightweightWebServer.HttpNotFoundHandler
) ) { WebRequest.Create( webserver.Uri ).GetResponse().Close(); } }</pre>The web server
randomizes a listener port (in the range of 40000-41000, although that is easily configurable)
and exposes its own URI via the <span class="codetext">LightweightWebServer.Uri</span> property.
By implementing <span class="codetext">IDisposable</span> the scope in which the server
operates is easily defined. Exceptions thrown from within the handler are forwarded
to the caller when the server is disposed:<pre></pre><pre>    [Test]
    [ExpectedException( <span style="color: #0000ff">typeof</span>(
AssertionException ) )] <span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> VerifyThatExceptionsAreForwardedToTestMethod()
{ <span style="color: #0000ff">using</span> ( LightweightWebServer webserver = <span style="color: #0000ff">new</span> LightweightWebServer( <span style="color: #0000ff">delegate</span> {
Assert.Fail( "<span style="color: #8b0000">Works!</span>" ); } ) ) { WebRequest.Create(
webserver.Uri ).GetResponse().Close(); } }</pre>The handlers themselves receive an <span class="codetext">HttpListenerContext</span>,
from which both request and response objects are accessible. This makes anything from
asserting on query parameters to serving content trivial:<pre></pre><pre>    [Test]
    <span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> VerifyThatContentHandlerReturnsValidContent()
{ <span style="color: #0000ff">string</span> content = "<span style="color: #8b0000">The
quick brown fox jumps over the lazy dog</span>"; <span style="color: #0000ff">using</span> (
LightweightWebServer webserver = <span style="color: #0000ff">new</span> LightweightWebServer( <span style="color: #0000ff">delegate</span>(
HttpListenerContext context ) { <span style="color: #0000ff">using</span> ( StreamWriter
sw = <span style="color: #0000ff">new</span> StreamWriter( context.Response.OutputStream
) ) sw.Write( content ); } ) ) { <span style="color: #0000ff">string</span> returned; <span style="color: #0000ff">using</span> (
WebResponse resp = WebRequest.Create( webserver.Uri ).GetResponse() ) returned = <span style="color: #0000ff">new</span> StreamReader(
resp.GetResponseStream() ).ReadToEnd(); Assert.AreEqual( content, returned ); } }</pre><p>
We use this class internally to mock anything from web services to proxy servers.
You can grab the class sources <a href="http://www.tomergabel.com/content/binary/LightweightWebServer.zip">here</a> --
it's distributed under a Creative Commons Public Domain license, so you can basically
do anything you want with it. If it's useful to anyone, I'd love to hear comments
and suggestions!
</p><img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=f204d6c8-6299-46c2-afc9-390ab6685e4e" /></body>
      <title>Lightweight web server for testing purposes</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,f204d6c8-6299-46c2-afc9-390ab6685e4e.aspx</guid>
      <link>http://www.tomergabel.com/LightweightWebServerForTestingPurposes.aspx</link>
      <pubDate>Sun, 09 Dec 2007 21:18:06 GMT</pubDate>
      <description>&lt;p&gt;
Quick link: &lt;a href="http://www.tomergabel.com/content/binary/LightweightWebServer.zip"&gt;download&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In my work at &lt;a href="http://www.semingo.com"&gt;Semingo&lt;/a&gt; I often encounter situations
where it's impossible to unit- or integration-test a component without accessing the
web. This happens in one of two cases: either the component itself is web-centric
and makes no sense in any other context, or I simply require an actual web server
to test the components against.
&lt;/p&gt;
&lt;p&gt;
Since I firmly believe that tests should be self-contained and rely on external resources
as little as possible, a belief which also extends to integration tests, I wrote a
quick-and-dirty pluggable web server based on the .NET &lt;span class="codetext"&gt;HttpListener&lt;/span&gt; class.
The unit-tests for the class itself serve best to demonstrate how it's used; for instance,
the built-in &lt;span class="codetext"&gt;HttpNotFoundHandler&lt;/span&gt; returns 404 on all
requests:
&lt;/p&gt;
&lt;pre&gt;    [Test]
    [ExpectedException( &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(
WebException ) )] [Description( "&lt;span style="color: #8b0000"&gt;Instantiates an HTTP
server that returns 404 on all " +&lt;br&gt;
"&lt;/span&gt;&lt;span style="color: #8b0000"&gt;requests, and validates that behavior.&lt;/span&gt;"
)] &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; VerifyThatHttpNotFoundHandlerBehavesAsExpected()
{ &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; ( LightweightWebServer webserver = 
&lt;br&gt;
&lt;span style="color: #0000ff"&gt; new&lt;/span&gt; LightweightWebServer( LightweightWebServer.HttpNotFoundHandler
) ) { WebRequest.Create( webserver.Uri ).GetResponse().Close(); } }&lt;/pre&gt;The web server
randomizes a listener port (in the range of 40000-41000, although that is easily configurable)
and exposes its own URI via the &lt;span class="codetext"&gt;LightweightWebServer.Uri&lt;/span&gt; property.
By implementing &lt;span class="codetext"&gt;IDisposable&lt;/span&gt; the scope in which the server
operates is easily defined. Exceptions thrown from within the handler are forwarded
to the caller when the server is disposed:&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;    [Test]
    [ExpectedException( &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(
AssertionException ) )] &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; VerifyThatExceptionsAreForwardedToTestMethod()
{ &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; ( LightweightWebServer webserver = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LightweightWebServer( &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt; {
Assert.Fail( "&lt;span style="color: #8b0000"&gt;Works!&lt;/span&gt;" ); } ) ) { WebRequest.Create(
webserver.Uri ).GetResponse().Close(); } }&lt;/pre&gt;The handlers themselves receive an &lt;span class="codetext"&gt;HttpListenerContext&lt;/span&gt;,
from which both request and response objects are accessible. This makes anything from
asserting on query parameters to serving content trivial:&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;    [Test]
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; VerifyThatContentHandlerReturnsValidContent()
{ &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; content = "&lt;span style="color: #8b0000"&gt;The
quick brown fox jumps over the lazy dog&lt;/span&gt;"; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (
LightweightWebServer webserver = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LightweightWebServer( &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;(
HttpListenerContext context ) { &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; ( StreamWriter
sw = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StreamWriter( context.Response.OutputStream
) ) sw.Write( content ); } ) ) { &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; returned; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (
WebResponse resp = WebRequest.Create( webserver.Uri ).GetResponse() ) returned = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StreamReader(
resp.GetResponseStream() ).ReadToEnd(); Assert.AreEqual( content, returned ); } }&lt;/pre&gt;
&lt;p&gt;
We use this class internally to mock anything from web services to proxy servers.
You can grab the class sources &lt;a href="http://www.tomergabel.com/content/binary/LightweightWebServer.zip"&gt;here&lt;/a&gt; --
it's distributed under a Creative Commons Public Domain license, so you can basically
do anything you want with it. If it's useful to anyone, I'd love to hear comments
and suggestions!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=f204d6c8-6299-46c2-afc9-390ab6685e4e" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=08ee53ca-6d1a-4406-a7c4-579f6414db2a</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,08ee53ca-6d1a-4406-a7c4-579f6414db2a.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So you want a web project, a build system and a reasonable IDE to take care of the
annoying details for you, right? The good news are that it's actually quite possible
and there're many ways to do this. The bad news are that it's nigh impossible to get
them to play along if you don't already know how to do that. It took me days to find
a solution that finally seems to work, and I'd like to share it with you. I'm probably
missing a few important details or did something really really stupid along the way
(I'd appreciate comments!), but this process does seem to work. <strong>I'm not going
into essentials of Java-based web development here</strong> -- if you want a more
basic explanation of the terminology, post a comment and I'll see what I can do...
</p>
        <p>
          <u>1. Goal</u>
        </p>
        <p>
I want to:
</p>
        <ul>
          <li>
Use a common, standard and powerful IDE to edit and debug my Java code, and preferably
provide a usable GUI interface for dependency and project management; 
</li>
          <li>
Use a common, standard servlet container to host my servlet and still be able to control
and debug everything from the same IDE; 
</li>
          <li>
Have a convenient way to handle internal-and-external dependencies without worrying
too much about the details; 
</li>
          <li>
Be able to quickly compile, test and package my servlet for deployment; 
</li>
          <li>
            <em>
              <strong>Understand as little as possible about the dependency stack of the tools
involved</strong>
            </em>
          </li>
        </ul>
        <p>
I'm going to tell you how to achieve most of these goals, with two glaring omissions:
I won't show you how to do testing (I haven't successfully managed servlet unit testing
so far -- different post on that) and I can't help but delve into some of the more
annoying details involved with these tools and their dependencies. Sorry about that.
Additionally, some of the information here applies even if you use different tools,
but you're bound to face issues not covered here; don't assume I know more than you
do -- seek the answers, post them somewhere, and maybe the next person will actually
find what they're looking for!
</p>
        <p>
          <u>2. Tools</u>
        </p>
        <p>
The tools used are:
</p>
        <ul>
          <li>
            <a href="http://java.sun.com/javase/downloads/index.jsp">J2SE JDK</a> is an obvious
must-have. Version used: JDK 6 update 3; 
</li>
          <li>
            <a href="http://www.eclipse.org/">Eclipse</a> (but please don't download it just yet)
for code editing, debugging and project management; 
</li>
          <li>
            <a href="http://www.eclipse.org/webtools/">Web Tools Platform</a>: this is the Eclipse
plug-in that adds web development capabilities to the IDE, including J2EE dependency
management, hosting and running servlets from within the Eclipse workspace etc. This
would be a good time to run along to the <a href="http://download.eclipse.org/webtools/downloads/">WTP
web-site</a> and download the Web Tools Platform All-In-One package. I only used the
release version (2.0.1 at the time of writing this), so if you use another version
your mileage may vary; 
</li>
          <li>
            <a href="http://maven.apache.org/">Apache Maven</a> is the newfangled build system
from Apache slated to replace <a href="http://ant.apache.org/">ant</a>. I've used
it for the last few days and so far it appears to be quite robust and even fairly
well-integrated into Eclipse (see next item). Version used: 2.0.8; 
</li>
          <li>
            <a href="http://m2eclipse.codehaus.org/">M2eclipse</a> is the Eclipse plug-in for
Maven integration. I've only found one problem with it so far, which I'll detail later
on; 
</li>
          <li>
            <a href="http://tomcat.apache.org/">Apache Tomcat</a> is a solid choice in servlet
containers. It's robust, fast and open-source, and has terrific Eclipse integration.
I haven't given any of the other containers a serious whirl yet though.</li>
        </ul>
        <p>
          <u>3. Preparations</u>
        </p>
        <p>
Unlike Visual Studio, with the tools mentioned above there's no straightforward installation
procedure. You'll have to designate at least a workspace directory (where your Eclipse
projects, settings etc. go) and some location where the tools themselves go. For me,
it's C:\Dev\Eclipse and C:\Tools respectively.
</p>
        <ul>
          <li>
Setting up Java: 
<ul><li>
Install the JDK and remember where it was installed (nominally in <span class="codetext">%PROGRAMFILES%\Java\jdk1.6.0_03</span>) 
</li><li>
Set up a system-wide <span class="codetext">JAVA_HOME</span> environment variable
pointing to the same directory</li></ul></li>
          <li>
Setting up Maven and Tomcat: 
<ul><li>
Extract both archives to your designated directory (e.g. for Maven it would be <span class="codetext">C:\Tools\apache-maven-2.0.8</span>) 
</li><li>
Add the Maven bin directory to your <span class="codetext">PATH</span> environment
variable (user- or system-wide, depending on your preference) 
</li><li>
Add whichever J2EE libraries you desire from the Tomcat installation to your class-path.
If you have no idea what I'm talking about, you'll probably just want to set the <span class="codetext">CLASSPATH</span> environment
variable to your equivalent of <span class="codetext">c:\tools\apache-tomcat-6.0.14\lib\servlet-api.jar;c:\tools\apache-tomcat-6.0.14\lib\jsp-api.jar</span></li></ul></li>
          <li>
Setting up Eclipse: 
<ul><li>
Extract the WTP all-in-one package (which contains Eclipse itself) to your designated
directory (e.g. <span class="codetext">C:\Tools\Eclipse</span>) 
</li><li>
Load Eclipse and point it to your designated workspace location 
</li><li>
Install M2Eclipse: 
<ul><li>
Go to Help-&gt;Software Updates-&gt;Find and Install..., select "Search for new features
to install" and click Next 
</li><li>
Click on New Remote Site..., use M2eclipse or whatever for the name and <a title="http://m2eclipse.codehaus.org/update/" href="http://m2eclipse.codehaus.org/update/">http://m2eclipse.codehaus.org/update/</a> for
the URL 
</li><li>
Click on Finish and let Eclipse install the M2Eclipse plug-in</li></ul></li><li>
Set up a web server runtime for Eclipse to host your servlets in: 
<ul><li>
Open Window-&gt;Preferences... 
</li><li>
Under Server select Installed Runtimes and click on Add... 
</li><li>
Choose (from Apache) the Apache Tomcat v6.0 runtime and click Next 
</li><li>
Enter the Apache installation directory (e.g. <span class="codetext">C:\Tools\apache-tomcat-6.0.14</span>)
in the appropriate location and click Finish</li></ul></li></ul></li>
        </ul>
        <p>
          <u>4. Creating a new web project</u>
        </p>
        <p>
First off, you must create the actual project, directory structure etc. To do this:
</p>
        <ul>
          <li>
Open a command prompt, go to your Eclipse workspace directory 
</li>
          <li>
Decide on your Maven group and artifact IDs; it's worth noting that the artifact ID
is also the directory name for the project 
</li>
          <li>
Type in <span class="codetext">mvn archetype:create -DgroupId=<strong>your.group.id</strong> -DartifactId=<strong>your.artifact.id</strong> -DarchetypeArtifactId=maven-archetype-webapp </span></li>
          <li>
You'll notice that a new directory was created under the workspace root 
</li>
          <li>
Edit the Maven project descriptor <span class="codetext">POM.XML</span> in the newly
created directory: 
<ul><li>
Add (after the <span class="codetext">&lt;url&gt;</span> tag, although I'm not sure
the order matters) the following section: <blockquote style="font-family: monospace">&lt;profiles&gt;<br />
    &lt;profile&gt;<br />
        &lt;id&gt;servlet&lt;/id&gt;<br />
        &lt;activation&gt;<br />
            &lt;activeByDefault&gt;false&lt;/activeByDefault&gt;<br />
        &lt;/activation&gt;<br />
        &lt;dependencies&gt;<br />
            &lt;dependency&gt;<br />
               
&lt;groupId&gt;javax.servlet&lt;/groupId&gt;<br />
               
&lt;artifactId&gt;servlet-api&lt;/artifactId&gt;<br />
               
&lt;version&gt;2.5&lt;/version&gt;<br />
               
&lt;scope&gt;provided&lt;/scope&gt;<br />
            &lt;/dependency&gt;<br />
            &lt;dependency&gt;<br />
               
&lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;<br />
               
&lt;artifactId&gt;jsp-api&lt;/artifactId&gt;<br />
               
&lt;version&gt;2.1&lt;/version&gt;<br />
               
&lt;scope&gt;provided&lt;/scope&gt;<br />
            &lt;/dependency&gt;<br />
        &lt;/dependencies&gt;<br />
    &lt;/profile&gt;<br />
&lt;/profiles&gt; </blockquote></li><li>
Under <span class="codetext">&lt;build&gt;</span>, add the following section: <blockquote style="font-family: monospace">&lt;plugins&gt;<br />
    &lt;plugin&gt;<br />
        &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;<br />
        &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;<br />
    &lt;/plugin&gt;<br />
    &lt;plugin&gt;<br />
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br />
        &lt;configuration&gt;<br />
            &lt;source&gt;1.5&lt;/source&gt;<br />
            &lt;target&gt;1.5&lt;/target&gt;<br />
        &lt;/configuration&gt;<br />
    &lt;/plugin&gt;<br />
&lt;/plugins&gt;</blockquote></li></ul></li>
          <li>
You can now thank my colleague <a href="http://www.aviransplace.com/">Aviran Mordo</a> for
finding out this bit of Voodoo. :-) 
</li>
          <li>
In the command prompt, now enter the project directory 
</li>
          <li>
Type in <span class="codetext">mvn eclipse:m2eclipse -Dwtpversion=1.5</span> to create
an Eclipse project 
</li>
          <li>
Run Eclipse if it's not already started, then from the package explorer right click
anywhere and click on Import... 
</li>
          <li>
Choose General-&gt;Existing Projects into Workspace. For root directory pick the workspace
directory 
</li>
          <li>
Choose the new project and click on Finish 
</li>
          <li>
At this point you may encounter a "Java compiler level does not match the version
of the installed Java project facet" error. If that's the case, just right-click on
the error (in the Problems view) and select Quick Fix, which will allow you to change
the Java project facet version to 6.0. If this isn't what you want, you probably know
enough to resolve the issue on your own... 
</li>
          <li>
You'll need a <span class="codetext">src/main/java</span> directory as a root source
folder (as per the <a href="http://maven.apache.org/maven-1.x/reference/conventions.html">Maven
convention</a>). Right-click on the project, select New-&gt;Source Folder and type
in <span class="codetext">src/main/java</span>. 
</li>
          <li>
Finally, in order to execute or debug the project on an actual running server, right-click
on the new project and select Properties. From there go to the Server tab and select
the runtime you created in the previous chapter.</li>
        </ul>
        <p>
At this point you have a Maven web project with a corresponding Eclipse project ready
for editing in your workspace. In practice you will have to do several things to have
any meaningful results.
</p>
        <ol>
          <li>
Add your own code into the mix, such as a servlet. When adding a new servlet (via
right-clicking the project, New-&gt;Other and choosing Web-&gt;Servlet) your <span class="codetext">WEB.XML</span> file
is automatically updated with the new servlet. 
</li>
          <li>
Add your own dependencies. Maven handles dependencies quite well; for instance, in
order to actually create a servlet you're going to need <span class="codetext">servlet-api.jar</span> in
your classpath; the easiest way to do this is to right-click the project, select Maven-&gt;Add
Dependency and then simply type in servlet and choose <span class="codetext">javax.servlet
servlet-api</span>. 
</li>
          <li>
When you wish to run or debug your servlet, right-click on its Java file and select
Run As-&gt;Run on Server (or Debug, as appropriate). Your applet should be happily
up and running.</li>
        </ol>
        <p>
          <u>5. Converting an existing project to Maven</u>
        </p>
        <p>
I'm not sure how to go about doing this for web projects, but converting regular projects
to use Maven is actually pretty straightforward; move your sources to the appropriate
directories according to the <a href="http://maven.apache.org/maven-1.x/reference/conventions.html">Maven
conventions</a>, right-click the project in Eclipse and choose Maven-&gt;Enable Dependency
Management; this will implicitly create a Maven project descriptor for you (<span class="codetext">POM.XML</span>)
and that's pretty much it. From that point on your Eclipse and Maven projects should
peacefully coexist, allowing you to leverage both tools for your purposes.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=08ee53ca-6d1a-4406-a7c4-579f6414db2a" />
      </body>
      <title>Beginner's Guide to Web Development (or, Getting Eclipse, WTP, Tomcat and Maven to play along)</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,08ee53ca-6d1a-4406-a7c4-579f6414db2a.aspx</guid>
      <link>http://www.tomergabel.com/BeginnersGuideToWebDevelopmentOrGettingEclipseWTPTomcatAndMavenToPlayAlong.aspx</link>
      <pubDate>Wed, 05 Dec 2007 13:10:05 GMT</pubDate>
      <description>&lt;p&gt;
So you want a web project, a build system and a reasonable IDE to take care of the
annoying details for you, right? The good news are that it's actually quite possible
and there're many ways to do this. The bad news are that it's nigh impossible to get
them to play along if you don't already know how to do that. It took me days to find
a solution that finally seems to work, and I'd like to share it with you. I'm probably
missing a few important details or did something really really stupid along the way
(I'd appreciate comments!), but this process does seem to work. &lt;strong&gt;I'm not going
into essentials of Java-based web development here&lt;/strong&gt; -- if you want a more
basic explanation of the terminology, post a comment and I'll see what I can do...
&lt;/p&gt;
&lt;p&gt;
&lt;u&gt;1. Goal&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;
I want to:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Use a common, standard and powerful IDE to edit and debug my Java code, and preferably
provide a usable GUI interface for dependency and project management; 
&lt;li&gt;
Use a common, standard servlet container to host my servlet and still be able to control
and debug everything from the same IDE; 
&lt;li&gt;
Have a convenient way to handle internal-and-external dependencies without worrying
too much about the details; 
&lt;li&gt;
Be able to quickly compile, test and package my servlet for deployment; 
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Understand as little as possible about the dependency stack of the tools
involved&lt;/strong&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I'm going to tell you how to achieve most of these goals, with two glaring omissions:
I won't show you how to do testing (I haven't successfully managed servlet unit testing
so far -- different post on that) and I can't help but delve into some of the more
annoying details involved with these tools and their dependencies. Sorry about that.
Additionally, some of the information here applies even if you use different tools,
but you're bound to face issues not covered here; don't assume I know more than you
do -- seek the answers, post them somewhere, and maybe the next person will actually
find what they're looking for!
&lt;/p&gt;
&lt;p&gt;
&lt;u&gt;2. Tools&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;
The tools used are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://java.sun.com/javase/downloads/index.jsp"&gt;J2SE JDK&lt;/a&gt; is an obvious
must-have. Version used: JDK 6 update 3; 
&lt;li&gt;
&lt;a href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt; (but please don't download it just yet)
for code editing, debugging and project management; 
&lt;li&gt;
&lt;a href="http://www.eclipse.org/webtools/"&gt;Web Tools Platform&lt;/a&gt;: this is the Eclipse
plug-in that adds web development capabilities to the IDE, including J2EE dependency
management, hosting and running servlets from within the Eclipse workspace etc. This
would be a good time to run along to the &lt;a href="http://download.eclipse.org/webtools/downloads/"&gt;WTP
web-site&lt;/a&gt; and download the Web Tools Platform All-In-One package. I only used the
release version (2.0.1 at the time of writing this), so if you use another version
your mileage may vary; 
&lt;li&gt;
&lt;a href="http://maven.apache.org/"&gt;Apache Maven&lt;/a&gt; is the newfangled build system
from Apache slated to replace &lt;a href="http://ant.apache.org/"&gt;ant&lt;/a&gt;. I've used
it for the last few days and so far it appears to be quite robust and even fairly
well-integrated into Eclipse (see next item). Version used: 2.0.8; 
&lt;li&gt;
&lt;a href="http://m2eclipse.codehaus.org/"&gt;M2eclipse&lt;/a&gt; is the Eclipse plug-in for
Maven integration. I've only found one problem with it so far, which I'll detail later
on; 
&lt;li&gt;
&lt;a href="http://tomcat.apache.org/"&gt;Apache Tomcat&lt;/a&gt; is a solid choice in servlet
containers. It's robust, fast and open-source, and has terrific Eclipse integration.
I haven't given any of the other containers a serious whirl yet though.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;u&gt;3. Preparations&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;
Unlike Visual Studio, with the tools mentioned above there's no straightforward installation
procedure. You'll have to designate at least a workspace directory (where your Eclipse
projects, settings etc. go) and some location where the tools themselves go. For me,
it's C:\Dev\Eclipse and C:\Tools respectively.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Setting up Java: 
&lt;ul&gt;
&lt;li&gt;
Install the JDK and remember where it was installed (nominally in &lt;span class="codetext"&gt;%PROGRAMFILES%\Java\jdk1.6.0_03&lt;/span&gt;) 
&lt;li&gt;
Set up a system-wide &lt;span class="codetext"&gt;JAVA_HOME&lt;/span&gt; environment variable
pointing to the same directory&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
Setting up Maven and Tomcat: 
&lt;ul&gt;
&lt;li&gt;
Extract both archives to your designated directory (e.g. for Maven it would be &lt;span class="codetext"&gt;C:\Tools\apache-maven-2.0.8&lt;/span&gt;) 
&lt;li&gt;
Add the Maven bin directory to your &lt;span class="codetext"&gt;PATH&lt;/span&gt; environment
variable (user- or system-wide, depending on your preference) 
&lt;li&gt;
Add whichever J2EE libraries you desire from the Tomcat installation to your class-path.
If you have no idea what I'm talking about, you'll probably just want to set the &lt;span class="codetext"&gt;CLASSPATH&lt;/span&gt; environment
variable to your equivalent of &lt;span class="codetext"&gt;c:\tools\apache-tomcat-6.0.14\lib\servlet-api.jar;c:\tools\apache-tomcat-6.0.14\lib\jsp-api.jar&lt;/span&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
Setting up Eclipse: 
&lt;ul&gt;
&lt;li&gt;
Extract the WTP all-in-one package (which contains Eclipse itself) to your designated
directory (e.g. &lt;span class="codetext"&gt;C:\Tools\Eclipse&lt;/span&gt;) 
&lt;li&gt;
Load Eclipse and point it to your designated workspace location 
&lt;li&gt;
Install M2Eclipse: 
&lt;ul&gt;
&lt;li&gt;
Go to Help-&amp;gt;Software Updates-&amp;gt;Find and Install..., select "Search for new features
to install" and click Next 
&lt;li&gt;
Click on New Remote Site..., use M2eclipse or whatever for the name and &lt;a title="http://m2eclipse.codehaus.org/update/" href="http://m2eclipse.codehaus.org/update/"&gt;http://m2eclipse.codehaus.org/update/&lt;/a&gt; for
the URL 
&lt;li&gt;
Click on Finish and let Eclipse install the M2Eclipse plug-in&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
Set up a web server runtime for Eclipse to host your servlets in: 
&lt;ul&gt;
&lt;li&gt;
Open Window-&amp;gt;Preferences... 
&lt;li&gt;
Under Server select Installed Runtimes and click on Add... 
&lt;li&gt;
Choose (from Apache) the Apache Tomcat v6.0 runtime and click Next 
&lt;li&gt;
Enter the Apache installation directory (e.g. &lt;span class="codetext"&gt;C:\Tools\apache-tomcat-6.0.14&lt;/span&gt;)
in the appropriate location and click Finish&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;u&gt;4. Creating a new web project&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;
First off, you must create the actual project, directory structure etc. To do this:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Open a command prompt, go to your Eclipse workspace directory 
&lt;li&gt;
Decide on your Maven group and artifact IDs; it's worth noting that the artifact ID
is also the directory name for the project 
&lt;li&gt;
Type in &lt;span class="codetext"&gt;mvn archetype:create -DgroupId=&lt;strong&gt;your.group.id&lt;/strong&gt; -DartifactId=&lt;strong&gt;your.artifact.id&lt;/strong&gt; -DarchetypeArtifactId=maven-archetype-webapp &lt;/span&gt; 
&lt;li&gt;
You'll notice that a new directory was created under the workspace root 
&lt;li&gt;
Edit the Maven project descriptor &lt;span class="codetext"&gt;POM.XML&lt;/span&gt; in the newly
created directory: 
&lt;ul&gt;
&lt;li&gt;
Add (after the &lt;span class="codetext"&gt;&amp;lt;url&amp;gt;&lt;/span&gt; tag, although I'm not sure
the order matters) the following section: &lt;blockquote style="font-family: monospace"&gt;&amp;lt;profiles&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;profile&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;id&amp;gt;servlet&amp;lt;/id&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;activation&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;activeByDefault&amp;gt;false&amp;lt;/activeByDefault&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/activation&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;dependencies&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;groupId&amp;gt;javax.servlet&amp;lt;/groupId&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;artifactId&amp;gt;servlet-api&amp;lt;/artifactId&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;dependency&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;groupId&amp;gt;javax.servlet.jsp&amp;lt;/groupId&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;artifactId&amp;gt;jsp-api&amp;lt;/artifactId&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;version&amp;gt;2.1&amp;lt;/version&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/dependency&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/dependencies&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/profile&amp;gt;&lt;br&gt;
&amp;lt;/profiles&amp;gt; &lt;/blockquote&gt; 
&lt;li&gt;
Under &lt;span class="codetext"&gt;&amp;lt;build&amp;gt;&lt;/span&gt;, add the following section: &lt;blockquote style="font-family: monospace"&gt;&amp;lt;plugins&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.mortbay.jetty&amp;lt;/groupId&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-jetty-plugin&amp;lt;/artifactId&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;source&amp;gt;1.5&amp;lt;/source&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;target&amp;gt;1.5&amp;lt;/target&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br&gt;
&amp;lt;/plugins&amp;gt;&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
You can now thank my colleague &lt;a href="http://www.aviransplace.com/"&gt;Aviran Mordo&lt;/a&gt; for
finding out this bit of Voodoo. :-) 
&lt;li&gt;
In the command prompt, now enter the project directory 
&lt;li&gt;
Type in &lt;span class="codetext"&gt;mvn eclipse:m2eclipse -Dwtpversion=1.5&lt;/span&gt; to create
an Eclipse project 
&lt;li&gt;
Run Eclipse if it's not already started, then from the package explorer right click
anywhere and click on Import... 
&lt;li&gt;
Choose General-&amp;gt;Existing Projects into Workspace. For root directory pick the workspace
directory 
&lt;li&gt;
Choose the new project and click on Finish 
&lt;li&gt;
At this point you may encounter a "Java compiler level does not match the version
of the installed Java project facet" error. If that's the case, just right-click on
the error (in the Problems view) and select Quick Fix, which will allow you to change
the Java project facet version to 6.0. If this isn't what you want, you probably know
enough to resolve the issue on your own... 
&lt;li&gt;
You'll need a &lt;span class="codetext"&gt;src/main/java&lt;/span&gt; directory as a root source
folder (as per the &lt;a href="http://maven.apache.org/maven-1.x/reference/conventions.html"&gt;Maven
convention&lt;/a&gt;). Right-click on the project, select New-&amp;gt;Source Folder and type
in &lt;span class="codetext"&gt;src/main/java&lt;/span&gt;. 
&lt;li&gt;
Finally, in order to execute or debug the project on an actual running server, right-click
on the new project and select Properties. From there go to the Server tab and select
the runtime you created in the previous chapter.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
At this point you have a Maven web project with a corresponding Eclipse project ready
for editing in your workspace. In practice you will have to do several things to have
any meaningful results.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Add your own code into the mix, such as a servlet. When adding a new servlet (via
right-clicking the project, New-&amp;gt;Other and choosing Web-&amp;gt;Servlet) your &lt;span class="codetext"&gt;WEB.XML&lt;/span&gt; file
is automatically updated with the new servlet. 
&lt;li&gt;
Add your own dependencies. Maven handles dependencies quite well; for instance, in
order to actually create a servlet you're going to need &lt;span class="codetext"&gt;servlet-api.jar&lt;/span&gt; in
your classpath; the easiest way to do this is to right-click the project, select Maven-&amp;gt;Add
Dependency and then simply type in servlet and choose &lt;span class="codetext"&gt;javax.servlet
servlet-api&lt;/span&gt;. 
&lt;li&gt;
When you wish to run or debug your servlet, right-click on its Java file and select
Run As-&amp;gt;Run on Server (or Debug, as appropriate). Your applet should be happily
up and running.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&lt;u&gt;5. Converting an existing project to Maven&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;
I'm not sure how to go about doing this for web projects, but converting regular projects
to use Maven is actually pretty straightforward; move your sources to the appropriate
directories according to the &lt;a href="http://maven.apache.org/maven-1.x/reference/conventions.html"&gt;Maven
conventions&lt;/a&gt;, right-click the project in Eclipse and choose Maven-&amp;gt;Enable Dependency
Management; this will implicitly create a Maven project descriptor for you (&lt;span class="codetext"&gt;POM.XML&lt;/span&gt;)
and that's pretty much it. From that point on your Eclipse and Maven projects should
peacefully coexist, allowing you to leverage both tools for your purposes.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=08ee53ca-6d1a-4406-a7c4-579f6414db2a" /&gt;</description>
      <category>Development</category>
      <category>Development/Java</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=ac38738f-475d-4f04-ba64-aead90a9fb17</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,ac38738f-475d-4f04-ba64-aead90a9fb17.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In case it wasn't obvious, I've been doing some Java development lately. One of the
curious things about doing development in the Java world is that, whereas in the Microsoft
world you get a fairly complete tool-chain direct from a commercial vendor, in the
Java world you're pretty much <em>dependant </em>on the open-source ecosystem built
around the essential Java technologies: Sun defines the APIs, the community provides
the tools. In many ways this is really really cool: many Java tools like JUnit are
so absolutely groundbreaking that they found their way into the common development
idiom irrespective of language, and the availability of tools for just about any purpose
is a tremendous advantage (being able to choose freely between Resin, Jetty, Tomcat
or any other commercial container, for instance, is a huge boon).
</p>
        <p>
This diversity and community-centric development ecosystem definitely comes with a
price though. Java tools, even the high-profile ones such as Eclipse, are extremely
difficult to work with for the uninitiated, with a learning curve somewhat like that
of Linux: if you take the time to learn the tools you can do astounding things and
remain in complete control of the system, but the sheer context required to do even
the most trivial thing can be - and often is - daunting.
</p>
        <p>
I've been battling these tools on and off for the last few weeks and often end up
having to figure something out on my own. Unlike the .NET ecosystem, it's usually
quite difficult to find a blog post detailing a solution to a particular problem.
To that end I intend to document my successes - victories, if you will - over the
tool-chain, and also the problems I encounter and haven't been able to solve, in the
hope of helping others and maybe myself in the process. These posts will go under
the Development-&gt;Java category, and I'd really appreciate any comments on the solutions
(so that I can improve my own work) as well as the problems (so I can actually solve
them). Here's to hoping :-)
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=ac38738f-475d-4f04-ba64-aead90a9fb17" />
      </body>
      <title>Kickstarting the Java category on this blog</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,ac38738f-475d-4f04-ba64-aead90a9fb17.aspx</guid>
      <link>http://www.tomergabel.com/KickstartingTheJavaCategoryOnThisBlog.aspx</link>
      <pubDate>Wed, 05 Dec 2007 09:48:11 GMT</pubDate>
      <description>&lt;p&gt;
In case it wasn't obvious, I've been doing some Java development lately. One of the
curious things about doing development in the Java world is that, whereas in the Microsoft
world you get a fairly complete tool-chain direct from a commercial vendor, in the
Java world you're pretty much &lt;em&gt;dependant &lt;/em&gt;on the open-source ecosystem built
around the essential Java technologies: Sun defines the APIs, the community provides
the tools. In many ways this is really really cool: many Java tools like JUnit are
so absolutely groundbreaking that they found their way into the common development
idiom irrespective of language, and the availability of tools for just about any purpose
is a tremendous advantage (being able to choose freely between Resin, Jetty, Tomcat
or any other commercial container, for instance, is a huge boon).
&lt;/p&gt;
&lt;p&gt;
This diversity and community-centric development ecosystem definitely comes with a
price though. Java tools, even the high-profile ones such as Eclipse, are extremely
difficult to work with for the uninitiated, with a learning curve somewhat like that
of Linux: if you take the time to learn the tools you can do astounding things and
remain in complete control of the system, but the sheer context required to do even
the most trivial thing can be - and often is - daunting.
&lt;/p&gt;
&lt;p&gt;
I've been battling these tools on and off for the last few weeks and often end up
having to figure something out on my own. Unlike the .NET ecosystem, it's usually
quite difficult to find a blog post detailing a solution to a particular problem.
To that end I intend to document my successes - victories, if you will - over the
tool-chain, and also the problems I encounter and haven't been able to solve, in the
hope of helping others and maybe myself in the process. These posts will go under
the Development-&amp;gt;Java category, and I'd really appreciate any comments on the solutions
(so that I can improve my own work) as well as the problems (so I can actually solve
them). Here's to hoping :-)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=ac38738f-475d-4f04-ba64-aead90a9fb17" /&gt;</description>
      <category>Development</category>
      <category>Development/Java</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=d4925bdc-73dc-4832-b101-15b6b27b9fb7</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,d4925bdc-73dc-4832-b101-15b6b27b9fb7.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been developing software with .NET professionally for the last five years or
so, and aside from the occasional foray into other languages I've more or less specialized
in that environment. While merrily hacking away at our back-end here at Semingo, we've
recently made the decision to develop an aspect of said back-end in Java. As it's
always a good practice to keep an open mind and experiment with other technologies
I've happily accepted the challenge.
</p>
        <p>
After working with Java and its associated tools for the past three or so weeks I
have several observations to make:
</p>
        <ol>
          <li>
The prominent free Java IDE, <a href="http://www.eclipse.org/">Eclipse</a>, is actually
a very full featured and impressive platform but takes a lot of getting used to. Some
of the idioms and concepts are radically different than Visual Studio; for instance,
whereas in Visual Studio you'd create an "ASP.NET Application Project", in Eclipse
you create (or convert to) a dynamic web project and then add something called <em>facet</em> to
your project; for instance, a Dynamic Web Module facet allows you to easily create
and debug servlets, and the "Axis2 Web Services Core" facet allows you to create <a href="http://ws.apache.org/axis2/">Axis2</a>-based
web services and work on them from within your IDE. To actually make use of these
features, however, one needs to develop a pretty hefty knowledge base on the various
technologies involved (J2EE and servlets, servlet containers like Tomcat, WTP etc.) 
<br /></li>
          <li>
Eclipse is next-to-useless without some tinkering; in particular, what I originally
attributed to very immature web development plug-ins - the <a href="http://www.eclipse.org/webtools/">WTP</a> umbrella
project I already mentioned - turned out to be the default memory settings of the
Eclipse launcher. The launcher hosts the Java VM and its baseline configuration is
simply inadequate. In my case adding the following switches: <span class="codetext">-vmargs
-Xmx512M -XX:MaxPermSize=128M</span> to the command line resolved all of the problems
I had with the various WTP plug-ins, as well as the myriad crashes I've experienced
with the IDE. In fact it's rock-stable now.<br /></li>
          <li>
The Java language has some unexpected caveats; for instance, whereas in C# the designers
eschewed fall through in the <span class="codetext">switch</span> statement (you can
group labels to implementations, but you cannot fall through from the implementation
of one case statement to the next), the Java designers elected to maintain C-style
behavior. I'm of the belief that switch statement fall through is the cause of a huge
number of subtle, hard-to-find bugs, and was surprised to learn of this discrepancy
between the two languages.<br /></li>
          <li>
Enumerations in Java, a relatively new feature added in 1.5, are an <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html">impressively
diverse</a> feature which is a great deal more powerful than its C# counterpart. I
only wish the designers would also allow for a more simplified "SOME_CONSTANT = 3"
type syntax, as it's somewhat cumbersome to have to actually use constructors for
the purpose. Additionally Java does not (to my knowledge) support implicit conversion
operators, which makes necessary constructs such as <span class="codetext">SomeEnum.CONSTANT_VALUE.getConvertedValue()</span>.
It's not a huge issue but it's one of the many areas where syntactic sugar in C# is
useful.<br /></li>
          <li>
Speaking of syntactic sugar, there're several aspects where Java simply falls short
of C#: disposables, iterators and delegates. Yes, I know delegates are an essentially
religious issue for the Java designers (mostly for historical reasons, I suspect),
and I won't deny that anything you can do with delegates you can do with nested classes,
but at ridiculous verbosity. As for disposables, I find that the <span class="codetext">using</span> keyword
in C# is one of the most useful language constructs I've ever encountered, the use
of which goes way beyond the original intention of elegantly scoping unmanaged resource
use; finally, iterators are tremendously useful and cut a lot of unnecessary boilerplate
code out of the equation.<br /></li>
          <li>
The Java ecosystem is <em>riddled </em>with code- and buzz-words, to the point of
being annoying. If you thought .NET has too many sub-technologies and acronyms, you
should try Java. Just to get the taste buds going, here are some of the keywords I've
been messing with for the past couple of weeks: J2SE, J2EE, Servlet, Eclipse, WTP,
(Apache) Tomcat, Axis2, SAX, JAXP, JAX-RPC, JAR, WAR, AAR, EAR, JDBC, JavaDoc, JSP
and JavaBeans. And that's just off the top of my head! To someone with any sort of
Java experience this list wouldn't seem intimidating or even exhaustive, but to a
new-comer that's simply <strong>too much</strong>. There is also an import cultural
distinction: Visual Studio and its associated technologies (.NET, ASP.NET, ADO.NET
etc.) are designed to ease you in as you learn the ropes; I found it much easier to
simply start working with them and learn as I go, whereas with the Java counterparts
I usually found myself trying to rework code samples found on the 'net while scratching
my head.<br />
Now don't misunderstand me: the Java technologies are generally impressive, mature
and usable, but the learning curve is not nearly as comfortable as the competing technologies
from Microsoft, and the tools and documentation just aren't as polished.</li>
        </ol>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=d4925bdc-73dc-4832-b101-15b6b27b9fb7" />
      </body>
      <title>Working with Java</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,d4925bdc-73dc-4832-b101-15b6b27b9fb7.aspx</guid>
      <link>http://www.tomergabel.com/WorkingWithJava.aspx</link>
      <pubDate>Mon, 15 Oct 2007 14:00:15 GMT</pubDate>
      <description>&lt;p&gt;
I've been developing software with .NET professionally for the last five years or
so, and aside from the occasional foray into other languages I've more or less specialized
in that environment. While merrily hacking away at our back-end here at Semingo, we've
recently made the decision to develop an aspect of said back-end in Java. As it's
always a good practice to keep an open mind and experiment with other technologies
I've happily accepted the challenge.
&lt;/p&gt;
&lt;p&gt;
After working with Java and its associated tools for the past three or so weeks I
have several observations to make:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
The prominent free Java IDE, &lt;a href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt;, is actually
a very full featured and impressive platform but takes a lot of getting used to. Some
of the idioms and concepts are radically different than Visual Studio; for instance,
whereas in Visual Studio you'd create an "ASP.NET Application Project", in Eclipse
you create (or convert to) a dynamic web project and then add something called &lt;em&gt;facet&lt;/em&gt; to
your project; for instance, a Dynamic Web Module facet allows you to easily create
and debug servlets, and the "Axis2 Web Services Core" facet allows you to create &lt;a href="http://ws.apache.org/axis2/"&gt;Axis2&lt;/a&gt;-based
web services and work on them from within your IDE. To actually make use of these
features, however, one needs to develop a pretty hefty knowledge base on the various
technologies involved (J2EE and servlets, servlet containers like Tomcat, WTP etc.) 
&lt;br&gt;
&lt;li&gt;
Eclipse is next-to-useless without some tinkering; in particular, what I originally
attributed to very immature web development plug-ins - the &lt;a href="http://www.eclipse.org/webtools/"&gt;WTP&lt;/a&gt; umbrella
project I already mentioned - turned out to be the default memory settings of the
Eclipse launcher. The launcher hosts the Java VM and its baseline configuration is
simply inadequate. In my case adding the following switches: &lt;span class="codetext"&gt;-vmargs
-Xmx512M -XX:MaxPermSize=128M&lt;/span&gt; to the command line resolved all of the problems
I had with the various WTP plug-ins, as well as the myriad crashes I've experienced
with the IDE. In fact it's rock-stable now.&lt;br&gt;
&lt;li&gt;
The Java language has some unexpected caveats; for instance, whereas in C# the designers
eschewed fall through in the &lt;span class="codetext"&gt;switch&lt;/span&gt; statement (you can
group labels to implementations, but you cannot fall through from the implementation
of one case statement to the next), the Java designers elected to maintain C-style
behavior. I'm of the belief that switch statement fall through is the cause of a huge
number of subtle, hard-to-find bugs, and was surprised to learn of this discrepancy
between the two languages.&lt;br&gt;
&lt;li&gt;
Enumerations in Java, a relatively new feature added in 1.5, are an &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html"&gt;impressively
diverse&lt;/a&gt; feature which is a great deal more powerful than its C# counterpart. I
only wish the designers would also allow for a more simplified "SOME_CONSTANT = 3"
type syntax, as it's somewhat cumbersome to have to actually use constructors for
the purpose. Additionally Java does not (to my knowledge) support implicit conversion
operators, which makes necessary constructs such as &lt;span class="codetext"&gt;SomeEnum.CONSTANT_VALUE.getConvertedValue()&lt;/span&gt;.
It's not a huge issue but it's one of the many areas where syntactic sugar in C# is
useful.&lt;br&gt;
&lt;li&gt;
Speaking of syntactic sugar, there're several aspects where Java simply falls short
of C#: disposables, iterators and delegates. Yes, I know delegates are an essentially
religious issue for the Java designers (mostly for historical reasons, I suspect),
and I won't deny that anything you can do with delegates you can do with nested classes,
but at ridiculous verbosity. As for disposables, I find that the &lt;span class="codetext"&gt;using&lt;/span&gt; keyword
in C# is one of the most useful language constructs I've ever encountered, the use
of which goes way beyond the original intention of elegantly scoping unmanaged resource
use; finally, iterators are tremendously useful and cut a lot of unnecessary boilerplate
code out of the equation.&lt;br&gt;
&lt;li&gt;
The Java ecosystem is &lt;em&gt;riddled &lt;/em&gt;with code- and buzz-words, to the point of
being annoying. If you thought .NET has too many sub-technologies and acronyms, you
should try Java. Just to get the taste buds going, here are some of the keywords I've
been messing with for the past couple of weeks: J2SE, J2EE, Servlet, Eclipse, WTP,
(Apache) Tomcat, Axis2, SAX, JAXP, JAX-RPC, JAR, WAR, AAR, EAR, JDBC, JavaDoc, JSP
and JavaBeans. And that's just off the top of my head! To someone with any sort of
Java experience this list wouldn't seem intimidating or even exhaustive, but to a
new-comer that's simply &lt;strong&gt;too much&lt;/strong&gt;. There is also an import cultural
distinction: Visual Studio and its associated technologies (.NET, ASP.NET, ADO.NET
etc.) are designed to ease you in as you learn the ropes; I found it much easier to
simply start working with them and learn as I go, whereas with the Java counterparts
I usually found myself trying to rework code samples found on the 'net while scratching
my head.&lt;br&gt;
Now don't misunderstand me: the Java technologies are generally impressive, mature
and usable, but the learning curve is not nearly as comfortable as the competing technologies
from Microsoft, and the tools and documentation just aren't as polished.&lt;/li&gt;
&lt;/ol&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=d4925bdc-73dc-4832-b101-15b6b27b9fb7" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=acc91808-23c6-44a1-8fa0-e21274d1beea</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,acc91808-23c6-44a1-8fa0-e21274d1beea.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The Windows SDK command shell, <span class="codetext">setenv.cmd</span>, is immensely
useful, so much so that I wanted it as my default command prompt (i.e. when CMD is
run, no matter by whom). A quick Google search didn't turn out anything, so I eventually
figured it out myself. The trick is to add it to the command processor's AutoRun value
in the registry (run cmd /? from the command prompt if you don't know what I'm talking
about):
</p>
        <blockquote>
          <span class="codetext">reg add "HKCU\Software\Microsoft\Command Processor"
/v AutoRun /f /t REG_EXPAND_SZ /d "\"%programfiles%\Microsoft SDKs\Windows\v6.0\Bin\SetEnv.Cmd\"
/debug /x86 /vista" </span>
        </blockquote>
        <p>
You'll notice that I explicitly set the arguments for <span class="codetext">setenv.cmd</span>;
I can't explain it (nor bothered to delve into the script), but without these arguments
the script gets stuck along with the command prompt. You should obviously change the
values to your own environment.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=acc91808-23c6-44a1-8fa0-e21274d1beea" />
      </body>
      <title>Making the Windows SDK command shell your default one</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,acc91808-23c6-44a1-8fa0-e21274d1beea.aspx</guid>
      <link>http://www.tomergabel.com/MakingTheWindowsSDKCommandShellYourDefaultOne.aspx</link>
      <pubDate>Tue, 02 Oct 2007 19:18:28 GMT</pubDate>
      <description>&lt;p&gt;
The Windows SDK command shell, &lt;span class="codetext"&gt;setenv.cmd&lt;/span&gt;, is immensely
useful, so much so that I wanted it as my default command prompt (i.e. when CMD is
run, no matter by whom). A quick Google search didn't turn out anything, so I eventually
figured it out myself. The trick is to add it to the command processor's AutoRun value
in the registry (run cmd /? from the command prompt if you don't know what I'm talking
about):
&lt;/p&gt;
&lt;blockquote&gt;&lt;span class="codetext"&gt;reg add "HKCU\Software\Microsoft\Command Processor"
/v AutoRun /f /t REG_EXPAND_SZ /d "\"%programfiles%\Microsoft SDKs\Windows\v6.0\Bin\SetEnv.Cmd\"
/debug /x86 /vista" &lt;/span&gt;&lt;/blockquote&gt; 
&lt;p&gt;
You'll notice that I explicitly set the arguments for &lt;span class="codetext"&gt;setenv.cmd&lt;/span&gt;;
I can't explain it (nor bothered to delve into the script), but without these arguments
the script gets stuck along with the command prompt. You should obviously change the
values to your own environment.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=acc91808-23c6-44a1-8fa0-e21274d1beea" /&gt;</description>
      <category>Development</category>
      <category>Software</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=3389061f-c38b-4bff-8cf0-00f2312718a2</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,3389061f-c38b-4bff-8cf0-00f2312718a2.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Our test code makes extensive use of a lightweight web server implementation based
on the .NET 2.0 <span class="codetext">HttpListener</span> class (I'll write a separate
post on this, source code included, in the near future). The web server implementation
randomizes an incoming port and exposes its URI via a property; this is done for two
reasons: to avoid conflicts with other listeners on the machine, and to facilitate
multi-threading test runners (like <a href="http://www.testdriven.net/">TestDriven.NET</a>).
Even with a serial test-runner (like ReSharper's unit test driver, which is what most
of us at <a href="http://www.semingo.com">Semingo</a> use) this means that for an
average test suite a large number of web-server instances are initiated and disposed
of in very rapid succession. Our implementation creates each web server on its own
dedicated port (using <span class="codetext">Socket.Bind</span> to make sure that
the port is free), and closes the listener via <span class="codetext">HttpListener.Abort</span> when
the test ends.
</p>
        <p>
Although the entire test suite seems to run fine locally (both via ReSharper's test
runner and using NUnit-Console), at some point we started getting strange errors from
our <a href="http://www.lnbogen.com/ContinuousIntegrationAsQualityReflection.aspx">continuous
integration server</a>:
</p>
        <blockquote>
          <p>
            <span class="codetext">System.Net.HttpListenerException : Failed to listen on prefix
'http://+:40275/' because it conflicts with an existing registration on the machine.</span>
          </p>
        </blockquote>
        <p>
I verified this by running the tests with NUnit-Console on the CI server and it was
consistent (but only on that server). Since the only instances of <span class="codetext">HttpListener</span> used
throughout the test suite are those used by the test web servers, this means that <span class="codetext">HttpListener.Abort</span><strong>does
not properly unregister its own prefixes</strong>. Since the documentation for <span class="codetext">HttpListener</span> is
rather sparse and I couldn't find any mention of this issue on the web, I eventually
went the <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a> route. Check
out the Reflector decompiler output for both <span class="codetext">HttpListener.Dispose</span> (called
via <span class="codetext">Close</span>) and <span class="codetext">HttpListener.Abort</span> methods:
</p>
        <blockquote>
          <table cellspacing="0" cellpadding="5" border="1">
            <tbody>
              <tr>
                <td valign="top" width="200">
                  <p align="center">
                    <strong>
                      <span class="codetext">HttpListener.Dispose</span>
                    </strong>
                  </p>
                </td>
                <td valign="top" width="200">
                  <p align="center">
                    <strong>
                      <span class="codetext">HttpListener.Abort</span>
                    </strong>
                  </p>
                </td>
              </tr>
              <tr>
                <td valign="top" width="200">
                  <pre>
                    <span style="color: #0000ff">if</span> (<span style="color: #0000ff">this</span>.m_State
!= State.Closed) { <span style="color: #0000ff">this</span>.Stop(); <span style="color: #0000ff">this</span>.m_RequestHandleBound
= <span style="color: #0000ff">false</span>; <span style="color: #0000ff">this</span>.m_State
= State.Closed; }</pre>
                </td>
                <td valign="top" width="200">
                  <pre>
                    <span style="color: #0000ff">if</span> (<span style="color: #0000ff">this</span>.m_RequestQueueHandle
!= <span style="color: #0000ff">null</span>) { <span style="color: #0000ff">this</span>.m_RequestQueueHandle.Abort();
} <span style="color: #0000ff">this</span>.m_RequestHandleBound = <span style="color: #0000ff">false</span>; <span style="color: #0000ff">this</span>.m_State
= State.Closed;</pre>
                </td>
              </tr>
            </tbody>
          </table>
        </blockquote>
        <p>
The primary difference is the call to <span class="codetext">HttpListener.Stop</span>.
Here's a code snippet from that method:
</p>
        <blockquote>
          <pre>
            <span style="color: #0000ff">if</span> (<span style="color: #0000ff">this</span>.m_State
!= State.Stopped) { <span style="color: #0000ff">this</span>.RemoveAll(<span style="color: #0000ff">false</span>); <span style="color: #0000ff">this</span>.m_RequestQueueHandle.Close(); <span style="color: #0000ff">this</span>.m_RequestHandleBound
= <span style="color: #0000ff">false</span>; <span style="color: #0000ff">this</span>.m_State
= State.Stopped; <span style="color: #0000ff">this</span>.ClearDigestCache(); }</pre>
        </blockquote>
        <p>
I'll spare you the hunt and point the problem out. There are two tangible differences
between the two calls:
</p>
        <ol>
          <li>
            <span class="codetext">HttpListener.Close</span>
            <strong>closes</strong> the request
queue handle (which is used in calls to the native HTTP API) whereas <span class="codetext">HttpListener.Abort</span><strong>aborts </strong>it.
I didn't delve into this but the semantics seem to be the same as for the <span class="codetext">HttpListener</span> itself. 
</li>
          <li>
            <span class="codetext">HttpListener.Close</span> calls RemoveAll before disposing
of the queue handle, presumably in order to stop accepting incoming requests.</li>
        </ol>
        <p>
In order to solve the problem, you can either remove the prefixes manually, or call
the internal method like so:
</p>
        <blockquote>
          <pre class="code">listener.GetType().InvokeMember(<br /><span style="color: rgb(163,21,21)">"RemoveAll"</span>, <span style="color: rgb(43,145,175)">BindingFlags</span>.NonPublic
| <span style="color: rgb(43,145,175)">BindingFlags</span>.InvokeMethod | <span style="color: rgb(43,145,175)">BindingFlags</span>.Instance, <span style="color: rgb(0,0,255)">null</span>,
listener, <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,255)">object</span>[]
{ <span style="color: rgb(0,0,255)">false</span> } );</pre>
        </blockquote>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=3389061f-c38b-4bff-8cf0-00f2312718a2" />
      </body>
      <title>HttpListener.Abort does not unregister prefixes</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,3389061f-c38b-4bff-8cf0-00f2312718a2.aspx</guid>
      <link>http://www.tomergabel.com/HttpListenerAbortDoesNotUnregisterPrefixes.aspx</link>
      <pubDate>Tue, 25 Sep 2007 17:40:26 GMT</pubDate>
      <description>&lt;p&gt;
Our test code makes extensive use of a lightweight web server implementation based
on the .NET 2.0 &lt;span class="codetext"&gt;HttpListener&lt;/span&gt; class (I'll write a separate
post on this, source code included, in the near future). The web server implementation
randomizes an incoming port and exposes its URI via a property; this is done for two
reasons: to avoid conflicts with other listeners on the machine, and to facilitate
multi-threading test runners (like &lt;a href="http://www.testdriven.net/"&gt;TestDriven.NET&lt;/a&gt;).
Even with a serial test-runner (like ReSharper's unit test driver, which is what most
of us at &lt;a href="http://www.semingo.com"&gt;Semingo&lt;/a&gt; use) this means that for an
average test suite a large number of web-server instances are initiated and disposed
of in very rapid succession. Our implementation creates each web server on its own
dedicated port (using &lt;span class="codetext"&gt;Socket.Bind&lt;/span&gt; to make sure that
the port is free), and closes the listener via &lt;span class="codetext"&gt;HttpListener.Abort&lt;/span&gt; when
the test ends.
&lt;/p&gt;
&lt;p&gt;
Although the entire test suite seems to run fine locally (both via ReSharper's test
runner and using NUnit-Console), at some point we started getting strange errors from
our &lt;a href="http://www.lnbogen.com/ContinuousIntegrationAsQualityReflection.aspx"&gt;continuous
integration server&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;span class="codetext"&gt;System.Net.HttpListenerException : Failed to listen on prefix
'http://+:40275/' because it conflicts with an existing registration on the machine.&lt;/span&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I verified this by running the tests with NUnit-Console on the CI server and it was
consistent (but only on that server). Since the only instances of &lt;span class="codetext"&gt;HttpListener&lt;/span&gt; used
throughout the test suite are those used by the test web servers, this means that &lt;span class="codetext"&gt;HttpListener.Abort&lt;/span&gt; &lt;strong&gt;does
not properly unregister its own prefixes&lt;/strong&gt;. Since the documentation for &lt;span class="codetext"&gt;HttpListener&lt;/span&gt; is
rather sparse and I couldn't find any mention of this issue on the web, I eventually
went the &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt; route. Check
out the Reflector decompiler output for both &lt;span class="codetext"&gt;HttpListener.Dispose&lt;/span&gt; (called
via &lt;span class="codetext"&gt;Close&lt;/span&gt;) and &lt;span class="codetext"&gt;HttpListener.Abort&lt;/span&gt; methods:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;table cellspacing="0" cellpadding="5" border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;p align="center"&gt;
&lt;strong&gt;&lt;span class="codetext"&gt;HttpListener.Dispose&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="200"&gt;
&lt;p align="center"&gt;
&lt;strong&gt;&lt;span class="codetext"&gt;HttpListener.Abort&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;pre&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_State
!= State.Closed) { &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Stop(); &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_RequestHandleBound
= &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_State
= State.Closed; }&lt;/pre&gt;&lt;/td&gt;
&lt;td valign="top" width="200"&gt;
&lt;pre&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_RequestQueueHandle
!= &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) { &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_RequestQueueHandle.Abort();
} &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_RequestHandleBound = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_State
= State.Closed;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The primary difference is the call to &lt;span class="codetext"&gt;HttpListener.Stop&lt;/span&gt;.
Here's a code snippet from that method:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_State
!= State.Stopped) { &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.RemoveAll(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;); &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_RequestQueueHandle.Close(); &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_RequestHandleBound
= &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.m_State
= State.Stopped; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ClearDigestCache(); }&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
I'll spare you the hunt and point the problem out. There are two tangible differences
between the two calls:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;span class="codetext"&gt;HttpListener.Close&lt;/span&gt; &lt;strong&gt;closes&lt;/strong&gt; the request
queue handle (which is used in calls to the native HTTP API) whereas &lt;span class="codetext"&gt;HttpListener.Abort&lt;/span&gt; &lt;strong&gt;aborts &lt;/strong&gt;it.
I didn't delve into this but the semantics seem to be the same as for the &lt;span class="codetext"&gt;HttpListener&lt;/span&gt; itself. 
&lt;li&gt;
&lt;span class="codetext"&gt;HttpListener.Close&lt;/span&gt; calls RemoveAll before disposing
of the queue handle, presumably in order to stop accepting incoming requests.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
In order to solve the problem, you can either remove the prefixes manually, or call
the internal method like so:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;listener.GetType().InvokeMember(&lt;br&gt;
&lt;span style="color: rgb(163,21,21)"&gt;"RemoveAll"&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;BindingFlags&lt;/span&gt;.NonPublic
| &lt;span style="color: rgb(43,145,175)"&gt;BindingFlags&lt;/span&gt;.InvokeMethod | &lt;span style="color: rgb(43,145,175)"&gt;BindingFlags&lt;/span&gt;.Instance, &lt;span style="color: rgb(0,0,255)"&gt;null&lt;/span&gt;,
listener, &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;object&lt;/span&gt;[]
{ &lt;span style="color: rgb(0,0,255)"&gt;false&lt;/span&gt; } );&lt;/pre&gt;&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=3389061f-c38b-4bff-8cf0-00f2312718a2" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=3af1feae-7bd3-46a2-bb55-2cf131f43ba9</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,3af1feae-7bd3-46a2-bb55-2cf131f43ba9.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's actually pretty easy; get your web service up and running in axis, run <span class="codetext">svcutil.exe
http://someserver/someurl/someservice?wsdl</span> and you're good to go. Unless, of
course, you're trying to return arrays from the Java side (primitive arrays at least,
I didn't see much of a point testing with custom classes). Consider the following
contract:
</p>
        <blockquote>
          <pre>
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">interface</span> ServiceInterface
{ <span style="color: #0000ff"> int</span>[] doSomething( String someParameter );
}</pre>
        </blockquote>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
The generated WSDL looks something like this (edited for clarity... I hope):
</p>
        <blockquote>
          <pre>
            <span style="color: #0000ff">&lt;?</span>xml version="1.0" encoding="UTF-8"<span style="color: #0000ff">?&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">definitions</span><br /><span style="color: #ff0000">xmlns</span>:<span style="color: #ff0000">wsdl</span>=<span style="color: #0000ff">"http://schemas.xmlsoap.org/wsdl/"<br /></span><span style="color: #ff0000">xmlns</span>:<span style="color: #ff0000">xsd</span>=<span style="color: #0000ff">"http://www.w3.org/2001/XMLSchema"<br /></span><span style="color: #ff0000"> xmlns:soapenc</span>=<span style="color: #0000ff">"http://schemas.xmlsoap.org/soap/encoding/"</span><span style="color: #0000ff">&gt;<br /></span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">types</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">schema</span><span style="color: #ff0000">xmlns</span>=<span style="color: #0000ff">"http://www.w3.org/2001/XMLSchema"</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">import</span><span style="color: #ff0000">namespace</span>=<span style="color: #0000ff">"http://schemas.xmlsoap.org/soap/encoding/"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">complexType</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"ArrayOf_xsd_int"</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">complexContent</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">restriction</span><span style="color: #ff0000">base</span>=<span style="color: #0000ff">"soapenc:Array"</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">attribute</span><span style="color: #ff0000">ref</span>=<span style="color: #0000ff">"soapenc:arrayType"</span><span style="color: #ff0000">wsdl</span>:<span style="color: #ff0000">arrayType</span>=<span style="color: #0000ff">"xsd:int[]"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">restriction</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">complexContent</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">complexType</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">types</span><span style="color: #0000ff">&gt;<br /></span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">message</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"doSomethingResponse"</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">part</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"doSomethingReturn"</span><span style="color: #ff0000">type</span>=<span style="color: #0000ff">"impl:ArrayOf_xsd_int"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">message</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">message</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"doSomethingRequest"</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">part</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"someParameter"</span><span style="color: #ff0000">type</span>=<span style="color: #0000ff">"soapenc:string"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">message</span><span style="color: #0000ff">&gt;<br /></span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">portType</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"ServiceInterfaceService"</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">operation</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"doSomething"</span><span style="color: #ff0000">parameterOrder</span>=<span style="color: #0000ff">"someParameter"</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">input</span><span style="color: #ff0000">message</span>=<span style="color: #0000ff">"impl:doSomethingRequest"</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"doSomethingRequest"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">output</span><span style="color: #ff0000">message</span>=<span style="color: #0000ff">"impl:doSomethingResponse"</span><span style="color: #ff0000">name</span>=<span style="color: #0000ff">"doSomethingResponse"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">operation</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #c71585">wsdl</span>:<span style="color: #800000">portType</span><span style="color: #0000ff">&gt;</span></pre>
          <pre>
            <span style="color: #008000"> &lt;!--
More uninteresting stuff --&gt;</span>
            <span style="color: #0000ff">
              <br />
              <br />
            </span>
            <span style="color: #0000ff">
              <br />
              <br />
&lt;/</span>
            <span style="color: #c71585">wsdl</span>:<span style="color: #800000">definitions</span><span style="color: #0000ff">&gt;</span></pre>
        </blockquote>
        <p>
The WDSL is perfectly fine and is properly processed by Microsoft's <span class="codetext">svcutil.exe</span> tool;
the generated classes look and appear to function normally, but if you'll look at
the deserialized array on the client (.NET/WCF) side you'll find that the array has
been deserialized incorrectly, and <strong>all values in the array are 0</strong>.
You'll have to manually look at the SOAP response returned by Axis to figure out what's
wrong; here's a sample response (again, edited for clarity):
</p>
        <blockquote>
          <pre>
            <span style="color: #0000ff">&lt;?</span>xml version="1.0" encoding="UTF-8"<span style="color: #0000ff">?&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">soapenv</span>:<span style="color: #800000">Envelope</span><span style="color: #ff0000">xmlns</span>:<span style="color: #ff0000">soapenv</span>=<span style="color: #0000ff"><a href="http://schemas.xmlsoap.org/soap/envelope/">http://schemas.xmlsoap.org/soap/envelope/</a></span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #c71585">soapenv</span>:<span style="color: #800000">Body</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">doSomethingResponse</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000"><span style="color: #800000">doSomethingReturn</span></span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000"><span style="color: #800000">doSomethingReturn</span></span><span style="color: #ff0000">href</span>=<span style="color: #0000ff">"#id0"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000"><span style="color: #800000">doSomethingReturn</span></span><span style="color: #ff0000">href</span>=<span style="color: #0000ff">"#id1"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000"><span style="color: #800000">doSomethingReturn</span></span><span style="color: #ff0000">href</span>=<span style="color: #0000ff">"#id2"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000"><span style="color: #800000">doSomethingReturn</span></span><span style="color: #ff0000">href</span>=<span style="color: #0000ff">"#id3"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000"><span style="color: #800000">doSomethingReturn</span></span><span style="color: #ff0000">href</span>=<span style="color: #0000ff">"#id4"</span><span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000"><span style="color: #800000">doSomethingReturn</span></span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000"><span style="color: #800000">doSomethingResponse</span></span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">multiRef</span><span style="color: #ff0000">id</span>=<span style="color: #0000ff">"id4"</span><span style="color: #0000ff">&gt;</span>5<span style="color: #0000ff">&lt;/</span><span style="color: #800000">multiRef</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">multiRef</span><span style="color: #ff0000">id</span>=<span style="color: #0000ff">"id3"</span><span style="color: #0000ff">&gt;4</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">multiRef</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">multiRef</span><span style="color: #ff0000">id</span>=<span style="color: #0000ff">"id2"</span><span style="color: #0000ff">&gt;3</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">multiRef</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">multiRef</span><span style="color: #ff0000">id</span>=<span style="color: #0000ff">"id1"</span><span style="color: #0000ff">&gt;2</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">multiRef</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">multiRef</span><span style="color: #ff0000">id</span>=<span style="color: #0000ff">"id0"</span><span style="color: #0000ff">&gt;1</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">multiRef</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #c71585">soapenv</span>:<span style="color: #800000">Body</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #c71585">soapenv</span>:<span style="color: #800000">Envelope</span><span style="color: #0000ff">&gt;</span></pre>
        </blockquote>
        <p>
You'll notice that Axis does not generate values directly in the returned element,
but instead references external elements for values. This might make sense when there
are many references to relatively few discrete values, but whatever the case this
is not properly handled by the WCF <span class="codetext">basicHttpBinding</span> provider
(and reportedly by gSOAP and classic .NET web references as well).
</p>
        <p>
It took me a while to find a solution (after which I stumbled onto <a href="http://mail-archives.apache.org/mod_mbox/ws-axis-user/200406.mbox/%3CJMEEJJEOHBLPACIAPGKCOEJJCBAA.alex_chen@sbcglobal.net%3E">this
post</a>, which wasn't trivial to find): edit your Axis deployment's <span class="codetext">server-config.wsdd</span> file
and find the following parameter:
</p>
        <blockquote>
          <pre>
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">parameter</span>
            <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"sendMultiRefs"</span><span style="color: #ff0000">value</span>=<span style="color: #0000ff">"true"</span><span style="color: #0000ff">/&gt;</span></pre>
        </blockquote>
        <p>
Change it to <span class="codetext">false</span>, then redeploy via the command line,
which looks (under Windows) something like this:
</p>
        <blockquote>
          <span class="codetext">java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient
server-config.wsdl</span>
        </blockquote>
        <p>
The web service's response should now be deserializable by your .NET client.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=3af1feae-7bd3-46a2-bb55-2cf131f43ba9" />
      </body>
      <title>Getting WCF and Apache Axis to be friendly</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,3af1feae-7bd3-46a2-bb55-2cf131f43ba9.aspx</guid>
      <link>http://www.tomergabel.com/GettingWCFAndApacheAxisToBeFriendly.aspx</link>
      <pubDate>Tue, 18 Sep 2007 18:50:09 GMT</pubDate>
      <description>&lt;p&gt;
It's actually pretty easy; get your web service up and running in axis, run &lt;span class="codetext"&gt;svcutil.exe
http://someserver/someurl/someservice?wsdl&lt;/span&gt; and you're good to go. Unless, of
course, you're trying to return arrays from the Java side (primitive arrays at least,
I didn't see much of a point testing with custom classes). Consider the following
contract:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; ServiceInterface
{ &lt;span style="color: #0000ff"&gt; int&lt;/span&gt;[] doSomething( String someParameter );
}&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
The generated WSDL looks something like this (edited for clarity... I hope):
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;xml version="1.0" encoding="UTF-8"&lt;span style="color: #0000ff"&gt;?&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;definitions&lt;/span&gt; 
&lt;br&gt;
&lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;wsdl&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.xmlsoap.org/wsdl/"&lt;br&gt;
&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;xsd&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://www.w3.org/2001/XMLSchema"&lt;br&gt;
&lt;/span&gt;&lt;span style="color: #ff0000"&gt; xmlns:soapenc&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.xmlsoap.org/soap/encoding/"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;br&gt;
&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;types&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;schema&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://www.w3.org/2001/XMLSchema"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;import&lt;/span&gt; &lt;span style="color: #ff0000"&gt;namespace&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.xmlsoap.org/soap/encoding/"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;complexType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"ArrayOf_xsd_int"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;complexContent&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;restriction&lt;/span&gt; &lt;span style="color: #ff0000"&gt;base&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"soapenc:Array"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;attribute&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ref&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"soapenc:arrayType"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;arrayType&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"xsd:int[]"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;restriction&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;complexContent&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;complexType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;types&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;br&gt;
&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;message&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"doSomethingResponse"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;part&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"doSomethingReturn"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"impl:ArrayOf_xsd_int"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;message&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;message&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"doSomethingRequest"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;part&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"someParameter"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"soapenc:string"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;message&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;br&gt;
&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;portType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"ServiceInterfaceService"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;operation&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"doSomething"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;parameterOrder&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"someParameter"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;input&lt;/span&gt; &lt;span style="color: #ff0000"&gt;message&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"impl:doSomethingRequest"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"doSomethingRequest"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;output&lt;/span&gt; &lt;span style="color: #ff0000"&gt;message&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"impl:doSomethingResponse"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"doSomethingResponse"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;operation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;portType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: #008000"&gt; &amp;lt;!--
More uninteresting stuff --&amp;gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;span style="color: #0000ff"&gt;
&lt;br&gt;
&lt;br&gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585"&gt;wsdl&lt;/span&gt;:&lt;span style="color: #800000"&gt;definitions&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
The WDSL is perfectly fine and is properly processed by Microsoft's &lt;span class="codetext"&gt;svcutil.exe&lt;/span&gt; tool;
the generated classes look and appear to function normally, but if you'll look at
the deserialized array on the client (.NET/WCF) side you'll find that the array has
been deserialized incorrectly, and &lt;strong&gt;all values in the array are 0&lt;/strong&gt;.
You'll have to manually look at the SOAP response returned by Axis to figure out what's
wrong; here's a sample response (again, edited for clarity):
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;xml version="1.0" encoding="UTF-8"&lt;span style="color: #0000ff"&gt;?&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;soapenv&lt;/span&gt;:&lt;span style="color: #800000"&gt;Envelope&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;soapenv&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&lt;a href="http://schemas.xmlsoap.org/soap/envelope/"&gt;http://schemas.xmlsoap.org/soap/envelope/&lt;/a&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;soapenv&lt;/span&gt;:&lt;span style="color: #800000"&gt;Body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;doSomethingResponse&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;&lt;span style="color: #800000"&gt;doSomethingReturn&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;&lt;span style="color: #800000"&gt;doSomethingReturn&lt;/span&gt;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;href&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"#id0"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;&lt;span style="color: #800000"&gt;doSomethingReturn&lt;/span&gt;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;href&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"#id1"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;&lt;span style="color: #800000"&gt;doSomethingReturn&lt;/span&gt;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;href&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"#id2"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;&lt;span style="color: #800000"&gt;doSomethingReturn&lt;/span&gt;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;href&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"#id3"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;&lt;span style="color: #800000"&gt;doSomethingReturn&lt;/span&gt;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;href&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"#id4"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;&lt;span style="color: #800000"&gt;doSomethingReturn&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;&lt;span style="color: #800000"&gt;doSomethingResponse&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"id4"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;5&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"id3"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;4&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"id2"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;3&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"id1"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;2&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"id0"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;1&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;multiRef&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585"&gt;soapenv&lt;/span&gt;:&lt;span style="color: #800000"&gt;Body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #c71585"&gt;soapenv&lt;/span&gt;:&lt;span style="color: #800000"&gt;Envelope&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
You'll notice that Axis does not generate values directly in the returned element,
but instead references external elements for values. This might make sense when there
are many references to relatively few discrete values, but whatever the case this
is not properly handled by the WCF &lt;span class="codetext"&gt;basicHttpBinding&lt;/span&gt; provider
(and reportedly by gSOAP and classic .NET web references as well).
&lt;/p&gt;
&lt;p&gt;
It took me a while to find a solution (after which I stumbled onto &lt;a href="http://mail-archives.apache.org/mod_mbox/ws-axis-user/200406.mbox/%3CJMEEJJEOHBLPACIAPGKCOEJJCBAA.alex_chen@sbcglobal.net%3E"&gt;this
post&lt;/a&gt;, which wasn't trivial to find): edit your Axis deployment's &lt;span class="codetext"&gt;server-config.wsdd&lt;/span&gt; file
and find the following parameter:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parameter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"sendMultiRefs"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"true"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Change it to &lt;span class="codetext"&gt;false&lt;/span&gt;, then redeploy via the command line,
which looks (under Windows) something like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;span class="codetext"&gt;java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient
server-config.wsdl&lt;/span&gt;&lt;/blockquote&gt; 
&lt;p&gt;
The web service's response should now be deserializable by your .NET client.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=3af1feae-7bd3-46a2-bb55-2cf131f43ba9" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=0dd13c52-1a63-4913-af09-215ac2e76b22</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,0dd13c52-1a63-4913-af09-215ac2e76b22.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you have a WCF service that returns a stream to the caller, you should be extra-careful
with the source of these streams. In my case I was redirecting a file stream over
a MessageContract that looks something like this:
</p>
        <pre class="code">    [<span style="color: rgb(43,145,175)">MessageContract</span>] <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(43,145,175)">ItemInfo </span> {<br />
...</pre>
        <pre class="code">        [<span style="color: rgb(43,145,175)">MessageBodyMember</span>] <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(43,145,175)">Stream</span> ItemStream;
}</pre>
        <p>
It took one of the integration tests to fail... oddly to figure out that the stream
wasn't getting disposed of after the operation was completed. The solution appears
to be fairly simple, add the following lines to your service wrapper (if your concrete
implementation is WCF-aware you can always just stick this straight in the implementation
code):
</p>
        <pre class="code">
          <span style="color: rgb(0,128,0)">// Make sure stream gets
disposed at the end of the operation </span>
          <span style="color: rgb(43,145,175)">OperationContext</span>.Current.OperationCompleted
+= <span style="color: rgb(0,0,255)">delegate</span> { item.ItemStream.Dispose();
};</pre>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=0dd13c52-1a63-4913-af09-215ac2e76b22" />
      </body>
      <title>WCF and streams: Making sure your streams are disposed of</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,0dd13c52-1a63-4913-af09-215ac2e76b22.aspx</guid>
      <link>http://www.tomergabel.com/WCFAndStreamsMakingSureYourStreamsAreDisposedOf.aspx</link>
      <pubDate>Mon, 10 Sep 2007 12:40:15 GMT</pubDate>
      <description>&lt;p&gt;
If you have a WCF service that returns a stream to the caller, you should be extra-careful
with the source of these streams. In my case I was redirecting a file stream over
a MessageContract that looks something like this:
&lt;/p&gt;
&lt;pre class="code"&gt;    [&lt;span style="color: rgb(43,145,175)"&gt;MessageContract&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;ItemInfo &lt;/span&gt; {&lt;br&gt;
...&lt;/pre&gt;&lt;pre class="code"&gt;        [&lt;span style="color: rgb(43,145,175)"&gt;MessageBodyMember&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Stream&lt;/span&gt; ItemStream;
}&lt;/pre&gt;
&lt;p&gt;
It took one of the integration tests to fail... oddly to figure out that the stream
wasn't getting disposed of after the operation was completed. The solution appears
to be fairly simple, add the following lines to your service wrapper (if your concrete
implementation is WCF-aware you can always just stick this straight in the implementation
code):&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,128,0)"&gt;// Make sure stream
gets disposed at the end of the operation &lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;OperationContext&lt;/span&gt;.Current.OperationCompleted
+= &lt;span style="color: rgb(0,0,255)"&gt;delegate&lt;/span&gt; { item.ItemStream.Dispose();
};&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=0dd13c52-1a63-4913-af09-215ac2e76b22" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=fb6e88a4-d0e1-475e-9671-dd436535b6b9</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,fb6e88a4-d0e1-475e-9671-dd436535b6b9.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Installing Microsoft <a href="http://msdn2.microsoft.com/en-us/teamsystem/aa718825.aspx">Team
Foundation Server</a> is a ridiculously arduous and difficult process. I'll spare
you my own complaints and simply list the checklist for installing this beast. This
assumes you're installing TFS in a domain-enabled environment and in single-server
mode; this is the typical configuration for a small-to-medium-size organization:
</p>
        <ol>
          <li>
Designate a machine to host your Team Foundation Server repository. This machine <strong>must
not double as a domain controller </strong>as this configuration is not supported
by TFS. 
</li>
          <li>
Set up at two regular user accounts (<strong>not</strong> administrators, and if you
have any group policies you may - according to your configuration - want to keep these
users out of the relevant OUs) in your Active Directory. I used the trivial TFSService
and TFSReports accounts. Also you'll need a user with administrative privileges on
the target server; I personally prefer to avoid the associated headaches, so I simply
used a domain administrator user for installation purposes (but used the aforementioned
two users to set the beast up). 
</li>
          <li>
If necessary, install Windows 2003 Server (whatever flavor) on the machine; don't
forget the necessary service packs and updates. If your pipe is fat enough, just let
Windows Update do its magic. 
</li>
          <li>
Add an Application Server role, make sure you enable ASP.NET 2.0 during the installation
process 
</li>
          <li>
Install SQL Server 2005. Make sure you read the installation guide first though,
as you'll need to set it up to "Use the built-in System account," enable all
services except Notification and finally select Windows authentication as the
preferred authentication mechanism. You'll also need to let the SQL Server installer
install a bunch of prerequisites before actual installation begins. 
</li>
          <li>
Install SQL Server 2005 <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=d07219b2-1e23-49c8-8f0c-63fa18f26d3a&amp;DisplayLang=en">Service
Pack 2</a>. 
</li>
          <li>
From the TFS installation media, install hot-fix 913393 for .NET Framework. 
</li>
          <li>
Install <a href="http://www.microsoft.com/downloads/details.aspx?familyid=b922b28d-806a-427b-a4c5-ab0f1aa0f7f9&amp;displaylang=en">Windows
SharePoint Services 2.0 with Service Pack 2.0</a>. Make sure you select <strong>server
farm mode</strong> when installing, or you'll just have to redo the installation. 
</li>
          <li>
Install Team Foundation Server itself. 
</li>
          <li>
Back up the reporting services encryption key (you can find a description of the procedure <a href="http://msdn2.microsoft.com/en-us/library/ms400729(vs.80).aspx">here</a>). 
</li>
          <li>
Install hot-fix 919156, a.k.a the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=c18c756e-8f80-4987-b3bf-600068a9e3c4&amp;displaylang=en">Quiescence
GDR</a> (no, I have no idea what GDR stands for). 
</li>
          <li>
Install <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A9AB638C-04D2-4AEE-8AE8-9F00DD454AB8&amp;displaylang=en">Team
Foundation Server Service Pack 1</a>. 
</li>
          <li>
Make sure TCP port 8090 is open in your firewall software if you want web access to
your Team Foundation Server (to be honest, I haven't found any use for it yet.) 
</li>
          <li>
Install Team Explorer from the installation media (required for many add-ons, including
eScrum). 
</li>
          <li>
Install <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=BB4A75AB-E2D4-4C96-B39D-37BAF6B5B1DC&amp;displaylang=en">Visual
Studio 2005 Team Suite Service Pack 1</a>. This can, and will, take forever.</li>
        </ol>
        <p>
If at this point you're not thoroughly exhausted, you might want to set yourself up
a with a project. We're currently evaluating the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=55a4bde6-10a7-4c41-9938-f388c1ed15e9&amp;displaylang=en">Microsoft
eScrum</a> template for our purposes; my colleague <a href="http://www.lnbogen.com">Oren
Ellenbogen</a>, in his capacity as Scrum Master, will probably be posting his thoughts
on eScrum as a platform. In the meantime here's a quick list of solutions to problems
we've encountered while configuring the beast:
</p>
        <ol>
          <li>
Make sure you install the various prerequisites; in this case, .NET Framework 2.0,
IIS, TFS and Team Explorer, <a href="http://ajax.asp.net/Default.aspx?tabid=47">AJAX
Extensions 1.0</a> and the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=EFB9C819-53FF-4F82-BFAF-E11625130C25&amp;displaylang=en">Anti-Cross
Site Scripting Library</a></li>
          <li>
At this point you're liable to get a strange SharePoint-related error if you try and
create an eScrum-based project; if that's the case (or as a preemptive measure), just
run <span class="codetext">iisreset</span> on the TFS server. 
</li>
          <li>
If you can't seem to access the eScrum website (nominally at <em>http://yourserver/eScrum</em>)
you may have to reconfigure the eScrumAppPool identity from the IIS manager (right
click the application pool, chose Properties, go to the Identity tab and enter the
right information under Configurable) 
</li>
          <li>
You may also get 404 errors from the eScrum website even though it's very obviously
configured. We've found that the solution described <a href="http://dotnet.org.za/ahmeds/archive/2005/04/20/18451.aspx">here</a> works
as well: 
<ul><li>
From the command prompt, type <span class="codetext">cd "%ProgramFiles%\Common Files\Microsoft
Shared\Web Server Extensions\60\BIN"</span></li><li>
Run <span class="codetext">STSADM.EXE -o addpath -url http://localhost/eScrum -type
exclusion</span></li><li>
Run <span class="codetext">iisreset</span> again</li></ul></li>
          <li>
eScrum reports only update once every 1 hour. If this bothers you, follow the instructions <a href="http://blogs.vertigo.com/personal/steventap/Blog/Lists/Posts/Post.aspx?ID=24">here</a> to
reduce the lag.</li>
        </ol>
        <p>
Hope this saves someone out there a lot of time and headache (and if so, a comment
or e-mail is always appreciated...)
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=fb6e88a4-d0e1-475e-9671-dd436535b6b9" />
      </body>
      <title>How to install TFS and eScrum and remain (sort of) sane</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,fb6e88a4-d0e1-475e-9671-dd436535b6b9.aspx</guid>
      <link>http://www.tomergabel.com/HowToInstallTFSAndEScrumAndRemainSortOfSane.aspx</link>
      <pubDate>Mon, 13 Aug 2007 12:08:18 GMT</pubDate>
      <description>&lt;p&gt;
Installing Microsoft &lt;a href="http://msdn2.microsoft.com/en-us/teamsystem/aa718825.aspx"&gt;Team
Foundation Server&lt;/a&gt; is a ridiculously arduous and difficult process. I'll spare
you my own complaints and simply list the checklist for installing this beast. This
assumes you're installing TFS in a domain-enabled environment and in single-server
mode; this is the typical configuration for a small-to-medium-size organization:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Designate a machine to host your Team Foundation Server repository.&amp;nbsp;This machine&amp;nbsp;&lt;strong&gt;must
not double as a domain controller &lt;/strong&gt;as this configuration is not supported
by TFS. 
&lt;li&gt;
Set up at two regular user accounts (&lt;strong&gt;not&lt;/strong&gt; administrators, and if you
have any group policies you may - according to your configuration - want to keep these
users out of the relevant OUs) in your Active Directory. I used the trivial TFSService
and TFSReports accounts. Also you'll need a user with administrative privileges on
the target server; I personally prefer to avoid the associated headaches, so I simply
used a domain administrator user for installation purposes (but used the aforementioned
two users to set the beast up). 
&lt;li&gt;
If necessary, install Windows 2003 Server (whatever flavor) on the machine; don't
forget the necessary service packs and updates. If your pipe is fat enough, just let
Windows Update do its magic. 
&lt;li&gt;
Add an Application Server role, make sure you enable ASP.NET 2.0 during the installation
process 
&lt;li&gt;
Install SQL Server 2005.&amp;nbsp;Make sure you read the installation guide first&amp;nbsp;though,
as you'll need to set it up to "Use the built-in System account,"&amp;nbsp;enable all
services except&amp;nbsp;Notification and finally select Windows authentication as the
preferred authentication mechanism. You'll also need to let the SQL Server installer
install a bunch of prerequisites before actual installation begins. 
&lt;li&gt;
Install SQL Server 2005 &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=d07219b2-1e23-49c8-8f0c-63fa18f26d3a&amp;amp;DisplayLang=en"&gt;Service
Pack 2&lt;/a&gt;. 
&lt;li&gt;
From the TFS installation media, install hot-fix 913393&amp;nbsp;for .NET Framework. 
&lt;li&gt;
Install &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=b922b28d-806a-427b-a4c5-ab0f1aa0f7f9&amp;amp;displaylang=en"&gt;Windows
SharePoint Services 2.0 with Service Pack 2.0&lt;/a&gt;. Make sure you select &lt;strong&gt;server
farm mode&lt;/strong&gt; when installing, or you'll just have to redo the installation. 
&lt;li&gt;
Install Team Foundation Server itself. 
&lt;li&gt;
Back up the reporting services encryption key (you can find a description of the procedure &lt;a href="http://msdn2.microsoft.com/en-us/library/ms400729(vs.80).aspx"&gt;here&lt;/a&gt;). 
&lt;li&gt;
Install hot-fix 919156, a.k.a&amp;nbsp;the&amp;nbsp;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=c18c756e-8f80-4987-b3bf-600068a9e3c4&amp;amp;displaylang=en"&gt;Quiescence
GDR&lt;/a&gt; (no, I have no idea what GDR stands for). 
&lt;li&gt;
Install &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A9AB638C-04D2-4AEE-8AE8-9F00DD454AB8&amp;amp;displaylang=en"&gt;Team
Foundation Server Service Pack 1&lt;/a&gt;. 
&lt;li&gt;
Make sure TCP port 8090 is open in your firewall software if you want web access to
your Team Foundation Server (to be honest, I haven't found any use for it yet.) 
&lt;li&gt;
Install Team Explorer from the installation media (required for many add-ons, including
eScrum). 
&lt;li&gt;
Install &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=BB4A75AB-E2D4-4C96-B39D-37BAF6B5B1DC&amp;amp;displaylang=en"&gt;Visual
Studio 2005 Team Suite Service Pack 1&lt;/a&gt;. This can, and will, take forever.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
If at this point you're not thoroughly exhausted, you might want to set yourself up
a with a project. We're currently evaluating the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=55a4bde6-10a7-4c41-9938-f388c1ed15e9&amp;amp;displaylang=en"&gt;Microsoft
eScrum&lt;/a&gt; template for our purposes; my colleague &lt;a href="http://www.lnbogen.com"&gt;Oren
Ellenbogen&lt;/a&gt;, in his capacity as Scrum Master, will probably be posting his thoughts
on eScrum as a platform. In the meantime here's a quick list of solutions to problems
we've encountered while configuring the beast:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Make sure you install the various prerequisites; in this case, .NET Framework 2.0,
IIS, TFS and Team Explorer, &lt;a href="http://ajax.asp.net/Default.aspx?tabid=47"&gt;AJAX
Extensions 1.0&lt;/a&gt; and the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=EFB9C819-53FF-4F82-BFAF-E11625130C25&amp;amp;displaylang=en"&gt;Anti-Cross
Site Scripting Library&lt;/a&gt; 
&lt;li&gt;
At this point you're liable to get a strange SharePoint-related error if you try and
create an eScrum-based project; if that's the case (or as a preemptive measure), just
run &lt;span class="codetext"&gt;iisreset&lt;/span&gt; on the TFS server. 
&lt;li&gt;
If you can't seem to access the eScrum website (nominally at &lt;em&gt;http://yourserver/eScrum&lt;/em&gt;)
you may have to reconfigure the eScrumAppPool identity from the IIS manager (right
click the application pool, chose Properties, go to the Identity tab and enter the
right information under Configurable) 
&lt;li&gt;
You may also get 404 errors from the eScrum website even though it's very obviously
configured. We've found that the solution described &lt;a href="http://dotnet.org.za/ahmeds/archive/2005/04/20/18451.aspx"&gt;here&lt;/a&gt; works
as well: 
&lt;ul&gt;
&lt;li&gt;
From the command prompt, type &lt;span class="codetext"&gt;cd "%ProgramFiles%\Common Files\Microsoft
Shared\Web Server Extensions\60\BIN"&lt;/span&gt; 
&lt;li&gt;
Run &lt;span class="codetext"&gt;STSADM.EXE -o addpath -url http://localhost/eScrum -type
exclusion&lt;/span&gt; 
&lt;li&gt;
Run &lt;span class="codetext"&gt;iisreset&lt;/span&gt; again&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
eScrum reports only update once every 1 hour. If this bothers you, follow the instructions &lt;a href="http://blogs.vertigo.com/personal/steventap/Blog/Lists/Posts/Post.aspx?ID=24"&gt;here&lt;/a&gt; to
reduce the lag.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Hope this saves someone out there a lot of time and headache (and if so, a comment
or e-mail is always appreciated...)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=fb6e88a4-d0e1-475e-9671-dd436535b6b9" /&gt;</description>
      <category>Development</category>
      <category>Software</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=75500713-39c5-4a76-9ff3-b4d0136aafdf</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,75500713-39c5-4a76-9ff3-b4d0136aafdf.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Imagine that you work mostly with C#. Imagine that on occasion you sprinkle SQL, Java
and JavaScript into your daily routine, and that you also use the command line
a lot.
</p>
        <p>
Can you see the problem?
</p>
        <p>
Didn't think so. I'll clue you in: the last one in that list has one distinct difference
with the first four. <a href="http://www.youtube.com/watch?v=MiMWJ1xBo8w&amp;mode=related&amp;search=">Look
around you</a>. Have you found what we're looking for?
</p>
        <p>
That is correct. The answer is: the semicolon. A lightweight, generally meaningless
way to end a statement in most common languages. Arguably useless to users, arguably
beneficial to parsers, and the cause of almost half an hour of continuous head-scratching
by both programmer and DBA. How so?
</p>
        <blockquote>
          <p>
            <span class="codetext">C:\Temp&gt;mysql -C -usomeuser -phispassword thedatabase;<br />
ERROR 1044 (42000): Access denied for user 'someuser'@'%' to database 'thedatabase;'</span>
          </p>
        </blockquote>
        <p>
I'll let you draw your own conclusions.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=75500713-39c5-4a76-9ff3-b4d0136aafdf" />
      </body>
      <title>The risks of common languages</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,75500713-39c5-4a76-9ff3-b4d0136aafdf.aspx</guid>
      <link>http://www.tomergabel.com/TheRisksOfCommonLanguages.aspx</link>
      <pubDate>Wed, 18 Jul 2007 17:16:46 GMT</pubDate>
      <description>&lt;p&gt;
Imagine that you work mostly with C#. Imagine that on occasion you sprinkle SQL, Java
and&amp;nbsp;JavaScript into your daily routine, and that you also use the command line
a lot.
&lt;/p&gt;
&lt;p&gt;
Can you see the problem?
&lt;/p&gt;
&lt;p&gt;
Didn't think so. I'll clue you in: the last one in that list has one distinct difference
with the first four. &lt;a href="http://www.youtube.com/watch?v=MiMWJ1xBo8w&amp;amp;mode=related&amp;amp;search="&gt;Look
around you&lt;/a&gt;. Have you found what we're looking for?
&lt;/p&gt;
&lt;p&gt;
That is correct. The answer is: the semicolon. A lightweight, generally meaningless
way to end a statement in most common languages. Arguably useless to users, arguably
beneficial to parsers, and the cause of almost half an hour of continuous head-scratching
by both programmer and DBA. How so?
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;span class="codetext"&gt;C:\Temp&amp;gt;mysql -C -usomeuser -phispassword thedatabase;&lt;br&gt;
ERROR 1044 (42000): Access denied for user 'someuser'@'%' to database 'thedatabase;'&lt;/span&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I'll let you draw your own conclusions.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=75500713-39c5-4a76-9ff3-b4d0136aafdf" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=939f14a7-ebd3-42b9-a1ce-4b92ab03311b</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,939f14a7-ebd3-42b9-a1ce-4b92ab03311b.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been working with <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino
Mocks</a> for a couple of days now and I'm duly impressed. Aside from being generally
useful, the Rhino Mocks syntax is mostly natural and some very clever design hacks
are used to make it work the way you'd expect it to. (In case you don't know what
mocking frameworks are, the subject <a href="http://msdn.microsoft.com/msdnmag/issues/04/10/NMock/">has
been tackled</a><a href="http://www.mockobjects.com/files/endotesting.pdf">ad nauseam</a>.
Just take your pick.)
</p>
        <p>
There is one caveat that is not immediately visible in the <a href="http://www.ayende.com/Wiki/Default.aspx?Page=Rhino%20Mocks%20Record-playback%20Syntax">Record-Playback
syntax</a>, though:
</p>
        <blockquote>
          <pre>
            <span style="color: #0000ff">internal</span>
            <span style="color: #0000ff">interface</span> IFoo
{ <span style="color: #0000ff">int</span> Bar(); }</pre>
          <pre>[Test]
[ExpectedException( <span style="color: #0000ff">typeof</span>(
InvalidOperationException ), "<span style="color: #8b0000">Type 'System.Object' doesn't
match the return type <font color="#333333">" +</font><br /></span><span style="color: #8b0000"><font color="#333333">"</font>'System.Int32'
for method 'IFoo.Bar();'</span>" )] <span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> TestRecordSyntax_ReturnTypeMismatchBehavior()
{<br />
MockRepository mocks = <span style="color: #0000ff">new</span> MockRepository(); IFoo
mock = mocks.CreateMock&lt;IFoo&gt;(); <span style="color: #0000ff">using</span> (
mocks.Record() ) Expect.Call( mock.Bar() ).Return( <span style="color: #0000ff">new</span><span style="color: #0000ff">object</span>()
); }</pre>
        </blockquote>
        <p>
This simple test merely returns an incorrectly typed return value for the <span class="codetext">IFoo.Bar</span> method,
so with the <span class="codetext">ExpectedException</span> in place you'd expect
it to succeed, but you're in for a surprise:
</p>
        <blockquote>
          <p>
[failure] RecordPlaybackTests.TestSetup.ConsistentReturnTypeMismatchBehavior<br />
TestCase 'RecordPlaybackTests.TestSetup.ConsistentReturnTypeMismatchBehavior'<br />
failed: Exception of type 'MbUnit.Core.Exceptions.ExceptionExpectedMessageMismatchException'
was thrown. Expected exception message: "<strong>Type 'System.Object' doesn't match
the return type 'System.Int32' for method 'IFoo.Bar();</strong>'", got "<strong>Previous
method 'IFoo.Bar();' require a return value or an exception to throw.</strong>".
</p>
        </blockquote>
        <p>
To understand this, consider the following flow:
</p>
        <ol>
          <li>
A method call expectation is set (by calling <span class="codetext">mock.Bar()</span>) 
</li>
          <li>
Attempting to set a wrong return type results in the expected exception being thrown
from Rhino Mocks. This happens <em>before</em> the Return constraint is set 
</li>
          <li>
Because <span class="codetext">using</span> calls <span class="codetext">IDisposable.Dispose</span> in
the <span class="codetext">finally</span> block, the <span class="codetext">mocks.Record</span> object
calls <span class="codetext">mocks.ReplayAll()</span></li>
          <li>
            <span class="codetext">ReplayAll</span> asserts because a required expectation (return
value) is not yet set, masking the expected exception!</li>
        </ol>
        <p>
This is in fact how I first encountered this behavior, however there are several scenarios
where this can happen. One example: setting up a return value that throws an exception
on construction, possibly due to invalid arguments, causes the same behavior thereby
masking the true cause of the error.
</p>
        <p>
An alternative syntax suggested by <a href="http://www.ayende.com">Ayende</a> (author
of Rhino Mocks) is:
</p>
        <pre>    With.Mocks( <span style="color: #0000ff">delegate</span> { Expect.Call( mock.Bar()
).Return( <span style="color: #0000ff">new</span><span style="color: #0000ff">object</span>()
); } ); </pre>
        <p>
Aside from the esthetical aspect (i.e. butt-ugly), this syntax introduces a minor
issue: you cannot Edit-and-Continue methods with anonymous delegates. This may not
be a big deal for test code but it's worth noting.
</p>
        <p>
All in all I don't consider this a big issue, but it can bite and should
therefore be understood and documented. This post will be reflected in the <a href="http://www.ayende.com/Wiki/Rhino+Mocks.ashx">Rhino
Mocks wiki</a> shortly and will hopefully save someone a little grief in the future...
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=939f14a7-ebd3-42b9-a1ce-4b92ab03311b" />
      </body>
      <title>Beware the using pattern with Rhino Mocks</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,939f14a7-ebd3-42b9-a1ce-4b92ab03311b.aspx</guid>
      <link>http://www.tomergabel.com/BewareTheUsingPatternWithRhinoMocks.aspx</link>
      <pubDate>Mon, 09 Jul 2007 05:53:40 GMT</pubDate>
      <description>&lt;p&gt;
I've been working with &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino
Mocks&lt;/a&gt; for a couple of days now and I'm duly impressed. Aside from being generally
useful, the Rhino Mocks syntax is mostly natural and some very clever design hacks
are used to make it work the way you'd expect it to. (In case you don't know what
mocking frameworks are, the subject &lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/10/NMock/"&gt;has
been tackled&lt;/a&gt; &lt;a href="http://www.mockobjects.com/files/endotesting.pdf"&gt;ad nauseam&lt;/a&gt;.
Just take your pick.)
&lt;/p&gt;
&lt;p&gt;
There is one caveat that is not immediately visible in the &lt;a href="http://www.ayende.com/Wiki/Default.aspx?Page=Rhino%20Mocks%20Record-playback%20Syntax"&gt;Record-Playback
syntax&lt;/a&gt;, though:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IFoo
{ &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Bar(); }&lt;/pre&gt;&lt;pre&gt;[Test]
[ExpectedException( &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(
InvalidOperationException ), "&lt;span style="color: #8b0000"&gt;Type 'System.Object' doesn't
match the return type &lt;font color="#333333"&gt;" +&lt;/font&gt;
&lt;br&gt;
&lt;/span&gt;&lt;span style="color: #8b0000"&gt; &lt;font color="#333333"&gt;"&lt;/font&gt;'System.Int32'
for method 'IFoo.Bar();'&lt;/span&gt;" )] &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestRecordSyntax_ReturnTypeMismatchBehavior()
{&lt;br&gt;
MockRepository mocks = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MockRepository(); IFoo
mock = mocks.CreateMock&amp;lt;IFoo&amp;gt;(); &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (
mocks.Record() ) Expect.Call( mock.Bar() ).Return( &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;()
); }&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This simple test merely returns an incorrectly typed return value for the &lt;span class="codetext"&gt;IFoo.Bar&lt;/span&gt; method,
so with the &lt;span class="codetext"&gt;ExpectedException&lt;/span&gt; in place you'd expect
it to succeed, but you're in for a surprise:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
[failure] RecordPlaybackTests.TestSetup.ConsistentReturnTypeMismatchBehavior&lt;br&gt;
TestCase 'RecordPlaybackTests.TestSetup.ConsistentReturnTypeMismatchBehavior'&lt;br&gt;
failed: Exception of type 'MbUnit.Core.Exceptions.ExceptionExpectedMessageMismatchException'
was thrown. Expected exception message: "&lt;strong&gt;Type 'System.Object' doesn't match
the return type 'System.Int32' for method 'IFoo.Bar();&lt;/strong&gt;'", got "&lt;strong&gt;Previous
method 'IFoo.Bar();' require a return value or an exception to throw.&lt;/strong&gt;".
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
To understand this, consider the following flow:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
A method call expectation is set (by calling &lt;span class="codetext"&gt;mock.Bar()&lt;/span&gt;) 
&lt;li&gt;
Attempting to set a wrong return type results in the expected exception being thrown
from Rhino Mocks. This happens &lt;em&gt;before&lt;/em&gt; the Return constraint is set 
&lt;li&gt;
Because &lt;span class="codetext"&gt;using&lt;/span&gt; calls &lt;span class="codetext"&gt;IDisposable.Dispose&lt;/span&gt; in
the &lt;span class="codetext"&gt;finally&lt;/span&gt; block, the &lt;span class="codetext"&gt;mocks.Record&lt;/span&gt; object
calls &lt;span class="codetext"&gt;mocks.ReplayAll()&lt;/span&gt; 
&lt;li&gt;
&lt;span class="codetext"&gt;ReplayAll&lt;/span&gt; asserts because a required expectation (return
value) is not yet set, masking the expected exception!&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
This is in fact how I first encountered this behavior, however there are several scenarios
where this can happen. One example: setting up a return value that throws an exception
on construction, possibly due to invalid arguments, causes the same behavior thereby
masking the true cause of the error.
&lt;/p&gt;
&lt;p&gt;
An alternative syntax suggested by &lt;a href="http://www.ayende.com"&gt;Ayende&lt;/a&gt; (author
of Rhino Mocks) is:
&lt;/p&gt;
&lt;pre&gt;    With.Mocks( &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt; { Expect.Call( mock.Bar()
).Return( &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;()
); } ); &lt;/pre&gt;
&lt;p&gt;
Aside from the esthetical aspect (i.e. butt-ugly),&amp;nbsp;this syntax introduces a minor
issue: you cannot Edit-and-Continue methods with anonymous delegates. This may not
be a big deal for test code but it's worth noting.
&lt;/p&gt;
&lt;p&gt;
All in all I don't consider this&amp;nbsp;a big issue, but it can&amp;nbsp;bite and should
therefore be understood and documented. This post will be reflected in the &lt;a href="http://www.ayende.com/Wiki/Rhino+Mocks.ashx"&gt;Rhino
Mocks wiki&lt;/a&gt; shortly and will hopefully save someone a little grief in the future...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=939f14a7-ebd3-42b9-a1ce-4b92ab03311b" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=f5915b65-3486-44c4-bf0c-5db4bea21e52</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,f5915b65-3486-44c4-bf0c-5db4bea21e52.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.tomergabel.com/content/binary/PicasaWebDownloader12.zip">Quick
download link</a> (v1.2)
</p>
        <p>
I wanted to simple way to download an entire <a href="http://picasaweb.google.com">PicasaWeb</a> album.
Right-click and save simply will not do, installing the <a href="http://picasa.google.com/">Picasa</a> application
is completely out of the question (I use <a href="http://www.faststone.org/">FastStone</a>,
in case you were wondering) and I couldn't find any easy way of doing this, so I whipped
up a quick and dirty application. It's pretty self-explanatory, really:
</p>
        <p align="center">
          <a href="http://www.tomergabel.com/content/binary/WindowsLiveWriter/PicasaWebDownloader_2BEF/picasawebdownloader.png" atomicselection="true">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="161" alt="picasawebdownloader" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/PicasaWebDownloader_2BEF/picasawebdownloader_thumb.png" width="320" border="0" />
          </a>
        </p>
        <p>
Download the application (source included) <a href="http://www.tomergabel.com/content/binary/PicasaWebDownloader11.zip">here</a>.
</p>
        <p>
I also used the chance to give <a href="http://www.icsharpcode.net/OpenSource/SD/">#Develop</a> a
serious whirl, and I can honestly say that it's damn impressive; in several hours
of use the only real qualms I've had with it are the non-configurable keyboard
bindings (at least I couldn't find any configuration menu for this; it wouldn't be
an issue if the default bindings weren't slightly different from what I'm used to)
and the lack of immediate/watch debug windows. The dialog editor is full-featured
and the environment seems to be quite responsive and robust. I really am impressed.
</p>
        <p>
          <strong>
            <u>Update (20-Aug-2007)</u>
          </strong>: Version 1.1 is now downloadable. I've
added support for AuthKeys (as per <a href="http://skolima.jogger.pl/">skolima</a>'s
request) so you should now be able to download private albums as well (assuming you
have the appropriate key). Also added a compiled binary to the archive, doh!
</p>
        <p>
          <strong>
            <u>Update (11-Sep-2008)</u>
          </strong>: Version 1.2 is available for download,
and includes the following improvements: 
</p>
        <ul>
          <li>
The tool now works for PicasaWeb albums from any valid top-level domain (this means
that albums hosted at www.picasaweb.ru will be properly handled.</li>
          <li>
Existing files will not be overwritten; instead I've taken a cue from common browsers
and am now adding a counter suffix to the filename. If an album has two pictures with
the name <tt>example.jpg</tt>, you can now expect to find two files named <tt>example.jpg</tt> and <tt>example
(2).jpg</tt> in your directory. This behavior is also applied if you already have
such a file in your directory prior to running the tool - any feedback as to whether
or not this is desirable will be appreciated!</li>
          <li>
Authentication keys may now include dashes (thanks, <a href="http://qboosh.pl/">Jakob</a>).</li>
        </ul>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=f5915b65-3486-44c4-bf0c-5db4bea21e52" />
      </body>
      <title>PicasaWeb Downloader</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,f5915b65-3486-44c4-bf0c-5db4bea21e52.aspx</guid>
      <link>http://www.tomergabel.com/PicasaWebDownloader.aspx</link>
      <pubDate>Sun, 01 Jul 2007 00:28:06 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.tomergabel.com/content/binary/PicasaWebDownloader12.zip"&gt;Quick
download link&lt;/a&gt;&amp;nbsp;(v1.2)
&lt;/p&gt;
&lt;p&gt;
I wanted to simple way to download an entire &lt;a href="http://picasaweb.google.com"&gt;PicasaWeb&lt;/a&gt; album.
Right-click and save simply will not do, installing the &lt;a href="http://picasa.google.com/"&gt;Picasa&lt;/a&gt; application
is completely out of the question (I use &lt;a href="http://www.faststone.org/"&gt;FastStone&lt;/a&gt;,
in case you were wondering) and I couldn't find any easy way of doing this, so I whipped
up a quick and dirty application. It's pretty self-explanatory, really:
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.tomergabel.com/content/binary/WindowsLiveWriter/PicasaWebDownloader_2BEF/picasawebdownloader.png" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="161" alt="picasawebdownloader" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/PicasaWebDownloader_2BEF/picasawebdownloader_thumb.png" width="320" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Download the application (source included) &lt;a href="http://www.tomergabel.com/content/binary/PicasaWebDownloader11.zip"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
I also used the chance to give &lt;a href="http://www.icsharpcode.net/OpenSource/SD/"&gt;#Develop&lt;/a&gt; a
serious whirl, and I can honestly say that it's damn impressive; in several hours
of use the only real&amp;nbsp;qualms I've had with it are the&amp;nbsp;non-configurable keyboard
bindings (at least I couldn't find any configuration menu for this; it wouldn't be
an issue if the default bindings weren't slightly different from what I'm used to)
and the lack of immediate/watch debug windows. The dialog editor is full-featured
and the environment seems to be quite responsive and robust. I really am impressed.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;u&gt;Update (20-Aug-2007)&lt;/u&gt;&lt;/strong&gt;: Version 1.1 is now downloadable. I've
added support for AuthKeys (as per &lt;a href="http://skolima.jogger.pl/"&gt;skolima&lt;/a&gt;'s
request) so you should now be able to download private albums as well (assuming you
have the appropriate key).&amp;nbsp;Also added a compiled binary to the archive, doh!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;u&gt;Update (11-Sep-2008)&lt;/u&gt;&lt;/strong&gt;: Version 1.2 is available for download,
and includes the following improvements: 
&lt;ul&gt;
&lt;li&gt;
The tool now works for PicasaWeb albums from any valid top-level domain (this means
that albums hosted at www.picasaweb.ru will be properly handled.&lt;/li&gt;
&lt;li&gt;
Existing files will not be overwritten; instead I've taken a cue from common browsers
and am now adding a counter suffix to the filename. If an album has two pictures with
the name &lt;tt&gt;example.jpg&lt;/tt&gt;, you can now expect to find two files named &lt;tt&gt;example.jpg&lt;/tt&gt; and &lt;tt&gt;example
(2).jpg&lt;/tt&gt; in your directory. This behavior is also applied if you already have
such a file in your directory prior to running the tool - any feedback as to whether
or not this is desirable will be appreciated!&lt;/li&gt;
&lt;li&gt;
Authentication keys may now include dashes (thanks, &lt;a href="http://qboosh.pl/"&gt;Jakob&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;
&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=f5915b65-3486-44c4-bf0c-5db4bea21e52" /&gt;</description>
      <category>Development</category>
      <category>Software</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=8a75a79a-19cb-42dc-8de3-49e827bce201</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,8a75a79a-19cb-42dc-8de3-49e827bce201.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
My brother was going on and on about a coding challenge he found as part of the "<a href="http://www.flownet.com/ron/papers/lisp-java/">Lisp
as an Alternative to Java</a>" study (the challenge instructions are outlined <a href="http://www.flownet.com/ron/papers/lisp-java/instructions.html">here</a>,
and you can find the sample dictionary and input data by following the study link);
eventually I agreed to give it a try.
</p>
        <p>
          <strong>
            <u>Spoiler alert: Do not read on if you want to take on this challenge!</u>
          </strong>
        </p>
        <p>
Although I had to stop in the middle because I had company, the initial (hacked-together,
very inefficient and completely uncommented C# 2.0 code) version took me 1 hour and
20 minutes. While technically correct this version performed abysmally, but it
served as a good basis for further optimizations; a second, optimized version took
another 30 minutes and with another 20 or so minutes to clean it up, the final version
took a grand total of <strong>2 hours and 20 minutes</strong>. Total length is 193
lines of code (including comments and white-space), which you can <a href="http://www.tomergabel.com/content/binary/LispChallenge.zip">find
here</a>.
</p>
        <p>
The crux of the solution is a very simple tree structure to hold the word dictionary.
Each node has a 10-entry branch table, each entry representing a phone digit; a node
can have an arbitrary number of leaves, each leaf representing a dictionary word.
This allows for a very simple (and hopefully efficient) inner search loop:
</p>
        <ul>
          <li>
Use successive digits as indices for traversal into the tree; 
</li>
          <li>
When a node with leaves is encountered, the leaves (dictionary words) are added to
the potential result set. The rest of the input is then recursively encoded; 
</li>
          <li>
If no leaves are encountered for the entire input set, a digit is added to the encoded
string and the rest of the input is again encoded. A boolean flag is passed along
with the recursion to make sure two consecutive digits are never encoded.</li>
        </ul>
        <p>
This is basically a prefix tree (or <a href="http://en.wikipedia.org/wiki/Prefix_tree">trie</a>).
With the provided dictionary and input sets, runtime on my 1.7GHz Pentium M-equipped
laptop is approximately three seconds. I haven't properly profiled the application
for CPU and memory utilization because, frankly, it's good enough. There's also a
lot of leeway for optimizations: the current tree implementation is woefully inefficient,
as tree traversal can result in additional memory pressure.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=8a75a79a-19cb-42dc-8de3-49e827bce201" />
      </body>
      <title>Fun coding challenge</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,8a75a79a-19cb-42dc-8de3-49e827bce201.aspx</guid>
      <link>http://www.tomergabel.com/FunCodingChallenge.aspx</link>
      <pubDate>Sat, 09 Jun 2007 22:57:22 GMT</pubDate>
      <description>&lt;p&gt;
My brother was going on and on about a coding challenge he found as part of the "&lt;a href="http://www.flownet.com/ron/papers/lisp-java/"&gt;Lisp
as an Alternative to Java&lt;/a&gt;" study (the challenge instructions are outlined &lt;a href="http://www.flownet.com/ron/papers/lisp-java/instructions.html"&gt;here&lt;/a&gt;,
and you can find the sample dictionary and input data by following the study link);
eventually I agreed to give it a try.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;u&gt;Spoiler alert: Do not read on if you want to take on this challenge!&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Although I had to stop in the middle because I had company, the initial (hacked-together,
very inefficient and completely uncommented C# 2.0 code) version took me 1 hour and
20 minutes. While technically correct this version&amp;nbsp;performed abysmally, but it
served as a good basis for further optimizations; a second, optimized version took
another 30 minutes and with another 20 or so minutes to clean it up, the final version
took a grand total of &lt;strong&gt;2 hours and 20 minutes&lt;/strong&gt;. Total length is 193
lines of code (including comments and white-space), which you can &lt;a href="http://www.tomergabel.com/content/binary/LispChallenge.zip"&gt;find
here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The crux of the solution is a very simple tree structure to hold the word dictionary.
Each node has a 10-entry branch table, each entry representing a phone digit; a node
can have an arbitrary number of leaves, each leaf representing a dictionary word.
This allows for a very simple (and hopefully efficient) inner search loop:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Use successive digits as indices for traversal into the tree; 
&lt;li&gt;
When a node with leaves is encountered, the leaves (dictionary words) are added to
the potential result set. The rest of the input is then recursively encoded; 
&lt;li&gt;
If no leaves are encountered for the entire input set, a digit is added to the encoded
string and the rest of the input is again encoded. A boolean flag is passed along
with the recursion to make sure two consecutive digits are never encoded.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
This is basically a prefix tree (or &lt;a href="http://en.wikipedia.org/wiki/Prefix_tree"&gt;trie&lt;/a&gt;).
With the provided dictionary and input sets, runtime on my 1.7GHz Pentium M-equipped
laptop is approximately three seconds. I haven't properly profiled the application
for CPU and memory utilization because, frankly, it's good enough. There's also a
lot of leeway for optimizations: the current tree implementation is woefully inefficient,
as tree traversal can result in additional memory pressure.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=8a75a79a-19cb-42dc-8de3-49e827bce201" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=7577aed0-917a-4c35-810d-a0c47b558211</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,7577aed0-917a-4c35-810d-a0c47b558211.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
With my project finally nearing completion, it's nigh time for Microsoft to release
yet another update to the .NET Compact Framework 2.0. <a href="http://www.microsoft.com/downloads/details.aspx?familyid=aea55f2f-07b5-4a8c-8a44-b4e1b196d5c0&amp;displaylang=en">Service
Pack 2</a> ought to bring it to about "beta 2" level.
</p>
        <p>
Check out these gems:
</p>
        <span>
          <ul>
            <li>
NETCF deadlocks on exit if native callback delegate has been called on native thread
(<em>this is one of the few bugs in the CF I </em>haven't<em> encountered. Ironic,
considering we make heavy use of native code in our project.</em>)</li>
            <li>
              <span>Access violation marshaling a class with a string field (<em>there is a dent
in the nearby wall on account of this one.</em>)</span>
            </li>
            <li>
TypeLoadException using generics with NETCF 2.0 (<em>TypeLoadExceptions in general
are a lot of fun in the CF.)</em></li>
            <span>
              <span>
                <li>
Installing multiple locales of same MSI results in multiple instances of NetCF showing
up in Add Remove Programs (<em>we've had some complaints regarding this from our client.
They'll be mighty pleased to hear this, I'm sure.)</em></li>
              </span>
            </span>
          </ul>
          <p>
            <span>Now don't get me wrong - I think the CF is an impressive platform, or at the
very least could've been. I would venture to say that the people on the CF implementation
team are probably skilled professionals just doing the best job they can. But I can't
forgive Microsoft - as a company - for shipping a half-baked, half-assed product that
even at version 2.0 and after two service packs is still riddled with bugs! It boggles
the mind that for any but the most hard-core developers, a <a href="http://www.opennetcf.org/home.ocf">third-party
extension</a> to the .NET CF is practically a necessity because the class library
itself is <em>simply inadequate</em>.</span>
          </p>
          <p>
            <span>As an aside, I seriously doubt we'll chance regression bugs this close to the
launch date, so we'll probably stick with SP1 (we've worked around the issues we've
encountered anyway.)</span>
          </p>
        </span>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=7577aed0-917a-4c35-810d-a0c47b558211" />
      </body>
      <title>Perfect timing</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,7577aed0-917a-4c35-810d-a0c47b558211.aspx</guid>
      <link>http://www.tomergabel.com/PerfectTiming.aspx</link>
      <pubDate>Sun, 11 Mar 2007 14:40:49 GMT</pubDate>
      <description>&lt;p&gt;
With my project finally nearing completion, it's nigh time for Microsoft to release
yet another update to the .NET Compact Framework 2.0.&amp;nbsp;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=aea55f2f-07b5-4a8c-8a44-b4e1b196d5c0&amp;amp;displaylang=en"&gt;Service
Pack 2&lt;/a&gt; ought to bring it to about "beta 2" level.
&lt;/p&gt;
&lt;p&gt;
Check out these gems:
&lt;/p&gt;
&lt;span&gt; 
&lt;ul&gt;
&lt;li&gt;
NETCF deadlocks on exit if native callback delegate has been called on native thread
(&lt;em&gt;this is one of the few bugs in the CF I &lt;/em&gt;haven't&lt;em&gt; encountered. Ironic,
considering we make heavy use of native code in our project.&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;span&gt;Access violation marshaling a class with a string field (&lt;em&gt;there is a dent
in the nearby wall on account of this one.&lt;/em&gt;)&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;
TypeLoadException using generics with NETCF 2.0 (&lt;em&gt;TypeLoadExceptions in general
are a lot of fun in the CF.)&lt;/em&gt;
&lt;/li&gt;&lt;span&gt;&lt;span&gt; 
&lt;li&gt;
Installing multiple locales of same MSI results in multiple instances of NetCF showing
up in Add Remove Programs (&lt;em&gt;we've had some complaints regarding this from our client.
They'll be mighty pleased to hear this, I'm sure.)&lt;/em&gt;
&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;span&gt;Now don't get me wrong - I think the CF is an impressive platform, or at the
very least could've been. I would venture to say that the people on the CF implementation
team are probably skilled professionals just doing the best job they can. But I can't
forgive Microsoft - as a company - for shipping a half-baked, half-assed product that
even at version 2.0 and after two service packs is still riddled with bugs! It boggles
the mind that for any but the most hard-core developers, a &lt;a href="http://www.opennetcf.org/home.ocf"&gt;third-party
extension&lt;/a&gt; to the .NET CF is practically a necessity because the class library
itself is &lt;em&gt;simply inadequate&lt;/em&gt;.&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span&gt;As an aside, I seriously doubt we'll chance regression bugs this close to the
launch date, so we'll probably stick with SP1 (we've worked around the issues we've
encountered anyway.)&lt;/span&gt;
&lt;/span&gt;&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=7577aed0-917a-4c35-810d-a0c47b558211" /&gt;</description>
      <category>Development</category>
      <category>Development/Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=23428e06-234d-4899-8ff3-52016f2e5c0d</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,23428e06-234d-4899-8ff3-52016f2e5c0d.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
By far one of the most annoying aspects of the .NET Compact Framework is how heavily
it relies on P/Invoke to fill in the gaps. The framework itself is missing <em>huge</em> pieces
of functionality, and with the lack of C++/CLI for the Compact Framework a developer
is often time left with no choice but to hack around the missing functionality with
P/Invoke (or COM interop, if you have the patience to muck about with ATL).
</p>
        <p>
The problem is that, on occasion, a P/Invoke call would result in a <span class="codetext">MissingMethodException</span> (in
fact, if you're <em>really</em> unlucky, the type loader will throw the same exception
on loading the method actually making the P/Invoke call). Although a lot of the scenarios
have been thoroughly ironed out by now and can be resolved through a Google search
or some hacking on the developer's part, there is one scario that is esoteric enough
that I couldn't find any references to it on the internet: you can get a <span class="codetext">MissingMethodException</span> when <strong>you
are out of memory</strong>.
</p>
        <p>
We're working on an extremely large (in mobile proportions) and complex project, involving
massive amounts of .NET logic combined with a very large, performance-concious and
memory-hungry native codebase. We've had to hack around a lot of missing capabilities
in the .NET Compact Framework (as well as some bugs and/or shortcomings in other parts
of the OS), and one of our native calls would inconsistently throw a <span class="codetext">MisingMethodException</span>;
having reearched the problem for a day or two I was convinced that the problem was
an incorrect function prototype for the exported function and added explicit
calling convention declarations. This seemed to have resolved and I was content for
a couple of days, until the problem resurfaced.
</p>
        <p>
The exception content itself is next-to-useless, and since the same P/Invoke
call would work intermittently I was hoping that <a href="http://blogs.msdn.com/stevenpr/archive/2005/02/28/381744.aspx">enabling
the loader log</a> might supply some further information. Alas, all the log would
provide was the following line:
</p>
        <blockquote>
          <span class="codetext">
            <p>
Failed to find/load [SomeDll.dll] (even in [\Program Files\Somewhere\])
</p>
          </span>
        </blockquote>
        <p>
Not good. I then dug up <a href="http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx">another
article</a> on the subject and proceeded to enable the interop log, which provided
some additional information:
</p>
        <blockquote>
          <span class="codetext">
            <p>
JIT ERROR FOR PINVOKE METHOD (Managed -&gt; Native): 
<br />
[pinvokeimpl][preservesig]<br />
int Workarounds::GetSinkWrapper(out IImageSink , IImageEncoder );<br />
int (I4_VAL) GetSinkWrapper(IImageSink&amp; ** (INTF_REF) , IImageEncoder *(INTF_VAL)
);
</p>
          </span>
        </blockquote>
        <p>
I was originally interested in the bizarre native signature generation
(specifically the <span class="codetext">IImageSink&amp; **</span> parameter - where'd
the reference come from?), but upon reading some valid log files for working
methods I was convinced that it's a dead duck. I then set my attention to the JIT
message: what has the JIT to do with a native function? I theorized that the
JIT is responsible for the native signature generation for native functions and kept
working under that assumption. That narrowed the question down to, "what went
wrong with the JIT compiler?"
</p>
        <p>
Eventually it occured to me that this might be yet another manifestation of the memory limitation
issue (processes under Windows CE 5.0 are limited to a 32MB address space). The P/Invoke
call is made fairly late into the application; I added a dummy function to the
library which I called on application initialization. This forced the JIT to
take care of the native library before anything was sucking up memory, and the issue
was resolved.
</p>
        <p>
The moral of the story? If you get <span class="codetext">MissingMethodExceptions</span> on
your P/Invoke calls, fisrt make sure your DLL is actually deployed; then check
the DllImport signature (you can find a lot of useful resources on <a href="http://msdn2.microsoft.com/en-us/netframework/aa497275.aspx">this
FAQ</a>). Finally, make sure you're not out of memory.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=23428e06-234d-4899-8ff3-52016f2e5c0d" />
      </body>
      <title>.NET Compact Framework, P/Invoke and MissingMethodException</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,23428e06-234d-4899-8ff3-52016f2e5c0d.aspx</guid>
      <link>http://www.tomergabel.com/NETCompactFrameworkPInvokeAndMissingMethodException.aspx</link>
      <pubDate>Sat, 17 Feb 2007 14:26:26 GMT</pubDate>
      <description>&lt;p&gt;
By far one of the most annoying aspects of the .NET Compact Framework is how heavily
it relies on P/Invoke to fill in the gaps. The framework itself is missing &lt;em&gt;huge&lt;/em&gt; pieces
of functionality, and with the lack of C++/CLI for the Compact Framework a developer
is often time left with no choice but to hack around the missing functionality with
P/Invoke (or COM interop, if you have the patience to muck about with ATL).
&lt;/p&gt;
&lt;p&gt;
The problem is that, on occasion, a P/Invoke call would result in a &lt;span class="codetext"&gt;MissingMethodException&lt;/span&gt; (in
fact, if you're &lt;em&gt;really&lt;/em&gt; unlucky, the type loader will throw the same exception
on loading the method actually making the P/Invoke call). Although a lot of the&amp;nbsp;scenarios
have been thoroughly ironed out by now and can be resolved through a Google search
or some hacking on the developer's part, there is one scario that is esoteric enough
that I couldn't find any references to it on the internet: you can get a &lt;span class="codetext"&gt;MissingMethodException&lt;/span&gt; when &lt;strong&gt;you
are out of memory&lt;/strong&gt;.
&lt;/p&gt;
&lt;p&gt;
We're working on an extremely large (in mobile proportions) and complex project, involving
massive amounts of .NET logic combined with a very large, performance-concious and
memory-hungry native codebase. We've had to hack around a lot of missing capabilities
in the .NET Compact Framework (as well as some bugs and/or shortcomings in other parts
of the OS), and one of our native calls would inconsistently throw a &lt;span class="codetext"&gt;MisingMethodException&lt;/span&gt;;
having reearched the problem for a day or two I was convinced that the problem was
an incorrect function prototype for the exported function&amp;nbsp;and added explicit
calling convention declarations. This seemed to have resolved and I was content for
a couple of days, until the problem resurfaced.
&lt;/p&gt;
&lt;p&gt;
The exception content&amp;nbsp;itself is next-to-useless, and since the same P/Invoke
call would work intermittently I was hoping that &lt;a href="http://blogs.msdn.com/stevenpr/archive/2005/02/28/381744.aspx"&gt;enabling
the loader log&lt;/a&gt; might supply some further information. Alas, all the log would
provide was the following line:
&lt;/p&gt;
&lt;blockquote&gt;&lt;span class="codetext"&gt; 
&lt;p&gt;
Failed to find/load [SomeDll.dll] (even in [\Program Files\Somewhere\])
&lt;/span&gt;&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Not good. I then dug up &lt;a href="http://blogs.msdn.com/netcfteam/archive/2005/07/24/442609.aspx"&gt;another
article&lt;/a&gt; on the subject and proceeded to enable the interop log, which provided
some additional information:
&lt;/p&gt;
&lt;blockquote&gt;&lt;span class="codetext"&gt; 
&lt;p&gt;
JIT ERROR FOR PINVOKE METHOD (Managed -&amp;gt; Native): 
&lt;br&gt;
[pinvokeimpl][preservesig]&lt;br&gt;
int Workarounds::GetSinkWrapper(out IImageSink , IImageEncoder );&lt;br&gt;
int (I4_VAL) GetSinkWrapper(IImageSink&amp;amp; ** (INTF_REF) , IImageEncoder *(INTF_VAL)
);
&lt;/p&gt;
&lt;/span&gt;&lt;/blockquote&gt; 
&lt;p&gt;
I was originally interested in the&amp;nbsp;bizarre&amp;nbsp;native signature&amp;nbsp;generation
(specifically the &lt;span class="codetext"&gt;IImageSink&amp;amp; **&lt;/span&gt; parameter - where'd
the reference come from?), but upon reading some&amp;nbsp;valid log files for working
methods I&amp;nbsp;was convinced that it's a dead duck. I then set my attention to the&amp;nbsp;JIT
message: what has&amp;nbsp;the JIT to do with a native function? I theorized that the
JIT is responsible for the native signature generation for native functions and kept
working under that assumption. That narrowed the question down&amp;nbsp;to, "what went
wrong with the JIT compiler?"
&lt;/p&gt;
&lt;p&gt;
Eventually it occured to me that this might be yet another manifestation of the memory&amp;nbsp;limitation
issue (processes under Windows CE 5.0 are limited to a 32MB address space). The P/Invoke
call is made fairly late into the application; I added a dummy function&amp;nbsp;to the
library which I called on application initialization. This forced the&amp;nbsp;JIT to
take care of the native library before anything was sucking up memory, and the issue
was resolved.
&lt;/p&gt;
&lt;p&gt;
The moral of the story? If you get &lt;span class="codetext"&gt;MissingMethodExceptions&lt;/span&gt; on
your P/Invoke calls, fisrt make sure your DLL is actually deployed; then&amp;nbsp;check
the DllImport signature (you can find a lot of useful resources on &lt;a href="http://msdn2.microsoft.com/en-us/netframework/aa497275.aspx"&gt;this
FAQ&lt;/a&gt;). Finally, make sure you're not out of memory.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=23428e06-234d-4899-8ff3-52016f2e5c0d" /&gt;</description>
      <category>Development</category>
      <category>Development/Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=97dbec47-e9d8-4452-afd5-0ce6c898a8b9</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,97dbec47-e9d8-4452-afd5-0ce6c898a8b9.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was screwing around with XmlSerializer and manual recompilations (you can enable <a href="http://support.microsoft.com/kb/823196">raw
code output</a> from the XmlSerializer) and somehow this happened:
</p>
        <p align="center">
          <a href="http://www.tomergabel.com/content/binary/omg_compilergone_large.png">
            <img src="http://www.tomergabel.com/content/binary/omg_compilergone_sm.png" border="0" />
          </a>
        </p>
        <p>
.NET Framework reinstall time, I guess...
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=97dbec47-e9d8-4452-afd5-0ce6c898a8b9" />
      </body>
      <title>Three words: Oh, My, God</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,97dbec47-e9d8-4452-afd5-0ce6c898a8b9.aspx</guid>
      <link>http://www.tomergabel.com/ThreeWordsOhMyGod.aspx</link>
      <pubDate>Tue, 06 Feb 2007 14:28:41 GMT</pubDate>
      <description>&lt;p&gt;
I was screwing around with XmlSerializer and manual recompilations (you can enable &lt;a href="http://support.microsoft.com/kb/823196"&gt;raw
code output&lt;/a&gt; from the XmlSerializer) and somehow this happened:
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.tomergabel.com/content/binary/omg_compilergone_large.png"&gt;&lt;img src="http://www.tomergabel.com/content/binary/omg_compilergone_sm.png" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
.NET Framework reinstall time, I guess...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=97dbec47-e9d8-4452-afd5-0ce6c898a8b9" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=a67e5118-6194-417f-8ea0-a128415ec09f</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,a67e5118-6194-417f-8ea0-a128415ec09f.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p style="font-size: xx-small;">
          <u>Footnote</u>: This is fast becoming a series of posts on the woes of using the
.NET Compact Framework. In fact, I've added a subcategory for this exact purpose;
you can access the category and its RSS feed from the Categories list on the right-hand
side of the screen.
</p>
        <p>
Here's another one of those "bang your head repeatedly against the wall and look for
a sharp object" issues: closing a stream derived from <span class="codetext">HttpWebResponse.GetResponseStream</span> takes
an abnormally long time. In fact, the (blocking) call to <span class="codetext">Stream.Close</span> takes
approximately the same amount of time as it would to read to the end of the stream.
I've only encountered <a href="http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/04839a0cb5fb4655/8ed0dad89ee3b282?&amp;hl=en#8ed0dad89ee3b282">one
other reference</a> to this in a newsgroup post from 2004, which (according to Todd,
the original author of the post) was never actually answered.
</p>
        <p>
Seeing as I was trying to use <span class="codetext">HttpWebRequest</span> to create
a minimalistic download manager for one of our applications, I had to come up with
a solution: one option was to close the stream asynchronously and just let the download
run its course, wasting valuable memory, CPU time and bandwidth; another was to never
close the stream and make do with a resource leak. Not content with these solutions
I decided to dig into the framework code with the ever-useful <a href="http://www.aisto.com/roeder/DotNet/">Reflector</a>.
The first hurdle was locating the assemblies; they're not trivial to find, but if
you look hard enough you can find actually useful versions in your Visual Studio 2005
installation folder, under <span class="codetext">SmartDevices\SDK\CompactFramework\2.0\v2.0\Debugger\BCL</span>.
These are regular .NET Assembly PEs so it's trivial to load them up in Reflector.
</p>
        <p>
Some digging into the BCL sources proved that <span class="codetext">HttpWebRequest</span> does,
in fact, read until the end of the stream when closing; this is the relevant code
excerpt, from <span class="codetext">HttpWebRequest.doClose</span>:
</p>
        <blockquote>
          <pre>
            <span style="color: rgb(0, 0, 255);">if</span> (!<span style="color: rgb(0, 0, 255);">this</span>.m_doneReading)<br />
{<br /><span style="color: rgb(0, 0, 255);">byte</span>[] buffer1 = <span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 255);">byte</span>[0x100];<br /><span style="color: rgb(0, 0, 255);">while</span> (<span style="color: rgb(0, 0, 255);">this</span>.ReadInternal(buffer1,
0, buffer1.Length, <span style="color: rgb(0, 0, 255);">true</span>) != 0)<br />
{<br />
}<br />
}</pre>
        </blockquote>
        <p>
It only started to make sense when I did some reading on HTTP (a protocol I'm not
deeply familiar with). Apparently, HTTP 1.1 connections are <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.6.2">persistent
by default</a>, which means the connection is maintained even after the request is
completed, and further requests are served from the same connection. Technically,
this means that the <span class="codetext">KeepAlive</span> property of <span class="codetext">HttpWebRequest</span> is
true by default, and a <span class="codetext">Connection="Keep-alive"</span> header
is added to the HTTP request. I can only surmise that, with persistent connections,
the response must be read in full in order to allow future requests (if the response
was cut off, some concurrency issues may apply). Unfortunately, setting the <span class="codetext">KeepAlive</span> property
to false did not resolve the issue and the connection was maintained until closed.
</p>
        <p>
Since I could find no way to resolve the problem, I decided to hack around it:
</p>
        <blockquote>
          <pre>stream.GetType().BaseType<br />
.GetField( "<span style="color: rgb(139, 0, 0);">m_doneReading</span>", BindingFlags.Instance
| BindingFlags.NonPublic )<br />
.SetValue( stream, <span style="color: rgb(0, 0, 255);">true</span> );</pre>
        </blockquote>
        <p>
Screwing around with BCL internals is obviously NOT a recommended practise and it's
something I tried very hard to avoid, however this problem had to be resolved in one
way or another. I traced the code a bit deeper to see if this would actually have
the expected results; apparently <span class="codetext">HttpWebRequest</span> keeps
an internal "reference counter" (actually a bitfield, but same principle) on
the connection. According to the implementation for <span class="codetext">HttpWebRequest.connectionRemoveRef</span>,
if the reference counter reaches 0 the private <span class="codetext">m_connection</span> field
of the request becomes null, and the connection is released. I started out by testing
this:
</p>
        <p align="center">
          <a href="http://www.tomergabel.com/content/binary/netcf_stream_connbefore.png" atomicselection="true">
            <img style="border-width: 0px;" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/OnHttpWebRequestandClosingStreams_D4D8/netcf_stream_connbefore_thumb%5B1%5D.png" border="0" height="103" width="240" />
          </a>
          <a href="http://www.tomergabel.com/content/binary/netcf_stream_connafter.png" atomicselection="true">
            <img style="border-width: 0px;" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/OnHttpWebRequestandClosingStreams_D4D8/netcf_stream_connafter.png" border="0" height="103" width="240" />
          </a>
          <br />
          <span style="font-size: xx-small;">Before and after - you can see that the m_connection
field becomes null</span>
        </p>
        <p>
Unfortunately I have no idea how to test whether ot not the connection is actually
disposed (conceptually, if <span class="codetext">KeepAlive</span> is set to false
then the connection should be immediately closed); when I find the time I'll try and
track the HTTP session using Wireshark, but currently this horrible hack will just
have to do.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=a67e5118-6194-417f-8ea0-a128415ec09f" />
      </body>
      <title>On HttpWebRequest and Closing Streams</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,a67e5118-6194-417f-8ea0-a128415ec09f.aspx</guid>
      <link>http://www.tomergabel.com/OnHttpWebRequestAndClosingStreams.aspx</link>
      <pubDate>Tue, 16 Jan 2007 13:33:43 GMT</pubDate>
      <description>&lt;p style="font-size: xx-small;"&gt;
&lt;u&gt;Footnote&lt;/u&gt;: This is fast becoming a series of posts on the woes of using the
.NET Compact Framework. In fact, I've added a subcategory for this exact purpose;
you can access the category and its RSS feed from the Categories list on the right-hand
side of the screen.
&lt;/p&gt;
&lt;p&gt;
Here's another one of those "bang your head repeatedly against the wall and look for
a sharp object" issues: closing a stream derived from &lt;span class="codetext"&gt;HttpWebResponse.GetResponseStream&lt;/span&gt; takes
an abnormally long time. In fact, the (blocking) call to &lt;span class="codetext"&gt;Stream.Close&lt;/span&gt; takes
approximately the same amount of time as it would to read to the end of the stream.
I've only encountered &lt;a href="http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/04839a0cb5fb4655/8ed0dad89ee3b282?&amp;amp;hl=en#8ed0dad89ee3b282"&gt;one
other reference&lt;/a&gt; to this in a newsgroup post from 2004, which (according to Todd,
the original author of the post) was never actually answered.
&lt;/p&gt;
&lt;p&gt;
Seeing as I was trying to use &lt;span class="codetext"&gt;HttpWebRequest&lt;/span&gt; to create
a minimalistic download manager for one of our applications, I had to come up with
a solution: one option was to close the stream asynchronously and just let the download
run its course, wasting valuable memory, CPU time and bandwidth; another was to never
close the stream and make do with a resource leak. Not content with these solutions
I decided to dig into the framework code with the ever-useful &lt;a href="http://www.aisto.com/roeder/DotNet/"&gt;Reflector&lt;/a&gt;.
The first hurdle was locating the assemblies; they're not trivial to find, but if
you look hard enough you can find actually useful versions in your Visual Studio 2005
installation folder, under &lt;span class="codetext"&gt;SmartDevices\SDK\CompactFramework\2.0\v2.0\Debugger\BCL&lt;/span&gt;.
These are regular .NET Assembly PEs so it's trivial to load them up in Reflector.
&lt;/p&gt;
&lt;p&gt;
Some digging into the BCL sources proved that &lt;span class="codetext"&gt;HttpWebRequest&lt;/span&gt; does,
in fact, read until the end of the stream when closing; this is the relevant code
excerpt, from &lt;span class="codetext"&gt;HttpWebRequest.doClose&lt;/span&gt;:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.m_doneReading)&lt;br&gt;
{&lt;br&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] buffer1 = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[0x100];&lt;br&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;while&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.ReadInternal(buffer1,
0, buffer1.Length, &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;) != 0)&lt;br&gt;
{&lt;br&gt;
}&lt;br&gt;
}&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
It only started to make sense when I did some reading on HTTP (a protocol I'm not
deeply familiar with). Apparently, HTTP 1.1 connections are &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.6.2"&gt;persistent
by default&lt;/a&gt;, which means the connection is maintained even after the request is
completed, and further requests are served from the same connection. Technically,
this means that the &lt;span class="codetext"&gt;KeepAlive&lt;/span&gt; property of &lt;span class="codetext"&gt;HttpWebRequest&lt;/span&gt; is
true by default, and a &lt;span class="codetext"&gt;Connection="Keep-alive"&lt;/span&gt; header
is added to the HTTP request. I can only surmise that, with persistent connections,
the response must be read in full in order to allow future requests (if the response
was cut off, some concurrency issues may apply). Unfortunately, setting the &lt;span class="codetext"&gt;KeepAlive&lt;/span&gt; property
to false did not resolve the issue and the connection was maintained until closed.
&lt;/p&gt;
&lt;p&gt;
Since I could find no way to resolve the problem, I decided to hack around it:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;stream.GetType().BaseType&lt;br&gt;
.GetField( "&lt;span style="color: rgb(139, 0, 0);"&gt;m_doneReading&lt;/span&gt;", BindingFlags.Instance
| BindingFlags.NonPublic )&lt;br&gt;
.SetValue( stream, &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt; );&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Screwing around with BCL internals is obviously NOT a recommended practise and it's
something I tried very hard to avoid, however this problem had to be resolved in one
way or another. I traced the code a bit deeper to see if this would actually have
the expected results; apparently &lt;span class="codetext"&gt;HttpWebRequest&lt;/span&gt; keeps
an internal&amp;nbsp;"reference counter" (actually a bitfield, but&amp;nbsp;same principle)&amp;nbsp;on
the connection. According to the implementation for &lt;span class="codetext"&gt;HttpWebRequest.connectionRemoveRef&lt;/span&gt;,
if the reference counter reaches 0 the private &lt;span class="codetext"&gt;m_connection&lt;/span&gt; field
of the request becomes null, and the connection is released. I started out by testing
this:
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.tomergabel.com/content/binary/netcf_stream_connbefore.png" atomicselection="true"&gt;&lt;img style="border-width: 0px;" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/OnHttpWebRequestandClosingStreams_D4D8/netcf_stream_connbefore_thumb%5B1%5D.png" border="0" height="103" width="240"&gt;&lt;/a&gt; &lt;a href="http://www.tomergabel.com/content/binary/netcf_stream_connafter.png" atomicselection="true"&gt;&lt;img style="border-width: 0px;" src="http://www.tomergabel.com/content/binary/WindowsLiveWriter/OnHttpWebRequestandClosingStreams_D4D8/netcf_stream_connafter.png" border="0" height="103" width="240"&gt;&lt;/a&gt; 
&lt;br&gt;
&lt;span style="font-size: xx-small;"&gt;Before and after - you can see that the m_connection
field becomes null&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
Unfortunately I have no idea how to test whether ot not the connection is actually
disposed (conceptually, if &lt;span class="codetext"&gt;KeepAlive&lt;/span&gt; is set to false
then the connection should be immediately closed); when I find the time I'll try and
track the HTTP session using Wireshark, but currently this horrible hack will just
have to do.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=a67e5118-6194-417f-8ea0-a128415ec09f" /&gt;</description>
      <category>Development</category>
      <category>Development/Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=126c1dc1-3229-431e-aea4-c96eaff53dbb</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,126c1dc1-3229-431e-aea4-c96eaff53dbb.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been hacking away quite a bit at an application that contains large managed
and unmanaged portions, and a necessarily complex interop layer in between. It appears
that interop marshalling behaves somewhat differently between the full and Compact
framework. Here's a somewhat laconic list of the issues I've encountered and how to
resolve them:
</p>
        <ol>
          <li>
You may encounter <span class="codetext">NotSupportedException</span> on calls to <span class="codetext">Marshall.SizeOf</span>.
Although the documentation does not specify this as a possible exception, experience
shows that this is a result of wrong marshalling attributes: for example, although trying
to marshal a <span class="codetext">bool</span> to <span class="codetext">UnmanagedType.I4</span> makes
sense from a C programmer's perspective, it results in the behavior described above.
The article describing this is called "<a href="http://msdn2.microsoft.com/en-us/library/ms172514.aspx">Using
the MarshalAsAttribute Attribute</a>," but the version in my locally installed copy
of MSDN Library (August 2006) does not contain this information. 
</li>
          <li>
Annoyingly, the default marshalling, or even an explicit <span class="codetext">UnmanagedType.Bool</span>,
results in corrupt values (probably some minor framework bug). I worked around this
by defining the member as <span class="codetext">int</span> and manually giving it
the value 0 or -1. 
</li>
          <li>
It's not obvious, but you can't use <span class="codetext">UnmanagedType.LPArray</span> from
within structures - it only works on P/Invoke method declaration parameters. The only
way to do this is to manually call <span class="codetext">Marshal.StructureToPtr</span> and
do some pointer arithmetic with <span class="codetext">IntPtr</span> (annoying, but
at least it's safe code). 
</li>
          <li>
The marshaller always <a href="http://msdn2.microsoft.com/en-us/library/f1cf4kkz.aspx">frees
up memory</a>; although this makes a lot of sense from the .NET perspective, it probably
means that you'll have to code in some sort of deep copying mechanism in your native
code if you want any of that information in your state. This also has performance
repercussions you should consider when architecting your interop layer.</li>
        </ol>
        <p>
I'll post updates to this as I come across more issues.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=126c1dc1-3229-431e-aea4-c96eaff53dbb" />
      </body>
      <title>Unusual Marshalling Behavior in the .NET Compact Framework</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,126c1dc1-3229-431e-aea4-c96eaff53dbb.aspx</guid>
      <link>http://www.tomergabel.com/UnusualMarshallingBehaviorInTheNETCompactFramework.aspx</link>
      <pubDate>Tue, 09 Jan 2007 16:34:43 GMT</pubDate>
      <description>&lt;p&gt;
I've been hacking away quite a bit at an application that contains&amp;nbsp;large managed
and unmanaged portions, and a necessarily complex interop layer in between. It appears
that interop marshalling behaves somewhat differently between the full and Compact
framework. Here's a somewhat laconic list of the issues I've encountered and how to
resolve them:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
You may encounter &lt;span class="codetext"&gt;NotSupportedException&lt;/span&gt; on calls to &lt;span class="codetext"&gt;Marshall.SizeOf&lt;/span&gt;.
Although&amp;nbsp;the documentation does not specify this as a possible exception, experience
shows that this is a result of wrong marshalling attributes: for example, although&amp;nbsp;trying
to marshal a &lt;span class="codetext"&gt;bool&lt;/span&gt; to &lt;span class="codetext"&gt;UnmanagedType.I4&lt;/span&gt; makes
sense from a C programmer's perspective, it results in the behavior described above.
The article describing this is called "&lt;a href="http://msdn2.microsoft.com/en-us/library/ms172514.aspx"&gt;Using
the MarshalAsAttribute Attribute&lt;/a&gt;," but the version in my locally installed copy
of MSDN Library (August 2006) does not contain this information. 
&lt;/li&gt;
&lt;li&gt;
Annoyingly, the default marshalling, or even an explicit &lt;span class="codetext"&gt;UnmanagedType.Bool&lt;/span&gt;,
results in corrupt values (probably some minor framework bug). I worked around this
by defining the member as &lt;span class="codetext"&gt;int&lt;/span&gt; and manually giving it
the value 0 or -1. 
&lt;/li&gt;
&lt;li&gt;
It's not obvious, but you can't use &lt;span class="codetext"&gt;UnmanagedType.LPArray&lt;/span&gt; from
within structures - it only works on P/Invoke method declaration parameters. The only
way to do this is to manually call &lt;span class="codetext"&gt;Marshal.StructureToPtr&lt;/span&gt; and
do some pointer arithmetic with &lt;span class="codetext"&gt;IntPtr&lt;/span&gt; (annoying, but
at least it's safe code). 
&lt;/li&gt;
&lt;li&gt;
The marshaller always &lt;a href="http://msdn2.microsoft.com/en-us/library/f1cf4kkz.aspx"&gt;frees
up memory&lt;/a&gt;; although this makes a lot of sense from the .NET perspective, it probably
means that you'll have to code in some sort of deep copying mechanism in your native
code if you want any of that information in your state. This also has performance
repercussions you should consider when architecting your interop layer.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
I'll post updates to this as I come across more issues.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=126c1dc1-3229-431e-aea4-c96eaff53dbb" /&gt;</description>
      <category>Development</category>
      <category>Development/Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=7ec90416-01fd-46a7-a756-b02ea8c40642</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,7ec90416-01fd-46a7-a756-b02ea8c40642.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was writing some code with Visual Studio 2005, and pressed Alt+Keypad 8 (under <a href="http://www.jetbrains.com/resharper/index.html">ReSharper</a>,
this moves the current method up/down). Not only did this produce the ASCII code 8
- backspace (control character) or inverse bullet (printable character) - but
it also completely screwed up the font on the same line:
</p>
        <p align="center">
          <img src="http://www.tomergabel.com/content/binary/vs_bug_alt8.png" />
        </p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=7ec90416-01fd-46a7-a756-b02ea8c40642" />
      </body>
      <title>Curious</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,7ec90416-01fd-46a7-a756-b02ea8c40642.aspx</guid>
      <link>http://www.tomergabel.com/Curious.aspx</link>
      <pubDate>Sun, 07 Jan 2007 17:45:26 GMT</pubDate>
      <description>&lt;p&gt;
I was writing some code with Visual Studio 2005, and pressed Alt+Keypad 8 (under &lt;a href="http://www.jetbrains.com/resharper/index.html"&gt;ReSharper&lt;/a&gt;,
this moves the current method up/down). Not only did this produce the ASCII code 8
-&amp;nbsp;backspace (control character) or inverse bullet (printable character) -&amp;nbsp;but
it also completely screwed up the font on the same line:
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;img src="http://www.tomergabel.com/content/binary/vs_bug_alt8.png"&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=7ec90416-01fd-46a7-a756-b02ea8c40642" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=a73d1d21-8cea-4b60-960b-01f69eb053f3</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,a73d1d21-8cea-4b60-960b-01f69eb053f3.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
For some reason the Visual Studio 2005 debugger (on my native Smart Device project)
flat out refused to halt on Data Abort errors. Instead it would just show the
error information on the debug trace and crash the application: 
</p>
        <blockquote>
          <span class="codetext">Data Abort: Thread=81e27040 Proc=804c68c0 'Client.exe'<br />
AKY=00000041 PC=00eb1cc0(emnative.dll+0x00001cc0) RA=00eb6d6c(emnative.dll+0x00006d6c)
BVA=0e537510 FSR=00000007</span>
        </blockquote>
        <p>
For obvious reasons, I wasn't particularly happy with this. Digging into Google and
the documentation didn't help; after some serious headscratching I figured that the
Windows CE kernel must be catching these exceptions at some point, so from the <span class="codetext">Debug-&gt;Exceptions...</span> menu
I enabled, under Win32 Exceptions, catching of thrown Access Violations:
</p>
        <p align="center">
          <img src="http://www.tomergabel.com/content/binary/catch_dataabort_debug.png" />
        </p>
        <p>
After this, I managed to finally get proper trapping in the debugger, and easily find
out what code actually caused the access violation:
</p>
        <p align="center">
 <img src="http://www.tomergabel.com/content/binary/catch_dataabort_exception.png" /></p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=a73d1d21-8cea-4b60-960b-01f69eb053f3" />
      </body>
      <title>Catching Data Abort Exceptions</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,a73d1d21-8cea-4b60-960b-01f69eb053f3.aspx</guid>
      <link>http://www.tomergabel.com/CatchingDataAbortExceptions.aspx</link>
      <pubDate>Thu, 04 Jan 2007 15:50:12 GMT</pubDate>
      <description>&lt;p&gt;
For some reason the Visual Studio 2005 debugger (on my native Smart Device project)
flat out refused to halt on Data Abort errors.&amp;nbsp;Instead it would just show the
error information on the debug trace and crash the application:&amp;nbsp;
&lt;/p&gt;
&lt;blockquote&gt;&lt;span class="codetext"&gt;Data Abort: Thread=81e27040 Proc=804c68c0 'Client.exe'&lt;br&gt;
AKY=00000041 PC=00eb1cc0(emnative.dll+0x00001cc0) RA=00eb6d6c(emnative.dll+0x00006d6c)
BVA=0e537510 FSR=00000007&lt;/span&gt;&lt;/blockquote&gt; 
&lt;p&gt;
For obvious reasons, I wasn't particularly happy with this. Digging into Google and
the documentation didn't help; after some serious headscratching I figured that the
Windows CE kernel must be catching these exceptions at some point, so from the &lt;span class="codetext"&gt;Debug-&amp;gt;Exceptions...&lt;/span&gt; menu
I enabled, under Win32 Exceptions, catching of thrown Access Violations:
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;img src="http://www.tomergabel.com/content/binary/catch_dataabort_debug.png"&gt; 
&lt;/p&gt;
&lt;p&gt;
After this, I managed to finally get proper trapping in the debugger, and easily find
out what code actually caused the access violation:
&lt;/p&gt;
&lt;p align="center"&gt;
&amp;nbsp;&lt;img src="http://www.tomergabel.com/content/binary/catch_dataabort_exception.png"&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=a73d1d21-8cea-4b60-960b-01f69eb053f3" /&gt;</description>
      <category>Development</category>
      <category>Development/Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=933f35b1-4854-4793-8bb0-7fe2732bb46c</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,933f35b1-4854-4793-8bb0-7fe2732bb46c.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It really yanks my chain when I put my faith into what is presumably a solid foundation
for my code, and end up running into a huge number of unexpected pitfalls.
</p>
        <p>
Be warned: .NET Compact Framework is <strong>incomplete</strong>. Oh yes, it's a fleshed
out version of CF 1.0 with generics and various important bits and pieces finally
included (COM interop. I mean, seriously, .NET is useless without it even on the desktop),
but it's still lacking a lot of vital components (ActiveX hosting) and has
major shortcomings in others (no XSLT support). But that isn't the worst of it:
the documentation is sparse at best, and flat out wrong in some cases.
</p>
        <p>
          <strong>You cannot use asynchronous delegates in .NET CF 2.0.</strong>
        </p>
        <p>
In case it isn't clear to you, let me repeat it: you can't use <span class="codetext">Delegate.BeginInvoke</span>.
If you're really unlucky, like me, you'll write a bunch of code and go on to compile,
run, test and debug it and then run into a <a href="http://www.devx.com/codemag/Article/17441/0/page/6">completely
bogus</a><span class="codetext">NotSupportedException on</span> a seemingly innocuous
internal method call, and have to do some serious digging to figure out the culprit.
This goes particularly well with (admittedly documented) fineprint in methods such
as Windows Media Player's <span class="codetext">player.URL</span> property setter,
which for some reason <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmpsdk11/mmp_sdk/playerurl.asp">mustn't
be called</a> from an event handler.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=933f35b1-4854-4793-8bb0-7fe2732bb46c" />
      </body>
      <title>.NET CF: v2.0 my ass</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,933f35b1-4854-4793-8bb0-7fe2732bb46c.aspx</guid>
      <link>http://www.tomergabel.com/NETCFV20MyAss.aspx</link>
      <pubDate>Mon, 25 Dec 2006 01:59:25 GMT</pubDate>
      <description>&lt;p&gt;
It really yanks my chain when I put my faith into what is presumably a solid foundation
for my code, and end up running into a huge number of unexpected pitfalls.
&lt;/p&gt;
&lt;p&gt;
Be warned: .NET Compact Framework is &lt;strong&gt;incomplete&lt;/strong&gt;. Oh yes, it's a fleshed
out version of CF 1.0 with generics and various important bits and pieces finally
included (COM interop. I mean, seriously, .NET is useless without it even on the desktop),
but it's still lacking a lot of vital components (ActiveX hosting)&amp;nbsp;and&amp;nbsp;has
major shortcomings&amp;nbsp;in others (no XSLT support). But that isn't the worst of it:
the documentation is sparse at best, and flat out wrong in some cases.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;You cannot use asynchronous delegates in .NET CF 2.0.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In case it isn't clear to you, let me repeat it: you can't use &lt;span class="codetext"&gt;Delegate.BeginInvoke&lt;/span&gt;.
If you're really unlucky, like me, you'll write a bunch of code and go on to compile,
run, test and debug it and then run into a &lt;a href="http://www.devx.com/codemag/Article/17441/0/page/6"&gt;completely
bogus&lt;/a&gt; &lt;span class="codetext"&gt;NotSupportedException on&lt;/span&gt; a seemingly innocuous
internal method call, and have to do some serious digging to figure out the culprit.
This goes particularly well with (admittedly documented) fineprint in methods such
as Windows Media Player's &lt;span class="codetext"&gt;player.URL&lt;/span&gt; property setter,
which for some reason&amp;nbsp;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmpsdk11/mmp_sdk/playerurl.asp"&gt;mustn't
be called&lt;/a&gt; from an event handler.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=933f35b1-4854-4793-8bb0-7fe2732bb46c" /&gt;</description>
      <category>Development</category>
      <category>Development/Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=1592439b-d756-4818-8bd5-77b99cea14a0</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,1592439b-d756-4818-8bd5-77b99cea14a0.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <u>Update (January 16th, 2007)</u>: Not only does this apparently only work on the
emulator, you would do well to stay away from Managed DirectX in general because common
drivers, such as those on the <a href="http://www.willcom-inc.com/ja/lineup/ws/004sh/index.html">Willcom
W-Zero3</a> - do not <a href="http://msdn2.microsoft.com/en-us/library/ms229671%28VS.80%29.aspx">support
rendering</a> in landscape mode (I wonder which devices DO support those features).
After messing with this collectively for weeks we eventually went with the obsolete
GAPI. <font color="#ff0000">The code here will probably not work for you</font>.<br /></p>
        <p>
For some reason, elementary DirectX operations are not very well documented in the
.NET Compact Framework documentation; I kept running into InvalidCallExceptions for
no aparent reason, and couldn't figure out the "simple" way to lock surfaces from
the documentation (it's worth noting that I was only interested in basic 2D functionality).
</p>
        <p>
Basically you just need the right set of flags and the right order of operations.
Here's the code I used and that worked for me (even under the considerably buggy emulator).
To create the device, use the following parameters:
</p>
        <blockquote>
          <pre>PresentParameters p = <span style="color: rgb(0, 0, 255);">new</span> PresentParameters();
p.SwapEffect = SwapEffect.Discard; p.Windowed = <span style="color: rgb(0, 0, 255);">true</span>;
p.EnableAutoDepthStencil = <span style="color: rgb(0, 0, 255);">false</span>; p.PresentFlag
|= PresentFlag.LockableBackBuffer; p.MultiSample = MultiSampleType.None; m_device
= <span style="color: rgb(0, 0, 255);">new</span> Device( 0, DeviceType.Default, <span style="color: rgb(0, 0, 255);">this</span>,
CreateFlags.None, p ); </pre>
        </blockquote>
        <p>
To draw on the backbuffer, you can use the following code:
</p>
        <blockquote>
          <pre>m_device.BeginScene();

<span style="color: rgb(0, 0, 255);">using</span> (
Surface s = m_device.GetBackBuffer( 0, BackBufferType.Mono ) ) { <span style="color: rgb(0, 0, 255);">int</span> pitch; <span style="color: rgb(0, 0, 255);">using</span> (
GraphicsStream gs = s.LockRectangle( <span style="color: rgb(0, 0, 255);">this</span>.ClientRectangle,
LockFlags.None, <span style="color: rgb(0, 0, 255);">out</span> pitch ) ) { <span style="color: rgb(0, 128, 0);">//
Your code goes here...</span> } s.UnlockRectangle(); } m_device.EndScene(); m_device.Present();</pre>
        </blockquote>
        <p>
I hope this helps someone avoid a couple hours of frustration.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=1592439b-d756-4818-8bd5-77b99cea14a0" />
      </body>
      <title>Getting Surface.LockRectangle to work with .NET Compact Framework 2.0</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,1592439b-d756-4818-8bd5-77b99cea14a0.aspx</guid>
      <link>http://www.tomergabel.com/GettingSurfaceLockRectangleToWorkWithNETCompactFramework20.aspx</link>
      <pubDate>Tue, 19 Dec 2006 14:25:24 GMT</pubDate>
      <description>&lt;p&gt;
&lt;u&gt;Update (January 16th, 2007)&lt;/u&gt;: Not only does this apparently only work on the
emulator, you would do well to stay away from Managed DirectX in general because common
drivers, such as those on the &lt;a href="http://www.willcom-inc.com/ja/lineup/ws/004sh/index.html"&gt;Willcom
W-Zero3&lt;/a&gt; - do not &lt;a href="http://msdn2.microsoft.com/en-us/library/ms229671%28VS.80%29.aspx"&gt;support
rendering&lt;/a&gt; in landscape mode (I wonder which devices DO support those features).
After messing with this collectively for weeks we eventually went with the obsolete
GAPI. &lt;font color="#ff0000"&gt;The code here will probably not work for you&lt;/font&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
For some reason, elementary DirectX operations are not very well documented in the
.NET Compact Framework documentation; I kept running into InvalidCallExceptions&amp;nbsp;for
no aparent reason, and couldn't figure out the "simple" way to lock surfaces from
the documentation (it's worth noting that I was only interested in basic 2D functionality).
&lt;/p&gt;
&lt;p&gt;
Basically you just need the right set of flags and the right order of operations.
Here's the code I used and that worked for me (even under the considerably buggy emulator).
To create the device, use the following parameters:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;PresentParameters p = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; PresentParameters();
p.SwapEffect = SwapEffect.Discard; p.Windowed = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;
p.EnableAutoDepthStencil = &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;; p.PresentFlag
|= PresentFlag.LockableBackBuffer; p.MultiSample = MultiSampleType.None; m_device
= &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Device( 0, DeviceType.Default, &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;,
CreateFlags.None, p ); &lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
To draw&amp;nbsp;on the backbuffer, you can use the following code:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;m_device.BeginScene();

&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (
Surface s = m_device.GetBackBuffer( 0, BackBufferType.Mono ) ) { &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; pitch; &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (
GraphicsStream gs = s.LockRectangle( &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.ClientRectangle,
LockFlags.None, &lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; pitch ) ) { &lt;span style="color: rgb(0, 128, 0);"&gt;//
Your code goes here...&lt;/span&gt; } s.UnlockRectangle(); } m_device.EndScene(); m_device.Present();&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
I hope this helps someone avoid a couple hours of frustration.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=1592439b-d756-4818-8bd5-77b99cea14a0" /&gt;</description>
      <category>Development</category>
      <category>Development/Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=296d22b1-4d05-46ba-9d66-66d3533623df</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,296d22b1-4d05-46ba-9d66-66d3533623df.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
... from <a href="http://blog.opennetcf.org/afeinman/PermaLink,guid,b168f16d-5087-49ab-a4a5-58c63812107a.aspx">Alex
Feinman</a>. Don't ask me why.
</p>
        <p>
In other news, the .NET Compact Framework doesn't decode alpha channels even in bitmaps
that has them (well, it might decode the alpha channel, but it doesn't survive a <span class="codetext">Bitmap.LockBits</span> call
- maybe because there's no <span class="codetext">ImageFormat</span> with alpha...)
Still working around that. <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=296d22b1-4d05-46ba-9d66-66d3533623df" /></p>
      </body>
      <title>I really liked this post</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,296d22b1-4d05-46ba-9d66-66d3533623df.aspx</guid>
      <link>http://www.tomergabel.com/IReallyLikedThisPost.aspx</link>
      <pubDate>Wed, 13 Dec 2006 17:01:40 GMT</pubDate>
      <description>&lt;p&gt;
... from &lt;a href="http://blog.opennetcf.org/afeinman/PermaLink,guid,b168f16d-5087-49ab-a4a5-58c63812107a.aspx"&gt;Alex
Feinman&lt;/a&gt;. Don't ask me why.
&lt;/p&gt;
&lt;p&gt;
In other news, the .NET Compact Framework doesn't decode alpha channels even in bitmaps
that has them (well, it might decode the alpha channel, but it doesn't survive a &lt;span class="codetext"&gt;Bitmap.LockBits&lt;/span&gt; call
- maybe because there's no &lt;span class="codetext"&gt;ImageFormat&lt;/span&gt; with alpha...)
Still working around that. &lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=296d22b1-4d05-46ba-9d66-66d3533623df" /&gt;</description>
      <category>Development</category>
      <category>Personal</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=7e227aa7-97a0-4ba4-859f-5307295ece60</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,7e227aa7-97a0-4ba4-859f-5307295ece60.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
You might want to take a look at <a href="http://www.shahine.com/omar/WindowsMobileShortcomingsVsBlackberry.aspx">this
post</a> from Omar Shahine. His explanation (excuse? call it whatever you want) for
why Windows Mobile will probably never be as good as Blackberry in some respects is
honest to the point of being uncanny.
</p>
        <p>
I've often remarked how much I appreciate <a href="http://blogs.msdn.com/oldnewthing/archive/tags/History/default.aspx">Raymond
Chen's ramblings</a> about the decisions behind some of the more peculiar aspects
of Windows. However, where Raymond is uncompromising and unapollogetic
(to the point where readers sometimes comment that he is a "douchebag"), Omar is brutally
honest but not grounded to the point of being cynical.
</p>
        <p>
I reckon that top management cannot usually afford this sort of uncompromising honesty,
but given what is often seen in this industry such an attitude is refreshing even
coming from lower rings in the leadership ladder.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=7e227aa7-97a0-4ba4-859f-5307295ece60" />
      </body>
      <title>Uncanny honesty, coming from a manager...</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,7e227aa7-97a0-4ba4-859f-5307295ece60.aspx</guid>
      <link>http://www.tomergabel.com/UncannyHonestyComingFromAManager.aspx</link>
      <pubDate>Mon, 11 Dec 2006 12:11:36 GMT</pubDate>
      <description>&lt;p&gt;
You might want to take a look at &lt;a href="http://www.shahine.com/omar/WindowsMobileShortcomingsVsBlackberry.aspx"&gt;this
post&lt;/a&gt; from Omar Shahine. His explanation (excuse? call it whatever you want) for
why Windows Mobile will probably never be as good as Blackberry in some respects is
honest to the point of being uncanny.
&lt;/p&gt;
&lt;p&gt;
I've often remarked how much I appreciate &lt;a href="http://blogs.msdn.com/oldnewthing/archive/tags/History/default.aspx"&gt;Raymond
Chen's ramblings&lt;/a&gt; about the decisions behind some of the more peculiar aspects
of Windows.&amp;nbsp;However, where Raymond&amp;nbsp;is&amp;nbsp;uncompromising and&amp;nbsp;unapollogetic
(to the point where readers sometimes comment that he is a "douchebag"), Omar is brutally
honest but not grounded to the point of being cynical.
&lt;/p&gt;
&lt;p&gt;
I reckon that top management cannot usually afford this sort of uncompromising honesty,
but given what is often seen in this industry such an attitude is refreshing even
coming from lower rings in the leadership ladder.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=7e227aa7-97a0-4ba4-859f-5307295ece60" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=6f46fb7b-5707-47ec-a89f-3b15d89ab546</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,6f46fb7b-5707-47ec-a89f-3b15d89ab546.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
To make a long story short, I'm building a trivial query engine over a dataset
using XPath; for expressiveness purposes, I've allowed the users of said engine to
query for attributes, and assumed that I can simply go up the hierarchy from there
and access the elements directly.
</p>
        <p>
I was somewhat dumbfounded to find that each node in the resulting node set had its <span class="codetext">parentNode</span> property
set to <span class="codetext">null</span>; at first I was sure this has to do with
an implementation detail of MSXML3 (perhaps it returns copies of the attributes for...
I have no idea what possible gain could be derived from this.) A little more digging
proved that, and I quote from MSDN:
</p>
        <blockquote>
          <p>
In C/C++, <span class="codetext">IXMLDOMAttribute</span> inherits <span class="codetext">IXMLDOMNode</span> but
are not actually child nodes of the element and are not considered part of the document
tree. Attributes are considered members of their associated elements rather than independent
and separate. Thus <span class="codetext">IXMLDOMAttributeparentNode</span>, <span class="codetext">previousSibling</span>,
and <span class="codetext">nextSibling</span> members have the value <span class="codetext">Null</span>.
</p>
        </blockquote>
        <p>
Working under the assumption that this is an MSXML3-only problem, I digged a bit into
the <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html#ID-637646024">W3C
DOM specification</a> only to find that it is, in fact, a specification issue:
</p>
        <blockquote>
          <p>
Attr objects inherit the <span class="codetext">Node</span> interface, but since they
are not actually child nodes of the element they describe, the DOM does not consider
them part of the document tree. Thus, the <span class="codetext">Node</span> attributes <span class="codetext">parentNode</span>, <span class="codetext">previousSibling</span>,
and <span class="codetext">nextSibling</span> have a <span class="codetext">null</span> value
for Attr objects. The DOM takes the view that attributes are properties of elements
rather than having a separate identity from the elements they are associated with;
this should make it more efficient to implement such features as default attributes
associated with all elements of a given type.
</p>
        </blockquote>
        <p>
This seems to me a completely arbitrary design decision. It makes absolutely no sense
to inherit from what at first glance is an interface for first-class citizens in the
document (Node) and then castrate the interface with useless implementations. If,
contractually speaking, attributes <strong>never</strong> have siblings or parents,
then they shouldn't have those properties at all, otherwise this just frustrates
the developers wishing to make use of those properties, and wastes their time by forcing
them to dig through documentation to figure out what's wrong.
</p>
        <p>
And on top of it all, the decision doesn't even make sense in light of the "efficiency"
claim - how is it more efficient to partially implement an interface, instead of defining
a new one that's more contractually sound?
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=6f46fb7b-5707-47ec-a89f-3b15d89ab546" />
      </body>
      <title>Arbitraty design decisions that limit expresiveness</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,6f46fb7b-5707-47ec-a89f-3b15d89ab546.aspx</guid>
      <link>http://www.tomergabel.com/ArbitratyDesignDecisionsThatLimitExpresiveness.aspx</link>
      <pubDate>Sun, 10 Dec 2006 19:10:52 GMT</pubDate>
      <description>&lt;p&gt;
To make a long story short, I'm building a trivial query engine&amp;nbsp;over a dataset
using XPath; for expressiveness purposes, I've allowed the users of said engine to
query for attributes, and assumed that I can simply go up the hierarchy from there
and access the elements directly.
&lt;/p&gt;
&lt;p&gt;
I was somewhat dumbfounded to find that each node in the resulting node set had its &lt;span class="codetext"&gt;parentNode&lt;/span&gt; property
set to &lt;span class="codetext"&gt;null&lt;/span&gt;; at first I was sure this has to do with
an implementation detail of MSXML3 (perhaps it returns copies of the attributes for...
I have no idea what possible gain could be derived from this.) A little more digging
proved that, and I quote from MSDN:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
In C/C++, &lt;span class="codetext"&gt;IXMLDOMAttribute&lt;/span&gt; inherits &lt;span class="codetext"&gt;IXMLDOMNode&lt;/span&gt; but
are not actually child nodes of the element and are not considered part of the document
tree. Attributes are considered members of their associated elements rather than independent
and separate. Thus &lt;span class="codetext"&gt;IXMLDOMAttributeparentNode&lt;/span&gt;, &lt;span class="codetext"&gt;previousSibling&lt;/span&gt;,
and &lt;span class="codetext"&gt;nextSibling&lt;/span&gt; members have the value &lt;span class="codetext"&gt;Null&lt;/span&gt;.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Working under the assumption that this is an MSXML3-only problem, I digged a bit into
the &lt;a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html#ID-637646024"&gt;W3C
DOM specification&lt;/a&gt; only to find that it is, in fact, a specification issue:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Attr objects inherit the &lt;span class="codetext"&gt;Node&lt;/span&gt; interface, but since they
are not actually child nodes of the element they describe, the DOM does not consider
them part of the document tree. Thus, the &lt;span class="codetext"&gt;Node&lt;/span&gt; attributes &lt;span class="codetext"&gt;parentNode&lt;/span&gt;, &lt;span class="codetext"&gt;previousSibling&lt;/span&gt;,
and &lt;span class="codetext"&gt;nextSibling&lt;/span&gt; have a &lt;span class="codetext"&gt;null&lt;/span&gt; value
for Attr objects. The DOM takes the view that attributes are properties of elements
rather than having a separate identity from the elements they are associated with;
this should make it more efficient to implement such features as default attributes
associated with all elements of a given type.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
This seems to me a completely arbitrary design decision. It makes absolutely no sense
to inherit from what at first glance is an interface for first-class citizens in the
document (Node) and then castrate the interface with useless implementations. If,
contractually speaking, attributes &lt;strong&gt;never&lt;/strong&gt; have siblings or parents,
then&amp;nbsp;they shouldn't have those properties at all, otherwise this just frustrates
the developers wishing to make use of those properties, and wastes their time by forcing
them to dig through documentation to figure out what's wrong.
&lt;/p&gt;
&lt;p&gt;
And on top of it all, the decision doesn't even make sense in light of the "efficiency"
claim - how is it more efficient to partially implement an interface, instead of defining
a new one that's more contractually sound?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=6f46fb7b-5707-47ec-a89f-3b15d89ab546" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=78b9b239-2cf4-410d-b1bb-80669d118ce3</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,78b9b239-2cf4-410d-b1bb-80669d118ce3.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Quick link: To download the wrapper classes click <a href="http://www.tomergabel.com/content/binary/IStreamWrapper.zip">here</a></p>
        <p>
While working on a large application targetting the .NET Compact Framework 2.0 I realized
that I'll need to feed some native code (specifically, the XSLT processor in MSXML
3.0 SP1) with an <span class="codetext">IStream</span> implementation.
</p>
        <p>
Articles about interoperating with unmanaged code in the CF are not exactly abundant;
to save you the time I spent on incorrect and/or conflicting research, here's the
bottom line:
</p>
        <ul>
          <li>
            <strong>There is no Managed C/C++ for .NET Compact Framework 2.0</strong>. To some
this may be old news, but you should really pay attention to this point if you're
going to do any serious development against CF. 2.0 adds support for managed
COM/ActiveX interop, but otherwise you're completely stuck with P/Invoke. 
</li>
          <li>
Although it's not immediately obvious, CF 2.0 <strong>does</strong> support exposing managed
classes via COM. 
</li>
          <li>
The CF is missing some usually-minor classes from the BCL; in this case I was missing <span class="codetext">System.Runtime.InteropServices.ComTypes.IStream</span>.
Annoying but easy to work around. 
</li>
          <li>
Finally, as an aside, MSXML 3.0 SP1 for Windows Mobile <strong>does not support </strong>the <span class="codetext">IXslTemplate</span> and <span class="codetext">IXslProcessor</span> interfaces,
meaning that MSXML 3.0's already <a href="http://blogs.msdn.com/antosha/archive/2006/07/24/677560.aspx">lackluster
performance</a> in XSLT transformations is further hindered by not being able
to cache the interpreted stylesheets. This means that, if you use XSLT, your
application <strong>will not scale</strong>. I was not initially aware of this
issue, so I hope our data sets are small enough to handle this, or I may yet
come to regret the decision to use XSLT in this project.</li>
        </ul>
        <p>
I managed to save quite a bit of time by leveraging <a href="http://www.sturmnet.org/blog/archives/2005/03/03/cds-csharp-extractor/">Oliver
Sturm's work</a>, which was originally intended for the desktop. Since the CF is missing
a whole bunch of minor classes, the managed definition of IStream included, I originally
mucked about with <span class="codetext">midl</span> trying to generate these definitions
from the .IDL files. After this proved to be a genuine chore, I just ripped the definitions
straight out of the .NET Framework 2.0 assemblies with the ever-useful <a href="http://www.aisto.com/Roeder/DotNet/">Reflector</a>.
</p>
        <p>
You can download the class file <a href="http://www.tomergabel.com/content/binary/IStreamWrapper.zip">here</a>.
If you use this it would really be cool if you could drop me an e-mail, and I bet <a href="http://www.sturmnet.org/blog/archives/2005/03/03/cds-csharp-extractor/">Oliver</a> would
be equally appreciative. Enjoy!
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=78b9b239-2cf4-410d-b1bb-80669d118ce3" />
      </body>
      <title>Managed IStream wrapper for .NET Compact Framework 2.0</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,78b9b239-2cf4-410d-b1bb-80669d118ce3.aspx</guid>
      <link>http://www.tomergabel.com/ManagedIStreamWrapperForNETCompactFramework20.aspx</link>
      <pubDate>Sun, 10 Dec 2006 13:31:16 GMT</pubDate>
      <description>&lt;p&gt;
Quick link: To download the wrapper classes click &lt;a href="http://www.tomergabel.com/content/binary/IStreamWrapper.zip"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
While working on a large application targetting the .NET Compact Framework 2.0 I realized
that I'll need to feed some native code (specifically, the XSLT processor in MSXML
3.0 SP1) with an &lt;span class="codetext"&gt;IStream&lt;/span&gt; implementation.
&lt;/p&gt;
&lt;p&gt;
Articles about interoperating with unmanaged code in the CF are not exactly abundant;
to save you the time I spent on incorrect and/or conflicting research, here's the
bottom line:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;There is no Managed C/C++ for .NET Compact Framework 2.0&lt;/strong&gt;. To some
this may be old news, but you should really pay attention to this point if you're
going to do any serious&amp;nbsp;development against CF. 2.0 adds support for managed
COM/ActiveX interop, but otherwise you're completely stuck with P/Invoke. 
&lt;/li&gt;
&lt;li&gt;
Although it's not immediately obvious, CF 2.0 &lt;strong&gt;does&lt;/strong&gt; support&amp;nbsp;exposing&amp;nbsp;managed
classes via COM. 
&lt;/li&gt;
&lt;li&gt;
The CF is missing some usually-minor classes from the BCL; in this case I was missing &lt;span class="codetext"&gt;System.Runtime.InteropServices.ComTypes.IStream&lt;/span&gt;.
Annoying but easy to work around. 
&lt;/li&gt;
&lt;li&gt;
Finally, as an aside, MSXML 3.0 SP1 for Windows Mobile &lt;strong&gt;does not support &lt;/strong&gt;the &lt;span class="codetext"&gt;IXslTemplate&lt;/span&gt; and &lt;span class="codetext"&gt;IXslProcessor&lt;/span&gt; interfaces,
meaning that MSXML 3.0's&amp;nbsp;already &lt;a href="http://blogs.msdn.com/antosha/archive/2006/07/24/677560.aspx"&gt;lackluster
performance&lt;/a&gt;&amp;nbsp;in XSLT transformations is further hindered by not being able
to cache the interpreted stylesheets. This means that, if you use XSLT,&amp;nbsp;your
application &lt;strong&gt;will not scale&lt;/strong&gt;. I was not&amp;nbsp;initially aware of this
issue, so&amp;nbsp;I hope our data sets are small enough to handle this, or I may yet
come to regret the decision to use XSLT in this project.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I managed to save quite a bit of time by leveraging &lt;a href="http://www.sturmnet.org/blog/archives/2005/03/03/cds-csharp-extractor/"&gt;Oliver
Sturm's work&lt;/a&gt;, which was originally intended for the desktop. Since the CF is missing
a whole bunch of minor classes, the managed definition of IStream included, I originally
mucked about with &lt;span class="codetext"&gt;midl&lt;/span&gt; trying to generate these definitions
from the .IDL files. After this proved to be a genuine chore, I just ripped the definitions
straight out of the .NET Framework 2.0 assemblies with the ever-useful &lt;a href="http://www.aisto.com/Roeder/DotNet/"&gt;Reflector&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
You can download the class file &lt;a href="http://www.tomergabel.com/content/binary/IStreamWrapper.zip"&gt;here&lt;/a&gt;.
If you use this it would really be cool if you could drop me an e-mail, and I bet &lt;a href="http://www.sturmnet.org/blog/archives/2005/03/03/cds-csharp-extractor/"&gt;Oliver&lt;/a&gt; would
be equally appreciative. Enjoy!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=78b9b239-2cf4-410d-b1bb-80669d118ce3" /&gt;</description>
      <category>Development</category>
      <category>Development/Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=bffddb10-d312-40b2-9514-ae5bf5e21a84</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,bffddb10-d312-40b2-9514-ae5bf5e21a84.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As I mentioned before, I've had well over 300 trackback/pingback spam notifications
from dasBlog. Since this was well beyond what I was willing to mess with by hand,
I whipped up a quick Outlook macro to do the work for me:
</p>
        <pre>
          <span style="color: #0000ff">Sub</span> DeleteTrackback() <span style="color: #0000ff">Dim</span> oSel
As Outlook.Selection <span style="color: #0000ff">Dim</span> oItem As Outlook.MailItem <span style="color: #0000ff">Dim</span> oShell <span style="color: #0000ff">Set</span> oShell
= <span style="color: #0000ff">CreateObject</span>("<span style="color: #8b0000">Shell.Application</span>") <span style="color: #0000ff">Set</span> oSel
= <span style="color: #0000ff">Application</span>.ActiveExplorer.Selection <span style="color: #0000ff">For</span> x
= 1 To oSel.Count <span style="color: #0000ff">Set</span> oItem = oSel.Item(x) <span style="color: #0000ff">If</span> (<span style="color: #0000ff">Left</span>(oItem.Subject,
19) = "<span style="color: #8b0000">Weblog trackback by</span>") <span style="color: #0000ff">Or</span> _
(<span style="color: #0000ff">Left</span>(oItem.Subject, 18) = "<span style="color: #8b0000">Weblog
pingback by</span>") <span style="color: #0000ff">Then</span> Index = <span style="color: #0000ff">InStr</span>(1,
oItem.Body, "<span style="color: #8b0000">Delete Trackback:</span>") <span style="color: #0000ff">If</span> (Index
&lt;&gt; 0) <span style="color: #0000ff">Then</span> URL = <span style="color: #0000ff">Mid</span>(oItem.Body,
Index + 18) URL = <span style="color: #0000ff">Left</span>(URL, <span style="color: #0000ff">Len</span>(URL)
- 1) oShell.ShellExecute URL, "<span style="color: #8b0000"></span>", "<span style="color: #8b0000"></span>",
"<span style="color: #8b0000">open</span>", 1 <span style="color: #0000ff">End</span><span style="color: #0000ff">If</span><span style="color: #0000ff">End</span><span style="color: #0000ff">If</span><span style="color: #0000ff">Next</span><span style="color: #0000ff">End</span><span style="color: #0000ff">Sub</span></pre>
        <p>
To use this macro, create a new macro and paste the source code; then select all the
"Trackback/Pingback" notifications messages and run the macro. It could obviously
be customized to work on entire folders or whatever, but that I leave to you. One
final suggestion: if you (like me) keep a 15-tab Firefox window open at all times,
you may want to open a new window (not tab, window!) so that you can then close all
the URLs at once.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=bffddb10-d312-40b2-9514-ae5bf5e21a84" />
      </body>
      <title>Outlook macro to take care of trackback spam</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,bffddb10-d312-40b2-9514-ae5bf5e21a84.aspx</guid>
      <link>http://www.tomergabel.com/OutlookMacroToTakeCareOfTrackbackSpam.aspx</link>
      <pubDate>Mon, 13 Nov 2006 09:53:02 GMT</pubDate>
      <description>&lt;p&gt;
As I mentioned before, I've had well over 300 trackback/pingback spam notifications
from dasBlog. Since this was well beyond what I was willing to mess with by hand,
I whipped up a quick Outlook macro to do the work for me:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; DeleteTrackback() &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; oSel
As Outlook.Selection &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; oItem As Outlook.MailItem &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; oShell &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt; oShell
= &lt;span style="color: #0000ff"&gt;CreateObject&lt;/span&gt;("&lt;span style="color: #8b0000"&gt;Shell.Application&lt;/span&gt;") &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt; oSel
= &lt;span style="color: #0000ff"&gt;Application&lt;/span&gt;.ActiveExplorer.Selection &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; x
= 1 To oSel.Count &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt; oItem = oSel.Item(x) &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;Left&lt;/span&gt;(oItem.Subject,
19) = "&lt;span style="color: #8b0000"&gt;Weblog trackback by&lt;/span&gt;") &lt;span style="color: #0000ff"&gt;Or&lt;/span&gt; _
(&lt;span style="color: #0000ff"&gt;Left&lt;/span&gt;(oItem.Subject, 18) = "&lt;span style="color: #8b0000"&gt;Weblog
pingback by&lt;/span&gt;") &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt; Index = &lt;span style="color: #0000ff"&gt;InStr&lt;/span&gt;(1,
oItem.Body, "&lt;span style="color: #8b0000"&gt;Delete Trackback:&lt;/span&gt;") &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; (Index
&amp;lt;&amp;gt; 0) &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt; URL = &lt;span style="color: #0000ff"&gt;Mid&lt;/span&gt;(oItem.Body,
Index + 18) URL = &lt;span style="color: #0000ff"&gt;Left&lt;/span&gt;(URL, &lt;span style="color: #0000ff"&gt;Len&lt;/span&gt;(URL)
- 1) oShell.ShellExecute URL, "&lt;span style="color: #8b0000"&gt;&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;&lt;/span&gt;",
"&lt;span style="color: #8b0000"&gt;open&lt;/span&gt;", 1 &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
To use this macro, create a new macro and paste the source code; then select all the
"Trackback/Pingback" notifications messages and run the macro. It could obviously
be customized to work on entire folders or whatever, but that I leave to you. One
final suggestion: if you (like me) keep a 15-tab Firefox window open at all times,
you may want to open a new window (not tab, window!) so that you can then close all
the URLs at once.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=bffddb10-d312-40b2-9514-ae5bf5e21a84" /&gt;</description>
      <category>Development</category>
      <category>Personal</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=e7c518a3-0a01-49b7-9de5-23f4b8e892b0</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,e7c518a3-0a01-49b7-9de5-23f4b8e892b0.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The <a href="http://www.tomergabel.com/EffectiveCommunicationInSoftwareDevelopmentIntroduction.aspx">previous
post</a> in this series was an overview of the various communication hurdles developers
and managers face. Here I will describe one of the methods we use at <a href="http://www.monfort.co.il/">Monfort</a> to
tackle these issues.
</p>
        <p>
We've been working very closely with one of our clients on a large variety of
projects, most of which are based off of a shared technological foundation (I suppose
you could call it a "framework," although it technically isn't). These projects generally
fall into one of three categories:
</p>
        <ol>
          <li>
Improvements to our technological infrastructure. These are either extremely
large projects (measured in man-years) or fairly small projects (usually several
weeks); 
</li>
          <li>
Product derivatives, demonstrations and platform ports that make use of the pre-existing
technological infrastructure; 
</li>
          <li>
New products that make little or no use of the pre-existing infrastructure.</li>
        </ol>
        <p>
Over the years the volume of work we do for this client has increased considerably,
creating the need for additional personnel in order to meet the demand. The caveat
is, obviously, increased managerial overhead. This can take one of two forms:
</p>
        <ol>
          <li>
Project management, in which a manager is directly related to all aspects of a particular
project. As soon as an order is placed for the project, the manager is responsible
to bring the project to fruition. More projects equate more project management; 
</li>
          <li>
Customer relations, in which a manager is responsible for maintaining contact with
the client and providing the initial technical contact point. The person in charge
has to have a very deep technical grip of the relevant technologies and be able to
communicate effectively with both business and engineering personnel (the client's
representatives as well as their customers). Finally, he has to maintain constant
vigilance so that new projects will actually move beyond the initial "what if" stages.</li>
        </ol>
        <p>
Although good project managers are hard to find, the real problems became evident
only when we added personnel to the customer relations position, which up until
that point was (for the most part) filled by just one person. The first hurdle was
in bringing additional people up to speed; the relevant knowledge was kept in e-mail
archives and the heads of several people, which adds up to very inefficient indexing.
A newly commissioned customer relations manager has to know a lot of non-trivial details:
the representatives of the various clients he'll be working with, the work methodology
against a variety of clients and similar information. The issue of knowledge
sharing becomes a much bigger issue when the manager moves beyond that point and goes
out to the field: he has to be kept up-to-date on all concurrent projects for
those customers, prospects for future projects and the various proposals and
discussions that had taken place, whether he was involved or not. When two or three
different people all share in those responsibilities, they have to be constantly synchronized 
</p>
        <p>
This is a <em>lot</em> of information, and it became very obvious very quickly that
we needed some system to manage and store it. After spending a lot of time thinking
about this, I arrived at a fairly coherent list of requirements from the knowledge
sharing platform we will employ:
</p>
        <ul>
          <li>
Any one of the customer relations managers should be able to freely access and update
information;</li>
          <li>
There should be no artificial limitations to the way information is written,
presented or interlinked;</li>
          <li>
The platform should be easy, if not trivial, to learn and use;</li>
          <li>
The platform should be web-based and accessible from everywhere (we often require
access to information for client sites).</li>
        </ul>
        <p>
Eventually, I came to the conclusion that the only knowledge/content management
system that could actually work in our corporate environment is a wiki.
</p>
        <p>
If you've been living under a rock for the past few years it's possible that you've
managed not to hear about <a href="http://www.wikipedia.org">Wikipedia</a>; the collaborative
encyclopedia is one of the most ambitious and impressive projects to have attained
a degree of success on the Internet. What distinguishes Wikipedia from similar, less
successful projects is that the knowledge stored in Wikipedia is <em>completely freeform</em>:
anyone can edit it, there are no predetermined schemas and no mandatory information
fields - anyone can enter data in the way they deem fit. Here-in lies both the
beauty and danger of a wiki: it doesn't brute-force the information into patterns.
This means that knowledge can be shared in any conceivable way and content editors
are free to interlink this knowledge in any way they deem appropriate. The danger
here is that most people aren't disciplined enough to invent their own patterns. In
our case this did not pose a problem, since only a small number of people were expected
to be involved in the effort.
</p>
        <p>
In the next post: installing, configuring and learning to effectively use the wiki.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=e7c518a3-0a01-49b7-9de5-23f4b8e892b0" />
      </body>
      <title>Effective communication in software development: Why wiki?</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,e7c518a3-0a01-49b7-9de5-23f4b8e892b0.aspx</guid>
      <link>http://www.tomergabel.com/EffectiveCommunicationInSoftwareDevelopmentWhyWiki.aspx</link>
      <pubDate>Thu, 12 Oct 2006 10:17:08 GMT</pubDate>
      <description>&lt;p&gt;
The &lt;a href="http://www.tomergabel.com/EffectiveCommunicationInSoftwareDevelopmentIntroduction.aspx"&gt;previous
post&lt;/a&gt; in this series was an overview of the various communication hurdles developers
and managers face. Here I will describe one of the methods we use at &lt;a href="http://www.monfort.co.il/"&gt;Monfort&lt;/a&gt; to
tackle these issues.
&lt;/p&gt;
&lt;p&gt;
We've been&amp;nbsp;working very closely with one of our clients on a large variety of
projects, most of which are based off of a shared technological foundation (I suppose
you could call it a "framework," although it technically isn't). These projects generally
fall into one of three categories:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Improvements to our technological infrastructure.&amp;nbsp;These are either extremely
large projects (measured in man-years)&amp;nbsp;or fairly small projects (usually several
weeks); 
&lt;li&gt;
Product derivatives, demonstrations&amp;nbsp;and platform ports that make use of the pre-existing
technological infrastructure; 
&lt;li&gt;
New products that make little or no use of the pre-existing infrastructure.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Over the years the volume of work we do for this client has increased considerably,
creating the need for additional personnel in order to meet the demand. The caveat
is, obviously, increased managerial overhead. This can take one of two forms:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Project management, in which a manager is directly related to all aspects of a particular
project. As soon as an order is placed for the project, the manager is responsible
to bring the project to fruition. More projects equate more project management; 
&lt;li&gt;
Customer relations, in which a manager is responsible for maintaining contact with
the client and&amp;nbsp;providing the initial technical contact point. The person in charge
has to have a very deep technical grip of the relevant technologies and be able to
communicate effectively with both business and engineering personnel (the client's
representatives as well as their customers). Finally, he has to maintain constant
vigilance so that new projects will actually move beyond the initial "what if"&amp;nbsp;stages.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Although good project managers are hard to find, the real problems became evident
only when we added personnel to the customer relations position, which&amp;nbsp;up until
that point was (for the most part) filled by just one person. The first hurdle was
in bringing additional people up to speed; the relevant knowledge was kept in e-mail
archives and the heads of several people, which adds up to&amp;nbsp;very inefficient indexing.
A newly commissioned customer relations manager has to know a lot of non-trivial details:
the representatives of the various clients he'll be working with, the work methodology
against a variety of clients and similar information.&amp;nbsp;The issue of knowledge
sharing becomes a much bigger issue when the manager moves beyond that point and goes
out&amp;nbsp;to the field: he has to be kept up-to-date on all concurrent projects for
those customers, prospects for future projects and&amp;nbsp;the various proposals and
discussions that had taken place, whether he was involved or not. When two or three
different people all share in those responsibilities, they have to be constantly synchronized 
&lt;/p&gt;
&lt;p&gt;
This is a &lt;em&gt;lot&lt;/em&gt; of information, and it became very obvious very quickly that
we needed some system to manage and store it. After spending a lot of time thinking
about this,&amp;nbsp;I arrived at a fairly coherent list of requirements from the knowledge
sharing platform we will employ:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Any one of the customer relations managers should be able to freely access and update
information;&lt;/li&gt;
&lt;li&gt;
There&amp;nbsp;should be&amp;nbsp;no artificial limitations to the way information is written,
presented or interlinked;&lt;/li&gt;
&lt;li&gt;
The platform should be easy, if not trivial, to learn and use;&lt;/li&gt;
&lt;li&gt;
The platform should be web-based and accessible from everywhere (we often require
access to information for client sites).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Eventually, I came&amp;nbsp;to the conclusion that the only knowledge/content management
system that could actually work in our corporate environment is a wiki.
&lt;/p&gt;
&lt;p&gt;
If you've been living under a rock for the past few years it's possible that you've
managed not to hear about &lt;a href="http://www.wikipedia.org"&gt;Wikipedia&lt;/a&gt;; the collaborative
encyclopedia is one of the most ambitious and&amp;nbsp;impressive projects to have attained
a degree of success on the Internet. What distinguishes Wikipedia from similar, less
successful projects is that the knowledge stored in Wikipedia is &lt;em&gt;completely freeform&lt;/em&gt;:
anyone can edit it, there are no predetermined schemas and&amp;nbsp;no mandatory information
fields -&amp;nbsp;anyone can enter data in the way they deem fit. Here-in lies both the
beauty and danger of a wiki: it doesn't brute-force the information into patterns.
This means that knowledge can be shared in any conceivable way and&amp;nbsp;content editors
are free to interlink this knowledge in any way they deem appropriate. The danger
here is that most people aren't disciplined enough to invent their own patterns. In
our case this did not pose a problem, since only a small number of people were expected
to be involved in the effort.
&lt;/p&gt;
&lt;p&gt;
In the next post: installing, configuring and learning to effectively use the wiki.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=e7c518a3-0a01-49b7-9de5-23f4b8e892b0" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=c6894f93-5d00-4fab-9fc6-a38a6144a4bd</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,c6894f93-5d00-4fab-9fc6-a38a6144a4bd.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
(This is the first in a series of posts, in which I will try to articulate the various
problems of communication in the software field and possible ideas on how to solve
those problems.)
</p>
        <p>
One of the most interesting aspects of being a software developer is communication.
Perhaps the single most important trait of a good software developer is the ability
to communicate with varying audiences:
</p>
        <ul>
          <li>
First and foremost, a software developer must be able to communicate effectively with
the other developers on his team. The usual tools apply: e-mails, whiteboard, hall
meetings, source code comments. For a developer this is relatively easy, since it
is unnecessary to translate the technical abstractions into a coherent conceptual
model: the abstractions themselves are familiar to all sides of the conversation. 
</li>
          <li>
A software developer must also be able to communicate effectively with his team leader,
project manager, boss - whatever you want to call it. This isn't quite as easy, as
such communication can have serious repercussions on the project, the work environment
and - potentially - the developer's career. Managers are usually not privy to the
ultra-technical subculture of software developers, and although they almost always
come from the same background they have just as often given up on subtle technicalities. 
</li>
          <li>
Finally, a software developer must be able to communicate effectively with clients. At
some point in almost every developer's career he is required to meet and at least
converse with a client, sometimes in order to figure out a bug, sometimes in order
to gather requirements for a new project. A lot of developers would rather avoid these
encounters because they are forced to re-think everything they say and translate abstractions.
A client is not, generally, heavily interested in technical matters, so
these must be explained carefully and coherently; most developers I know find this
process frustrating and draining.</li>
        </ul>
        <p>
A developer that delves into management is assumed to already be proficient in the
above scenarios, but management brings a whole new slew of communication problems
to the table:
</p>
        <ul>
          <li>
A manager is required to communicate with clients on a whole different level. When
a developer is asked to make an estimate, the estimate forms a basis for the cost
and schedule estimates his manager provides to the clients. The difference is
that the manager is required to explain these estimates and is <strong>personally
accountable </strong>to same. It is the manager's job to continuously communicate
with the client, reassure, explain and assume responsibility for whatever
pitfalls and hurdles the project encounters, and generally make sure the
project is on track. A manager is also required to act as a filter between the client
and the developers on the team for everyone's sake: on the one hand the manager is
required to "protect" the developers and the project from ridiculous requests and
whims on the client's side, and on the other hand he is required to make sure the
client's requirements are fulfilled to his satisfaction. 
</li>
          <li>
A manager must communicate effectively with the developers on his team. He must
establish trust and confidence, so that he can constantly be aware of what goes on
with his team while avoiding micromanagement and wasteful status meetings. This isn't
easy because the manager and the developer are fundamentally on opposite sides: efficiency
vs "doing the right thing", choosing wisely instead of following trends, cutting corners
instead of continuous refactoring and improvement. The only glue they have is the
desire for a successful project. A good manager must communicate his decisions to
the developers on his team to constantly maintain the trust and confidence he has
built; a frustrated or uptight developer is an inefficient developer. 
</li>
          <li>
Finally, a manager must be able to communicate effectively with other managers. This
is the least trivial form of communication for a variety of reasons: sometimes the
corporate atmosphere requires managers to be ultra-competitive. It is hard
working for a shared goal ("the good of the company") when one is constantly
competing with one's peers. Even lack of competition can be an issue when
two managers from different schools of management must collaborate, or when one manager
is frustrated by the other's inefficiency. And even when <em>all</em> managers are <em>equally</em> efficient and <em>equally</em> dedicated
to the shared goal, they must still share information between them and make sure the
collective company process is on track.</li>
        </ul>
        <p>
You'll notice that the two lists are in opposite order. This is no coincidence; I
ordered the lists so that the more difficult of the tasks are further down the list,
so for developers the most difficult form of communication is usually with customers,
whereas for managers it's communication with other managers.
</p>
        <p>
The next post will deal with knowledge management and how we've used a wiki internally
in our organization to alleviate the overhead of communication between managers.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=c6894f93-5d00-4fab-9fc6-a38a6144a4bd" />
      </body>
      <title>Effective communication in software development: Introduction</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,c6894f93-5d00-4fab-9fc6-a38a6144a4bd.aspx</guid>
      <link>http://www.tomergabel.com/EffectiveCommunicationInSoftwareDevelopmentIntroduction.aspx</link>
      <pubDate>Thu, 28 Sep 2006 09:35:37 GMT</pubDate>
      <description>&lt;p&gt;
(This is the first in a series of posts, in which I will try to articulate the various
problems of communication in the software field and possible ideas on how to solve
those problems.)
&lt;/p&gt;
&lt;p&gt;
One of the most interesting aspects of being a software developer is communication.
Perhaps the single most important trait of a good software developer is the ability
to communicate with varying audiences:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
First and foremost, a software developer must be able to communicate effectively with
the other developers on his team. The usual tools apply: e-mails, whiteboard, hall
meetings, source code comments. For a developer this is relatively easy, since it
is unnecessary to translate the technical abstractions into a coherent conceptual
model: the abstractions themselves are familiar to all sides of the conversation. 
&lt;li&gt;
A software developer must also be able to communicate effectively with his team leader,
project manager, boss - whatever you want to call it. This isn't quite as easy, as
such communication can have serious repercussions on the project, the work environment
and - potentially - the developer's career. Managers are usually not privy to the
ultra-technical subculture of software developers, and although they almost always
come from the same background they&amp;nbsp;have just as often given up on subtle technicalities. 
&lt;li&gt;
Finally, a software developer must be able to communicate effectively with clients.&amp;nbsp;At
some point in almost every developer's career he is required to meet and at least
converse with a client, sometimes in order to figure out a bug, sometimes in order
to gather requirements for a new project. A lot of developers would rather avoid these
encounters because they are forced to re-think everything they say and translate abstractions.
A client is not, generally,&amp;nbsp;heavily interested in&amp;nbsp;technical matters, so
these must be explained carefully and coherently; most developers I know find this
process frustrating and draining.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
A developer that delves into management is assumed to already be proficient in the
above scenarios, but management brings a whole new slew of communication problems
to the table:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
A manager is required to communicate with clients on a whole different level. When
a developer is asked to make an estimate, the estimate forms a basis for the cost
and schedule estimates&amp;nbsp;his manager provides to the clients. The difference is
that the manager is required to explain these estimates and is &lt;strong&gt;personally
accountable &lt;/strong&gt;to same. It is the manager's job to&amp;nbsp;continuously communicate
with the client, reassure, explain&amp;nbsp;and assume responsibility for&amp;nbsp;whatever
pitfalls&amp;nbsp;and hurdles the project encounters, and&amp;nbsp;generally make sure the
project is on track. A manager is also required to act as a filter between the client
and the developers on the team for everyone's sake: on the one hand the manager is
required to "protect" the developers and the project from ridiculous requests and
whims on the client's side, and on the other hand he is required to make sure the
client's requirements are fulfilled to his satisfaction. 
&lt;li&gt;
A manager&amp;nbsp;must communicate effectively with the developers on his team. He must
establish trust and confidence, so that he can constantly be aware of what goes on
with his team while avoiding micromanagement and wasteful status meetings. This isn't
easy because the manager and the developer are fundamentally on opposite sides:&amp;nbsp;efficiency
vs "doing the right thing", choosing wisely instead of following trends, cutting corners
instead of continuous refactoring and improvement. The only glue they have is the
desire for a successful project. A good manager must communicate his decisions to
the developers on his team to constantly maintain the trust and confidence he has
built; a frustrated or uptight developer is an inefficient developer. 
&lt;li&gt;
Finally, a manager must be able to communicate effectively with other managers.&amp;nbsp;This
is the least trivial form of communication for a variety of reasons: sometimes the
corporate atmosphere requires managers to be ultra-competitive. It&amp;nbsp;is&amp;nbsp;hard
working for a shared goal ("the good of the company") when&amp;nbsp;one is&amp;nbsp;constantly
competing with&amp;nbsp;one's peers. Even lack of competition can be&amp;nbsp;an issue when
two managers from different schools of management must collaborate, or when one manager
is frustrated by the other's inefficiency. And even when &lt;em&gt;all&lt;/em&gt; managers are &lt;em&gt;equally&lt;/em&gt; efficient&amp;nbsp;and &lt;em&gt;equally&lt;/em&gt; dedicated
to the shared goal, they must still share information between them and make sure the
collective company process is on track.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
You'll notice that the two lists are in opposite order. This is no coincidence; I
ordered the lists so that the more difficult of the tasks are further down the list,
so for developers the most difficult form of communication is usually with customers,
whereas for managers it's communication with other managers.
&lt;/p&gt;
&lt;p&gt;
The next post will deal with knowledge management and how we've used a wiki internally
in our organization to&amp;nbsp;alleviate the overhead of communication between managers.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=c6894f93-5d00-4fab-9fc6-a38a6144a4bd" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=8cd6046a-5e82-4f7a-84f4-960739589add</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,8cd6046a-5e82-4f7a-84f4-960739589add.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This wasn't an easy riddle by any means. One has to either have a <em>lot</em> of
experience developing both C and C++, or take a very hard look at the standards to
spot the differences. Bottom line? I couldn't find a solution. Fortunately a brother
and a colleague both came through:
</p>
        <p>
          <strong>
            <u>Solution 1: Ugly Hack</u>
          </strong>
        </p>
        <p>
Tal (one of my colleagues at <a href="http://www.monfort.co.il">Monfort</a>) came
up with the following concept:
</p>
        <blockquote>
          <pre>#include &lt;stdio.h&gt;

<span style="color: #0000ff">int</span> main()
{ <span style="color: #0000ff">int</span> a = 1<span style="color: #008000">//**/10</span> ; <span style="color: #0000ff">printf</span>(
"<span style="color: #8b0000">%d\n</span>", a ); <span style="color: #0000ff">return</span> 0;
}</pre>
        </blockquote>
        <p>
This deserves some explanation: originally C did not support single-line comments
(<font color="#008000">//</font>); these were added to a later version of the standard
called C99. So what happens is, if you compile this code with an old C compiler the
"<span class="codetext" style="color: #008000">//**/</span>" string is parsed as a
division operator and an empty comment, resulting in 1/10=0. A modern C compiler (or
any C++ compiler) will treat the entire line as a comment and the result is 1. 
One way to easily test this is to compile with <span class="codetext">gcc -std=c89
file.c</span>.
</p>
        <p>
          <strong>
            <u>Solution 2: Elegant Hack</u>
          </strong>
        </p>
        <p>
I didn't have the time to properly look for a detailed comparison of C and C++ standards
(I'll save you the time: <a href="http://david.tribble.com/text/cdiffs.htm">this looks
to be</a> a good source). There are probably quite a few ways to achieve the goal,
however my brother Mickey suggested one I find quite elegant:
</p>
        <blockquote>
          <pre>#include &lt;stdio.h&gt;

<span style="color: #0000ff">int</span> main()
{ <span style="color: #0000ff">printf</span>( "<span style="color: #8b0000">%d\n</span>", <span style="color: #0000ff">sizeof</span>(
'c' ) == <span style="color: #0000ff">sizeof</span>( <span style="color: #0000ff">char</span> )
); <span style="color: #0000ff">return</span> 0; }</pre>
        </blockquote>
        <p>
Seems odd? Apparently one of the (relatively small) breaking changes between C and
C++ is how character literals are handled. In C a character literal takes the type <span class="codetext">int</span>,
whereas in C++ a character literal has the expected size (<a href="http://david.tribble.com/text/cdiffs.htm#C99-char-literal">source</a>).
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=8cd6046a-5e82-4f7a-84f4-960739589add" />
      </body>
      <title>Solution: Another riddle for C/C++ developers</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,8cd6046a-5e82-4f7a-84f4-960739589add.aspx</guid>
      <link>http://www.tomergabel.com/SolutionAnotherRiddleForCCDevelopers.aspx</link>
      <pubDate>Tue, 26 Sep 2006 08:43:14 GMT</pubDate>
      <description>&lt;p&gt;
This wasn't an easy riddle by any means. One has to either have a &lt;em&gt;lot&lt;/em&gt; of
experience developing both C and C++, or take a very hard look at the standards to
spot the differences. Bottom line? I couldn't find a solution. Fortunately a brother
and a colleague both came through:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;u&gt;Solution 1: Ugly Hack&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Tal (one of my colleagues at &lt;a href="http://www.monfort.co.il"&gt;Monfort&lt;/a&gt;) came
up with the following concept:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;

&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; main()
{ &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; a = 1&lt;span style="color: #008000"&gt;//**/10&lt;/span&gt; ; &lt;span style="color: #0000ff"&gt;printf&lt;/span&gt;(
"&lt;span style="color: #8b0000"&gt;%d\n&lt;/span&gt;", a ); &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 0;
}&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This deserves some explanation: originally C did not support single-line comments
(&lt;font color="#008000"&gt;//&lt;/font&gt;); these were added to a later version of the standard
called C99. So what happens is, if you compile this code with an old C compiler the
"&lt;span class="codetext" style="color: #008000"&gt;//**/&lt;/span&gt;" string is parsed as a
division operator and an empty comment, resulting in 1/10=0. A modern C compiler (or
any C++ compiler) will treat the entire line as a comment and the result is 1.&amp;nbsp;
One way to easily test this is to compile with &lt;span class="codetext"&gt;gcc -std=c89
file.c&lt;/span&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;u&gt;Solution 2: Elegant Hack&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I didn't have the time to properly look for a detailed comparison of C and C++ standards
(I'll save you the time: &lt;a href="http://david.tribble.com/text/cdiffs.htm"&gt;this looks
to be&lt;/a&gt; a good source). There are probably quite a few ways to achieve the goal,
however my brother Mickey suggested one I find quite elegant:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;

&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; main()
{ &lt;span style="color: #0000ff"&gt;printf&lt;/span&gt;( "&lt;span style="color: #8b0000"&gt;%d\n&lt;/span&gt;", &lt;span style="color: #0000ff"&gt;sizeof&lt;/span&gt;(
'c' ) == &lt;span style="color: #0000ff"&gt;sizeof&lt;/span&gt;( &lt;span style="color: #0000ff"&gt;char&lt;/span&gt; )
); &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 0; }&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Seems odd? Apparently one of the (relatively small) breaking changes between C and
C++ is how character literals are handled. In C a character literal takes the type &lt;span class="codetext"&gt;int&lt;/span&gt;,
whereas in C++ a character literal has the expected size (&lt;a href="http://david.tribble.com/text/cdiffs.htm#C99-char-literal"&gt;source&lt;/a&gt;).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=8cd6046a-5e82-4f7a-84f4-960739589add" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=28dd9dd3-5fac-4858-8f44-82952a734949</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,28dd9dd3-5fac-4858-8f44-82952a734949.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#000000">Write a program that compiles under both C and C++ compilers,
and outputs "0" for C and "1" for C++ (or whatever, the actual numbers are not
the point). You obviously may not use compiler-dependant macros, __CPLUSPLUS__-type
macros or anything of the sort.</font>
        </p>
        <p>
          <font color="#000000">Once again, I'll post the solution in a couple of days.</font>
        </p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=28dd9dd3-5fac-4858-8f44-82952a734949" />
      </body>
      <title>Another riddle for C/C++ developers</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,28dd9dd3-5fac-4858-8f44-82952a734949.aspx</guid>
      <link>http://www.tomergabel.com/AnotherRiddleForCCDevelopers.aspx</link>
      <pubDate>Tue, 12 Sep 2006 13:40:55 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font color="#000000"&gt;Write a program that compiles under both C and C++ compilers,
and outputs "0" for C and "1" for C++&amp;nbsp;(or whatever, the actual numbers are not
the point). You obviously may not use compiler-dependant macros, __CPLUSPLUS__-type
macros or anything of the sort.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#000000"&gt;Once again, I'll post the solution in a couple of days.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=28dd9dd3-5fac-4858-8f44-82952a734949" /&gt;</description>
      <category>Development</category>
    </item>
    <item>
      <trackback:ping>http://www.tomergabel.com/Trackback.aspx?guid=1d67512c-5c8b-4dc8-ac75-acf265866175</trackback:ping>
      <pingback:server>http://www.tomergabel.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.tomergabel.com/PermaLink,guid,1d67512c-5c8b-4dc8-ac75-acf265866175.aspx</pingback:target>
      <dc:creator>Tomer Gabel</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here's one possible solution for the riddle I <a href="http://www.tomergabel.com/ACuteRiddleInC.aspx">posted</a> a
few days ago:
</p>
        <ol>
          <li>
Replace <span class="codetext"><strong>i &lt; N</strong></span> with <span class="codetext"><strong>-i
&lt; N</strong></span></li>
          <li>
Replace <span class="codetext"><strong>i--</strong></span> with <span class="codetext"><strong>N--</strong></span></li>
          <li>
Replace <span class="codetext"><strong>i &lt; N</strong></span> with <span class="codetext"><strong>i
+ N</strong></span></li>
        </ol>
        <p>
This isn't a particularly hard riddle - it took me about 10 minutes to come up with
the solution, although I imagine a developer with more recent C experience will
be much quicker. Regardless it's a pretty good way to tone those C muscles.
</p>
        <img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=1d67512c-5c8b-4dc8-ac75-acf265866175" />
      </body>
      <title>Solution: A cute riddle in C</title>
      <guid isPermaLink="false">http://www.tomergabel.com/PermaLink,guid,1d67512c-5c8b-4dc8-ac75-acf265866175.aspx</guid>
      <link>http://www.tomergabel.com/SolutionACuteRiddleInC.aspx</link>
      <pubDate>Tue, 12 Sep 2006 13:23:00 GMT</pubDate>
      <description>&lt;p&gt;
Here's one possible solution for the riddle I &lt;a href="http://www.tomergabel.com/ACuteRiddleInC.aspx"&gt;posted&lt;/a&gt; a
few days ago:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Replace &lt;span class="codetext"&gt;&lt;strong&gt;i &amp;lt; N&lt;/strong&gt;&lt;/span&gt; with &lt;span class="codetext"&gt;&lt;strong&gt;-i
&amp;lt; N&lt;/strong&gt;&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
Replace &lt;span class="codetext"&gt;&lt;strong&gt;i--&lt;/strong&gt;&lt;/span&gt; with &lt;span class="codetext"&gt;&lt;strong&gt;N--&lt;/strong&gt;&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;
Replace &lt;span class="codetext"&gt;&lt;strong&gt;i &amp;lt; N&lt;/strong&gt;&lt;/span&gt; with &lt;span class="codetext"&gt;&lt;strong&gt;i
+ N&lt;/strong&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
This isn't a particularly hard riddle - it took me about 10 minutes to come up with
the solution, although I imagine a&amp;nbsp;developer with more recent C experience will
be much quicker.&amp;nbsp;Regardless it's a pretty good way to&amp;nbsp;tone those C muscles.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.tomergabel.com/aggbug.ashx?id=1d67512c-5c8b-4dc8-ac75-acf265866175" /&gt;</description>
      <category>Development</category>
    </item>
  </channel>
</rss>