Friday, December 21, 2012

Using Dynamic Instead of Type Casting

Yesterday I was writing some NUnit tests for an MVC controller. My test was making sure that a property on the model being placed in the view had a property set correctly:

   1:  var sut = new MyController(fakeProvider);
   2:  var result = (ViewResult) sut.Index(id);
   3:  var model = result.Model;
   4:  Assert.That(model.MyProperty, Is.EqualTo(expectedValue);

Often type casting can be full of syntactic noise. I could refactor that code to remove a line:

   1:  var sut = new MyController(fakeProvider);
   2:  var model = ((ViewResult) sut.Index(id)).Model;
   3:  Assert.That(model.MyProperty, Is.EqualTo(expectedValue);

All those parenthesis on line two are like fingernails on a chalkboard to me. Luckily I was having a problem with the razor view when I was trying to preview the controller that resulted in me hacking away at my code until it looked like:

   1:  var sut = new MyController(fakeProvider);
   2:  dynamic result = sut.Index(id);
   3:  Assert.That(result.Model.MyProperty, Is.EqualTo(expectedValue);

I didn’t even notice until this morning when working on another action in the controller that I had removed the need for casting my ActionResult to a ViewResult in my test. What a happy accident. I suspect that the compiler is doing the type casting for me under the covers, but I leave ILDASM to @vcsjones, so I’ll never know for sure.

I am filing that little tidbit in my bag of tricks and will definitely be using that in the future.

Tuesday, December 4, 2012

Mani-Pedis with Kyro


I just finished reading a well written article "Why I'm No Metrosexual" Kyro Beshay in which he laments the lack of skuomorphism (or at least a beveled button) in Windows 8.

The foundation of his argument is that we need this visual cues to tell us how to interact with an interface. I find this argument without merit in as much as I'm sure Kyro has managed to navigate his way around the internet using hyperlinks and not just buttons. Nothing in the physical world would translate an underlined word as something to interact with, yet billions of hyperlinks are clicked each day.

Then how do we know to click on these underlined words? Someone taught us. There was probably a time in each of our lives when we first looked at an HTML hyperlink and never thought to click the word. Then one day we saw someone else browsing a page, and they clicked a word and it took them to another part of the page, or a whole new document. From then on we looked for clues that the words in the text we were reading would take us to some other, releated content.

In recent months, or in the coming months, you will be introduced to the new Windows Start screen. "Can I click on on those tiles?" Kyro asks. This is as valid a qeustion as, "Can I click on those words?"  It takes only a few seconds to be taught that every tile on the Start screen will open an application for you, and just a few minutes more to learn that the live tiles are infinately more helpful in providing information, even to the point of preventing you from needing to launch the application in the first place. Why can't a button also be a billboard?

So Kyro, why not come out with me for a mani-pedi, and I'll teach you the visual language of Windows 8. Its really not that hard.

Friday, October 12, 2012

Wednesday, October 10, 2012

Influencer Appreciation Week: Jonathan Cogley


In 2008, I was the only developer where I worked. While it afforded my the opportunity to "work the whole stack". it also meant I could often get stuck, and getting unstuck was hard. I decided that there was probably a user group that I could join to spend some time with my peers. An internet search landed me at the RockNUG website. As it happened they had just had their monthly meeting and the speaker, Jonathan Cogley, had given a talk on TDD. Since I had discovered TDD the previous year, I clicked on his bio to learn a bit more. On his site I happened across a job posting. There are very few moments in life you can attribute to "fate", but here I was staring at a job description that read as if I had written it in response to the question "write a job posting for your dream job". A week later I had a new job. Working at Thycotic was an amazing experience. I learned about what doing development right looks like and I got to help many other companies see the benefits of Agile and TDD as well.

Thank you Jonathan for giving me the opportunity to learn and spread the joys of Agile and TDD.

Tuesday, October 9, 2012

Influencer Appreciation Week: Jean Paul Boodhoo & Joey Beninghove


In 2006 I was working on a Smart Client application. Scouring the internet for help with "best practices" I stumbled across an episode of DNRTV with Jean Paul Boodhoo. He was talking about this thing called test driven development. I had read a couple of books on XP, and I had written a couple of unit test in my previous job, but I had never heard of this concept of TDD. It made perfect sense to me, but I had alot of questions. I sent a very long rambling email to JP, not really expecting him to respond. I was shocked the next day when he actually called me on the phone to help answer my questions. It was amazing, and started me on my way to becoming and Agile developer.

A few months later Joey Beninghove managed to get JP to Richmond to teach his 1 week Nothing but .NET class. I immediately signed up. The class was amazing. It introduced me to the concept of design patterns and helped me understand TDD better that I had managed to learn on my own. It also came with my first copy of ReSharper.

Thank you Jean Paul, for taking the time to respond to me, for introducing me to Agile. And thank you to Joey Beninghove for making the class possible.

Monday, October 8, 2012

Influencer Appreciation Week: Scott Guthrie


I personally preferred ASP development over Cold Fusion development. I think that was mostly influenced by my oreference for Visual InterDev. That's not to say I didn't have my complaints. Making good objects was tedious. Handling form data was tedious. Typing all those <% %> was tedious.

Then in 2001 I read about a new thing being developed by Microsoft called ASP.NET.  Man this thing was awesome and made making my pages so much easier. I could make a page and the controls would automagially maintain state between page posts. I could load a page on my WAP phone and it worked!

I couldn't afford Visual Studio but I slowly migrated my development time from Visual InterDev to spending most of my time in WebMatrix. A language war broke out, and being a self-taught developer my insecurity drove me to learn C# because I thought it looked more like what "real" programmers use (I had pervious.y made several failed attempts to learn to make applications in C++).

I fell in love with ASP.NET and still love it today. thank you Scott Guthrie for giving us ASP.NET.

Influencer Appreciation Week: David Schwartz

I was an interactive designer who wrote the occasional PERL script and Java applet, when my friend David called me to ask if an idea he had for a website was possible. The idea was to have a page where someone would log in daily and answer a few questions that would be customized by an administrator.

I had recently read about this thing from Microsoft called Active Server Pages and told him I though that with ASP, his idea was possible. He asked if I could build a prototype and I agreed. After a trip to Barnes and Noble, I sat down with "ASP for Dummies" and the prototype turned in to yet another failed dot com.

This was the start of my career as a professional programmer. Thank you David for turning me into a web developer.

Influencer Appreciation Week

I am declaring this week "Influencer Appreciation Week".

This weekend I attended Richmond Code Camp. Spending a day with my peers, I reflected upon how I love what I do. People who get paid to do what they love are very lucky and I really appreciate how my career has turned out with respect to my overall life happiness. But I didn't get here on my own. I began my career as a graphic designer. I landed here as a result of interactions with people who directly or indirectly nudged me into where I am today.

So I thought I would spend this week thanking them.

Saturday, June 30, 2012

You’ve just gotta fight your way through

This afternoon I saw a tweet by Jamie González that quoted Ira Glass, "Nobody tells this to people who are beginners, I wish someone told me. All of us who do creative work, we get into it because we have good taste. But there is this gap. For the first couple years you make stuff, it’s just not that good. It’s trying to be good, it has potential, but it’s not. But your taste, the thing that got you into the game, is still killer. And your taste is why your work disappoints you. A lot of people never get past this phase, they quit. Most people I know who do interesting, creative work went through years of this. We know our work doesn’t have this special thing that we want it to have. We all go through this. And if you are just starting out or you are still in this phase, you gotta know its normal and the most important thing you can do is do a lot of work. Put yourself on a deadline so that every week you will finish one story. It is only by going through a volume of work that you will close that gap, and your work will be as good as your ambitions. And I took longer to figure out how to do this than anyone I’ve ever met. It’s gonna take awhile. It’s normal to take awhile. You’ve just gotta fight your way through."

That was me. As a young graphic designer fresh out of school, I was frustrated by my inability to be as awesome and creative as the designers I was working with. At some point I stopped becoming a designer and identified as a developer because I thought I was a better developer than I was a designer.  

Today, while I do some graphic design and focus on the client end of development, my company pays me for pushing bytes, not pixels. 

The funny thing is, the only reason the same thing didn't happen to me in programming was that I was isolated and ignorant as a beginning programmer and thought I was great at it. Had I had the good fortune of working with great developers early on, I might have given up on that, too. 

Sometimes ignorance really is bliss.

Monday, June 25, 2012

Polyframework

Last year at MADExpo, I was introduced to the world of Ruby. While I have only gotten half-way through the getting started guide, just being exposed to a new language, and more importantly, a new point of view for development, has made me a better developer. But this isn't a post about being a polyglot, for that go listen to Scott Hanselman talk with Ivan Towlson on Hanselminutes. I want to talk about a being Polyframework.

Recently I began to learn Backbone.js in ernest. For the last six months I have spent a majority of my time developing pages with Knockout.js, so as I started learning Backbone, it was only natural for me to compare what I was learning with what I do daily in Knockout. What I am finding is that learning Backbone has helped give me a better understanding of Knockout. I think this is because working with a new framework helps give you a new perspective.

It got me thinking about all the other frameworks I use, and how knowing more than one framework for any given problem domain has made me better at using all of them.

The open source community has a love affair with Ninject. At work, we use Autofac. I find that each does something better than the other. I find that the perspective of using one makes me better at solving problems with the other.

When I first learned TDD, I was taught using MbUnit. It took me months to stop complaining about NUnit. Now I usually choose NUnit but having used MBUnit, NUnit, and xUnit have prepared me so that I won't have to complain when I get that project that requires me to use MSTest. I will have enough perspective to figure it out and get on with my life.

As I write this it occurs to me that this doesn't just apply to just frameworks, but toolsets as well. Last month, just for kicks, I set up a new VM so I could try using CodeRush instead of ReSharper. Man talk about moving my cheese. But I learned that its not a matter of, "can it refactor" but more a matter of "what key command initiates refactoring?"

I complain a lot about SVN, get lost in bash hell when hunking a commit in Git, and love the TortoiseHg Workbench. All of them have taught me how to evaluate a good implementation of a feature vs a bad implementation and reflect on each tools pros and cons.

So the next time you find yourself in File > New Project, consider trying a different NuGet package for logging/testing/injection/scaffolding.

Saturday, June 23, 2012

Talking About What You Do

I live in the metropolitan DC area, and it seems like whenever you meet someone new, the first question after introducing yourself is usually, "what do you do?" I have become increasingly self concious about how I answer that question in the last year. My typical response is either, "I'm a software developer," or, "I build websites". But that to me is not a satisfactory answer as it in no way relays the challenges or rewards of how I spend the majority of my waking moments.

When my wife asks me over dinner how my day was, I struggle to formulate and answer that conveys the frustration of a useless expection message, or the joy of seeing three hours of work come to life inside a UI -- without having her eyes glaze over in the first thiry seconds.

Some days an analogy comes very easy to me, but most days I keep my answers short, such as, "I had a bug that took me all day to figure out how to fix," or "I made this really cool interface today."

How do you talk about what you do to people outside our profession?

How I Got Started (and Ended Up) In Computers and Programming

Scott Hanselman recently stated, "I like hearing stories about how people got into computers and programming. Perhaps if I blog my story, you'll share yours."

My first computer was a Commodore VIC-20. I was in the 5th or 6th grade at the time. I think it was a Hanukah present, and I remember being very excited about it. The coolest part was that my parents also bought a cassette player for it that allowed the computer to store and load programs from a standard cassette. 

Along with the VIC-20 came a few weeks for BASIC lessons from a local computer  store. I remember coming home after my first lesson and I wrote a program that would scroll my name across the TV screen as it oscillated through all the colors of the rainbow. From that moment on, computers had me hooked.

I remember getting magazines with games printed inside and I would spend hours typing in the code to my computer to play them. Usually I would modify the code in some vain way to make myself the main character or some other nonsense.

In 7th grade we actually had a computer class in school. We had a computer lab full of Commodore PET computers. I had been doing it home so much that I essentially became a teaching assistant helping other kids and helping the teach write programs to administer math tests.

My best friend got an Apple IIe and we spent a lot of time trying to dial into NORAD just like Matthew Broderick in "War Games." We also spent a lot of time with the game "Where in the World is Carmen San Diego." 

For my Bar Mitzvah I got an Apple IIc. It came with a green screen, but it also had an RF modulator so I could hook it up to our TV. I also got a subscription to Nibble and would enter in the programs from it. The one program I remember most was a simple program that was merely a list of pixel coordinates that when run would render an image of Alfred E. Newman.

For some reason, probably my interest in girls, I never got deeper into programming other that entering or fidgeting with the programs that were listed in magazines like Nibble. 

In high school we had these fancy new Macintosh computers, and they had a program called Page Maker. With page maker I could print out documents that looked like professionals had made it. That got me interested in graphic design. My only programming was to make flash cards and simple forms in HyperCard.

In college I took a semester of Pascal, but I found that spending a couple of hours in MacKermit writing a program and then having to walk across campus to get the printed result was not terribly exciting. I wanted to make video games, but somehow I could never get past the "Hello World!" part of any of the numerous C, C++, Turbo Pascal, etc. books I bought thinking that spending an hour with a book and a night on my Mac would somehow produce a blockbuster video game like Mortal Kombat.

So the programming thing never took off for me and I graduated with a BFA in graphic design. But I was still a geek, and the first job I got out of school was for a "New Media" company that was starting to make interactive cd-roms. My limited programming background made me more useful writing lingo script for Macromedia director than as a junior designer on a team of seasoned graphic designers. In addition to the cd-roms, we would occasionally make these things called HTML pages for this new thing called the world wide web. I got really good and being able to craft pixel perfect HTML tables that would look just like the Photoshop mockups. 

Eventually we were doing more website projects than cd-rom projects and our HTML pages were rapidly evolving from the giant image maps and needed more interactivity. I started learning how to modify PERL scripts I found on the internet for our needs. My company sent me to Java classes and I felt more like a "real" programmer having stepped up from a scripting language to something I could actually compile.

Then one day a friend from college called me and told me of an idea where foster children could log on an interact with their social worker using forms on a web page. I had built a few cold fusion pages but I had recently read about this new feature form Microsoft called active server pages and I told him that I thought ASP could do what he was asking. The next day I went to the book store and bought ASP for Dummies, fired up my PowerMac that had a Windows 95 emulator card in it that we used for IE compatibility testing, and wrote my first ASP application.

A year later I quit my job and went into business with my friend trying to sell this case management system. In the process I moved from the Mac and BBEdit to the PC and Visual InterDev. By the time we threw in the towel on our Dot-Com millionaire dreams i had gone from Graphic Designer to Designer/Developer. 

From ASP I moved up to ASP.NET using WebMatrix for a good long while before convincing my boss to splurge on MSDN so we could get Visual Studio. By then I was spending a lot of time on the MSDN website and was learning about good development practices and things like application blocks from the patterns and practices group.

In what I consider to be a pivotal moment in my development career, I somehow stumbled across a DotNetRocks TV episode with J.P.Boodhoo. I instantly knew that TDD was the only way I wanted to write software, but the episode left me with a lot of questions, which I sent to J.P. in a long email that rambled on and on, much like this blog post. I really didn't expect a response, and I certainly was shocked when he called me the next day because he felt it would be easier to answer my questions on the phone than by email. not long after I was able to attend his Nothing But .NET class where I learned all about TDD and Design Patterns. 

When I look back, that was the moment that I feel I truly became a software developer. After that class, the development process made so much more sense. I began listening to Dot Net Rocks, reading blogs of other TDD/XP, and Alt.Net practitioners. I stopped thinking of software as job and began to appreciate it as a craft that I truly enjoyed.

Sometimes I feel inferior to my colleagues who can write "real" software, managing pointers or writing assembly language. Some days I wake up worried that I'm going to be shunned for not having graduated with BS, or for having never written a compiler. But most days, I get to go to work, write some code I'm really proud of, and produce application experiences that my product owner never thought was possible. And for those days I am always grateful.

Tuesday, June 12, 2012

Why Would I Write Unit Tests When I Get Paid by the Hour?

This morning I read an entertaining post by Jonas Hovgaard about how he has abandoned some sound patterns and practices for what he considers to be increased productivity. It is timely in that just this weekend I read another great post about “flipping the bit” by Uncle Bob. These two completely opposite posts have one thing in common, they both are concerned with productivity.

Personally, I’m on Uncle Bob’s side. But I am on his side because I am going to be the one maintaining today’s code tomorrow. This has not always been the case. I once was a consultant churning out website after website with pseudo CMS capabilities. I suspect that Jonas is as well based on his statement, “In my personal scenario (creating around 20-30 apps every year).” I imagine Jonas doesn’t maintain applications, but rather cranks out site after site at Acme Webapp Co. In that kind of environment, the business model works by spending as little time as possible getting the minimal functionality possible to get client acceptance and payment. In that environment code that is hard to maintain isn’t a problem, it’s a business model.

Jonas hasn’t abandoned testing altogether, as he as adopted acceptance testing using Selenium, and he is right about the fact the the most important test for your code is the user acceptance test. But in the end if its working for him, more power to him.

I would like to take a moment to comment on some of his ideas.

I agree, it's absolutely awesome that I can change the concrete type or lifecycle with ease, but for gods sake, I don't even dare to count the hours I have spent creating these abstractions, making me able to do something I never freaking do.

I don’t like interfaces for their extensibility. I agree that we hardly every swap implementations. Occasionally we may swap a logger but I have never needed to replace my SQL data tier with an Oracle one. That’s not why I love interfaces. I love them because it allows me to write one section of my code without worrying about how I am implementing another section at the same time. I use interfaces mostly because I want mocks. Even if I didn’t do TDD but were doing F5DD, I would still want to program against an interface, implement fakes for lower level layers, and code my way down from the html.

But also I spent hours trying to understand what Ninject or StructureMap did with my classes. When I finally understood, I handed over the application to the next developer who also was forced to spent time understanding some IOC.

Ah, the magic of frameworks. It makes me sad that someone would abandon sound principles because they didn’t like the tools they have chosen. I love IoC containers, but like Jonas I have often been frustrated trying to locate “where the magic is happening.” I had one particularly sucky day trying to locate how something was being injected in a global action filter. Magic on top of magic. The aversion to magic is a bad reason to abandon a sound principle. IoC is not defined by the containers that we use. I myself am very fond of the Service Locator pattern (scroll down half-way.) This is a no-nonsense pattern for straightforward dependency injection.

At the end of the day, I want to write code that I am proud to share. For me this means well tested code because my tests are my insurance to myself that I have done well. My tests also serve as a guide to my fellow developers as to how I intend my code to be consumed and the current requirements it was written to fulfill. And most importantly my tests (and my commit messages, but that’s a whole different post) tell my future self what the hell I was thinking when I wrote this crap because we all hate the code we wrote yesterday.

But hey, I have to maintain my code, and I’m not getting paid by the hour to do it.

Friday, May 11, 2012

Don’t Forget to Secure your TypeKit!

Today I made a stupid mistake. I am using TypeKit and I added my reference like so:

<script type="text/javascript" src="http://use.typekit.com/….js"></script>

Can you see what’s wrong?

It works great in local development, however when I deploy to production, I will be using HTTPS. When my page tries to hit the TypeKit servers over HTTP, my browser is going to complain about insecure connections.

I could switch to

<script type="text/javascript" src="https://use.typekit.com/….js"></script>

but instead I decided to make my link protocol relative:

<script type="text/javascript" src="//use.typekit.com/….js"></script

this way it will call the protocol that my site is currently serving. TypeKit does support HTTPS.

Tuesday, May 8, 2012

Don’t be a Richard, or How to Manage App Store Releases

As a software developer, I understand the desire to get paid for your work. I was one of the few people who didn’t whine when RedGate decided to charge for .NET Reflector. Their change in plans didn’t affect their currently released software, only future releases. So if you were happy with what you had, you could go on in blissful happiness.

The nature of “App Store” releases makes the decision to go from free (or freemium) to paid more complicated. If you update your app, I can decide not to install the update, but I then have to be very careful on how I manage my device. I can’t go back and install previous versions. So if you update your app to take what was once free and require an in-app purchase to unlock it, you are being a Richard.

You want to make the software better, great. You want to get paid for your hard work, great. But don’t alienate me in the process. A better experience would be to release your updated version as a brand new app, end-of-life the existing app with one last update to notify users that the version is no longer supported and link to the new app. Existing users who are happy with what they have are happy. Nerds like me who have to have the latest and greatest install the new app and are happy. You get paid and are happy. Everyone wins.

Here’s my $1.99 for my that feature you removed, Richard.

Wednesday, April 25, 2012

Access IISExpress from Remote Machine

Today I tried to access my development site from a VM and was unable to connect. Thanks to @vcsjones, I learned that you can edit My Documents > IISExpress > config > applicationhost.config. Look for the sites section:

        <sites>
            <site name="MyApplication" id="0">
                <bindings>
                    <binding protocol="http" bindingInformation="*:2600:localhost" />
                </bindings>
            </site>
        </sites>
duplicate the localhost line and replace “localhost” with the hostname you want to allow.
Thanks Dr. Jones.

Wednesday, April 18, 2012

Testing the Order of Your Collections

I was trying to test that a service call was returning my data in order. I didn’t want to implement an IComparer to pass into CollectionAssert.IsOrdered(). Thanks to some insight from Ahmad on StackOverflow I was able to come up with the following assert:

Assert.That(result, Is.Ordered.By("Name"));
Simple!

Monday, March 12, 2012

“Natural” Scrolling with Logitech Touchpad

I love my new Logitech Touchpad. It makes my work PC experience one step closer to my home Apple development environment. The one annoyance has been that the Touchpad options do not include an option for inverting the scrolling to allow for the “natural” scrolling like that on the Mac since Lion. (If you haven’t tried natural scrolling, it take a few days to get used to but makes so much more sense in a touch world. Do you scroll down your phone browser page by swiping your finger up or down? Shouldn’t your touchpad have the same movement?)

I found a nice little script for AutoHotKey here. It works great and I’m much happier.

Tuesday, March 6, 2012

Detecting Element Visibility in WatiN

I recently needed to check the visibility of an element in a WatiN test and I came across a very helpful post by Ashley Tate. I turned his method into the following extension method which makes my tests nice and easy.

   1:  public static class ElementExtensions
   2:  {
   3:      public static bool IsDisplayed(this Element element)
   4:      {
   5:          if (string.Equals(element.Style.Display, "none"))
   6:          {
   7:              return false;
   8:          }
   9:          return element.Parent == null || element.Parent.IsDisplayed();
  10:      }
  11:  }