In Praise of the Junior Developer

"She's a project," my boss said to me. "She's green, and even though she's been working here for several months, you should consider her like a brand new college graduate. She'll need a lot of oversight, a lot of hand-holding and you'll still be expected to finish your projects on time."

"Excellent," I said.

I'm not sure why my boss felt the need to warn me. Melissa is a new, green developer. I know that; I knew that from the moment the coding section of the interview began. She had trouble with the FizzBuzz test, stumbled over the differences between an abstract class and an interface, and generally showed that she needs some experience. This ain't my first interview; I know she's a newbie, that's she'll need some help (maybe a lot of help) to get started.

And it doesn't friggin matter. I'm happy to have her on my team.

We need junior programmers. And I don't mean my company specifically, I mean our industry as a whole. This profession runs on the backs of the juniors. They're the one who get the crap work, who check the nitty gritty details, who learn and advance and become seniors and leads and managers. They are the people who will eventually replace me. I'm not scared of them; I want to see them succeed. But to do that they're going to need teachers, mentors, someone to help answer their questions.

I've been saying for a long time that what this profession needs is more teachers of technology. The problem, I'm now beginning to realize, goes much deeper than that. The real issue is not a lack of people willing to teach others, it's a lack of compassion in doing so.

The odd thing about programming is that it's entirely mental (with all the different usages of that word applying). There's no real physical component. Sure, we type on a keyboard, but that's the result of the mental work in progress, not the end goal. And it's tiring. Programming is mentally exhausting work. If the brain is a muscle, then programmers work it to the metaphorical bone each and every day. Good programmers solve people's problems using code in an efficient, skillful manner.

When you think about it, that's also the issue with teaching: it's a mentally exhausting job. Now, instead of trying to work out problems, you're trying to work out how different people learn and then teach to their skills, which is infinitely more difficult that just solving static problems. People are dynamic, changing, varying from one to the next. If you're a good teacher, you can innately understand how people learn, and then construct situations in which they will acquire the skills they need in the most efficient manner.

Here's the rub: the skills that make you good at programming (solving problems) and the skills that make you a good teacher (solving people) are not, and never will be, fully compatible. You can be the greatest damn programmer in the world, and yet anybody you try to teach will be just as bewildered as before, if you don't have compassion for the learner.

Compassion bridges the gap between teacher and learner. The less skilled you are at teaching, the more compassion you need to have for your learner.

(I'm tempted to use the word patience here instead of compassion, but you can be patient and still not be compassionate. It's the difference between a boss needing work done and a teacher helping a student study; they might both wait a long time and be perfectly fine with that, but the boss will simply expect the work to be done, while the teacher will understand why it took such a long time and work to help the student improve that.)

Look, not everyone will be a good teacher. Not everyone will be a good programmer. But those of us who are in a position to help others learn should take advantage of that. At the very least, attempting to teach others will help your communication skills; by describing a problem, you increase your understanding of it, otherwise rubber duck debugging would not be a thing.

But everyone can be a compassionate teacher. I can, you can, even newbies like Melissa can. Skill doesn't matter, ability doesn't matter; compassion matters. Compassion is what makes a good programmer into a great teacher.

So, bring it on, Melissa. Bring it on, junior devs. We need you. And we'll be doing our level best to be compassionate, to be teachers, even if we're not very good at it. Despite all our misgivings, despite all the hate and impatience and intolerance you might run into out there in the wilds of the Internet, there are still those who want to see you succeed, and are willing to use our compassion to help you reach your goals. This industry runs on the backs of the junior developers, and we would be loathe to forget that.

Post image is Representatives of the database development team from the U.S. Department of Agriculture, used under license

The BugCatcher Chronicles #2 - Pine Hills

Elena

The flickering streetlamp fought valiantly, but in the end Elena was victorious once again.

The green mantis/cricket hybrid that had been resisting her invocations finally gave up the ghost, melting into the virtual ground before materializing as a tiny pixelated icon in the upper-right corner of her phone's screen. The evening had been good to them so far; this was the third such avatar they'd captured. The path of broken streetlamps they'd carved through the neighborhood was a testament to their success.

"Nice inputs, babe." said a voice, hovering over her left shoulder.

"Thanks, Greg. How's yours going?"

"Not too bad." A quick glance at his screen showed a pink rhinoceros beetle clacking its jaws at him. He spun the input selectors again, tapped the invoke button, and the beetle lost one of its jaws. Startled, it attempted to flee, but a quick invocation finally brought it down. The beetle evaporated and rematerialized, and the garage door at the house across the street started to rise of its own accord.

"Shit. Better move!"

Elena quickly followed Greg's fleeing footsteps, and the two scrambled over the next hill, pausing to catch their breath under one of the pine trees that the neighborhood was famous for. They'd gotten away, like they always did. The setting sun framed the outline of the cookie-cutter houses, melting them into an endless skyline of sameness. Elena wondered how any of the residents could find their own home amongst all these identical facades.

"Woo! Got 'em!" cheered Greg. "We're killing it tonight babe!"

"Yeah we are!" affirmed Elena, pulling her hood back up over her head. It was chilly tonight, and while she didn't feel like going home yet, the cold was started to seep through her jacket.

"Any more nearby?" she asked. "I don't see them."

"There may be another over that hill to the west." said Greg. "I mean, we had good luck there yesterday."

"Cool, let's go."

The two slid their phones back into their pockets, volume turned all the way up so as to hear the rhythmic beeps that signify a nearby bug. These bugs are what Elena and Greg are after; software bugs that exist in the real world that, somehow, this app BugCatcher can find and invoke. Once invoked, Elena and Greg get a new, custom-generated avatar for their collection.

Of course, whatever the bug actually does will also happen, hence the trail of broken streetlights and the now-stuck-open garage door.

Elena slid her left hand into Greg's right. He'd been the one to introduce her to the game and, frankly, it had been a lot of fun. Find a bug, try some inputs, capture the bug, see what it did. Everything they'd captured so far had involved broken streetlamps or sprinkler systems gone haywire or suddenly-loud music systems; in other words, nothing too serious. The worst thing that had happened was that they'd accidentally turned a car on, with no way to turn it off. It hadn't been shifted out of park, so Elena figured it was no big deal; it couldn't go anywhere.

As they crested the hill, Elena got a glimpse of the rest of the neighborhood. It was quite nice, to be sure, but it was also so... dull. Every house was the same, with a big green yard, 2.5 children and a dog. Bland, unoriginal, inoffensive, boring.

It didn't really bother her that they were out here catching bugs, breaking streetlamps and sprinkler systems. After all, if anybody could afford the mild chaos she and Greg were causing, it was these people. Goddamn rich people.

A low drone sounded from Greg's pocket, and Elena's started doing the same. A bug was nearby. As if by magic, Greg's phone appeared in his hand as though it had been there all along. Elena was a bit slower, but in a couple seconds they had located the bug. Apprehension turned to amazement as they beheld the monstrosity before them.

It had the body of a caterpillar, but the clacking mandibles of a fire ant. The thing writhed in an unnatural way, as if trying to shake some invisible bond that held it within the phone. It was huge, almost as big as the house nearby, with giant black eyes that seemingly reflected the virtual light which attempted to pass through them. Elena was amazed at the design quality of this particular avatar; whoever coded this up did a hell of a job.

Greg was quicker, as always, and his first few invocations started flying. Elena joined in on her app, working the opposite way Greg was, just like he'd taught her. Between the two of them, they'd always managed to find the right combination of inputs to invoke the bug and capture the monster before it had a chance to flee.

This one proved difficult. Several rounds went by, and nothing was taking. The caterpillar's writhing continued, and it looked to Elena like it was specifically programmed to come leaping out of her phone if she failed to catch it.

Finally something stuck. The leftmost input glowed with a red outline, and the monster's right side started limping. She'd found something!

"Red 47!" she whispered urgently to Greg. "That's the left input!"

A moment later, he whispered back: "Black 12 is the middle."

All they needed now was the right side. Her fingers flew across the screen as she desperately tried combination after combination, willing the app to give her the right answer so she might have this bug for her collection.

Sustaining hit after hit, the caterpillar monster finally collapsed, dead, and faded away. The pixelated avatar appeared, and despite herself she let out a whoop of joy.

"Nice job, babe," said Greg, though not without a hint of jealousy.

"Hey, it was you who figured out the middle input."

"Yeah, but you brought it down. Make sure to show that to Danny when we get back to campus."

The two started back the way they came. Only a moment later, the trees became illuminated in red and blue, and a police cruiser slammed to a stop right next to the pair of hunters. Another cruiser followed on the heels of the first one, and three offices exited the two vehicles.

"Hands up!" shouted the nearest officer. "Don't move."

Greg glanced at Elena, and she could tell what he was thinking. Should we move? She shook her head, almost imperceptibly, and raised her hands. No point. He reluctantly did the same.

The nearest officer took Greg over toward the nearby tree, cuffed him, and slid him into the back of the first cruiser. Another officer cuffed Elena, and as she was being walked to the second cruiser she belatedly realized that the officer that had cuffed her had also been speaking to her, though she couldn't remember what he had been saying.

I'm being arrested! For what?!

As she took a seat in the back of the cruiser, she wondered how the hell it had come to this. Goddamn rich people, thinking they own the world. It was just some broken streetlamps. We didn't do anything!

Frank

Twenty minutes before the police showed up way earlier than she'd expected them to, Georgia Huntsworth sat in an easy chair and stared blankly at the TV. The family insisted that having it on helped poor Frank, but Georgia just couldn't see how. The man was a vegetable, with no hope of waking up anytime soon. He'd have no idea it was even on, much less be able to watch it.

She sighed, and got up to fix another cup of coffee. A stronger one, this time. The gentle whirring of Frank's artificial breathing machine faded into the background as Georgia crossed into the house's kitchen. It would be a long night, but the machines would do most of the work. All she had to do was make sure he was comfortable; at least, as comfortable as she could imagine him being.

She placed the pot back on its mantle and leaned against the countertop. The job wasn't bad, per se, it was just boring. There really wasn't much to do for poor old Frank. She made him comfortable, she kept the TV on, and otherwise she chatted with her coworkers or her daughter or her beloved Zachary. It was a good job, just not very exciting.

The coffee was done, so Georgia poured herself a mug and went back to the easy chair. She glanced at Frank; nothing had changed, and she mentally chastised herself for thinking that something might. She sat down, dug out her phone, and starting to type a message for Zachary.

Then she realized that Frank was no longer breathing.

And, even worse, there was no whirring noise.

She checked the machine. It was off, and silent, though she'd been told that if it failed it's alarm would go off. She checked for Frank's pulse, found it, weak but present, and scrambled to dial 911. Once that call was finished, she straddled Frank's still body and began performing CPR on him, hoping to keep his blood pumping long enough to get him to the hospital.

Thirty seconds later, the red-and-blue flashes of the police cruisers arrived, and Georgia was impressed with their promptness, only to be disappointed when they left prematurely. They were followed a minute later by an ambulance. An EMT burst through the open front door, relieved Georgia, and together they loaded Frank into the ambulance.

Elena

The room was bright, unnaturally so, and Elena's eyes were having a hard time adjusting. When the burly detective (Elena assumed he was a detective, given that he didn't wear a uniform) slammed the door open and barged into the tiny room, she nearly jumped out of her chair.

"Well now, little missy, mind telling me what you were doing out in Pine Hills tonight?"

"I, uh, I was just playing a game," she stammered. "We both were."

"That's a hell of game, then." The detective's voiced boomed off the walls; Elena thought she saw the one-way mirror rattle. "Four broken street lamps, one garage door stuck open, two sprinkles systems that now need extensive repairs. You know the whole neighborhood saw you two, right?"

Elena hadn't known that, but it seemed blindingly obvious now, so out of fear of embarrassing herself she kept her mouth shut.

The detective wasn't fooled. "Right. So would it surprise you to learn that all that property damage wasn't all you did?"

"What? I swear, all we were doing was catching bugs!" Elena insisted.

"I'm sure. I doubt the family of Frank Doornbos will be so understanding."

What the hell is he talking about? Elena wondered. I don't know any Frank Doornbos. Probably some damn rich guy who lives in that neighborhood.

When she realized what the detective had actually said, Elena felt a chill run down her spine.

"What does that mean?"

"We've already arrested you for destruction of property. Our officers picked you up outside of Mr. Doornbos's home. We know you were playing BugCatcher, despite that game being illegal in this state. You really want to add obstruction of justice to your rap sheet?"

"I swear, I don't know what you are talking about." Elena couldn't believe what she was hearing. BugCatcher was illegal? Why hadn't Greg mentioned that?

"Oh, all right then. I'll spell it out for you. Frank Doornbos is dead. Whatever you two and that app did, it caused his artificial breathing machine to stop working. His nurse called 911, performed CPR, the works, but it was too late. He was dead before they reached the hospital."

Elena's arms and legs went numb. That bug, the last one they'd caught before the police picked them up, the huge jawed caterpillar thing. It had killed someone?

Her face must have given her away, because she looked up from the metal table in front of her to see the detective's eyes boring holes into her skull. Her mind furiously searched for something, anything, to say.

"No, see, you got it all wrong," Elena fought through tears that threatened to overwhelm her. This was all wrong, it was just some fun at the expense of rich people, they weren't doing any real harm. "We were just catching bugs, we didn't kill anyone."

"Oh, but see, you did." The detective smiled, if you could call a mouth full of teeth a smile. "You invoked that bug. That bug shut off the breathing machine, which killed Frank Doornbos. Therefore, you killed Frank Doornbos." He slammed a file down on the desk and Elena jumped. "We are charging you with second-degree murder. Your boyfriend has already confessed; you would be wise to do the same. We will notify your family, and it would be wise to get a lawyer."

The detective picked up the file and walked out of the brightly-lit room, the door slamming behind him. From within the room, sniffles turned to sobs, and the detective strode down the long hallway to his desk.

As he approached, he heard a low drone sounding from his desk drawer, and he grinned.

A Simple Caching Scheme for Web API using Dependency Injection

I use Dependency Injection (DI) quite a bit in my ASP.NET projects, particularly in Web API and MVC web applications. Recently, I had a need to implement a caching layer in one of my MVC apps, and such a layer would be best used if it could be injected into my clients layer (e.g. the layer that called an API and handled responses from the same). The solution I came up with seemed to be pretty simple, so I wanted to share it here.

In this post, we're going to set up a simple MVC project that consumes a Web API and implements a caching layer.

Requirements

For this project, I'm using two of my favorite NuGet packages:

The sample project, which is over on GitHub, is a fully-functional implementation of the strategy described in this post. Feel free to check it out, branch it, download it, whatever!

Setting Up the API

First, let's take a look at our sample API. Here's the class DateNumberObject, which represents a response returned from the API to the web project:

public class DateNumberObject  
{
    public DateTime CurrentDate { get; set; }
    public int RandomNumber { get; set; }

    public DateNumberObject()
    {
        CurrentDate = DateTime.Now;
        Random rand = new Random();
        RandomNumber = rand.Next(1, 200);
    }
}

As you can see, all this class does is return the current date and time and a random number.

We can now build our API, which is also rather simple. Here's a snippet from the API's controller:

[RoutePrefix("samples")]
public class SampleController : ApiController  
{

    [HttpGet]
    [Route("date")]
    public IHttpActionResult GetDateAndNumber()
    {
        return Ok(new DateNumberObject());
    }
}

That's all our API will do: return the current date and a random number. Since there's no caching taking place at the service layer, we will need to implement caching at the web layer.

Speaking of the web layer, in our sample solution it is an MVC5 project, and we will be using my favorite Dependency Injection tool, StructureMap.

Setting up StructureMap

If you've never set up StructureMap in your MVC projects, you'll want to read this section; otherwise, skip to the next section.

The first thing we need to do is download the StructureMap.MVC5 NuGet package, which will add a DependencyInjection folder and a StructuremapMvc file to our app:

Inside the Dependency Resolution folder will be a file called DefaultRegistry.cs, which will initially look something like this:

namespace WebApiCacheDemo.Mvc.DependencyResolution {  
    using Caching;
    using StructureMap.Configuration.DSL;
    using StructureMap.Graph;

    public class DefaultRegistry : Registry {
        #region Constructors and Destructors
        public DefaultRegistry() {
            Scan(
                scan => {
                    scan.TheCallingAssembly();
                    scan.WithDefaultConventions();
                    scan.With(new ControllerConvention());
                });
        }
        #endregion
    }
}

The way StructureMap works is that it keeps instances of classes that need to be "injected" into other classes in a Container class, and uses these instances any time a particular interface is called for in another class. You'll see exactly what this means in the next section.

The Uncached Example

Let's build the uncached example first, and we can begin by setting up the MVC client. For this project we'll be using RestSharp (which I have also written about before) to consume the API responses, so be sure to download the NuGet package.

Because we're using Dependency Injection, we need our clients to be injectable into our controllers. For this reason, we will make both an interface and a class for our client, like so:

public interface ISampleClient : IRestClient  
{
    DateNumberObject GetSampleDateAndNumberUncached();
}

public class SampleClient : RestClient, ISampleClient  
{
    public SampleClient()
    {
        BaseUrl = new Uri("http://localhost:58566/");
    }

    public DateNumberObject GetSampleDateAndNumberUncached()
    {
        RestRequest request = new RestRequest("samples/date", Method.GET);
        var response = Execute<DateNumberObject>(request);
        return response.Data;
    }
}

Note that we don't need to register this client with StructureMap because the naming follows the standard conventions (ISampleClient maps to SampleClient).

Now we need our controller...

[RoutePrefix("Home")]
public class HomeController : Controller  
{
    private ISampleClient _sampleClient;

    public HomeController(ISampleClient sampleClient)
    {
        _sampleClient = sampleClient;
    }

    [HttpGet]
    [Route("Uncached")]
    [Route("")]
    [Route("~/")]
    public ActionResult Uncached()
    {
        var model = _sampleClient.GetSampleDateAndNumberUncached();
        return View(model);
    }
}

...which returns a view:

@model WebApiCacheDemo.Contracts.Samples.DateNumberObject
@{
    ViewBag.Title = "Uncached Date Sample";
}

<h2>Uncached Results</h2>  
<div class="row">  
    <span><strong>Current Date:</strong></span>
    @Model.CurrentDate
</div>  
<div class="row">  
    <span><strong>Random Number:</strong></span>
    @Model.RandomNumber
</div>  

When we run this, we can see that the view returns the newest date and time, as shown in this gif:

That's exactly what we would expect to see, of course. Now, we can get down to implementing a cache at the web layer for this.

The Cached Example

The first thing we need is our CacheService interface and implementation, which I totally stole from this StackOverflow answer:

public class InMemoryCache : ICacheService  
{
    public T GetOrSet<T>(string cacheKey, Func<T> getItemCallback) where T : class
    {
        T item = MemoryCache.Default.Get(cacheKey) as T;
        if (item == null)
        {
            item = getItemCallback();
            MemoryCache.Default.Add(cacheKey, item, DateTime.Now.AddMinutes(30));
        }
        return item;
    }
}

public interface ICacheService  
{
    T GetOrSet<T>(string cacheKey, Func<T> getItemCallback) where T : class;
}

We also need our SampleClient class updated to use this cache service, like so:

public class SampleClient : RestClient, ISampleClient  
{
    private ICacheService _cache;
    public SampleClient(ICacheService cache)
    {
        _cache = cache;
        BaseUrl = new Uri("http://localhost:58566/");
    }

    public DateNumberObject GetSampleDateAndNumber()
    {
        return _cache.GetOrSet("SampleDateAndNumber", () => GetSampleDateAndNumberUncached());
    }

    public DateNumberObject GetSampleDateAndNumberUncached()
    {
        RestRequest request = new RestRequest("samples/date", Method.GET);
        var response = Execute<DateNumberObject>(request);
        return response.Data;
    }
}

NOTE: In my structure, I am intentionally implementing the cached and uncached operations as separate methods in the same client, so that either one can be used. This may or may not be the correct usage in your application.

Further, we need to update our controller:

[RoutePrefix("Home")]
public class HomeController : Controller  
{
    ...

    [HttpGet]
    [Route("Cached")]
    public ActionResult Cached()
    {
        var model = _sampleClient.GetSampleDateAndNumber();
        return View(model);
    }
}

The last step is to register the ICacheService implementing in StructureMap's DefaultRegistry.cs class:

namespace WebApiCacheDemo.Mvc.DependencyResolution {  
    ...

    public class DefaultRegistry : Registry {
        public DefaultRegistry() {
            ...
            var inMemoryCache = new InMemoryCache();
            For<ICacheService>().Use(inMemoryCache);
        }
    }
}

Now, when we run this sample, we will see the cached values for the date and number, as shown in the following gif:

Now we've successfully implemented our cache AND used Dependency Injection in the process!

Summary

With this structure, we've successfully implemented a caching layer into our MVC application, all while using StructureMap to provide Dependency Injection. This structure allows us to potentially swap cache providers (in case we, say, move to a database-located cache for server farms) without too much trouble, as well as injecting the cache service into our existing clients.

Don't forget to check out the sample project over on GitHub, and feel free to point out how you've used this implemention or where it can be improved in the comments.

Happy Coding!

Show Up, Kick Ass, Go Home

I refuse to work overtime. In the five years I've been at my current company, I've worked overtime exactly once, and that was because our server was literally on fire. Overtime is just not worth it to me.

I'm a salaried employee. A rather well-paid salaried employee, at least compared to many other professions. In the United States where I live (where I am classified as an "exempt" employee), that means that I will not be paid for work done above and beyond 40 hours a week. So, as far as I am concerned, my employer pays me to work 40 hours a week. I show up on time, I kick ass for 8 hours a day, and then I go home.

What I don't do, at least not on a regular basis, is work overtime.

Unpaid overtime dilutes your hourly rate. If you get paid a salary of $60k per year, that's approximately $29/hr if you work 40 hours a week. If you work just 5 hours more a week (45 hours per week), your hourly rate diminishes to approximately $26/hr. You've just devalued yourself by $3 an hour. Further, you've told your company that that's what your worth, since they're already paying you a set amount. From their perspective, overtime is free work, and who would turn down free work?

And for what? I'm an American, but one of the apparent ideals this country seems to hold is absolutely ludicrous to me: I don't live to work. I've written before that I live to live, to do things with my family. I don't want more money; I already have enough that my family and I can live comfortably, if not extravagantly. I want more time.

Time is the one thing I can't ever get more of. No amount of salary negotiations, of GitHub commits, of stand up meetings can ever replace the time with my family that I lose when I work. And "lose" is the correct word here; it's not time I can make back up.

I have to wonder: why do so many people do this? Why do so many people commit themselves body and soul to a company, to work? I don't have any proof, but I personally think it has a lot to do with the illusion of control.

See, in many people's lives, things are simply beyond our control. We can't always protect our children from every little thing; we can't always get that promotion we so desire; hell, we can't even always catch the damn Pokemon that we need to complete our collection. But we can do our job. We can file the correct paperwork, we can write the appropriate tests, we can get all the appropriate projects planned out months in advance. Those are things we can control.

Control is a big deal. Anything we can control, we tend to hold on to for far longer than we should, far longer than is rational (not that humans are always rational, of course). After all, why lose something when all it takes is our hard work to make it worthwhile?

But it's not. Hard work, work above and beyond what you get paid to do, is not worthwhile. It's the opposite of worthwhile, because it diminishes the amount of time you get to spend on other activities. It reduces the time spent with your family, with your loved ones, with your hobbies that give you purpose. It gives us control, but it also wastes our time. It's a time-sink.

Now, at this point in my life, my most valuable commodity is not money, it's time. I can't get any more, no matter how hard I work. I have a limited amount of keystrokes left in my life and I refuse to voluntarily use them up for some company, some effort, some goal that I don't believe in. I've done that before, and it never works out.

Fellow salaried employees: don't work overtime, at least not on a regular basis. Your time is more valuable than that.