<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" 
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    
    xmlns:content="http://purl.org/rss/1.0/modules/content/">

  <channel>
    <title>C# category of Luke Hutteman's public virtual MemoryStream</title>
    <link>http://www.hutteman.com/weblog/cat_c.html</link>
    <description>Get a complete rss feed (all categories) at &lt;a href="http://www.hutteman.com/weblog/rss.xml"&gt;http://www.hutteman.com/weblog/rss.xml&lt;/a&gt;</description>
    <dc:language>en-us</dc:language>
    <dc:creator>luke@hutteman.com</dc:creator>
    <dc:rights>Copyright 2008</dc:rights>
    <dc:date>2006-03-09T22:06:27-05:00</dc:date>
    <admin:generatorAgent rdf:resource="http://www.movabletype.org/?v=3.33" />
    <admin:errorReportsTo rdf:resource="mailto:luke@hutteman.com"/>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
    

    <item>
      <title>Why I Hate Frameworks</title>
      <link>http://www.hutteman.com/weblog/2006/03/09-245.html</link>
      <description>Benji Smith in Why I Hate Frameworks: So this week, we're introducing a general-purpose tool-building factory factory factory, so that all of your different tool factory factories can be produced by a single, unified factory. The factory factory factory will produce only the tool factory factories that you actually need, and each of those factory factories will produce a single... (112 words)</description>
      <guid isPermaLink="false">245@http://www.hutteman.com/weblog/</guid>
      <content:encoded><![CDATA[<p><a href="http://benjismith.net/">Benji Smith</a> in <a href="http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12">Why I Hate Frameworks</a>:</p>
<blockquote>
So this week, we're introducing a general-purpose tool-building factory factory factory, so that all of your different tool factory factories can be produced by a single, unified factory. The factory factory factory will produce only the tool factory factories that you actually need, and each of those factory factories will produce a single factory based on your custom tool specifications. The final set of tools that emerge from this process will be the ideal tools for your particular project.
</blockquote>
<p>
A great read that not only shows why I too hate most frameworks, but also over-engineered code in general. YAGNI FTW! (via <a href="http://pluralsight.com/blogs/dbox/archive/2006/03/08/19865.aspx">Don Box</a>)
</p>
]]></content:encoded>
              <category>C#</category>
              <category>Java</category>
      
      <dc:date>2006-03-09T22:06:27-05:00</dc:date>
      
    </item>
    <item>
      <title>JVM hack implementations, and why I love Java</title>
      <link>http://www.hutteman.com/weblog/2005/06/03-227.html</link>
      <description> During a Java debug session today, I was investigating an exception and noticed that its cause was set to itself; effectively leading to an infinite stacktrace (or so I thought). When I added a watch on exception.getCause(), this returned null though, so I initially assumed this was a bug in my IDE (I'm using a beta release of IDEA... (579 words)</description>
      <guid isPermaLink="false">227@http://www.hutteman.com/weblog/</guid>
      <content:encoded><![CDATA[<p>
During a Java debug session today, I was investigating an exception and noticed
that its <code>cause</code> was set to itself; effectively leading to an infinite
stacktrace (or so I thought).
</p><p>
When I added a watch on <code>exception.getCause()</code>, this returned
<code>null</code> though, so I initially assumed this was a bug in my IDE (I'm using a beta release of <a href="http://www.jetbrains.com/idea/features/newfeatures.html">IDEA 5.0</a>).
However, a quick check of the source-code of <code>Throwable</code> disproved that initial assumption. As
it turns out, this problem is caused by a JVM hack implementation.
</p><p>
Take a look at the excerpt from <code>Throwable</code> below:

<blockquote><pre>
  /**
   * The throwable that caused this throwable to get thrown, or null if this
   * throwable was not caused by another throwable, or if the causative
   * throwable is unknown.  If this field is equal to this throwable itself,
   * it indicates that the cause of this throwable has not yet been
   * initialized.
   *
   * @serial
   * @since 1.4
   */
  private Throwable cause = this;

  public Throwable getCause() {
      return (cause==this ? null : cause);
  }

  public synchronized Throwable initCause(Throwable cause) {
      if (this.cause != this)
          throw new IllegalStateException("Can't overwrite cause");
      if (cause == this)
          throw new IllegalArgumentException("Self-causation not permitted");
      this.cause = cause;
      return this;
  }
</pre></blockquote>

It turns out that self-causation is the default state; indicating that the
<code>cause</code> has not yet been initialized. In other words, it's nothing
but a hack to save the developer from either adding a <code>causeInitialized boolean</code>
to <code>Throwable</code>, or (if they really felt they need to save those 4 bytes),
doing something like

<blockquote><pre>
  private static Throwable NOT_INITIALIZED =
             new Throwable("CAUSE NOT INITIALIZED", null);
    
  private Throwable cause = NOT_INITIALIZED;
</pre></blockquote>

Now from a runtime-perspective, this hack really doesn't matter as <code>cause</code>
is <code>private</code> and the <code>this</code> initial value is never returned
to the user. Unfortunately from a debug-perspective, this implementation is utterly
confusing.
</p><p>
So why do I still say I love Java? Because, unlike .NET for instance, I have access to the
source-code in moments like this. Language-wise, I actually prefer C# over Java. Library-wise, I also tend to favor the .NET implementations
over their Java counterparts. But with .NET, if something works somewhat differently
from what I would expect, I don't have the option of checking the actual implementation.
To me, this is a <b>BIG DEAL</b>. Having the source available is not only helpful in situations
like this, but it's also a tremendous aid when you truly want to grok an API.
</p><p>
And yes, I'm aware of the existence of Rotor and decompilers, but
<ol type='a'>
<li>Rotor is an incomplete implementation, lacking all of WinForms for instance.</li>
<li>Decompilation is not perfect and sometimes leads to awkward looking code.</li>
<li>Checking code from either Rotor or decompiling a class tends to not be integrated in VS.NET, so I'm forced to leave the IDE for tasks like this.</li>
<li>.NET decompilers typically show only one decompiled method at a time (the ones I've tried did this anyway) instead of the full
class, leading to a more fragmented view of the code.</li>
<li>Decompiled code lacks comments and sometimes even lacks the original variable-names.</li>
</ol>
</p><p>
There's been some dialog going on for over a year now about open-sourcing Java, but as far as I'm concerned, Java's already open-source enough. I just wish .NET would follow Java's example on this aspect as well. I don't need a license to allow me to change the source, but it sure would be nice if Microsoft would surprise me and include the source in .NET 2.0...
</p>]]></content:encoded>
              <category>C#</category>
              <category>Java</category>
      
      <dc:date>2005-06-03T23:15:59-05:00</dc:date>
            <comments>http://www.hutteman.com/weblog/2005/06/03-227.html#comments</comments>
      
    </item>
    <item>
      <title>C# Continuations useful? Hell yeah!</title>
      <link>http://www.hutteman.com/weblog/2005/04/26-224.html</link>
      <description>Last week, Sam Ruby posted a very interesting article on continuations for &quot;people older than dirt&quot; (a category which I, according to his definition, fall into). The topic became even more interesting when Don Box posted how you can use a very similar syntax in the next iteration of C#. Shortly thereafter, Cedric Beust posted that he wasn't convinced on... (530 words)</description>
      <guid isPermaLink="false">224@http://www.hutteman.com/weblog/</guid>
      <content:encoded><![CDATA[<p>Last week, Sam Ruby posted a very interesting <a href="http://www.intertwingly.net/blog/2005/04/13/Continuations-for-Curmudgeons">article</a> on continuations for "people older than dirt" (a category which I, according to his definition, fall into). The topic became even more interesting when Don Box <a href="http://pluralsight.com/blogs/dbox/archive/2005/04/17/7467.aspx">posted</a> how you can use a very similar syntax in the next iteration of C#. Shortly thereafter, Cedric Beust <a href="http://beust.com/weblog/archives/000272.html">posted</a> that he wasn't convinced on the usefulness of this construct, and that a simple Java class without continuations pretty much does the same thing.
</p><p>
Despite having, like Cedric, mainly a Java background, I do think this construct will be useful, and would welcome it in the next release (that seems to be the established pattern anyway). Consider the example of trying to write a filtered Iterator. Using the C# 2.0, the code almost writes itself:

<pre>
    class Program
    {
        public static IEnumerable&lt;T> IteratorFilter&lt;T>(IEnumerable&lt;T> iterator,
                                                       Predicate&lt;T> predicate)
        {
            foreach (T value in iterator)
            {
                if (predicate(value))
                {
                    yield return value;
                }
            }
        }

        static void Main()
        {
            int[] values = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
            foreach(int i in IteratorFilter(values, 
                    delegate(int v){ return v%2 == 0; }))
            {
                Console.WriteLine(i); // even numbers only
            }
        }
    }
</pre>

The same can definitely not be said for Java. My initial version took quite a bit longer to create than the C# version, and ended up looking like this:

<pre>
    public interface Predicate&lt;T> {
        boolean evaluate(T value);
    }

    public class IteratorFilter&lt;T> implements Iterator&lt;T> {
        private Iterator&lt;T> _iterator;
        private Predicate&lt;T> _predicate;
        private T _currentValue;
        private boolean _hasNext = true;
    
        public IteratorFilter(Iterator&lt;T> iterator, Predicate&lt;T> predicate) {
            _iterator = iterator;
            _predicate = predicate;
            skipFiltered();
        }
    
        private void skipFiltered() {
            while (_iterator.hasNext()) {
                _currentValue = _iterator.next();
                if (_predicate.evaluate(_currentValue)) {
                    return;
                }
            }
            _hasNext = false;
        }
    
        public boolean hasNext() {
            return _hasNext;
        }
    
        public T next() {
            if (!_hasNext) {
                throw new NoSuchElementException();
            }
            T result = _currentValue;
            skipFiltered();
            return result;
        }
    
        public void remove() {
            throw new UnsupportedOperationException();
        }
    
        public static void main(String[] args) {
            Integer[] values = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
            Iterator&lt;Integer> i = new IteratorFilter&lt;Integer>(
                    Arrays.asList(values).iterator(), 
                    new Predicate&lt;Integer>() {
                        public boolean evaluate(Integer value) {
                            return value % 2 == 0;
                        }
                    });
    
            while(i.hasNext()) {
                System.out.println(i.next());
            }
        }
    }
</pre>

Ouch! Without continuations, there's no option to just iterate over the elements and filter out the unwanted values, like I did in the C# implementation. Instead, I'm forced to create a class that implements the <code>Iterator</code> interface, store <code>_currentValue</code> and <code>_hasNext</code> as fields, and create a <code>skipFiltered()</code> method to skip unwanted values.
</p><p>
I am aware that C#'s <code>IEnumarable</code> isn't exactly the same as a Java <code>Iterator</code>; in a way it's more like a subset of Java's <code>Collection</code>. However, creating a Java function that creates a new <code>Collection</code> (containing the filtered subset of the original) wouldn't be quite the same as it would create a second Collection and have all filtering done up-front, instead of just an iterator whose elements are fetched from the original in an on-demand fashion.
</p><p>
Disclaimer: I am by no means an expert on the new constructs in C# 2.0 or Java 5.0 (far from it) - if I've overlooked something, please let me know in the comment section below.
</p>]]></content:encoded>
              <category>C#</category>
              <category>Java</category>
      
      <dc:date>2005-04-26T00:41:59-05:00</dc:date>
            <comments>http://www.hutteman.com/weblog/2005/04/26-224.html#comments</comments>
      
    </item>
    <item>
      <title>Am I back on dial-up?</title>
      <link>http://www.hutteman.com/weblog/2005/04/20-222.html</link>
      <description>Many years ago, before I got broadband, I remember sometimes having to leave my computer turned on overnight to complete some huge (back then: anything over a few MBs) download, only to oftentimes find in the morning that my modem had hung up shortly after I went to bed. Last night, I felt like I was back in that age... (265 words)</description>
      <guid isPermaLink="false">222@http://www.hutteman.com/weblog/</guid>
      <content:encoded><![CDATA[<p>Many years ago, before I got broadband, I remember sometimes having to leave my computer turned on overnight to complete some huge (back then: anything over a few MBs) download, only to oftentimes find in the morning that my modem had hung up shortly after I went to bed.</p>

<p>Last night, I felt like I was back in that age again. I started downloading the <a href="http://lab.msdn.microsoft.com/teamsystem/">Visual Studio 2005 Team Suite Beta 2</a> from MSDN (which weighs in at a whopping 3.75GB) and was told it would take more than eight hours to complete. Then in the middle of the night (when one of my kids woke up and got me out of bed) I checked it, only to find that the download had stopped and the File Transfer Manager was just sitting idly waiting for me to press the "Resume" button (hopefully VS.NET itself will be smarter than the download manager you need to get it). So anyway, I continued the download and when I woke up this morning I found it had still only downloaded 24% :-(</p>

<p>I've had it running all day today and have gotten up to 63% right now, with a time remaining that fluctuates between 3 and 10 hours. If everything works out I guess it should complete by tomorrow, after which there's no doubt a  multi-hour install procedure coming up...</p>

<p>What the F is in this thing for it to be so freaking huge? A <a href="http://intellij.net/eap/products/idea/download.jsp">top-notch Java IDE</a> can fit in 40MB; is VS.NET really 100 times better / have 100 times more features? Guess I'll find out tomorrow...</p>]]></content:encoded>
              <category>C#</category>
      
      <dc:date>2005-04-20T00:10:19-05:00</dc:date>
            <comments>http://www.hutteman.com/weblog/2005/04/20-222.html#comments</comments>
      
    </item>
    <item>
      <title>DotNetRocks + iPod tip</title>
      <link>http://www.hutteman.com/weblog/2004/09/12-212.html</link>
      <description>I love listening to DotNetRocks on my iPod while driving to work, but one thing has been bothering me for a long time: when you pause the show halfway and then either dock the iPod or listen to something else, you lose where you were. This means that in order to continue listening later, you need to manually fast-forward back... (240 words)</description>
      <guid isPermaLink="false">212@http://www.hutteman.com/weblog/</guid>
      <content:encoded><![CDATA[<p>I love listening to <a href="http://www.franklins.net/dotnetrocks/">DotNetRocks</a> on my <a href="http://www.apple.com/ipod/">iPod</a> while driving to work, but one thing has been bothering me for a long time: when you pause the show halfway and then either dock the iPod or listen to something else, you lose where you were. This means that in order to continue listening later, you need to manually fast-forward back there.
</p><p>
I just found out that for audio-books, iPods do keep a bookmark though, and any AAC file will be recognized as an audiobook if it has a .m4b file-extension (instead of the default .m4a). So to be able to bookmark your DotNetRocks shows, follow the following directions:
<ul>
<li>Download the "Windows Media" version of the show.</li>
<li>Drag 'n drop it into iTunes, which will automatically convert the .wma file to a .m4a file. (you could have also downloaded the mp3 and manually converted that to aac through iTunes, but the sound-quality of WMAs is better and iTunes will auto-convert them).</li>
<li>After the conversion is complete, right-click on the file and select "Show Song File" - an explorer window will pop-up for the directory containing the converted file.</li>
<li>Rename the file-extension to .m4b.</li>
<li>Drag 'n drop this file back into iTunes (it will now show up as a "Protected AAC Audio File").</li>
<li>Remove the original file from iTunes.</li>
<li>Et Voila! Your iPod will now automatically set a bookmark when you pause DotNetRocks, and continue playing from there when you return later.</li>
</ul>
</p>]]></content:encoded>
              <category>C#</category>
              <category>Miscellaneous</category>
      
      <dc:date>2004-09-12T01:44:05-05:00</dc:date>
            <comments>http://www.hutteman.com/weblog/2004/09/12-212.html#comments</comments>
      
    </item>


  </channel>
</rss>
