<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5707533511952913639</id><updated>2012-02-16T06:51:26.677-05:00</updated><category term='C#'/><category term='C++/CLI'/><category term='Scala'/><category term='nroles'/><category term='oo'/><category term='mixin'/><category term='trait'/><category term='Nemerle'/><category term='aggregation'/><category term='Oxygene'/><category term='F#'/><category term='SQLServer'/><category term='DCI'/><category term='role'/><category term='Java'/><category term='Metaprogramming'/><title type='text'>Code Crafter</title><subtitle type='html'>Exit the Cruft, Enter the Craft</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-413415844250997668</id><published>2011-08-17T13:01:00.001-04:00</published><updated>2011-08-17T13:04:41.906-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='oo'/><title type='text'>Why is composition harder than inheritance?</title><summary type='text'>(just some random thoughts...)

Let's take this Java example:

class Base {
  public void method() {}
}
class Derived extends Base {}


See how easy it is for Derived to "reuse" code from Base? Derived is a subclass of Base, and in its constructor it calls Base's constructor, constructing a Base before constructing a Derived:

class Derived : Base {

  // this is what gets generated</summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/413415844250997668/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=413415844250997668' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/413415844250997668'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/413415844250997668'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2011/08/why-is-composition-harder-than.html' title='Why is composition harder than inheritance?'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-511967219773039749</id><published>2011-06-03T22:52:00.009-04:00</published><updated>2011-10-18T11:30:13.482-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DCI'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='role'/><category scheme='http://www.blogger.com/atom/ns#' term='nroles'/><title type='text'>DCI Example with NRoles</title><summary type='text'>The DCI (Data, Context, Interactions) architecture is a style that proposes an interesting separation of concerns between the domain model of a system (what the system is) and its behavior (what the system does), normally associated with its use cases. The rationale is that, since these parts incur change at different rates, isolating them from each other results in a system that's easier to </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/511967219773039749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=511967219773039749' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/511967219773039749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/511967219773039749'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2011/06/dci-example-with-nroles.html' title='DCI Example with NRoles'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-3004252319132653714</id><published>2011-05-29T06:05:00.008-04:00</published><updated>2011-08-03T10:24:20.766-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='trait'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='role'/><category scheme='http://www.blogger.com/atom/ns#' term='nroles'/><title type='text'>NRoles: An experiment with roles in C#</title><summary type='text'>In the last months, I've been developing in my spare time a proof-of-concept post-compiler with Mono.Cecil to enable roles in C#: NRoles. Roles are high level constructs that enable better code reuse through easier composition. They are very similar to traits as described in the traits paper (pdf).

Set up

NRoles is hosted on google code. You can get the latest source code with this mercurial </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/3004252319132653714/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=3004252319132653714' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/3004252319132653714'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/3004252319132653714'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2011/05/nroles-experiment-with-roles-in-c.html' title='NRoles: An experiment with roles in C#'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-5046912855791996045</id><published>2011-04-22T13:34:00.000-04:00</published><updated>2011-04-22T13:35:18.020-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Metaprogramming'/><category scheme='http://www.blogger.com/atom/ns#' term='Nemerle'/><title type='text'>More Macros in Nemerle</title><summary type='text'>
After a very brief introduction to Nemerle metaprogramming, what follows is some motivation and better expression macros examples.



Historically in C#, the using statement has been abused (guilty!) to provide a more convenient syntax to operations that have natural wrap up code which should be executed at the end of a logical scope. To enable a class to be usable like this, it just needs to </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/5046912855791996045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=5046912855791996045' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/5046912855791996045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/5046912855791996045'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2011/04/more-macros-in-nemerle.html' title='More Macros in Nemerle'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-1691830104132193285</id><published>2011-04-14T20:59:00.006-04:00</published><updated>2011-04-22T13:35:45.200-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Metaprogramming'/><category scheme='http://www.blogger.com/atom/ns#' term='Nemerle'/><title type='text'>Metaprogramming in Nemerle</title><summary type='text'>
Nemerle is a generally unknown .NET language that nevertheless has many impressive features. Its syntax is close to C#, but it has many functional programming constructs, like algebraic data types and pattern matching, that are not found in the Redmond language. It also has a very powerful metaprogramming system, where special constructs can participate in the compiler's execution pipeline and </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/1691830104132193285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=1691830104132193285' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/1691830104132193285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/1691830104132193285'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2011/04/metaprogramming-in-nemerle.html' title='Metaprogramming in Nemerle'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-3877227831091684489</id><published>2011-03-24T09:53:00.003-04:00</published><updated>2011-03-24T09:58:41.284-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mixin'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>C# Mixins With State</title><summary type='text'>
With the C# quasi-mixin pattern, one of the biggest limitations is that the mixins can't introduce state to a class. An alternative was for the mixin interface to require the composing classes to implement a property that the mixin would use as its own, as demonstrated in this example.



In the .NET Framework 4.0, the ConditionalWeakTable&lt;TKey, TValue&gt; class can be used to associate arbitrary </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/3877227831091684489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=3877227831091684489' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/3877227831091684489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/3877227831091684489'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2011/03/c-mixins-with-state.html' title='C# Mixins With State'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-8995646546535190360</id><published>2010-11-09T09:26:00.006-05:00</published><updated>2011-06-28T08:32:35.689-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aggregation'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Oxygene'/><title type='text'>Interface Implementation Through Aggregation</title><summary type='text'>
It's very tedious, mechanical and error-prone to implement an interface where all its members just delegate the call to some field or property that also implements the interface. For these C# types:



interface I {
  void M1();
  void M2();
  void M3();
}

class C : I {
  public void M1() { /*...*/ }
  public void M2() { /*...*/ }
  public void M3() { /*...*/ }
}



To implement the interface I</summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/8995646546535190360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=8995646546535190360' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/8995646546535190360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/8995646546535190360'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/11/interface-implementation-through_09.html' title='Interface Implementation Through Aggregation'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-535583633169236857</id><published>2010-10-29T13:55:00.004-04:00</published><updated>2010-11-05T11:46:38.986-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++/CLI'/><category scheme='http://www.blogger.com/atom/ns#' term='trait'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='role'/><title type='text'>Roles in C# Implementation</title><summary type='text'>
After seeing what roles in C# might look like, let's see the necessary transformations that would enable them. This is one possibility that a C# compiler could use to implement roles without having to make changes to the underlying CLR.


Roles


A role is transformed into a set of types: an interface (which the compositions will implement), a static class with the role code, and a class that </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/535583633169236857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=535583633169236857' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/535583633169236857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/535583633169236857'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/10/roles-in-c-implementation.html' title='Roles in C# Implementation'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-2403367977684819132</id><published>2010-10-26T11:28:00.008-04:00</published><updated>2010-10-29T13:58:23.106-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='trait'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='role'/><title type='text'>Roles in C#</title><summary type='text'>
Traits (pdf) are described as composable units of behavior, and are a natural evolutionary path for languages like C# or Java. Microsoft must be seriously looking at them, since it's sponsored some research about Traits in C# (pdf). I'll describe what I think is an extension to the traits idea that would make a great feature in C# (and in Java, VB.NET, ...): roles.



Roles are already a reality</summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/2403367977684819132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=2403367977684819132' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/2403367977684819132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/2403367977684819132'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/10/roles-in-c.html' title='Roles in C#'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-4642078835626415146</id><published>2010-08-04T22:31:00.017-04:00</published><updated>2010-08-05T11:38:19.620-04:00</updated><title type='text'>Working Effectively with Legacy Code</title><summary type='text'>
It's a known fact of life that code bases, if not actively nurtured, deteriorate with time. Maintaining, fixing bugs, extending, creating new features; all exert forces that push a design beyond its original intended boundaries, breaking the envelope of its original frame. Not long after its first release (sometimes, even before it), there's not even a trace of design, there's no conceptual </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/4642078835626415146/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=4642078835626415146' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/4642078835626415146'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/4642078835626415146'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/08/working-effectively-with-legacy-code.html' title='Working Effectively with Legacy Code'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_VNI-E-dho7o/TFrWPlpj5pI/AAAAAAAAANM/TH_7k6QSz-A/s72-c/WEWLC.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-4058688090554471370</id><published>2010-04-21T12:04:00.009-04:00</published><updated>2011-03-28T09:18:26.690-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>A more understandable IComparable</title><summary type='text'>
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler



In the .NET framework the IComparable&lt;T&gt; interface is used to compare values:



public interface IComparable&lt;T&gt; {
  int CompareTo(T other);
}



The comparison is done with the CompareTo method. It returns zero if the current object is equal to the passed in </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/4058688090554471370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=4058688090554471370' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/4058688090554471370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/4058688090554471370'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/04/more-understandable-icomparable.html' title='A more understandable IComparable'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-7045201164293535403</id><published>2010-03-10T12:52:00.008-05:00</published><updated>2010-04-03T09:20:11.387-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scala'/><category scheme='http://www.blogger.com/atom/ns#' term='trait'/><category scheme='http://www.blogger.com/atom/ns#' term='mixin'/><title type='text'>Scala Traits Under the Hood</title><summary type='text'>
Scala is a very feature-rich language built on top of the JVM (there's also a version on the CLR, but the focus is clearly on the JVM). Besides its functional features, it introduces a number of constructs that facilitate large scale components development and code reuse. Scala has traits, which are a great tool for orthogonal code reuse.



In its simplest form, a trait can be used just like an</summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/7045201164293535403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=7045201164293535403' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/7045201164293535403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/7045201164293535403'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/03/scala-traits-under-hood.html' title='Scala Traits Under the Hood'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-8146214056368990604</id><published>2010-02-12T12:31:00.007-05:00</published><updated>2011-03-28T12:17:22.419-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mixin'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>C# Quasi-Mixins Example</title><summary type='text'>
As an example, I'll adapt one of the mixins found in the book Fundamentals of Object-Oriented Design in UML to use the C# quasi-mixins pattern.



Given the following (simplified) domain classes:



namespace Domain {

  public enum Medium { 
    Email,
    SnailMail, 
    IntergalacticMail
  }

  public class Customer {
    public string Name { get; set; }
    public string Address { get; set; </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/8146214056368990604/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=8146214056368990604' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/8146214056368990604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/8146214056368990604'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/02/c-quasi-mixins-example.html' title='C# Quasi-Mixins Example'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-3214593977019811880</id><published>2010-02-04T12:46:00.020-05:00</published><updated>2011-03-28T12:15:18.864-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mixin'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>C# Quasi-Mixins Pattern</title><summary type='text'>
Extension methods are an interesting feature of C#. They allow for behavior to be added to existing classes. For example, a ToXml() method can be added to class Object, effectively making that method available everywhere:



public static class XmlSerializableExtension {
  public static string ToXml(this Object self) {
    if (self == null) throw new ArgumentNullException();
    var serializer =</summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/3214593977019811880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=3214593977019811880' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/3214593977019811880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/3214593977019811880'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/02/c-quasi-mixins-pattern.html' title='C# Quasi-Mixins Pattern'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-4521230227792566230</id><published>2010-01-31T18:10:00.016-05:00</published><updated>2010-02-01T13:01:58.250-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Revisiting IDisposable</title><summary type='text'>
In my last post, I've introduced a better alternative to the official pattern for implementing the IDisposable interface in .NET:



public class BetterDisposableClass : IDisposable {

  public void Dispose() {
    CleanUpManagedResources();
    CleanUpNativeResources();
    GC.SuppressFinalize(this);
  }

  protected virtual void CleanUpManagedResources() { 
    // ...
  }
  protected virtual </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/4521230227792566230/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=4521230227792566230' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/4521230227792566230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/4521230227792566230'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/01/revisiting-idisposable.html' title='Revisiting IDisposable'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-6765883555262223294</id><published>2010-01-26T18:28:00.019-05:00</published><updated>2010-02-11T10:37:31.706-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>A Better IDisposable Pattern</title><summary type='text'>
In .NET, objects that implement the IDisposable interface are objects that need special cleanup code to run deterministically when they're not needed anymore. (Another interesting use of this interface is to delimit a scope, but I'll focus on the original cleanup use case in this post.)



public interface IDisposable {
  // cleanup resources
  void Dispose();
}



Most .NET languages have a </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/6765883555262223294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=6765883555262223294' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/6765883555262223294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/6765883555262223294'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2010/01/better-idisposable-pattern.html' title='A Better IDisposable Pattern'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-6877235201412316143</id><published>2009-10-13T16:45:00.012-04:00</published><updated>2010-02-11T10:35:33.827-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Java: BigDecimal's Big Problems</title><summary type='text'>
In Java, the BigDecimal class has a failed abstraction around equality comparisons that will inevitably lead to bugs. There are 2 problems:



1. the method compareTo is inconsistent with the method equals



Equality (equals) of two BigDecimals takes scales (number of decimal places) into account, whereas comparison (compareTo) doesn't.



So,



new BigDecimal("1.00").equals(new BigDecimal("</summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/6877235201412316143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=6877235201412316143' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/6877235201412316143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/6877235201412316143'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2009/10/java-bigdecimals-big-problems.html' title='Java: BigDecimal&apos;s Big Problems'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-9067673005100021850</id><published>2009-09-18T12:28:00.015-04:00</published><updated>2010-03-25T21:42:23.247-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>C# Static Classes are not Real Classes</title><summary type='text'>
In C# and in Java, there's a common idiom to provide utility functions as static methods of classes that cannot be instantiated. This stems from the limitation that these languages don't allow the definition of any function outside of a class. This can be seen as an anti-pattern, because what's missing is the ability to declare functions, not only classes; like in C++.



The class has to be </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/9067673005100021850/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=9067673005100021850' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/9067673005100021850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/9067673005100021850'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2009/09/c-static-classes-are-not-real-classes.html' title='C# Static Classes are not Real Classes'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-5553259732979992635</id><published>2009-08-08T17:31:00.014-04:00</published><updated>2010-02-26T15:59:55.923-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Optional Parameters and Method Overloads</title><summary type='text'>
The ability to declare optional parameters is another feature that will be introduced in C# 4.0. A natural complement to method overloads, it generally helps code to be more concise. Until now, method overloads have been used for the awkward responsibility of creating default values for what otherwise would be much better expressed as optional parameters. Many overloads have been created for </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/5553259732979992635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=5553259732979992635' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/5553259732979992635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/5553259732979992635'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2009/08/optional-parameters-and-method.html' title='Optional Parameters and Method Overloads'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-2052106038087703223</id><published>2009-08-01T14:29:00.006-04:00</published><updated>2010-02-01T13:06:14.064-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Named Parameters Increase Readability</title><summary type='text'>
When reading C# code, sometimes there are method calls which aren't readily obvious. The method can have too many parameters, or a series of parameters of the same type. This can make things a little confusing. A more aggravating case is that of boolean parameters. It's hard to find out what true or false mean in some cases.



var creditScore = customer.CheckCredit(false, true);



Normally, we</summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/2052106038087703223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=2052106038087703223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/2052106038087703223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/2052106038087703223'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2009/02/named-parameters-increase-readability.html' title='Named Parameters Increase Readability'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-1302962485229983846</id><published>2009-07-30T13:18:00.015-04:00</published><updated>2010-02-02T12:14:25.033-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='F#'/><title type='text'>F#: Why the rec?</title><summary type='text'>
I've been looking into F# for a while now, and I think it's an awesome addition to the .NET framework. It's more expressive and concise than C#. It's functional by heart, with discriminated unions, pattern matching, tail-call optimization, and it also supports object oriented programming (being a .NET language, it just had to) and imperative programming. Its type inference creates the feel of a </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/1302962485229983846/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=1302962485229983846' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/1302962485229983846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/1302962485229983846'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2009/07/f-why-rec.html' title='F#: Why the rec?'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-997779142481807125</id><published>2008-08-01T12:45:00.014-04:00</published><updated>2011-11-18T12:02:32.347-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQLServer'/><title type='text'>Painful SQL Server Pagination</title><summary type='text'>
When I used MySQL back in 2000, I took for granted the ability to paginate result sets in the server with the simple LIMIT clause. (Other open source databases, like Firebird and PostgreSQL, have similar constructs.) Querying for a page of the result set is as simple as this:



# Fetches rows 21-30
# 20 is an offset, 10 is the number of records to fetch
select * from Users limit 20, 10;



You </summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/997779142481807125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=997779142481807125' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/997779142481807125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/997779142481807125'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2008/08/painful-sql-server-pagination.html' title='Painful SQL Server Pagination'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5707533511952913639.post-1195818849469671637</id><published>2008-07-19T09:18:00.036-04:00</published><updated>2010-07-09T14:52:07.970-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>C# Extension Methods and Null References</title><summary type='text'>
With extension methods in C# 3.0, you can create methods that operate as if they were instance methods of other classes. You can "add" methods to any class, even to core classes like System.String and System.Object.



This example creates two string extensions:



public static class StringExtensions {
  public static string HtmlEncode(this string input) {
    return AntiXss.HtmlEncode(input);
</summary><link rel='replies' type='application/atom+xml' href='http://codecrafter.blogspot.com/feeds/1195818849469671637/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5707533511952913639&amp;postID=1195818849469671637' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/1195818849469671637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5707533511952913639/posts/default/1195818849469671637'/><link rel='alternate' type='text/html' href='http://codecrafter.blogspot.com/2008/07/c-extension-methods-and-null-references.html' title='C# Extension Methods and Null References'/><author><name>Jordão</name><uri>http://www.blogger.com/profile/07178574753933019008</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
