DaedTech

Stories about Software

By

You Can Tell a Lot About Developers From Their Scratchpads

What is a Scratchpad?

When you have a question like “what exception is thrown when I try to convert a long that is too big to an integer” or “what is the difference in performance between iterating over a list or a dictionary converted to a list” what do you do? Google it? Phone a friend? Open up an instance of your IDE and give it a try? I think that sooner or later, most developers ‘graduate’ to the latter, particularly for things that can’t be answered with a quick search or question of a coworker. And, if they wind up doing this enough times, they start creating a project or project(s) with titles like “dummy”, “scratchpad”, “throwaway”, “junk”, etc — you get the idea.

As this practice grows and flourishes, it starts to replace google searches and ask a coworker to a degree, even when those things might be quicker. If you get very used to setting up experiments in this fashion, it tends to be almost as quick as a search, and there’s less potential for wrong or misleading information. This is a very useful practice but, more interestingly for the purposes of this post, I think the makeup of this scratchpad (I’m using this term because it’s what I name mine) can tell you a lot about the developer using it. In fact, I believe strongly enough in this that I see a lot of value in the interview question “tell me about your scratchpad and how you use it.”

I’ll say in advance that I’m going to paint with some broad strokes here. So, please read the following while bearing in mind the caveat that there will, of course, be exceptions to the ‘rules’ that I’m describing. In the examples below that describe a single type of scratchpad, please note that I’m referring to situations where this is the primary or only scratchpad that the developer uses. I’ll describe the “arsenal” of scratchpads further down.

No Scratchpad

If someone doesn’t have something like this, they’re quite likely either not very seasoned as a developer or else not very inquisitive when it comes to understanding their craft. The lack of such a playpen project implies that they either don’t experiment or that they experiment in production code, which is pretty low rent and sloppy. (One possible exception is that they experiment in a project’s unit tests, which is actually a pretty reasonable thing to do, and an example of a reason for my “broad strokes” caveat). In either case, they’re lacking a place that they can go in and just throw some code around to see what happens.

Extrapolating out to the way a person with no scratchpad works, it seems very likely that you will observe a lot of “debugger driven development” and “programming by coincidence”. The reason I say this is that this person’s natural reaction to a lack of understanding of some facet of code will most likely be to try it in the production code, fire up the application, and hope it works. I mean, lacking a playpen and tests, what else can you really do? It’s all well and good to ask a coworker or read something on stack overflow, but at some point an implementation has to happen, and when it does, it’s going to be in the production code and it’s probably going to be copy-pasted in as a matter of faith.

I’d be leery of a programmer with no scratchpad. It might be lack of experience, lack of curiosity, or lack of interest, but I’d view this as most likely a lack of something.

Application Scratchpad

This is a scratchpad project that has the kitchen sink, from persistence on up to the GUI. In shops/groups that make a single product, it may be as simple as a duplicate of that project. In shops with more projects, it may be one of them or a composite of them. But, whatever it is, it’s a full fledged application.

Extra points here for being clever enough to have a consequence-free, dummy environment and for recognizing the value of experimentation. This is usually a sign of an inquisitive developer who wants to take things apart and poke at them, or at least a conscientious one who wants to try things out in dress-rehearsal before going live. I’d take some points away, however, for the monolithic approach here, assuming that this is the primary scratchpad and not an auxiliary or temporary approach. The reason I’m not such a fan of this is that it’s indicative of someone who hasn’t yet learned to think of an application in seams, components, modules, units, etc.

I mean, think about how this goes. “I wonder what happens if I use a string array instead of a string list here” leads to trying out the change and then firing up an entire application, complete with GUI bells and whistles, database access, file reads/writes, loggers, etc. This represents a view of the software that essentially says “it’s all or nothing, baby — here we go.” Good on them for the experimentation, but we can certainly do better.

Console Based Scratchpad

The console scratchpad (and this is a little Visual Studio specific, though it’s applicable to other IDE/environments as well) is one in which the main running application is one that writes to and reads from the console. If you wanted to time stuff you’d be doing so using a lot of System.out.println() or Console.WriteLine() or whatever the equivalent in your choice of language.

This correlates with the good characteristics of the GUI/application scratchpad (curiosity, judiciousness) but adds a bit more sophistication. A developer with a console based scratchpad understands how to decompose and abstract concepts and how to isolate problems. I think that this is potentially indicative of a competent and potentially great developer perhaps ready for a push.

Class Library Scratchpad

The most sophisticated scratchpad, in my mind, is the class library scratchpad. This is a scratchpad that has no program output of any sort and cannot be run independently. What this means is that the developer is used to reasoning about units and experimenting in very small, isolated fast feedback loops. Someone doing things this way clearly understands that increasingly complex applications are assembled from solutions to manageable problems rather than with some kind of irreducibly complex, inter-connected gestalt. Someone with this style of scratchpad is almost certainly a unit tester and most likely a practitioner of TDD (I certainly recognize my own bias here). But the most important thing here is the ultra fast and simple feedback loop, where answers to “how does this work” are provided right in the IDE itself (and extra points for anyone running a continuous integration tool like NCrunch.

Monolithic Scratchpad

A monolithic scratchpad is one that tends to be a developer’s only scratchpad. I think that this tends to be indicative of an architecturally minded developer capable of thinking in significant abstractions. The monolithic scratchpad is one that encompasses all of the projects above in one. It has test projects for fast feedback. It has a persistence model or two and a domain of sorts. It has a web front end and a desktop front end and mobile front end. In short, the developer organically evolves this scratchpad to suit whatever experimentation needs arise, demonstrating an ability to grow an application in response to whatever needs arise. Someone with this sort of scratchpad setup is someone I’d keep my eye on as a potential architect.

Arsenal of Scratchpads

An arsenal of scratchpads is indicative of a developer seasoned enough to understand that different questions call for different environments, but someone more silo-oriented and, perhaps, very well organized in a sense. While it may not occur to this person to blend scratchpad needs into an ad-hoc, decently architected application, the work nevertheless exists in such a way that it’s easy to find, access, and use. Since the response to new situations is new scratchpads, the critical fast feedback loop is there since they never get very big. I think that this practice is indicative of someone who might excel in small to medium sized picture development work or, who might do well on the path to project management. A monolith scratchpadder and an arsenal scratchpadder could probably form a pretty good leadership tandem on a project.

What Does your Scratchpad Look Like?

I’d like to reemphasize that this is a fairly lighthearted post that I fully acknowledge may completely miss the mark in categorizing some people. But, I do think there’s a grain of truth to it, and I stand by my assertion that this would make for an excellent interview question. If you have one of these types of scratchpads and either reinforce or poke holes in my premise, please weigh in. Same if you have a scratchpad setup I hadn’t thought of.

By

Announcement: New Post Categories

In the wee hours of the morning this morning/last night, I did an overhaul of post categories on the blog. When I started out, I didn’t really see the purpose of categories versus tags, so I just made everything a category and had the tag cloud display categories. That was a workable solution at the time, but ultimately not scalable as anyone who saw the giant category list can attest. Over the course of time, I came to realize this but allowed myself to be a boiled frog until last night I said “screw it” and hopped out of the pot. I downloaded a helpful wordpress plugin so that I didn’t have to mess with the database directly and changed all of my existing categories to tags.

From there, I created a handful of more general categories that I feel reflect the broader categories of my posting. Some of them are obvious (.NET and Java) and others are named for running series of posts that I do (abstractions, design patterns, etc). I went rather tediously back through all of my posts and assigned them categories that seemed a good fit, though I must admit I didn’t spend a ton of time on the oldest posts. I also am generally trying to minimize the number of categories assigned to posts – one is ideal and some may occasionally be in two, but that’s really about it, I think. We’ll see. This new classification system is rather evolutionary, so I’ll adapt it as I make new posts and use it from here forward. If you have any issues with a post’s categorization, please feel free to comment in that post or to shoot me an email (erik at my domain).

Also, I should note that there is no loss of information. The previous categories are now all tags, so if you wanted to see all “WPF” posts for instance, you can go to https://daedtech.com/tag/wpf instead of https://daedtech.com/category/wpf. I’m hoping that in general this makes the site a little more readable and organized.

By

Splitting Strings With Substrings

The String.Split() method in C# is probably something with which any C# developer is familiar.

string x = "Erik.Dietrich";
var tokens = x.Split('.');

Here, “tokens” will be an array of strings containing “Erik” and “Dietrich”. It’s not exactly earth shattering to tokenize a string in this fashion. And some incarnation or another of this predates .NET, C# and probably even my time on this planet.

It’s Actually Harder Than You’d Think to Split Strings Using Sub-Strings

But what about if we want to split over a string instead?

What about if we have “..” as a delimiter instead of ‘.’ and I want to split “Erik..Dietrich” in the same way? Probably an overload of String.Split() that takes a string instead of a char, right? Well, actually no. As it turns out, the API for string.Split() is pretty unintuitive.

First of all, that call to x.Split(‘.’) is not actually invoking Split(char), but rather Split(params char[]). (Notwisthanding the fact that this isn’t advertised in the MSDN page unless you drill into the individual method.)

So, calling x.split(‘.’) and x.Split(‘.’, ‘&’, ‘%’, ‘^’) are equally valid, syntax-wise in the case of “Erik.Dietrich” (and in this case, both will give me back my first and last name).

So, what one might expect is that there would be an overload Split(params[] string) to allow the same behavior as splitting over zero or more characters. Nope. Instead you have Split(string[] separator, StringSplitOptions options).

What’s Really Not Great about the Default Way to Split Strings with Sub-Strings

Two things suck about this.

  1. I have to specify some enum that I don’t care about in the first place and that has only two options, one of which is “none”. I mean, really? You can’t just assume “none” and let users specify a different case if they want with another overload?
  2. But what sucks even more about this is that params have to be the last argument in the parameter list, so that option is out the window. You no longer get that snazzy params syntax that the char version has, and now you have to actually awkwardly create a string array. So, here is the new syntax following the old. Note that the new syntax is pretty hideous.
string x = "Erik.Dietrich";
var tokens = x.Split('.');

string y = "Erik..Dietrich";
var newTokens = y.Split(new string[] { ".." }, StringSplitOptions.None)

This Gets a Lot Easier and Prettier using Regex.Split

I was getting ready to write something to hide this mess from myself as a client, when I stumbled across a better alternative than rolling my own extension method or string splitting class: Regex.Split(). Here’s how it works:

string x = "Erik..Dietrich"
var tokens = Regex.Split(x, "..");

No fuss, no muss, and exactly what String.Split() should do. Granted, the arguments to Regex.Split() are both single strings (so if you want to specify multiple delimiters, you’ll have to cook up a regex recipe) and it’s a static method, but it has the advantage of already existing in the framework and being a much, much cleaner API than x.Split().

Use in good health!

By the way, if you liked this post and you're new here, check out this page as a good place to start for more content that you might enjoy.

By

Feed Paper: Help Yourself To My Intellectual Property

The Pledge

When it comes to US intellectual property law, specifically patents as they pertain to software, I have a very scorched Earth philosophy. Don’t tweak it. Don’t reform it. Don’t debate over it. Don’t worry about it. Just delete it. Yes, to me, it’s like a nasty, tangled mass of bad code where it’s easier to get rid of it and address what breaks than it is to try to salvage it in its current form. I understand the need for patents on things such as medicines that have prohibitive startup investment cost, but when it comes to things like “gravity” effects on your cell phone, it’s just not worth having a system where established powerhouses can bury the little guy or blast away at each other and drive up costs, benefiting no one but lawyers. But, this post is not intended to spark a debate about ownership of ideas and intellectual property.

Instead, I’m putting my money where my mouth is. I’m going to give away what I think could be a pretty cool and viable idea. Why? Well, because I’m not exactly made of time, and I’d rather trade the small chance that I’d ever parlay this into a winning business idea for the slightly greater chance that someone might take it and run with it (or point me to it if it already exists). In other words, I want this thing enough that I just want someone to do it. Maybe one day I’d get around to it, but if you want to do it first, faster, and better, please be my guest.

The Turn

Every day in my feed reader, an entry from Alvin Ashcraft called “Dew Drop” appears. Here is one such entry. It’s a link collection that he dutifully fills out every day, organizing by category. In the linked entry, he has “Top Links” at, well, the top, followed by Web Development, XAML, etc, ending up eventually with a set of other link collections and a book. You know what this reminds me of? A newspaper. I mean, the “Top Links” is pretty obviously “Front Page”, and then you’ve got your .NET equivalent of Business, Metro, Sports, Politics, etc.

Morning Dew is a nice collection of links, as are some of the others also linked in there (I personally look at Jason Haley’s and the Morning Brew a lot). And, if those weren’t enough, I have my own collection of links. Pictured here, in alphabetical order, are the ones that fit on my screen:

As you can see, my screen just barely fits A through C. So, I have an alphabetized list of feeds that have some parenthetical number of unread articles, and some of those articles have links to even more articles, some of which I may already have in my reader, and others that I don’t. In some of these places, some of these things are summarized, and in others, I may just have to go go with the title or the author. I think we can do better, so I propose “FeedPapyr”. Feedpaper.com was taken, so I bought the domain feedpapyr.us (see what I did there?) for 6 bucks.

What I envision is pretty simple. At its core, the site is just a feed reader. But, instead of having laundry lists of feeds, you create newspapers. You categorize the feeds into custom defined sections and the reader handles truncating them to fit into a newspaper-style layout. If the posts have images with them, those are rendered as well. They are not formatted in full post form, but rather somewhat like the view on the right in my google reader screenshot, but like a newspaper. And, when you click on an article, it “pops out” with a focused, higher z-index feel window as you read it, and retreats back when you’re done with it (there’s no need to preserve the whole “continued on page 22” thing with the actual paper). Users can “thumb through” the paper, starting with their “Top Links” and delving into other sections if they have time. They can add to the size of their papers over the course of time, promote and demote things, and swap in and out content creators. I feel that this format would lend itself particularly well to consumption of tablet or ultra book devices.

A user can create an arbitrary number of papers, just as in real life one might subscribe to multiple newspapers. I personally would love this. I’d definitely have at least one programming paper, but probably also one about Chicago sports, one about science/technology, etc. It could have ads just like normal papers to finance it, and offer a “subscribe to avoid the ads” model as well (but financing is a little far afield right now). It would basically be a newspaper that was auto-formatted for the reader with custom content that was specifically chosen and subscribed to by the reader on a case by case basis.

The Prestige

It’s not normally my style to go buying up domain names on a whim, but feedpapyr.us is now in my possession. If this idea is something that interests you, please get in touch with me. I’m happy to brainstorm and collaborate but if you think it’s something you’d really like to run with, I’m perfectly happy to let you have the domain name (of course, maybe you don’t like that name and would rather have your own anyway). If this is all a moot point because something like this already exists and I’m just a clueless idiot, please, please point me at it because I would love it. At the end of the day, I’d like to see this get done and I don’t have a lot of time. Sooner or later, I’m going to build myself a “feedpapyr” because I just want one. But, if someone builds one first that I can use, so much the better.

By

Unit Testing DateTime.Now Without Isolation

My friend Paul pointed something out to me the other day regarding my post about TDD even when you have to discard tests. I believe that this trick was taken from the book Working Effectively With Legacy Code by Michael Feathers (though I haven’t yet read this one, so I can’t be positive.

I was writing some TDD test surrounding the following production method:

public virtual void SeedWithYearsSince(DropDownList list, int year)
{
    for (int index = year; index <= DateTime.Now.Year; index++)
        list.Items.Add(new ListItem(index.ToString()));
}

and the problem I was having is that any tests that I write and check in will be good through the end of 2012 and essentially have an expiration date of Jan 1st, 2013.

What Paul pointed out is that I could refactor this to the following:

protected virtual int CurrentYear
{
    get
    {
        return DateTime.Now.Year;
    }
}

public virtual void SeedWithYearsSince(DropDownList list, int year)
{
    for (int index = year; index <= CurrentYear; index++)
          list.Items.Add(new ListItem(index.ToString()));
    
}

And, once I've done that, I can introduce the following class into my test class:

public class CalenderDropDownFillerExtension : CalendarDropdownFiller
{
    private int _currentYear;
    protected override int CurrentYear
    {
        get
        {
            return _currentYear;
        }
    }

    public CalenderDropDownFillerExtension(DateTimeFormatInfo formatInfo, int yearToUse) : base(formatInfo)
    {
        _currentYear = yearToUse;
    }
            
}

With all that in place, I can write a test that no longer expires:

[TestMethod, Owner("ebd"), TestCategory("Proven"), TestCategory("Unit")]
public void Adds_Two_Items_When_Passed_2011()
{
    var filler = new CalenderDropDownFillerExtension(new DateTimeFormatInfo(), 2012);
    var list = new DropDownList();
    filler.SeedWithYearsSince(list, 2011);

    Assert.AreEqual(2, list.Items.Count);
}

In this test, I use the new class that requires me to specify the current year. It overrides the base class, which uses DateTime.Now in favor of the "current" year I've passed it, which has nothing to do with the non-deterministic quantity "Now". As a result, I can TDD 'til the cows come home and check everything in so that nobody accuses me of having a Canadian girlfriend. In other words, I get to have my cake and eat it too.