NOthingyoumissed

George Mauer is on the Net

Goodbye wordpress.com

I finally got off my ass and installed my own version of wordpress so I’m moving this blog (such as it is) over to http://georgemauer.net/blog/ If you really care look there for updates.

June 19, 2009 Posted by | Album | Leave a comment

Screencast: Keeping Features Out Your Way With Branching

Pop quiz:  What’s the software developer’s biggest enemy?  It’s not marketing.  It’s not those snot-nosed DBAs.  The rigid chair that will invariably give you arthritis?  Nah.  Your know-nothing boss?  Not even close.  No, the developer’s biggest enemy is the customer.

That’s right customers and their god d*mn feature requests and bug reports!  Life would be so much easier without them.  And acknowledging the absurdity of that statement, unless you are some kind of programmer Adonis (which unlike a regular Adonis physically implies only that your esophagus is invulnerable to lesions caused by Bawls) and write flawless code you will have to deal with feature requests that can rapidly pile up and overwhelm your development process.

I had mentioned previously on this blog that I am working with a team of Indian contractors and this is exactly what they found happening with the latest high stakes omg-fix-this-now-or-we-all-die release.  The team was behind and the release went out mere minutes before users started working with it.  Of course in the rush to finish on time bugs cropped up and features were left out.  Lots of features.

So immediately the next morning, with tickets raining down and demands for new drops every day the team got to work.  And the daily releases never came.  On the 3rd day we finally dived into their process with them to identify the problem.  

Simply speaking, they couldn’t reach a stopping point.  By the time certain features were ready to go others were half-implemented and so no release could be scheduled.  It was like some sort of real life Zeno’s paradox.  Fortunately this one has a solution.  Fully acknowledging that it is probably named differently in a dozen books and Agile pamphlets (just not any that I’ve seen), I call it branch-per-release or “how to use source control to get yourself out of a tight spot”. 

The idea is blatantly simple:

  1. Chose a release date
  2. Decide which features will fit in that release date
  3. Use your source control chops to create a branch for that release
  4. Decide what release each of the features on your plate goes in
  5. Create a branch for each of those releases
  6. Implement each feature set in the branch for its release
  7. When development on a branch is completed and tested, reintegrate into trunk.
  8. Rinse, repeate.

I have created a presentation and a series of screencasts (3 x 5 minutes thank you Jing) to demonstrate the process.  And here they all are:

Apparently embedding videos on wordpress.com is a pain in the *ss (as is code highlighting) so as mere links they must stay.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

June 4, 2009 Posted by | ALT.Net, Programming | Leave a comment

The GoGaRuConf Pr0n Affair Rhinos vs Rabbits and A Challenge

Well I don’t have many (any?) readers so I’m not going to go into depth linking and summarizing something that is

Gotta have at least one picture of a Rhino

Gotta have at least one picture of a Rhino

 handled in a million different places probably best on Martin Fowler’s blog (is the terminology blog correct here? Bible? Holy Testament?).

 

Super short version: Ruby on Rails prides itself on being an edgy community; at a conference, a slide deck contained a prolonged analogy between a technology and porn; people got offended.  There, that hits all the high notes.  I posted my thoughts as a comment on the hanselblog but then thought hey, I really haven’t updated my own blog in a while and I actually have (what I think is) an original insight on this so here we go.

For the record, I am mostly with Martin Fowler and others who urge professionalism and think the presntation was in poor taste to begin with (as in a cheap use of a lame analogy) but I think that I have something else to add to the discussion.

Let me start with this, I am notoriously thick skinned.  Really.  Like a Rhino (see sidebar for gratuitous picture of a Rhino).  You would have to know me quite well to understand how deep it goes but suffice to say that it is a product of my life philosophy and I do not remember the last time I was truly offended.  That being said, I am hopefully not a jerk and do not expect others to hold to the same standard.  However, because I cannot use myself as a guage I have had immense difficulty walking the line between offensiveness and expressiveness.  This is something that I have been actively working on for years, and I would like to think with results (I somehow swindled a lovely girl into an engagement even).  Hence my keen interest in this current discussion of appropriateness.

All conversation of gender roles, stereotypes, and feelings aside I think the argument of really boils down to this:  

  1.  The more edgy/expressive/offensive you get the more thin-skinned people you will exclude.  
  2. If a community allows offensive behavior repeatedly then the offended parties will be excluded from that community.  
  3. Why in the world would a tech movement want to exclude people – many brilliant people even – solely on these grounds?

Logically, this argument is a check-mate.  You want your ideas to be inclusive?  Then you must work to be inclusive as well.

But there is a caveat.  Many things are offensive; why would thin-skinned people want to spend their lives in an offended state?  Seriously, a lot of this stuff is actually pretty funny, we’d for love you to join in.   

So here’s the proposal, how about we BOTH work on this?  Yes that means you rabbits as well as us rhinos.  I will continue learning about sensitivity, about people’s feelings, about why I shouldn’t use the N-word even though I think its constant use would strip it of its power, and all the other social norms.  I won’t compromise my expressiveness, but I will try to consciously and responsibly make an decision of who I will offend.  You in the meantime should watch George Carlin and Bill Hicks, try to see what’s funny about Family Guy, and maybe even occasionally read SomethingAwful all with an open mind.  You must try to see humor on its own terms and to distinguish an bad person from a crass one.  You should do this seriously and with commitment.

The thing is that many people will probably take even this suggestion as offensive in itself, that I am suggesting people with “refined social standards” need to change as well as us juvenile bozos.  Here your own argument for sensitivity stands against you.   You must realize that for many people being sensitive to your feelings is f*ing difficult.  Like really really really hard.  I know that checking my speech almost always leaves a bad taste in my mouth that I have to then obsess over for hours afterwards. And if you still don’t care then F you.

I don’t have a crescendo of an ending planned so let me just state that I did indeed learn some things from this whole affair and am quite happy at the ideas that it has brought to the forefront.  I doubt that someone will seriously take me up on my challenge and I will continue down my own path of social learning regardless but if you’re really going to be intellectually honest you can hopefully admit that I have a point.  And then tag, you’re it.

May 1, 2009 Posted by | Other, Programming | 8 Comments

Of Cavemen Jeff Atwood and SOLID

Jeff Jeff Jeff,

Reading your blog has always been a bit like programmer masturbation, it mostly serves to make the reader feel great about what an inquisitive and intellectual developer they are.  That’s ok though, it keeps people reading and just through the sheer volume and accessibility of your writing you’ve pounded into people’s skulls some extremely useful ideas, frequently without them even realizing it.

Heck, it was you that got me into reading programming blogs (tip of the hat to Steve Yegge as well) and that is precisely why this whole tiff with Uncle Bob is just silly and your latest defense the lamest of all.  You reach far more people than Uncle Bob does, you acknowledge that the SOLID principles are good ones, you say that the problem is with capturing the ear of the uninformed – and then you put them down?  Give me a break!

I don’t have time to rant at length like others have but consider this:

Captain Caveman!

You know who were really the original unreachables?  Cavemen.  Completely in isolation from each other they decided it a hassle constantly having to seek out rock outcropping roofs and moss mattresses and all on their own they started piling rocks on each other to make houses.

Sure when the Assyrians invented the arch the Egyptian and Aztec builders didn’t hear about it, but eventually the Romans came along and in that very Roman way searched out the best ideas and decided to apply them to their own projects.  Good thing the Assyrians didn’t have bloggers.  They might have declared the arch unfit for popularization due to the infeasability of their marketing.

We’re at the very beginning of this stuff, lets encourage the good ideas, no matter who is listening.

Update: InfoQ has a roundup of the whole debacle.

February 16, 2009 Posted by | ALT.Net, Programming | Leave a comment

Error Handling and the Message Repackaging Anti-Pattern

I currently have an interesting responsibility at work.  I am functioning as the manager and single-point-of-contact for a team in India working on imporving the codebase for one of our more important ASP.Net sites.  I know what you’re thinkin.  Did I say interesting?  I meant infuriating.  At the very least I should get a good “Lessons Learned” post out of this.

Overall the experience hasn’t been too bad though.  I’ve been managing to maintain a decent rapport with their project manager and team lead, deadlines have been missed, but no more than I secretly expected, and overall they seem like fairly competent guys.  Their work isn’t innovative, Agile, testable, or well factored, but its decent enough.

Except for the exceptions.

Browsing one of their recent commits to our SVN lately (ok, so technically speaking they couldn’t figure out Subversion so they ftp-ed and I did the commit for them) I was shocked to discover the following error-handling anti-pattern repeated 41 times!

try {
  // Do Stuff
}
catch(Exception ex) {
  throw new Exception(ex.Message);
}

Do I get to name it?  Let’s call it the message repackaging anti-pattern.  And in case you’re not already reeling from this, the following is a mildly edited-down version of the letter I sent (Notice the eschewed profanity.  I believe a not insignificant achievement.)


Dear Team,

While looking through some of your committed code I noticed quite a few (a quick search shows 41) places where you have code of the following form.
try {
 // ...
}
catch(Exception ex) {
 throw new Exception(ex.Message);
}
Let me be absolutely clear: This is the worst possible way of handling exceptions!
Let’s go over why:
  1. Not doing anything inside the exception. If nothing happens within the catch block then what purpose does it serve? I have seen people prepare their code like this in anticipation of going back and adding logging at some later date. Although this is not necessarily the best logging solution, it is acceptable when you actually implement the code! However, preparing your method like this in anticipation of some future date does nothing but make the code difficult to read. It’s not like it is that hard to go back later and add a try…catch block; if you’re using a refactoring tool like CodeRush it is literally four keystrokes. 
  2. Catching the base Exception. Not every exception can have something be done about it. The canonical example is an OutOfMemoryException or one implying the database might be down. Is there anything to do in this case other than drop the user to an error page? I would even go so far as to say that most exceptions fall in this category – you just can’t do anything about them.  I strongly encourage you to read Stop Catching Exceptions for a more in depth discussion.
  3. Treating the message as if it were the most important thing. Exceptions usually carry a heck of a lot more information than just their message. They carry their type and a StackTrace and a list of any inner exceptions. Many specializations of the Exception base have even more information specific to that type of error. Out of all that information, the message is arguably the least important – for debugging I would take a StackTrace over a message any day. But by creating an exception off of the message you are effectively stripping out all this useful stuff! If for some reason, you must create a new exception, at least use the constructor overload that includes the original error as an InnerException: new Exception(“I don’t know why I’m creating this”, ex);
  4. Why create a new Exception object at all? You already have a perfectly valid exception object. It is a simple matter to do:
    try {
     // ...
    }
    catch(Exception ex) {
     // Log or otherwise handle the exception
     throw; // Same as throw ex;
    }
So in conclusion
  • Don’t catch an exception if you aren’t going to do anything with it.
  • Try to catch exceptions at the appropriate level and for the appropriate task. (logging inside private methods is probably unnecessary)
  • Do not create a new exception, throw the old one.
Please take this as healthy constructive criticism. I hope that you agree with me on these points and that we can take care of this issue properly from now on.

 


A bit harsh perhaps, but I feel like for all the reasons above the immensity of this mistake cannot be overstated.  If you are doing this in your code STOP NOW and apologize to the maintenance gods!  You might even need to sacrifice a goat to appease them.  It’s that bad.

In any case, the recent commit has only 38 instances of this error.  So at least we’re getting better!

January 16, 2009 Posted by | Programming | , , , | 2 Comments

Re: What is Unit Testing?

In a post last month Zachariah Young posts that 

… unit tests … verify that the business logic is correct.  I believe that for it to be unit testing it has to use a testing framework like nunit or junit.

I say thar be dragons!  Tying your understanding of unit testing to a specific tool allows you to neatly sidestep thinking about whatThar be dragons  testing actually does.  Additionally, you deny credit to an excellent tool like NUnit by pigeonholing its purpose.

Consider for a minute what NUnit actually is.  Yes their own website claims that they are specifically a “unit testing framework for all” but what does it actually do?  In my opinion it is a framework for setting up an application’s state, executing code, and then asserting that the resulting state is as you expected. That’s pretty broad.  Way broader than the confines of mere unit testing.  

Take the excellent WatiN or (no longer maintained) NUnitASP tools.  Both can be run using NUnit but neither is used to build a true unit test.  WatiN for example remote controls your browser to investigate how your page will react to certain stiumuli.  What unit does WatiN test?  Your Page_Load method?  Your page renderer?  Whether the viewstate persists that you had entered some text halfway up the page before submitting and the text is not cleared when your page returns with a validation error?  The localhost routing mechanism on your PC?  Or does it test the integration of all of these?

I made the same exact mistake myself when I decided to ‘see what this TDD thing’ is all about last April.  I ultimately had to delete my entire testing project after I came to the realization that each test bit off far too large a chunk making it utterly impossible to maintain once true refactoring started.  I nearly cried that day.

But out of the ashes I was reborn with what I hope (but don’t really expect) to be the final zen-like understanding of this unit testing thing.  The first aha moment was when I finally caved in and decided to learn Rhino Mocks and my understanding sharpened when I caved again and looked into the new Rhino Mocks 3.5 AAA syntax.  Overall the lesson seems to be that I’m always wrong and I will eventually give in on everything and like it.  My girlfriend will be happy to hear that.

Let me tell you how I understand unit testing now.  Imagine a room.  You are standing on the outside and can comunicate with its ouccupants through a two way loudspeaker.  This room is your unit – if it helps you can imagine the room as painted black.  Now in testing you present your unit with a problem:

Given that you are on 735 Bourbon St New Orleans, Louisiana how far is it to my grandmother’s house?

I used to think that unit testing involved merely waiting for the answer:

Your grandmother’s house is 1345 miles away and you haven’t visited in months you shmuck.

Now I realize its more about everything else that is said.  “Where does your grandmother live?” and “Can you be so kind as to  slip an atlas under the door?” should definitely be questions that you hear over that loudspeaker.  If you’ve separated your resposibilities properly the unit will also require a calculator that given two points on a map can tell you the distance (the specific calculator implementation should depend on whether you intend to fly or use the highway system).  The unit might even request that you hang a EnRouteToGrandmas = true sign on the door.  

The point is that you’re not so concerned with the final answer as much as you are with the unit asking the right questions.  Afterall, without that information know that it could not possibly be doing what you mean for it to do!

And so I define unit testing as

Verifying that given an input, a piece of code makes all the external requests that you would expect where the unit is small enough that the number of these can be enumerated with ease.

Note that this definition does not necessitate automated testing and this is something that I again think is basically correct.  After all, a framework should not do anything that you cannot do for yourself.

The beautiful part is if you’re limiting the amount of requests that you’re going to expect – let’s say no more than four – single responsibility emerges almost all on its own.  After all, how much can a piece of code do if its not communicating with the external world?

So there you go, thats my understanding of unit testing.  I look forward to being proven wrong in the future and having to refactor everything all over again.  But until that time,  Zachariah, you’ve been blogo-served!

Disclaimer:  I do not know Zachariah personally but he seems like a smart guy that is highly involved in the ALT.Net community.  I do not purport to be more knowledgeable than him in programming issues, I just disagree with him on this one point.

kick it on DotNetKicks.com

January 15, 2009 Posted by | ALT.Net, Programming | , , | Leave a comment

New Years Resolutions

Ok, so just like everyone else in the universe I’m posting some resolutions on my blog.  The first and most obvious if you look at the dates of my previous posts is to blog more.  A heck of a lot more.  I’m aiming for once a week.  Nothing intense, I’m no Steve Yegge and I don’t have all that much to say but I do have some thoughts that I need to start writting down and I do need to practice my writting. 

That being said, some career development-oriented resolutions:

  • Attend at least one professional – preferably an ALT.Net centered – conference.  Got to figure out which one first.
  • Learn about continuous integration and how to use a build system.  I am thinking NANT, CruiseControl.NET or TFS.  I just want to be able to build all these awesome open source projects so that I can…
  • …read other people’s code.  For all my complaining of being a lonely developer working in a godawful architecture I certainly make few enough attempts to connect with well written code.
  • Learn more about dynamic languages.  I have spent plenty of time in the PHP world and I’ve got to say, I just don’t get it.  Yes some tasks can be done with slightly less code, but you have to give up such IDE luxuries like Intellisense and automatic refactoring.  With all the chatter lately of Ruby and with IronRuby 71% complete maybe I’ll try my hand at that. 
  • Javascript.  Find an excuse to get beyond the basics.  I think it is a language with much to teach me and I want to learn.  It doesn’t hurt that JQuery as about as awesome as can be.
  • Learn more about .NET internals and the CLR.  I would love to be able to get a deep enough understanding to design my own language – not that I have any intention of doing something so crazy.

January 1, 2009 Posted by | Album | Leave a comment

Links For Motivated Programmers

Aggregation Sites

Forums

Funny

Blogs

August 7, 2008 Posted by | Programming | Leave a comment

Stephen Bohlen Is My Savior

One of the tools that I’ve set out to learn in my quest to become a better developer is Alt.NET’s baby NHibernate.  Unfortunately, being my company’s sole developer, my manager has alotted me roughly “go fuck yourself” hours for learning this mountain of an API.  I’ve tried reading through articles on Codebetter and Codeproject, only to find articles discussing very different and nuanced things.  No step-by-step tutorial.  I’ve tried sic-ing Intern Justen on the monster only to have him thwarted by anything more complicated than a simple get and save object.  I need a very through walk through.

Enter Stephen Bolen who has created a series of beautiful screencasts called Summer of NHibernate (available on his blog) in which he builds projects from the ground up.  Not only does it show me exactly how to create, configure, and test an NHibernate project but it also is great for a poor directionless aspiring star like myself to see how a real pro structures his project, his naming schemes, and his general style.  Kudos Stephen, here’s hoping this post gives you a well deserved PageRank boost.

June 30, 2008 Posted by | Programming | Leave a comment

Backing up and Restoring Databases in Oracle

This article is specifically about how to use oracle’s exp and imp utilities to create a dump file of all objects contained within an Oracle User(s) including the schema, procedures, package, constraints, sequences, jobs, and data; pretty much everything except DB Links. When you are done, you should be able to back up a database and restore it at a future date.

What you will need for this:

  • Oracle installed on your machine (You can download Oracle XE for free here)
  • A Database to back up (Sample schemas here, but then again you probably have one if you’re reading this)
  • Windows (maybe?) – I have no clue how this process works on a Linux or Mac system, though I imagine it’s exactly the same.

Creating a Backup

An Oracle install typically comes with the excellent exp command line utility (also there’s similar the exp data pump) to see if it’s installed and its manual type at the command prompt:

C:\Temp>exp -?

There are many articles online explaining this utility. The important parameters here for a simple, straightforward backup of a user are OWNER and FILE. Since the command line utility is not within oracle you don’t have to mess around with oracle directories or permissions or anything like that. To backup a database type:

C:\Temp>exp scott/tiger@XE owner=(scott) file=scott.dmp

Break it down:

  • exp – start our utility, don’t be silly
  • scott/tiger – the username/password of the account we will be using to pull out the information. It can be any account with the ability to access the user schema you’re trying to save, I usually just use the same schema
  • @XE – An ‘@’ symbol followed by the TNS name for the oracle instance the database you’re backing up is in, look in your tnsnames.ora for installed names. Do not omit this, as the utility might have a default and you might end up backing up the wrong database.
  • owner=(scott) – a comma separated list of users you want to back up. We could have used owner=(user1,user2) or – when there is only one user – owner=user1.
  • file=scott.dmp – the file that the backup will be stored in. The above set-up will create c:\Temp\scott.dmp with the contents of everything that is owned by the scott User in the XE instance of Oracle.

Restoring the Backup

This part is (slightly) more difficult. The command line utility to use is called imp

C:\Temp>imp -?

The important parameters are FILE, TOUSER, FROMUSER

Because you exported everything owned by a user, you must first ensure the user exists in the garget database. You can do a CREATE USER SQL statement or, if using the Toad for Oracle client you can use the Create User pop-up.

If the user already exists however and you want to restore them to the saved state you must first remove all of the user’s objects. The easiest way to do this is to drop and recreate your user. In Toad you can select the user from the Users view and click on the Script tab to see a script for dropping and restoring the user. In the case of the Scott Schema you would see

DROP USER SCOTT CASCADE;

CREATE USER SCOTT

IDENTIFIED BY VALUES ‘F894844C34402B67′

DEFAULT TABLESPACE USERS

TEMPORARY TABLESPACE TEMP

PROFILE DEFAULT

ACCOUNT UNLOCK;

– 2 Roles for SCOTT

GRANT RESOURCE TO SCOTT;

GRANT CONNECT TO SCOTT;

ALTER USER SCOTT DEFAULT ROLE ALL;

– 1 System Privilege for SCOTT

GRANT UNLIMITED TABLESPACE TO SCOTT;

Notice that there are actually six SQL statements here (count the semi-colons), you must run them all in order. (First drop the user, then create the user, then grant roles, etc.). Also notice that the password is stored as an encrypted hash value; ‘F894844C34402B67′ is the encoding of the ‘tiger’ password. If you would like to change the password just take out the values keyword: IDENTIFIED BY ‘MyNewPassword’.  Otherwise, keep the line as is.  Finally, since you are dropping and recreating the user notice that you must be logged in from a different user account – one with the permissions to do so. If you have access to the System user it will do nicely, this is the only time that you need to be logged in as a different user, make sure you get in and get out as quickly as possible to minimize potential damage.

Now with the Scott user created and cleared of any objects that might conflict with the ones we are trying to restore, we are ready to run the import.

C:\Temp>imp scott/release1@XE file=scott.dmp fromuser=(scott) touser=(scott)

Break Down:

  • imp scott/release1@XE – just like explained above, what user should the utility log in as when doing the import and at what Oracle instance. The user should have permissions to create tables, packages, etc. and to insert data.
  • file=scott.dmp – a file created by the exp command described above
  • fromuser=(scott) – since the .dmp file can create objects for multiple users, will search the file for all objects owned by this user(s) and import those. When there is only one user we can also omit the paretheses.
  • touser=(scott) – the objects we’re importing will be created need to be owned by a user already in the database, this is the user they will be created under. If our target database had two empty users scott and allan, and we did something like imp scott/release1@XE file=scott.dmp fromuser=scott touser=allan then the end result is that scott will still be empty but all of the objects saved to the file from the scott user will now have been imported to the allan user.

And you’re done. Don’t forget to check for invalid objects if you are transferring data between two different oracle instances or users. Enjoy!

 

Errors That I’ve Commonly Run Into

· You are attempting to run imp and you get IMP-00015: following statement failed because the object already exists scrolled to the screen. Generally this means that you forgot to empty the target user. Drop and recreate them or manually drop all the objects the import is complaining about.

· You are attempting to run imp and you get IMP-00010: not a valid export file, header failed verification. This in my experience is caused not so much by a mismatch in the versions of Oracle as Google would suggest but by a mismatch in the versions of the exp and imp utilities. For example if I go to my Oracle Server I can check the version of the export utility

C:\Documents and Settings\Administrator.WESTWAY-AD1>exp

Export: Release 10.2.0.1.0 – Production on Wed Jun 25 16:50:19 2008

 

And if I try the same thing on my Desktop I get:

C:\Temp>exp

Export: Release 9.2.0.1.0 – Production on Wed Jun 25 16:49:27 2008

You will have to find and download the same version of each. Sorry about that.

June 25, 2008 Posted by | Album | Leave a comment

Follow

Get every new post delivered to your Inbox.