Raganwald No Hire

Raganwald (Regenald Braithwaite) had an interesting post on github about hiring practices of some companies. To my knowledge I’ve never been subject to such practices. It’s a bit off-topic here but it spurned some thought for me. I’d much rather hire or have hired to work with a person who is imminently qualified and skilled than someone with whom I politically align. In fact, I often work with (and work well with) people who don’t agree with me politically. It can actually be more fun to hear other people’s opinions but it doesn’t matter as far as the job goes. Let’s all agree to be professional when it comes to getting things done, and we’ll all get along just fine. Personally, I get along with pretty much everyone I work with.

Also, Raganwald used an example of a law in the Province of Ontario where it’s illegal to ask in an interview about a candidate’s marital status. I’m not sure I care for that law but then I wouldn’t care whether a person is an unmarried woman likely to get married and leave. It’s about the job performance. I’d want to hire the best person for the job even if they are likely to leave; granted I’d do what I could to prevent or delay that. Honestly, I would be interested in knowing a little about the person just because. I just like people I guess.

I’m fairly conscious of what I post publicly but still manage to make gaffes on occasion. Point is just be professional, hire good people, and have some understanding.

-j

 
June 26, 2009 19:00 by josh
E-mail | Permalink
blog comments powered by Disqus

Fluent NHibernate With Firebird

Well it works if a bit clunky first try by me. Thanks to some help on the Fluent NH email list and reading a couple docs, I got a really simplistic implementation based on the SQLLite version.

Config code:

   1:   public BootStrap()
   2:          {
   3:              _userName = "test";
   4:              _password = "test";
   5:              DbFile = "test.db";
   6:              ConnectionString = String.Format("ServerType=1;User={0};Password={1};Dialect=3;Database={2}", _userName, _password, DbFile);
   7:   
   8:              //setup firebird configuration
   9:              firebird = new FirebirdConfiguration();
  10:              firebirdConfig = Fluently.Configure().Database(
  11:                       firebird.ConnectionString(c => c
  12:                       .Is(ConnectionString)));
  13:          }

 

Create the Session:

   1:  public ISessionFactory CreateSessionFactory()
   2:          {
   3:              if (_sessionFactory == null)
   4:              {
   5:                  _sessionFactory = firebirdConfig.Mappings(m => m.FluentMappings.AddFromAssemblyOf<BootStrap>())
   6:                      .ExposeConfiguration(BuildSchema)
   7:                      .BuildSessionFactory();
   8:              }
   9:   
  10:              return _sessionFactory;
  11:          }

 

Build the Schema:

   1:  private void BuildSchema(Configuration config)
   2:          {
   3:              //quit if it alread exists
   4:              if (File.Exists(DbFile)) return;
   5:              
   6:              //user firebird to create the database
   7:              FbConnection.CreateDatabase(ConnectionString);
   8:   
   9:              // this NHibernate tool takes a configuration (with mapping info in)
  10:              // and exports a database schema from it
  11:              new SchemaExport(config)
  12:                  .Create(false, true);
  13:          }

 

Now the problem is I’m inserting test data each time test runs so there is an ever increasing number of records without getting cleaned up. So just have to manage the data state and it will work.  That said, SQLLite is the better option.  Firebird doesn’t support auto-increment keys and seems easier to manage.  Also, this sample code wouldn’t run on 64bit. It seems to have problems opening the process. Perhaps there is a 64 bit dll I should have been using though.

-j

 
June 25, 2009 22:46 by josh
E-mail | Permalink
blog comments powered by Disqus

Fluent NHibernate And You

I finally got around to writing a little code with Fluent NHibernate and I like it. Of course I knew I probably would, but it does something I didn’t realize.. at least with SQL Lite, it creates the Schema for you from the mapped entities (might be an NHibernate feature). You can grab the source and see it in action with the sample project. Now this is both good and bad because I will have to come up with a versioning approach to deal with this. Basically you do these things:

Create your entities

   1:  public class WebLink
   2:  {
   3:    public virtual int Id { get; private set; }
   4:    public virtual string URL { get; set; }
   5:    public virtual string Name { get; set; }
   6:    public virtual bool OpenNewWindow { get; set; }
   7:   }

Create the entity maps

   1:  public class WebLinkMap : ClassMap<WebLink>
   2:  {
   3:    public WebLinkMap()
   4:    {
   5:      Id(x => x.Id);
   6:      Map(x => x.URL);
   7:      Map(x => x.Name);
   8:    }
   9:  }

Setup configuration and get an ISession object

   1:  public ISessionFactory CreateSessionFactory()
   2:  {
   3:    if (_sessionFactory == null)
   4:   
   5:    {
   6:      _sessionFactory = Fluently.Configure()
   7:        .Database(SQLiteConfiguration.Standard
   8:         .UsingFile(DbFile))
   9:        .Mappings(m =>
  10:        m.FluentMappings.AddFromAssemblyOf<BootStrap>())
  11:        .ExposeConfiguration(BuildSchema)
  12:        .BuildSessionFactory();
  13:    }
  14:   
  15:    return _sessionFactory;
  16:  }
  17:   
  18:  private void BuildSchema(Configuration config)
  19:  {
  20:    // delete the existing db on each run
  21:    if (File.Exists(DbFile))
  22:        File.Delete(DbFile);
  23:   
  24:    // this NHibernate tool takes a configuration (with mapping info in)
  25:    // and exports a database schema from it
  26:    new SchemaExport(config)
  27:        .Create(false, true);
  28:  }

Add your data

   1:  public void SetupData()
   2:  {
   3:    var sessionFactory = BootStrapper.CreateSessionFactory();
   4:    using (var session = sessionFactory.OpenSession())
   5:    {
   6:      // populate the database
   7:      using (var transaction = session.BeginTransaction())
   8:      {
   9:        //links
  10:        var link1 = new WebLink { URL = "http://semperfifund.org", Name = "semper fi fund", OpenNewWindow = true };
  11:        var link2 = new WebLink { URL = "http://www.woundedwarriorproject.org/", Name = "wounded warriors", OpenNewWindow = true };
  12:        var link3 = new WebLink { URL = "http://www.sunshineacres.org/", Name = "sunshine acres", OpenNewWindow = true };
  13:   
  14:        SaveLinks(session, link1, link2, link3);
  15:        transaction.Commit();
  16:      }
  17:    }
  18:  }
  19:   
  20:  private void SaveLinks(ISession session, params WebLink[] links)
  21:  {
  22:    foreach (var link in links)
  23:      session.SaveOrUpdate(link);
  24:  }

Query for data

   1:  [Test]
   2:  public void have_links()
   3:  {
   4:    var sessionFactory = BootStrapper.CreateSessionFactory();
   5:    using (var session = sessionFactory.OpenSession())
   6:    {
   7:      // retreive all stores and display them
   8:      using (session.BeginTransaction())
   9:      {
  10:        var links = session.CreateCriteria(typeof(WebLink)).List<WebLink>();
  11:   
  12:        //make sure there are links
  13:        Assert.GreaterThan(links.Count, 0);
  14:      }
  15:    }
  16:  }

 

As you can see, I am using a Unit Test (MBUnit) in that last snippet. I do most spike & throw away code like that these days. I used to use a console app but find that too crude anymore. (my opinion only)

Really, though, that is about all there is to it. I was planning on trying to get it working with Firebird db but SQL Lite will do the job. I might try to figure out hot to do it with Firebird  anyway just to help out the FNH project.

 
June 24, 2009 07:00 by josh
E-mail | Permalink
blog comments powered by Disqus

Var – A Warning

I try to learn and reflect on my code style regularly. I occurred to me the other day that my use of the var keyword could be better.  I had started using var for every declaration in my c# code. It looked like this:

   1:  var elementList = new List<FieldElement>();
   2:   
   3:  var resourceKind = (new T()).ResourceKind;
   4:  var schema = GetSchema(connection, resourceKind);
   5:   
   6:  var complexTypeName = GetSingularTypeName(resourceKind);

That’s great and all but it’s not immediately clear what schema and complexTypeName variables are just by reading the code. I suggest using the specific type in declaration of those variables like this:

   1:  var elementList = new List<FieldElement>();
   2:   
   3:  var resourceKind = (new T()).ResourceKind;
   4:  XmlSchema schema = GetSchema(connection, resourceKind);
   5:   
   6:  string complexTypeName = GetSingularTypeName(resourceKind);

That’s better.  As a matter of personal opinion, you might want to change the resourceKind declaration to this:

   1:  string resourceKind = (new T()).ResourceKind;

 

The T defined in this case so I know what type it is, but it might not be obvious to other people. Clarity is important for maintaining code. Don’t assume that because you know what you were thinking now that you will remember later. One oft repeated rule is to code as if the next guy to work with your code is a homicidal axe murder who knows where you live.

 
June 22, 2009 07:00 by josh
E-mail | Permalink
blog comments powered by Disqus

Learning With Podcasts

A lot of us devs listen to music while working. Why not learn something at the same time, or even sit back and learn while not working? I do, and wanted to share a few good sources.

I’m a little late to the party, but I’ve noticed this podcast series called Herding Code, which looks great! There’s a lot of topics so go check it out and be sure to check out this episode with Damien Guard.

I also recommend Hanselminutes, Railscasts, NPR’s Cartalk, and Coffee Break Spanish (along with other Lingua Network podcasts).

 
June 19, 2009 12:00 by josh
E-mail | Permalink
blog comments powered by Disqus

A Few Random Tips

Extra Power

If you use a laptop as a main dev box, keep a second power cord in your laptop bag. That way all you have to do to hit the road is unplug it and slip it into you laptop bag. I typically keep my laptop bag ready to go, so the only thing I need to add before I leave is the laptop itself and, sometimes, the wireless mouse.

Ubuntu CD

I carry one in my laptop bag and have one in my home desk. I’ve saved files being lossed many times by booting Ubuntu, mounting the drive, and copying them to a USB drive.

TDD.Net

I write unit tests, and strive to use TDD all of the time. Running tests and getting the results is important. I find the Visual Studio test runner to be too slow. TestDriven.Net is my favorite test runner and VS add-in.

 
June 16, 2009 09:16 by josh
E-mail | Permalink
blog comments powered by Disqus

Dark Side Of Domain Expertise

Domain expertise has a great value especially in development. In fact, it can be crucial for success. It also has a downside. When development becomes so engrained in the prevailing culture, it becomes easy to continue and even encourage bad habits.

Inevitably, a certain way of doing things will evolve during a product’s lifecycle. It becomes are part of the culture, and is learned and repeated by new developers on the project. In knowing a codebase, it is far too easy to think in the same manner. The path of least resistance is sometimes the only one you see, and even when it’s not you may not feel you have the time to change. The way its been done already is too deep to change in time for your next release.

Been there. Done that. Many times.

I advocate TDD for many reasons. Clarity, maintainability, and adaptability being among those. Sometimes I see code and have to wonder what in the world was the author thinking. Not just because of style or buggy-ness, but code that literally looked like it shouldn’t work. Plenty of times, seen uncommented code which was as clear as mud.

Avoiding the rut while becoming a master of the domain isn’t easy. Unit Testing is a good way to do it. You’ll learn while coding and develop clarity in the codebase. Additionally, you will be setting the stage for better habits and maintainability in the future.

Roy Osherove has a .Net Unit Testing book, which was just published. It would be a good way to learn more about Unit Testing. It’s on my reading list.

 
June 15, 2009 21:44 by josh
E-mail | Permalink
blog comments powered by Disqus

HP Mini 1030NR – Webcam Issue

I got an HP Mini 1030NR from Best Buy for one of the kids, and it’s quite a nice little lappy. It’s not going to win any races, but it does the job nicely. Battery life is good at close to 3 hours. It comes with a 16gig SSD, which isn’t a lot but you’re not meant to install a lot on these. The point is a small, portable, cheap internet device.

It has decent hardware specs, but there seems to be a default settings issue with the camera. It’s WAY too dark, and is unusable. I found a few suggestions on the ‘net about how to resolve it. One was to manually update the driver with some driver choices. Another was to physically remove a foil lense cover, which I didn’t feel right about. The last was to open up the settings and turn the brightness up from zero, which is the default. One way of doing that was to install MSN Messenger and use Options –> Audio and Video settings to change settings. I did that since it also gives you a picture preview.

Solved well enough. Skype video now works fine.

 
June 9, 2009 07:00 by josh
E-mail | Permalink
blog comments powered by Disqus

Win7 – 2, WinXP – 1 ..Vista - 0

I have to say I’m fairly impressed with Windows 7 thus far. There is a minor security annoyance, but much less than which Vista still annoys me. It also performs a lot better than Vista. WinXP still should hold the performance bar according to benchmarks(here, here, here), but I don’t really see it running in VMWare Fusion on Mac. Perhaps Win7 is more virtualization friendly, or is better about file access management. I don’t know. I do know Win7 has a quicker feel, and a much more pleasant UI than XP and Vista.

Well if behavior is any grade, I can say Win7 is leading in the Windows OS race. I currently have 2 Win7 vm’s, 1 WinXP vm, and 0 Vista vm’s on my Mac. That 1 XP vm was my main development vm until recently. I’ve been flipping between the 32bit and the 64bit Win7 machines since it went Release Candidate. At this point, I’m only keep XP around for legacy reasons, which should drop off not long after Win7 is RTM.

My other virtual machines are Fedora 10 and Ubuntu 9.04, which are both very nice themselves. They just don’t have the .Net stack and tools, so I don’t run them as much. I can use Mono in OSX so I don’t run linux very often lately.

Visual Studio and .Net has kept me on Windows. Win7 looks to be the first really good reason to run Windows other than .Net in a long while.

-j

 
June 7, 2009 23:46 by josh
E-mail | Permalink
blog comments powered by Disqus

VMWare Fusion Sneak Peak

I’ve been granted a sneak peak of VMWare Fusion v.next. While I’m not sure why I was selected, I sure do appreciate it. There are rules to follow, and I don’t think I’m breaking any by telling you that the next version looks good. I didn’t do anything special. Just installed and ran, then opened my Windows 7 RC machine. Worked fine; perhaps a little better since the usual mangled boot screen wasn’t nearly as bad. In the current released Fusion, Win 7 boot screen gets a little weird and plays disco-flashy or something for a few seconds before going to the login screen. Some else saw it and declared my MBP was possessed. Anyway, the rules prevent me from saying too much specific but I can say it looks good so far. With Windows 7 due around October 22 of this year, looks like VMWare Fusion will be ready for it.

I will be using it run Win7, and do some development work on it. I’ve also booted Ubuntu 9.04, Fedora 10, and WinXP. All ran fine.

It just sunk in as I wrote this that I am running Visual Studio 2010 Beta on Windows 7 Release Candidate in VMWare Fusion Beta.

-j

 
June 3, 2009 09:00 by josh
E-mail | Permalink
blog comments powered by Disqus


about josh

another programmer blogging about his misadventures in writing code.

Contact

contact us for website & software consulting

Decide

decide on pragmatic solutions

Develop

develop your product together

Succeed

achieve your goals with our services