The Inquisitive Coder – Davy Brion's Blog

Trying to walk that thin line between intelligence and ignorance

Archive for the 'Off Topic' Category

Got 15 Minutes To Help Out With A University Study? I Mean, To Play A Game?

Posted by Davy Brion on 8th March 2010

Bram De Moor, one of my coworkers, has developed a small game which is a part of a university study. I can’t tell you what the study is about, since that would ruin the purpose of the game (and if anyone leaves a comment mentioning it, it will be deleted) but it’s pretty interesting. The game itself is pretty nicely done, though you obviously shouldn’t expect too much. So if you can spare about 15 minutes and want to participate in this study, download the game here, play it and answer the questionnaire at the end. Don’t do it for yourself, do it for science! ;)

Posted in Off Topic | No Comments »

Wanna Review My Code?

Posted by Davy Brion on 23rd February 2010

I just wrote some code, and i’d like your opinion on it.  The thing is, i’m not going to provide any context as to what it does or why certain decisions were made since i know you guys like to be challenged.  You also might want to keep the following in mind when reading it:

  1. it might contain bugs that i’m not aware of
  2. it contains weird parts that were either brainfarts on my part, things i did on purpose to avoid possible issues, or both
  3. it contains at least one bug that i know about, yet don’t care about
  4. i removed the comments that i originally put in it to make things more interesting
  5. i haven’t tested the code yet
  6. i haven’t even executed it yet
  7. i think it’s ok… but i’m not sure

Questions will be answered if you have them (and i’m sure you will) though i can’t make any promises as to how soon i can answer them… I will post a follow-up post to discuss the code in its entirety later on, though i’ll probably wait a few days to do so.

This is the code:

    public class TenantSessionFactoryManager : ITenantSessionFactoryManager

    {

        private readonly ITenantContext tenantContext;

        private readonly ITenantInfoHolder tenantInfoHolder;

        private readonly string mappingAssemblyName;

 

        private readonly object writeLock = new object();

        private Dictionary<Guid, ISessionFactory> sessionFactories;

 

        public TenantSessionFactoryManager(ITenantContext tenantContext, ITenantInfoHolder tenantInfoHolder, string mappingAssemblyName)

        {

            this.tenantContext = tenantContext;

            this.tenantInfoHolder = tenantInfoHolder;

            this.mappingAssemblyName = mappingAssemblyName;

            sessionFactories = new Dictionary<Guid, ISessionFactory>();

        }

 

        public ISession CreateSessionForCurrentTenant()

        {

            var tenantId = tenantContext.CurrentTenantId;

 

            if (!sessionFactories.ContainsKey(tenantId))

            {

                CreateSessionFactoryForCurrentTenant();

            }

 

            return sessionFactories[tenantId].OpenSession();

        }

 

        private void CreateSessionFactoryForCurrentTenant()

        {

            lock (writeLock)

            {

                var tenantId = tenantContext.CurrentTenantId;

 

                if (!sessionFactories.ContainsKey(tenantId))

                {

                    var connectionString = tenantInfoHolder.GetDatabaseConnectionString(tenantId);

 

                    var sessionFactory = new Configuration()

                        .Configure()

                        .AddProperties(new Dictionary<string, string>

                                {

                                       { "connection.connection_string", connectionString },

                                    { "cache.region_prefix", "Tenant_" + tenantId }

                                })

                        .AddAssembly(mappingAssemblyName)

                        .BuildSessionFactory();

 

                    var newDictionary = new Dictionary<Guid, ISessionFactory>(sessionFactories);

                    newDictionary[tenantId] = sessionFactory;

                    sessionFactories = newDictionary;

                }

            }

        }

 

        public void RemoveSessionFactoryForTenant(Guid tenantId)

        {

            if (!sessionFactories.ContainsKey(tenantId))

            {

                return;

            }

 

            lock (writeLock)

            {

                if (!sessionFactories.ContainsKey(tenantId))

                {

                    return;

                }

 

                var sessionFactory = sessionFactories[tenantId];

 

                var newDictionary = new Dictionary<Guid, ISessionFactory>(sessionFactories);

                newDictionary.Remove(tenantId);

                sessionFactories = newDictionary;

 

                sessionFactory.Dispose();

            }

        }

    }

Posted in Off Topic | 16 Comments »

Never Underestimate Your Own Stupidity

Posted by Davy Brion on 7th January 2010

I was trying to deploy one of our applications on a customer’s environment.  We have a database server on their network, and a web server.  I installed the database, installed the web application and tried to run it.  It didn’t.  Our logfile showed this:

System.InvalidOperationException: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.

I figured i had made a mistake with the configuration of SQL Server, so i checked some settings and tried it again.  Still didn’t work.  Did this a couple of times but i couldn’t get it to connect to the database and i kept getting the same error.

Eventually i wrote a stupid winforms app with a button that would connect to a database based on a connection string in its app.config file.  Copied it to the webserver, copied the connection string from the web application to the config file of the stupid winforms app and tried it.  Still got the same exception.

I figured there might be a problem with connecting to the database from the web server, so i copied the stupid winforms app to the database server and tried it there.  It still didn’t work, even though i could connect without problems using SQL Server Management Studio.

After a while i finally noticed that i had mistyped the name of the database server in the connection string, and once i typed the correct name, everything worked :)

Total time lost: about 90 minutes.

Required change: adding 1 extra character to the connection string.

Then again, i would’ve noticed this sooner if the exception message was a bit more clear about the actual problem (not finding the server) ;)

Posted in Off Topic | 9 Comments »

Ohloh’s Project Cost?

Posted by Davy Brion on 21st December 2009

I was looking at Ohloh’s estimated project cost for Agatha and something is… wrong:

code_only_cost markup_onlycode_and_markup

The result for ‘Code Only’ might be a somewhat representative estimate, but look at how screwed up the numbers are once markup is included.  Now, i don’t know if you’ve ever looked at the Agatha codebase but there certainly aren’t over 66000 lines of markup to be found.  There is a bit of XML here and there, mostly WCF configuration in the example solution but that still doesn’t come nowhere near 66000 lines.  It doesn’t even add up to 1000 lines.

A similar result can be found when looking at the estimations of Rhino Tools:

rt_code_only rt_markup_only rt_code_and_markup

Over 70000 lines of markup compared to 54000 lines of code? I highly doubt it.

Just something to keep in mind when looking at Ohloh’s estimates, i guess ;)

Posted in Off Topic | 2 Comments »

The Padawan That Couldn’t

Posted by Davy Brion on 14th December 2009

Once upon a time in a galaxy not far enough away, there was a Jedi Knight happily going along his business. He knew the ways of the Force and used them when fit, yet knew when to use lesser means when they were good enough. He enjoyed teaching Padawans the ways of the Force and on most days, tried to do so to the best of his ability. He had always felt that he could teach it to anyone, even to those with lower midi-chlorian counts.

One day, the Jedi Knight was introduced to someone who wanted to be a Jedi Knight. During the screening process, it quickly became apparent that she had a rather low midi-chlorian count. It was doubtful that she was even fit for training, let alone actually working as a Jedi Knight. Nevertheless, a deal was made, the details of which i’ll spare you, so she could begin an apprenticeship with the Jedi Knight. After all, the Jedi Knight arrogantly thought “if anyone can teach her, it’s me”. Thus began the adventure.

The Jedi Knight knew that he would have to start from scratch with this Padawan. The little she knew had to be unlearned, only to be replaced with other bits of knowledge. She was to go through a careful path of learning steps, each one of them slightly increasing in difficulty. On the first day of her journey, she was told about the Force. The Jedi Knight tried explaining, in a high-level, what kind of things she would need to learn, and how those techniques and skills would benefit her. After that, she was assigned her first task.

Not surprisingly, there were some bumps in the road during that first task. The Jedi Knight was used to this. “They all have a slow first week”, he thought, thinking that the situation would gradually improve. The Padawan asked questions, the Jedi Knight answered them and tried to explain everything as clearly as he possibly could. Alas, some of the questions were repeated. The Jedi Knight again tried to answer them, in some cases even showing her the way by completing parts of the task himself. He had hoped that this would encourage the Padawan, that it would foster her willingness to learn and try harder.

At the same time, the Jedi Knight was responsible for the battle against a legacy system which was created with the best of intentions, but over time had been taken over by the Sith. There was no peace, no order, no structure, only chaos, darkness, and disrespect to everything the Force is supposed to stand for. The Jedi Knight couldn’t face this challenge on his own, and was thankful to have a few worthy Jedi’s on his side to help win the battle. And although he had to lead them in battle, he gladly shared some of his responsibilities with his most trusted lieutenant. And as if the battle wasn’t challenging enough, he was now also responsible for this young Padawan. One that required a great deal of attention and help no less.

Frustrated by the lack of progress shown by the Padawan, he started delegating parts of her education to his most trusted lieutenant. Just as they shared the duty of defeating their foe, they started sharing the burden of bringing this Padawan along. Which turned out to be quite a hefty task. After a few days, she still had problems with her first assignment. She still kept asking the same questions, they were just phrased differently. Sometimes, she would ask questions which indicated that she really hadn’t understood the previous answers. His lieutenant told him about the questions she asked, and they turned out to be very similar to the ones she had already asked the Jedi Knight. He had answered them as well as he could, yet she continued asking the same questions to the Jedi Knight.

At this point, the Jedi Knight sought refuge in his iPod. It helped him seclude himself to some extent, not only so he could focus on his own assignments and thoughts, but also to encourage the Padawan to try thinking for herself a bit more before asking questions. The Padawan didn’t quite catch up on that. If she felt like asking a question, yet noticed that the Jedi Knight was trying to focus on his work she would come over to the desk of the Jedi Knight with an ever-impressing silence, and would knock her knuckles on his desk in rapid succession. The sound and mere thought of which still haunts and frightens the Jedi Knight to this day.

The Jedi Knight started keeping count of the questions she asked. There was one day where she asked 17 questions, almost half of them were duplicates of previous questions. This was no longer in the first week. This was week four. The Jedi Knight had all but lost hope that this Padawan would ever learn the ways of the Force. His lieutenant started complaining that he was also losing too much time on her, and that he was getting behind on his own tasks. So the Jedi Knight had to have a bit of a talk with the Padawan.

He explained to her that maybe learning the ways of the Force weren’t within her capabilities and that she might have to look into a different career path. Much to his delight, she agreed. She even seemed relieved in some way. The Jedi Knight told her that she was asking too many questions, and that she was incapable of comprehending the answers, no matter how clearly they were given to her. Again, she agreed. He also said that she should reduce the number of questions she asked, and that she should try to finish her remaining task as well as she could without slowing down the Jedi’s. Of course, the Jedi Knight knew that the task would most likely had to be redone later on by one of the Jedi’s.

The Jedi Knight felt better after the talk, but only a couple of hours later, the endless barrage of questions resumed. The Jedi Knight was starting to look forward to his upcoming vacation in the Caribbean more and more, thinking about how he would spend his days drinking Mojito’s while relaxing on the beach, listening to George Carlin’s “Free Floating Hostility” bit and enjoying the weather. He even started to lose his interest in the Force, and was getting seriously demotivated. He eventually met with Master Yoda to inform him that he was no longer willing to spend time trying to mentor this Padawan. Yoda also had a talk with the Padawan, essentially telling her the same things the Jedi Knight already told her. A few days later, the apprenticeship was stopped, and the Padawan went her own way.

The Jedi Knight was still demotivated, slightly burned out even (though there were other reasons for this). He eventually went on his vacation to the Caribbeans to regain his strength and came back ready to get back to where he belonged. Closely aligned with the Force, yet armed with the knowledge that he certainly wasn’t capable of teaching its ways to just about anyone.

Posted in Off Topic | 6 Comments »

How Dependent On Google Are You?

Posted by Davy Brion on 9th December 2009

I use GMail, and i really can’t imagine going without it anymore.  I also use Google Reader, and while i know there are other online RSS readers, i can’t really think of a reason to even try something else because i don’t have any issues with Google Reader.   Whenever i need to search for something, i google.  I’ve tried Bing a couple of times but wasn’t impressed, so i’ll stick with Google’s search engine.  I occasionally use Google Maps and Google Streetview.  I use Google Adsense to display ads on my blog. I use Google Analytics to look at the traffic on my blog, and i use Google Feedburner to see how many people subscribe to my blog’s RSS feed.

I’m pretty dependent on Google as far as accessing information goes, but i’m also very dependent on Google bringing people to my site when i want to publish information:

search_engine_traffic

feedreaders

The first graph shows that 96.64% of people who reach my blog through a search engine do so through Google.  The second graph shows that slightly over 75% of my subscribers use Google Feedfetcher (which is used by Google Reader, iGoogle, etc…)

If Google ever starts hating me, i’m pretty much screwed :)

Posted in Off Topic | No Comments »

The Biggest WHY Comment I’ve Ever Seen

Posted by Davy Brion on 26th November 2009

One of my coworkers wrote the following WHY comment yesterday:

// __          ___    ___     __    ___ 

// \ \        / / |  | \ \   / /   |__ \

//  \ \  /\  / /| |__| |\ \_/ /       ) |

//   \ \/  \/ / |  __  | \   /       / /

//    \  /\  /  | |  | |  | |       |_| 

//     \/  \/   |_|  |_|  |_|       (_) 

//

// Because the normal ChildWindow causes a memoryleak.

// The memory leak was created because the ChildWindow subscribed to the RootVisual_GotFocus multiple times...

Posted in Off Topic | 5 Comments »

New Hardware, New Software

Posted by Davy Brion on 1st November 2009

I bought a new iMac last week (the 21.5″ since the 27″ is just a bit too over the top for my taste ;) ) to replace my aging MacBook. Performance of the machine is very nice and in general it’s just a great system. The screen is fantastic as well and i’m definitely loving the resolution (1920*1080). The new Magic Mouse is excellent, though i do miss the middle-click (which i used to use extensively to open links on sites in new tabs).

But the best part of it is that i also upgraded to the newly released VMWare Fusion 3. As some of you already know, i use my Mac for all regular computer usage, and i use a virtual machine to run Windows which i only use when i’m doing .NET development at home. I was still using a virtualized Windows XP on my MacBook because for one, i can’t stand Vista and i figured it would be way too slow to run in a virtual machine on the MacBook anyway. But for the past 2 months or so, i’ve been using Windows 7 at work and much to my surprise, i’m actually very happy with it. It’s still butt-ugly, but at least it runs nicely, it’s fast, it’s stable, and it hardly ever annoys me. It’s like Windows 2000 all over again :p. So i figured it was time to make the switch at home as well. So now i have a virtual Windows 7 with Visual Studio 2008 running on the iMac (only when i wanna do .NET stuff obviously) and it’s running very well. Performance is really unbelievable, considering that it’s virtualized and i only gave the VM 2GB of RAM. I did disable Aero (i could use it, but the difference was noticeable) but i kept the typical new Windows look, if only because the classic look is even worse.

While writing code at home had become more of a chore than a joy because of the slowness of running a virtual Windows XP on the MacBook, it’s now really enjoyable again :)

Posted in Off Topic | 4 Comments »

Wrong On So Many Levels

Posted by Davy Brion on 19th October 2009

Today i actually said the following sentence in a meeting:

“are you sure you can cleanly add the hardcoded identifier values in the generated database triggers?”

*shrug* What could possibly go wrong?

Posted in Off Topic | 1 Comment »

7 Years As A Professional Software Developer

Posted by Davy Brion on 27th September 2009

It’s that time of the year again! I have now been working as a software developer for the past 7 years. I don’t know why that means something to me, but it does. Last year, i gave an overview of my short career which people seemed to find interesting, so i figured i might as well add this to my list of ‘blogging traditions’.

So what have i done in the past year? Well, as i mentioned in last year’s post, i finally started working at my company’s home office instead of working at client locations, and it has definitely been the best year of my career so far.

When i made the switch, i thought that we (as a development company) were already pretty good, but i had some very clear changes/improvements in mind that i wanted us to achieve in the first year. More specifically, i wanted to see big improvements in the following areas:

  • Increase the efficiency of our automated testing practices.
  • Get people to write loosely coupled code.
  • Increase overall performance and scalability of the code we write.
  • Get people to truly care about code quality and proper software development practices

My coworkers started writing automated tests way before i did. But before i came aboard, none of our automated tests would ever substitute the implementation of a component during tests. No mocks, no stubs, just the real thing all the time. If we had tests for code that was somewhat dependent on data access components, then those tests would effectively be dependent on a real database. If we had tests for code that was somewhat dependent on processing files, then those tests would effectively be dependent on real files.

We had thousands and thousands of tests which took a long time to run, were rather fragile, and required a lot of maintenance effort to keep them running at all times. These days, our tests only use the database when we are testing our queries and our NHibernate mappings. We use mocks to substitute the data layer when we are testing our business code, and we also moved to using MVP patterns in the UI layer so we could start writing automated tests for a lot of our UI code as well. Obviously, all of that required us to write our code in loosely coupled manner, which we now all do with Dependency Injection and using an Inversion Of Control container. So i am pretty happy with the results of the first two goals.

The third goal (performance and scalability) is also coming along nicely. The architecture that we use (and if you’ve been reading this blog for a while, you’ll probably have a pretty good view on what our architecture typically looks like), in combination with the libraries that we use, gives us plenty of possibilities to write scalable and performant code. One of our clients made us perform extensive stress testing for one of the projects we did for them, and the results were good. I’m pretty confident that our usage of the Request/Response WCF Service Layer plays a very large part in getting those results. Of course, we still have performance problems every now and then, but we now do a pretty good job of proactively keeping an eye on it (in most cases), and when performance problems do show up, we can usually fix them pretty easily.

So far so good, right? Then comes the final goal… getting people to truly care about code quality and proper software development practices. I am very happy with the progress that some people have made, but i am pretty disappointed that i can count them on one hand. Some people improved tremendously in the past year, while some only seem to care when they know their code is going to be reviewed. I was very disappointed when i noticed that some people didn’t mind resorting to technical shortcuts or not properly testing things when nobody was watching them. As a result, i’m now actually monitoring the commits for most of the projects that we have going and whenever i see something that doesn’t look right, i talk to the author of the particular piece of code about it.

I really don’t like the fact that i feel the necessity of doing that, but i’m gonna try this approach for a month or two to see if things improve. I hope to see more people actively reviewing other people’s changes in the upcoming months because this is a task that should always be shared instead of having only one person who does this. I hope that in a year, we’ll have enough peer-pressure to make sure everyone keeps playing it straight. Anyways, i’ll let you guys know about it next year ;)

So all in all, it’s been a very interesting year. I’ve worked on some cool things, i get enough variety in my work, i get to see (some) people grow continuously in their capabilities, and the amount of time i had to spend on doing things i’d rather not do was very low. Much lower than i can imagine in any other company anyways. Oh, and according to some of my coworkers i’m also responsible (to some extent) for an increase in our after-hours-beer-consumption as well as pizza deliveries. It has been a good year indeed :)

Posted in Off Topic | 4 Comments »