Archive for 2010

A Little Piece Of Advice For Tech Bloggers

6 commentsWritten on December 29th, 2010 by
Categories: Off Topic

I saw 2 blog posts today from tech bloggers who were talking about their new-year resolutions. Both of them said that they wanted to increase the number of posts they'll write next year. Both of them had over 50 posts this year. There's nothing bad (on the contrary) about writing 50 posts in a year. Hell, that's actually a great pace because it's reasonably sustainable and it leaves you with enough time to focus on a variety of things.

I've been blogging for 3,5 years and i have 565 posts so far. That's an average of 161 a year, or almost 13,5 a month or a little over 3 a week. That's insane. And it really isn't sustainable because you will run out of material before you know it and if you're not careful, you'll be tempted to stick to your posting schedule just to keep the visitor stats up. And let's be honest here: we all care about those stats just a little bit too much... don't trust the bloggers who say they don't ;) . And once you get into that habit of wanting to write posts just because you feel like you have to, it's time to take a small step back. You're blogging, which is great, but it really isn't all that important. It's not worth putting in the time and effort unless you really feel like doing it.

So to summarize my advice: blog when you want to, when you feel like you've got something interesting to share. Don't blog when you don't really feel like it and don't blog because you think you have to. Make sure you have enough spare time to spend on things outside of blogging and technology in general.

As for me, i'm aiming for 50 posts next year instead of the usual 161 and i don't think there's anything wrong with that. At all :)

What Should I Cover In My NHibernate Workshop?

9 commentsWritten on December 29th, 2010 by
Categories: NHibernate

I'm gonna do an NHibernate training/workshop in a few months, and before i can start preparing for it, i need to know what i'm going to cover in the workshop. The workshop should be 3 or maybe 4 days and the goal is that everyone attending it will learn a ton about what you can do with NHibernate, as well as how you should use it.

I just made a list of stuff that i'd like to cover, which is already pretty long. I'd rather start off with a long list and if necessary make some cuts if it turns out to be too much. If you guys have any tips on what else i should include, please let me know :)

Here's the current list:

  • Configuration
  • Classes & Mapping (hbm and FluentNHibernate)
    • entities
    • one-to-many associations (unidirectional & bidirectional)
    • many-to-one associations (unidirectional & bidirectional)
    • inheritance
  • Session/Transaction Management
    • session/transaction management in a web app
    • session/transaction management in a service layer
  • Transitive Persistence
    • transient and persistent entities
    • cascades
    • detached entities
  • Querying
    • HQL
    • criteria
    • QueryOver
    • LINQ
    • polymorphic queries
    • named queries
  • Performance optimisations
    • paging
    • projections
    • future queries
    • batching DML statements
    • executable HQL
    • retrieving data from stored procedures / views
    • using native SQL
  • optimistic concurrency
  • pessimistic locking
  • identifier strategies
  • inheritance strategies
  • advanced mappings
    • value types collections
    • components
    • component collections
    • (composite) user types
    • many-to-many associations (unidirectional & bidirectional)
    • polymorphic associations (one-to-many, many-to-one)
  • 2nd Level Cache
    • entities
    • collections
    • queries
  • stateless sessions (bulk data processing)
  • extending nhibernate
    • custom implementations of NHibernate components
    • event listeners

Highly Recommended Book: The Passionate Programmer

4 commentsWritten on December 19th, 2010 by
Categories: Books

I always felt that, for all the great books about developing software that we have, there weren't enough on how to approach your career as a software developer. Thankfully, Chad Fowler's The Passionate Programmer (subtitle: Creating a Remarkable Career in Software Development) covers exactly that. It's a quick read at only 200 pages, but it's filled to the brim with very wise advice. The book consists of the following 5 parts:

  1. Choosing Your Market
  2. Investing In Your Product
  3. Executing
  4. Marketing... Not Just For Suits
  5. Maintaining Your Edge

In these 5 parts, Chad offers a truckload of solid advice on things like figuring out which technologies to focus on, expanding your skill-set to more than just coding, improving yourself continuously, being as effective as you can be, getting the word out on how good you are, and making sure you keep improving as your career progresses.

Each part consists of multiple short chapters, each of which is kinda blog-post like in focus and length. Again, it's a very quick and easy read. And the electronic version is only $15. The advice you get from this book is a lot more valuable than the time and money you'll put into it :)

Virtual Method Performance Penalty, Revisited

18 commentsWritten on December 17th, 2010 by
Categories: C#, Performance

I wrote a post about a year ago which discussed a test of the performance difference between calling virtual methods and non-virtual methods. This morning, someone added the following comment to that post:

if you have 100 subclasses of class A, and they all override a method a, it will take a lot longer for it to figure out which version of a to call. Think of it as a switch statement with one case label verses a switch statement with 100 case labels. Since you’re just testing it with one method it’s not surprising that the cost is negligible.

My Bullshit-detector started beeping while reading that, so i just had to see if the number of subclasses indeed had an impact. I didn't go all the way up to 100 subclasses, but i went with 15. If there is indeed a performance penalty that grows with the number of subclasses in play, then surely i'd have to see some difference when using 15 subclasses over just 1, right?

In the original test, i had the following 2 classes:

    public class MyClass
    {
        public long someLong;

        public void IncreaseLong()
        {
            someLong++;
        }

        public virtual void VirtualIncreaseLong()
        {
            someLong++;
        }
    }

    public class MyDerivedClass : MyClass
    {
        public override void VirtualIncreaseLong()
        {
            someLong += 2;
        }
    }

Now, i wasn't quite sure whether the commenter meant having a bunch of classes that inherited directly from MyClass, or having a set of inheriting classes in a deep inheritance tree. Just to be sure, i tested both cases.

In the first case, i have classes like MyDerivedClass1, MyDerivedClass2, ... , MyDerivedClass15 that all inherit directly from MyClass. In the second case, MyDerivedClass1 inherits from MyClass, MyDerivedClass2 inherits from MyDerivedClass1, ... , and MyDerivedClass15 inherits from MyDerivedClass14.

The code of the test is still largely the same as it was in the previous post, with just some minor modifications to make sure that more of the code to be executed has been JIT'ed prior to the actual test-run:

    class Program
    {
        const int iterations = 1000000000;

        static void Main(string[] args)
        {
            var myObject = new MyClass();
            var myDerivedObject = new MyDerivedClass15();

            // we do this so there's no first-time performance cost while timing
            EnsureThatEverythingHasBeenJitted(myObject);
            EnsureThatEverythingHasBeenJitted(myDerivedObject);

            TestNormalIncreaseMethod(myObject, iterations);
            TestVirtualIncreaseMethod(myObject, iterations);

            TestNormalIncreaseMethod(myDerivedObject, iterations);
            TestVirtualIncreaseMethod(myDerivedObject, iterations);

            Console.ReadLine();
        }

        static void EnsureThatEverythingHasBeenJitted(MyClass theObject)
        {
            theObject.IncreaseLong();
            theObject.VirtualIncreaseLong();
            TestNormalIncreaseMethod(theObject, 1, false);
            TestVirtualIncreaseMethod(theObject, 1, false);
        }

        static void TestNormalIncreaseMethod(MyClass theObject, int numberOfTimes, bool printToConsole = true)
        {
            if (printToConsole) Console.WriteLine(string.Format("calling the IncreaseLong method of type {0} {1} times", theObject.GetType().Name, numberOfTimes));
            
            var stopwatch = Stopwatch.StartNew();
            for (var i = 0; i < numberOfTimes; i++)
            {
                theObject.IncreaseLong();
            }
            stopwatch.Stop();

            if (printToConsole) Console.WriteLine("Elapsed milliseconds: " + stopwatch.ElapsedMilliseconds);
        }

        static void TestVirtualIncreaseMethod(MyClass theObject, int numberOfTimes, bool printToConsole = true)
        {
            if (printToConsole) Console.WriteLine(string.Format("calling the VirtualIncreaseLong method of type {0} {1} times", theObject.GetType().Name, numberOfTimes));

            var stopwatch = Stopwatch.StartNew();
            for (var i = 0; i < numberOfTimes; i++)
            {
                theObject.VirtualIncreaseLong();
            }
            stopwatch.Stop();

            if (printToConsole) Console.WriteLine("Elapsed milliseconds: " + stopwatch.ElapsedMilliseconds);
        }
    }

In the first test (multiple direct subclasses of MyClass) i got the following result:

fifteen subclasses

(note: for this test, i used MyDerivedClass1 instead of MyDerivedClass15 as in the listed code)

In the second test (inheritance tree) i got the following result:

fifteen nested subclasses

As you can once again see, the difference is completely negligible. So here's what i propose: until someone actually shows a case where a clear-cut performance penalty is shown that is even slightly relevant to real-world usage, we should just drop the whole "virtual methods are expensive!"-thing.

Announcing: DrinksWithDevs (The Belgian Chapter)

5 commentsWritten on December 17th, 2010 by
Categories: Software Development

As i mentioned in my last post, i want to get together with developers regularly and in an informal manner. Enough people expressed interest to get it started, so i've created a Google Group called DrinksWithDevs-Belgium which we can use to plan the 'meetings'.

Everybody is welcome to join, so please feel free to do so. The idea is very simple: you can suggest a get-together at a bar (or restaurant) of your choice. If people respond, agree on a date, go out, talk about software development, have a few drinks and just have fun. Ideally, these get-togethers will happen pretty frequently and in various locations throughout the country. That way, you can just pick which ones you want to go to. If you can't make one, or don't feel like going, just skip one. Or skip a few, doesn't matter. Just show up when you want to.

Finally, i'd like to repeat the 'rules' again so that we're all very clear on this:

  • Leave your ego at home.
  • You pay for your own drinks :)
  • Open to all kinds of developers (.NET, Java, Ruby, Python, PHP, whatever...)

Hope to see some of you on these meetings in the future :)