Feelings of White   i wish i had raped the monkey but what i did instead was good too
Me, looking like Hot Sex inc. with my cool shades, a beer and my bountiful chest hair displayed for all to see
  • all
  • curator's pick
  • funny
  • narcissism
  • technical
  • the arts
  • the void
  • violent aggression
  • writing

Jimbo vs. The Tooltip

Here Are Your Choices!
The Flattened Defender
public interface IAppleStrategy { }

public class Apple
{

    public class Tasty : IAppleStrategy { }

    public class UnRipened : IAppleStrategy { }

    public class Rotten : IAppleStrategy { }
}
Vs 
The Nested Challenger
public class Apple
{
    public interface IStragegy { }
    

    public class Tasty : IStragegy { }

    public class UnRipened : IStragegy { }

    public class Rotten : IStragegy { }
}

Perhaps you already have a strong preference just from looking at them; that's fine. Instead of debating and declaring one a winner, lets examine how I arrived at my own decision, when I was recently faced with this question.


Nested classes + intellisense
= easier for developers

I was considering refactoring to the nested class scenario. I've grown somewhat fond of nested classes for their ability to group things together and for the way intellisense can provide targeted hints with its dropdown suggestions. Instead of trying to hunt down a TastyAppleStrategy or UnripenedAppleStrategy and wonder what else may exist, you can just type "Apple." and see all available choices. without ever hitting comments or navigating code. Its all right there for the developer stuck trying use my convoluted code. O 'course, get too nested and you've just got a rats nest.

It doesn't matter how brilliant or easy my code is, because my target audience (another developer) didn't write the code himself. And your code, regardless its nature, is always regarded as unintelligible goobledygook by other developers. As a general rule, being forced to understand it has pissed them off as well. They want to deal as little as possible with your code, so they can go back to writing their own. Everyone understands their own code, they've spend their whole life writing their own code; it makes sense. Even if you disagree on the merits of nested classes, let's assume for what follows next that they are roughly of equal merit. The main usage point was this function:

             

But what really happened with nested classes was less friendly tooltips:

             

Oh jeez, my meticulously constructed fantasy world crumbles around me. What if I abandon the refactor and stick with a flattened structure:

             

A flattened structure yields the most helpful tooltips. Since invoking DoSomething is the main use-case for developers-who-aren't-Me, I chose the one that's better documented by the IDE.

So, that's how I arrived at my choice. Seriously: The tooltip. Not like I planned out success criteria and did a focus group. More like 90% into the change to my obviously brilliant nested classes I noticed the tooltip, went "Aw Fuck!" and reverted the changes. The tooltip rules all!

There are a few points I'm attempting to make. One is to consider your target audience: other developers. Lazy, couldn't be bothered, highly overworked, incompetent, brilliant, will not read any specs, enjoy puzzling things out, developers. Naming and structuring your code is the biggest documentation you are likely to perform in any given project and there's a lot of potential things to guide your decision.

Much is written elsewhere involving the pursuit of technical excellence. Ways to code that in and of themselves that are beautiful monstrosities with no regard to the environment they inhabit. The best solutions integrate with the ecosystem of developer tools. "The Best Way To Code" stopped being an isolated academic question sometime around when our variables got colour-coded. The right(est) answer depends on your coding environment, Visual Studio version, your team-members, their prior experience and skill levels, what code-generators you're using -- you gotta consider it all. Which is ultimately impossible. If you want definite answers, go believe in creationism.

You could do worse than consider tooltips in your next design. And when Visual Studio changes their tool-tips next version, you betcha: Its time to refactor that code. The Game just changed and everything I said is antiquated.

2008 Dec 15 12:07 am; Filed under technical and tagged visual studio.
« Why I’m Throwing Away My Vote « before «
» after » Basic Math »
  • http://liamj.blogspot.com Liam

    I think that inner classes are nice (from a Java perspective). They're clean, they limit the scope and applicability when it's necessary. But holy hell are they hard to understand for someone who's never used them. They don't get used enough to be commonplace and as such, for a lot of programmers, they're hard to read, hard to debug and frustrating.

    I don't know if they have anonymous inner classes in C# but that's a whole different kettle of fish.

blog comments powered by Disqus

Subscribe

Recent Awesomeness

  • Neurotic Dad
  • #8 VA vs. Brevity
  • Lost in the Epilogue
  • Jamie Oliver’s Food Revolution
  • I shoulda got a fake fingernail
  • How did this shit get started?
  • Feeding the dragon, or plant, or.. shit I’m out of time
  • Why are you eating so much soy and corn?
  • Cop Out
  • I’m A Stay At Home Dad!
  • Firefly & Serenity
  • The Kitchen of Zarro Boogs
  • America’s Got Talent FTW!
  • Steamed Salmon with Tomato Basil Couscous
  • Dream Stealers Like Me

Other Opinions

Sorry, I know colors suck, I will fix it sometime...

Find things tagged

4400 Battlestar Galactica Battlestar Galactica cliff comics curation depression erron family fiction food funny game janine job kelly kyle liam lost manifesto meta mlp music nathan passionate diatribes plug poem Really Dumb Story relationships review revisionism sam sermon software spirituality star trek Star Trek Deep Space Nine suicide tamdhu testpoint the process travels video vlad wtf

What was I doing in..

  • March 2011 (2)
  • August 2010 (23)
  • July 2010 (4)
  • June 2010 (1)
  • May 2010 (2)
  • April 2010 (2)
  • January 2010 (1)
  • December 2009 (4)
  • November 2009 (2)
  • October 2009 (1)
  • August 2009 (2)
  • July 2009 (2)
  • June 2009 (1)
  • May 2009 (1)
  • April 2009 (3)
  • March 2009 (11)
  • February 2009 (6)
  • January 2009 (10)
  • December 2008 (3)
  • October 2008 (1)
  • August 2008 (2)
  • July 2008 (3)
  • June 2008 (1)
  • May 2008 (11)
  • April 2008 (7)
  • March 2008 (3)
  • February 2008 (1)
  • January 2008 (2)
  • December 2007 (1)
  • October 2007 (1)
  • September 2007 (3)
  • August 2007 (1)
  • June 2007 (3)
  • May 2007 (2)
  • March 2007 (5)
  • February 2007 (5)
  • January 2007 (13)
  • September 2006 (1)
  • June 2001 (3)
  • May 2001 (2)
  • April 2001 (2)
  • March 2001 (2)
  • February 2001 (1)
  • January 2001 (1)
  • November 2000 (5)
  • May 2000 (3)
  • April 2000 (5)
  • March 2000 (3)
  • February 2000 (3)
  • January 2000 (6)
  • December 1999 (17)

Copyright © 2009 Feelings of White | Powered by WordPress | Original site design by Stephen Reinhardt; tweaked by me