May 27 2009

NHibernate In Action

Category: Uncategorizedzvolkov @ 7:09 pm

Amongst other activities, lately I’ve been in the process of reading NHibernate In Action, the only NH book on the market. My general impression so far, the information delivery is much more cohesive and complete than the NH online manual and definitely helps building a better picture of NH as a whole, which is what’s missing with modern GOP (Google-Oriented-Programming) approach.

Now, with the best feeling, I can’t help but comment on the only bitter spoon in the otherwise sweet jar of the book, namely Chapter 1:

With the rest of the book covering progressively more advanced material, Chapter 1 is supposed to make a case for NH by comparing alternative data access techniques, introducing the notion of ORM and presenting unique NH features. As much as I hate being negative (what a positive phrase huh! :) ), I must say the chapter fails miserably.

If you’re a noob you won’t understand a thing of what they say as they randomly jump from topic to topic briefly hinting at things you’ve never heard of. If you’re an expert looking for an inspiration for making a business case for NH in your firm, you’ll be amazed at the level of argumentation along the lines of “w/o NH solving problems the NH way would be really difficult and that is why you need NH”.

While some paragraphs (like those comparing various data access techniques) suffer from extra brevity, some other (like the one on the 3-tiered architecture) set the level of discourse way too low. Consider the following pearl: “you’ve probably … worked with a relational database … if you haven’t, see Appendix A”. Ok, we may not know ORM, but who do they think we are, high-school students?!

Not only this chapter suffers from broken stream of thought and uneven level of presentation, the authors also seem to be unaware of other kinds of applications than Windows or Web GUI that may also benefit from ORM (like the guts of “enterprise” systems) nor do they give good examples of data-access problems that should not be solved with an ORM (such as for example data mining and reporting).

In short, don’t waste your precious time and skip this useless crap (I hope they rewrite it completely in the next edition). And, if you ever had any kind of experience with NH, skip Chapter 2 as well.

The rest of the book is well worth your time. Enjoy.


May 21 2009

free “alternative” to resharper by DevExpress

Category: Uncategorizedzvolkov @ 10:29 am

For C#: http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/

For VB: http://www.devexpress.com/Products/Visual_Studio_Add-in/VBRefactor/

While it’s far from Resharper in terms of features, it does have little gems not present in R#.
My personal favorite is “Tab to Next Reference” where you press Tab to highlight and jump to next occurrence of the identifier under cursor.

See http://msdn.microsoft.com/en-us/vcsharp/dd218053.aspx for more examples with screenshots.


May 19 2009

Visual Studio TFS and DiffMerge

Category: Uncategorizedzvolkov @ 9:09 am

There are tons of code comparison / merge tools out there, both paid ones (Araxys Merge, Beyond Compare, Compare It) and free ones (DiffMerge, WinMerge, WinDiff). I use DiffMerge because it’s free and has all the features I need.

Here are notes for myself on how to configure Visual Studio (specifically its TFS source control plug-in) to use DiffMerge as its code comparison tool.

Basically, go to Options / Source Control / Visual Studio Team Foundation Server / Configure User Tools / Add and enter following:

  • Extension: .*
  • Operation: Compare
  • Command: full path to DiffMerge executable
  • Arguments: /title1=%6 /title2=%7 %1 %2

and another one:

  • Extension: .*
  • Operation: Merge
  • Command: full path to DiffMerge executable
  • Arguments: /title1=%6 /title2=%8 /title3=%7 /result=%4 %1 %3 %2

The original instructions can be found on the following blogs:


May 09 2009

Going to The Burning Man

Category: Uncategorizedzvolkov @ 11:19 am

Just booked the tickets to go to The Burning Man

Here’s the plan:

  • on Saturday, August 29th Tanka, Matthew and I are driving from Maryland to New Jersey to leave Matthew with my mom. We still need to find a person to take care of our cat Inky while we’re away.
  • on Sunday, August 30th Tanka and I fly from Newark NJ to Reno, Nevada; pickup the rental car and checkin at the hotel in Reno. We’ll use the day to buy water, stove fuel, alcohol etc. Maybe we’ll also be able to rent a bicycle or two.
  • on Monday, August 31st we’ll take a 3 hour drive to the Black Rock City.
  • we will spend entire week at the burning man, and see The Man getting burned on Saturday the 5th
  • then on next Monday, September 7th, we’re driving back to Reno, stay at the hotel to wash and get sober :)
  • we’ll fly back to New Jersey on a redeye Tusday night and arrive to Newark early Wednesday the 9th.
  • we hope we will be able to drive back to our home in Maryland the same day so Matthew can go to school on Thursday the 10th

So far, the event tickets, flight, car and hotel add up to the total of ~$2500, which is not that bad considering the 2 hotels nights and 10 days car rental.

If you want to join, let me know, we can share the hotel and the car and camp together.


May 07 2009

Solo Whale

Category: Uncategorizedzvolkov @ 10:05 pm

Good news for those who liked Songs of the Humpback Whale, I transfered first track of the record from LP to MP3.

The track is called Solo Whale. First 2-3 minutes you can hear the whale enjoying himself — immitating sounds of a propeller, playing with his echo, trying to make higher and higher pitched sounds and so on. Then, at about 4 minutes, you can hear the sound of an explosion. The whale definitely does not like it, he sounds very upset and thoughtful, especially when the explosion repeats. He tryes playing again but you can hear he still thinks about the explosion and can’t relax. Eventualy he forgets and gets back to the original entertainment.

Here’s the recording. I recommend using stereo headphones for listening, to reduce the noise and improve the ambience. Enjoy!

songs.mp3 (10.85 mb)


May 06 2009

NHibernate, unit-tests, transactions and sessions

Category: Uncategorizedzvolkov @ 11:53 am

My biggest problem with NHibernate at the moment is the way its Sessions work. Not that they work any worse than Connections used to work in ADO.NET but with all NHibernate magic in place it is natural to expect that the Sessions can also be managed in some magical way :)
Consider, for example, the following code:

var file = Db.Retrieve<File>(message.FileId);
string outputFile = Path.Combine(OutputPath, file.BaseName);

My Db.Retrieve uses Spring’s NHibernate Template to open a Session, do Session.Load(fileId), and close Session. As Ayende explains in this post, Load returns a proxy object. The problem with this of course, is having no session open to get file.BaseName in the next line.

Possible solutions:

  1. Stop using Spring’s NHibernate Template and just use SessionFactory and Session Directly. This seems to be in line with the approach that Ayende advocates here.
  2. Do as Spring’s manual recommends, i.e. enable declarative transaction management. This way  the entire method will be decorated with [Transaction] attribute and that will instruct Spring to keep the Session open for the entire duration of the method. My problem with this is a lot of feedling with configs required to get the declarative transactions to work. Last time I tried it I could not get it to work and I don’t seem to have time right now.
  3. A variant of number two but with explicit transaction management. This is much easier to implement and this is what I do in my current project, but it is far from elegant as the code ends up looking like this:
private string GetBaseName(CommandMessage message)
{
    var tran = Db.BeginTransaction();
    try
    {

        var file = Db.Retrieve<File>(message.FileId);
        string outputFile = Path.Combine(OutputPath, file.BaseName);

        Db.Commit(tran);

        return outputFile;
    }
    catch (Exception)
    {
        Db.Rollback(tran);
        throw;
    }
}

I think, as more and more code gets this ugly, I’ll reconsider and go to Option 2. Ayende’s minimalistic approach seems too Zenish for my overcomplicated mind, at least for now :) .


May 04 2009

Songs of the Humpback Whale

Category: Uncategorizedzvolkov @ 7:09 pm

Yesterday afternoon I was in not-so-good mood which was definitely getting reflected in my daily actions. For example during my weekly ritual shopping at our local vinyl store called Joe’s Record Paradise I decided to check the section called Oddball, for normal rock-n-jass was definitely perceived as too mundane to heal my sore personality :) Amongst various and not so various crap from Haloween Songs and Freaky Sounds to How To Strip For Your Husband I found the following pearl:

 

Normally I think of myself as of person whose personal evolution moved beyond the early years of ethnic music, sounds of nature and other similar audio poop. But this sleeve intrigued me. Songs of whales? Is this an idiom? Perhaps it’s some form of ummm… oddball instrumental music? I had to check this out, and the price of $3.50 was in agreement with my wallet.

The in-store audition had to be quick as I had 6 other records to try and the line behind my back was growing impatient, although I didn’t have to be too nice to them, since each of them held a pack of 10 records or more and I could have easily been in their place. Still even 5 quick seconds of listening to Track 1 immediately caught my attention. Random sampling a few more spots on Side 1 confirmed my first judgement. This was magic. I don’t have an easy way to digitize the record for you to enjoy, but the very least I can do is share image of the gorgeous label (UPDATE: the MP3 of Track 1 is now available here)

 

Back at home, I warmed up a bottle of sake, the Wife fried a quick portion of shiitake mushrooms and off we went, listening to the lovely crazy alian sounds on the big speakers. The big speakers sounded better in terms of bass, however this was the day I regreted I don’t have extra 3-4k to by myself a nice HiFi subwoofer. In terms of pure bass the whales definitely are kings of the sea.

Closer examination of the record sleeve revealed a curious historical artifact:

As you can see, somebody in the distant year 1970, has read this article and ordered the record for the unbelievable price of $9.95, which considering the typical price of $1 per record was comparable to $100 in today’s money. The orignal owner of this record must have been wealthy, educated, and nuts!

The record is also accompanied with a small booklet, written in English and Japanese, of which I will share the most interesting part, namely a graphical depiction of the “music” the whales make:

Having listened to the record twice and having finished the bottle of sake, I went to YouTube to search for any modern relatives of this record, and, easily enough there they were, in large multitudes, most of them not-so-exciting but some of quite decent quality (ignore the video as it is just a slideshow):

 

So I went ahead and listened to a bunch of these after which I had even better idea: why not google? Indeed, why not. The mightly Google revealed an exellent resource, The Whalesong Project, which offers an even more exotic treat, the live streaming audio from Kihei Harbor of Maui, Hawai’i. The audio is encoded as mp3 but the link is packaged as Real Audio, so you will need a RAM-capable player (I recommend the free VLC) to, as they say, fully enjoy the trip.

I just left the sound on as I went to bed and — oh miracle — had the best sleep in months, complete with Lucid Dreams and have awaken to this world with fully refreshed spirit and more love in my heart towards these small silly two-legged creatures that rule the dry part of the planet.


May 04 2009

Is this reference really necessary?

Category: Uncategorizedzvolkov @ 2:43 pm

Ever wondered if your code really uses that reference or is it a remnant of some ancient version? Ever had to delete the reference and recompile only to find that it actually IS used?

Suffer no more: It turns out ReSharper has a context menu item to do exactly this: find all places where the reference is used!


May 02 2009

On my programming skills

Category: Uncategorizedzvolkov @ 8:45 pm

Amazing! I do software for about 15 years now and I still have no idea what I’m doing :)

Seriously, I still struggle with the basics:

  • overengineering vs. YAGNI
  • cutting corners in order to meet the deadline vs. pushing back on the business
  • risky innovations vs. tedious good old stuff
  • enjoying the freedom of working alone vs. the power of the team

But the worst of all is code complexity. My code tends to get evil. It even bites myself after a few weeks. I put tremendous effort in keeping it simple, readable, maintainable, elegant, beautiful, cohesive, loosely coupled, based on nice straightforward abstractions. But all this effort goes down the drain!

Don’t get me wrong, my code is pretty good by most people’s standards. I mean it’s flexible, more or less unit-testable, and does what it needs to do. However, it is far from simple.

Every change requires substantial refactoring. If another person opened my code with the intent of adding a feature he would HAVE to do something stupid. There’s no way he’d be able to do it RIGHT, even if he was a GENIUS, even if he was my own CLONE unfamiliar with the codebase. Why, why for God’s sake does this happen? Isn’t there some methodology, some technology, some meditation technique, anything at all?

Perhaps I should always write a level or two below what is now my current state-of-the-art level… Leave the innovation to home and hobby projects! But then I would have too much code duplication…

It’s not just controlling the innovation though. It’s being able to come up with new simple abstractions (to replace old abstractions that no longer work) again and again, even at the end of the project’s lifetime, when it seems that the conceptualization should not change already.