Caffeinated Coder

A Grande, Triple Shot, Non-Fat Core Dump by Russell Ball

Browsing Posts published by Russell Ball

In honor of the (relatively) new 1.0 status of LINQ to NHibernate, I’ve been spending the last few nights LINQifying some old NHibernate queries I’ve written and I must say that I’ve been very pleased.

There have traditionally been two ways of specifying NHibernate queries: HQL and the criteria query API.

Although I have an easier time deciphering HQL, which is basically a SQL-like string using classes instead of tables, I’ve tended to use the criteria API because it was somewhat strongly typed and thus easier to maintain with the help of refactoring tools like ReSharper.

Thanks to the new NHibernate LINQ provider, I can now work in a mode that is not only more type safe, but also much more readable.

Look at these before and after queries and judge for yourself:

Before (Criterion API)

   1: public IList<Call> GetCallsByDate(DateTime beginDate, int interpreterId)
   2: {
   3:     ICriteria criteria = Session.CreateCriteria(typeof(Call))
   4:         .CreateAlias("Customer", "Customer")
   5:         .Add(Restrictions.Gt("StartTime", beginDate))
   6:         .Add(
   7:            Restrictions.Or(
   8:                 Restrictions.Lt("EndTime", DateTime.Now), Restrictions.IsNull("EndTime")
   9:                 )
  10:             )
  11:         .Add(Restrictions.Eq("Interpreter.Id", interpreterId))
  12:         .AddOrder(Order.Desc("StartTime"))
  13:         .AddOrder(Order.Desc("Customer.Name"));
  14:
  15:     return criteria.List<Call>() as List<Call>;
  16: }

After (LINQ to NHibernate)

   1: public IList<Call> GetCallsByDateWithLinq(DateTime beginDate, int interpreterId)
   2: {
   3:     var query = from call in Session.Linq<Call>()
   4:                     where call.StartTime > beginDate
   5:                         && (call.EndTime == null || call.EndTime < DateTime.Now )
   6:                         && call.Interpreter.Id == interpreterId
   7:                     orderby call.StartTime descending, call.Customer.Name
   8:                     select call;
   9:
  10:     return query.ToList();
  11: }

Apparently the NHibernate guys are still working on a full featured LINQ provider for a future version of NHibernate, but decided that the LINQ provider in the contrib project has been tested enough and used in enough production systems to promote it to RTM status.

The one thing I did notice when peeking at the SQL in Profiler is that the Linq provider produced an extra join that the regular Criteria API figured out wasn’t necessary because I was just referencing the foreign key column in the where clause. I’m guessing that minor differences like this will be addressed in the next version of the provider.

In the meantime, I’m still hooked enough to want to use this approach instead.

If you want to give LINQ to NHibernate a test run, just download and reference the one required dll here (make sure you’re using the same version of NHibernate).

If you’re still not comfortable with LINQ sytnax, here’s a simple example based MSDN tutorial to get you started.

Popularity: 31% [?]

I’ve been involved in a recruiting effort for the last 5-6 weeks and I have to admit that I’m starting to get discouraged.

I don’t want to rant about how many subpar developers exists out there because those blog posts always annoy me and strike me as pathetically egotistical.

Besides, debating whether the skills of the average developer are good or bad seems like a moot point to me. Even if I rate the overall average as positive I would still want to work with people from the right side of the bell curve (a la Joel’s Smart and Gets Things Done philosophy). Besides getting more work done, they represent the greatest learning opportunity for me personally (yes I’m a wee bit selfish in that regard).

However, that is not an easy thing to do as evidenced by my need to create the Rejectomizer 2000.

Thus we invested some time and effort into crafting a good job description that would speak directly to the type of people we’re looking for.

Here’s an excerpt.

Who you are

You are a combat-hardened, grizzled C# veteran with years of coding experience under your belt. You’ve been using the .NET framework since its inception and know the ins-and-outs of threading, reflection, generics, and lambdas. You’ve done a fair share of ASP.NET and know how to use AJAX and Javascript frameworks like JQuery to good advantage. You’re interested in the possibility of eliminating boiler-plate SQL code with a good Object Relational Mapper and open to improving the design and reliability of your code through Test-Driven Development.

You are NOT the type of developer to just get things working without knowing exactly how and why they work. And while you’ve put out some pretty advanced, complex code, you’ve come to the realization that good code is simple code. If the developer sitting next to you can’t open your code and pick up where you’ve left off, your code isn’t that great after all.

While your code might be solid and you know a ton of stuff, you are constantly learning. You read technical blogs and books and try to stay on top of relevant technologies and patterns.

Aside from your technical ability, you pride yourself on getting things done. You’ve used methodologies and standards with a group of developers and know that sticking to the process helps everyone crank out quality work and get it out the door on time. You have a super-strong attention to detail and you take pride in your work. You’ve mentored junior developers and know when to hold their hand and when to let them beat their head against the wall for a while.

Finally, you’re a natural leader. You lead by example and set a high standard. You know when to be firm and draw the line, and when to solicit contributions and feedback from the group. You give clear direction and assign accountability, and everyone on your team feels like they’re doing their part.

Are we missing anything?

Oh, and if you happen to live in the Kansas City area (not accepting telecommuters at the present time) and are looking for a job at a cool company, shoot me an email

Popularity: 10% [?]

It appears as though I made a rather bone-headed mistake when configuring Subversion at work a few weeks ago.

Since we were not exposing our SVN server externally and decided that sending our code files in plain text across our internal network did not represent a significant security risk, we opted to not use SSL as a way to optimize performance.

I’m not sure why I assumed that the actual credentials would be encrypted even though I knew the content would not be.

Perhaps it was because we were using windows authentication security scheme in SVN. Maybe it was because I actually opened up the svn.simple file in the Subversion app data cache on my local machine and saw that my TortoiseSVN credentials were saved in an encrypted form on disk when using the ‘save credentials’ checkbox.

Whatever the reason, it was a very bad assumption.

Here is a screen shot from WireShark, my favorite packet sniffer. The blurred out part under authentication was my windows password in clear text. Oops…

packetsniffercredentials

Luckily, it was an easy matter to correct.

On the server-side, I simply had to check a box on the property tab of Visual SVN to turn SSL back on. On the client side, I had to have everyone run an svn switch command with the –relocate option to change their working directories to use the new url.

So what was the lesson learned?

Next time I make a mistake like this, I will use WireShark to gather all of the passwords of my fellow developers before I switch to the more secure option. Dumb…dumb…dumb…

Popularity: 22% [?]

I recently installed YSlow, a Firefox add-on integrated with the popular Firebug web development tool that does performance analysis based on the rules for high performance web sites developed by Yahoo.

I tried it on DosPecesCreations.com, the e-commerce site I recently built for my wife using Ruby on Rails, and was surprised to learn that the site received a failing grade according to the YSlow Report Card.

yslow_grade_before

It took me just over an hour of clicking on the explanations for failed failed categories and researching how to make some of the configuration changes in Apache to bring that grade up to a high B.

Bringing it up to an A would require me to use a Content Delivery Network like Akamai Technologies, which deploys content across multiple, geographically dispersed servers and dynamically chooses the fastest option in a given scenario based on proximity and available connections. However, since the customer base for the site is not international and we don’t have thousands of dollars a month to spend at the moment, I’ll just have to content myself with being a B student.

So what was the payoff for making these changes?

I wanted to have a somewhat objective way to measure the performance improvements, so I also downloaded HammerHead, another firebug add-on that provides average load times for pages with and without the cache being used.

Here are my baseline metrics.

yslow_2

Here are the results after I made the changes.

yslow_after_2

As you can see, I more than doubled the speed of the site with little effort and almost no coding changes. Here’s a quick summary of what I did:

  1. Reduced the size of the HTTP response
    • Enabled Gzip Compression -  This is done in Apache with an output filter, which I enabled by adding one line to the .htaccess in the root directory of the site.
    • Minified Javascript Files – This involved removing all the comments as well as unneeded white space characters (space, newline, and tab) from javascript files. Luckily there are tools such as JSMin that will do this for you. I ran the Ruby version of JSMin as a Rake task and was able to reduce my Prototype Javascript Library files by about 25%.
    • Removed Unused Javascript Reference – This sounds obvious, but by using the default option with the javascript_include_tag Rails helper tag I was referencing 6 Prototype files even though I was only using 2 of them. By removing the unused references, I was able to trim 65k from my pages.
  2. Reduced # of trips
    • Merged javascript files – The Rake task I used above also merged the remaining prototype files into one file so the client would have to make one less round trip to retrieve the files.
    • Enabled Caching – I configured Apache to use Far Future Expire tags for my static content (images, js, & css) and Cache-Control tags for my dynamic content (2 hour expiration). I followed the recommendation of disabling ETags as well even though this only appears to only interfere with caching on web farms and I’m currently on a single server.
  3. Maximized parallel download speed – I did this by moving all my scripts from the html header to the bottom of the page. Apparently javascript files can block parallel downloads so simply moving these from the header to the bottom of the page will increase the overall load time.

I used this resource while making all of the Apache configuration changes. If you’re using IIS, then you might want to try this post.

As someone who spends most of his time doing middle tier and database development, I was surprised to learn how much of a web application’s performance is affected by these front end concerns.

Luckily, all of these front-end recommendations were much easier to fix than almost any performance tuning efforts applied to the back end.

Popularity: 19% [?]

Trying to recover from an injury that I got while playing WhirlyBall at a company team-building event. Don’t they know that bad things happen when hyper-focused programmers try to do things that require multi-tasking.

  1. Give and Take in the Software Industry – This is the Secret Geek’s version of The Joel Test and The programmer’s bill of rights. I almost didn’t read it because the jfk_asking_the_users_for_feedbacktopic is a little old and tired, but Leon Bambrick reinvigorated it with his own humorous writing style as well as helpful step-ladder approach to each topic that serves as a good reminder that you can always progress further down the road to progress. I particularly like the following excerpt on having companies provide separate dev, QA, and Prod environments for their developers:
    “You can’t afford testers and you just want me to fix it in production, eh? That’s awesome. That’s great. Next time the dentist is drilling out a cavity in your mouth, I’m going to tell him “This is an urgent operation. Let’s not waste time on X-rays. Just start drilling, you’re bound to hit something that’s rotten. And let’s save a few dollars and cut out the anaesthetic altogether.”

    2009 Predictions, 2008 Predictions Revisited – Ted Neward judges the accuracy of his predictions from last year and provides us with a new set of forecasts for the coming year. Ted’s ability to combine insightful critical analysis with just the right amount of cynicism and humor make this a great read. My favorite is #1 of the 2009 predictions:

    “The ‘Cloud’ will become the next ‘ESB’ or ‘SOA’, in that it will be something that everybody will talk about, but few will understand and even fewer will do anything with.”
  2. Hoops & Yoyo’s Decaf Coffee Crisis – It’s about time that someone took a stand against the abomination known as decaf coffee. Here’s a hilarious Hallmark e-card that you can send to your favorite coffee addict.

Popularity: 13% [?]

Here’s the second half of my whirlwind chronological tour of my past year from the perspective of my blog and technical life (see first half here):

  1. rhinomocks-120x90 July: Take THAT legacy code – I didn’t write a single post during this month, however I had a very productive time at work as a result of finally getting the hang of Rhino.Mocks and the Dependency Injection pattern as well as convincing my boss to let me start ripping open test seams in our code base. I’ve been able to leave clusters of tests around every area of code I’ve touched since then and have been a much happier coder as a result.
  2. Aug: My Blogging Hiatus – I finally break 2 months of blogging silence with Blogging Hiatus: Next Stop Shark Jump. Although I suffered minor bouts of blogger guilt, I mostly just enjoyed the extra free time. Sofia finally started sleeping through the night so I was able to not only catch up on my sleep, but also enjoy get in some nighttime reading for the first time in ages. Besides indulging in rereading some light fantasy favorites, I made my way through the Kite Runner and Agile Web Development with Rails.
  3. Sept: Rethinking Links – Every since I started blogging, I sought to incorporate some way to comment on other posts that I liked. In the beginning, I fulfilled this need through a humorous series of posts that I called the Caffeinated Codeys. Although I had a great time writing these, I eventually felt too constrained by the format and frequency so I quietly abandoned it around the time Sofia was born. During this month I briefly experimented with an automated Delicious feed but quickly abandoned it in favor of the Triple Shot Links format, which I like quite a bit and plan to keep doing.
  4. Oct: A Tech Book Windfall – I responded to Jurgen Appelo’s $100 tech book contest questions with a couple of posts on what motivates and unmotivates me and as a result got myself some shiny new copies of Agile Software Development: Principles, Patterns and Practices, The Pragmatic Programmer: From Journeyman to Master, and Lean Software Development: An Agile Toolkit. Not surprisingly, I still haven’t had a chance to read them, but that’s what New Year’s Resolutions are for, right?
  5. Nov:  Progress on R# Jedi Training: I’ve been using R# for about a year and a half now, but it wasn’t until this month that I broke out of my novice rut. I came up with some techniques to extend my knowledge of this most excellent product earlier in the year, but it wasn’t until I volunteered to speak at the KC Day of Dot Net that my motivation kicked in enough to make some real progress. There’s nothing like the fear of public humiliation to help further your expertise in a given area.
  6. Dec: Milestones in both Rails and Source Control: I finish the year with a bang by launching my first Rails app into production, thus simultaneously completing one of my 2008 resolutions as well as making my wife a happy camper (it was an e-TortoiseSVNcommerce site for her jewelry business). On the work front, I spent most of the month on a VSS to SVN Migration project, thus ensuring my final victory over my most hated arch-nemesis.

I guess 2008 wasn’t such a bad year after all…

Popularity: 8% [?]

Here’s the first half of a whirlwind chronological tour of my past year from the perspective of my blog and technical life:

  1. Jan: Blogging Without a Net – I started off the year with a resolution to cast off the safety net of the massive GeeksWithBlogs blogging collective and venture out on my own. In the process, I pick up a few things on PHP as I tinker with my fancy new WordPress blogging engine.
  2. Feb: The Post That Launched a Thousand Flames – After getting roughed up a bit on Reddit for a post on programming language trends, I start wondering why .NET developers get no love in the industry and end up writing a post comparing .NET developers to American Tourists. Although the post languished in obscurity for several weeks, it ended up getting over 30,000 hits along with a combined total of 700 comments in the course of just a few days. As you can imagine, it was quite an eye-opening experience for a somewhat newbie blogger like myself. 
  3. Mar: Little Miss CaffeinatedCoder Arrives - At the spritely young age of 36, I become a father for the first time. This was by far the high point of the year for me. It also marked the beginning of a rather lengthy slowdown on the blogging front. To my credit, I did manage to squeeze in an interview with Jeff Atwood at the end of the month. I was thrilled that he responded to my email request and was impressed by the thoughtfulness of his answers.
  4. April: Networking Nirvana and Geek Rage – I began the month by making the rather egregious mistake of attending the Alt.NET conference in Seattle. The conference itself was amazing and allowed me to finally meet hoards of people who I had been following through my RSS Reader for ages. The mistake was rather in me naively believing my wife when she said it was OK to leave her alone with a 4 week old colicky baby for the weekend in order to attend. I’m still paying for that one…:-) The experience was also slightly tainted by a rather unpleasant exchange with a certain notorious Alt.NET’er in the comment section of my conference retrospective post and then later on twitter. It led me to publish a somewhat bitter post on the topic of geek community and eventually withdraw from twitter (although that decision ultimately had more to do with it being a productivity drain).  
  5. May: I Finally Get Organized - The act of trying to juggle the new demands of fatherhood along with my old interests in blogging and after-hours geek learning made me quickly realize that I was pretty inefficient and unorganized. In a fit of frustration, I picked up a copy of Getting Things Done and worked pretty hard to refactor and hone my organizational skills. I’ve stuck with most of the principals from the book and feel pretty good about relatively low levels of chaos in my life at the moment.
  6. June: SQL Is for the Birds – We finally take the ORM plunge at work and decide to use Castle’s Active Record as a replacement for our custom data access layer. I manage to get a good month of development time in before the project gets temporarily shelved to work on some legacy projects that took a higher priority. It was sad to have to return to writing raw SQL again, but the experience was positive enough to convince me to that ORM’s have progressed too far to still be spending time on doing manual CRUD.

Next up: my adventures with Ruby on Rails, Subversion, R#, mocking legacy code, and winning some free techie books.

Popularity: 5% [?]

Actually, it was more like a 5 Da’s punctuated by a steady stream of drool.

That was the resounding praise that came from Sofia, my little 9 month old hacker princess. She was reviewing BabySmash, Scott Hanselman’s Windows adaptation of the Mac game AlphaBaby.

In case you haven’t seen it, it is a game for toddlers that produces an array of smiling shapes, colorful letters, and silly laughter as your little one indiscriminately bangs upon the keyboard.

Don’t worry, it makes use of the window’s kiosk mode and various keyboard hooks so that there is no accidental formatting of the hard-drive by little fingers that accidentally stumble upon some deadly, archaic hotkey combination.

Here Sofia is brutalizing the keyboard on my home office computer and gleefully watching the results on my modest dual monitor setup (the third monitor is on indefinite hold as lobbyists make feverish pleas to the powerful Spousal Unit Committee of Ways And Means).

DSC00888

She particularly likes it when she inadvertently hits a key that triggers the Scooby-Doo laugh.

DSC00891Best of all, after the little one goes to bed, Papa developers can head over to codeplex and download the source code for the app.

It’s one of those new-fangled WPF apps, which means that if you’re like me you will be totally lost when you first start looking at it.

Luckily, Scott has written a several posts on the various technical aspects of the app. I skipped them the first time around because I had no prospects of using WPF at work or home anytime soon, but now I’m making my way through them out of curiosity about this application.

I’m hoping that WPF includes an ‘OnDrool’ event because I think my daughter would really appreciate it if I could enhance the application in this way.

Thanks to this Jeff Atwood post, I was even inspired to make my first paypal donation ever for free software. The donation button is set up for a very modest $8.00, so it appealed both to my innate cheapness and my new-found desire to directly reward developers who create cool things.

Thanks Scott!

In summary, if you have a (pre)toddler in your life who can’t wait to get their drooly little hands on your keyboard, then go check out BabySmash.

Popularity: 5% [?]

Kansas residents who try to file unemployment claims online after normal business are greeted with the following message.

kansas department of labor

Is the Kansas Department of Labor blazing new trails when it comes to e-commerce by becoming the first ever 12/5 service on the internets?

Could it be that they forging ahead with a more humane working environment for servers than those infamous 24/7 data center sweatshops?

Some rather short-sighted people that I have shared this information with have taken a more cynical view of the situation.

One friend suggested that perhaps the developers had a nightly mainframe batch processing to contend with and simply weren’t smart enough to figure out a way to save requests in a queue for processing the next day.

Someone else thought that perhaps the developers were a little too literal when they tried to translate the manual processes into working software.

It was even suggested that bureaucrats might have been to blame with a dogmatically simplistic interpretation of regulations governing application timelines.

As for me, I believe it is wrong to view this simply as one of the greatest WTF finds ever.

Instead I see it as some of the most innovative thinking about the web medium since Al Gore first invented the internets.

Startups and VC’s of the world take notice!

I have seen the future and Web 3.0 is 12/5 all the way.

Popularity: 5% [?]

srp_poster

I’m getting ready for a quiet New Year’s Eve at home with the family. This will be the first one in recent memory where I may actually remember what happened the next morning.

  1. Create Your Own Motivator Poster – I’m a big fan of the humorous anti-motivational posters that you can find on places like despair.com, so I was thrilled to discover a site that allowed you to design your own. I pulled the SRS example shown to the side from an elegant code post by Jarod Ferguson.
  2. Ten Things to Retire in 2009 – Jimmy Bogard kicks off the retrospective post season right with his round-up of annoying developer trends from 2008 that he would like to see disappear in the new year. My personal favorite is LINQ 2 Your Mom (#5) where he bemoans some of the LINQ abominations that have recently surfaced. Mom jokes (not the nice kind) are staple where I work and I nearly spit out my coffee laughing when I read it.
  3. SSL Spoofing Now Possible…. RUN FOR THE HILLS! – A great explanation of how SSL spoofing works, what can be done about it, and whether or not we should be concerned. The short answer is…probably not.

Popularity: 6% [?]

hermes kelly hermes Outlet hermes Store Gucci bags Hermes Kelly hermes kelly louisvuitton handbags cheap Louis Vuitton louis vuitton outlet

cheap louisvuitton

louis vuitton outlet

chanel handbags outlet

louis vuitton monogram canvas

hermes birkin

hermes handbags

louis vuitton outlet online