Search

Posts Tagged ‘programming’

My goals for this year are somewhat similar to last year, with a few notable changes.

  • Rehab.  The “incident” was a grand mal seizure that gave me two dislocated shoulders, both of which caused fractures, which need surgery.  I’m on seizure medication, and I’m not supposed to drive a car until April.  I have already gotten through one surgery, the other will be coming up in February.  If all goes well, I’ll be about 80% by April, and hopefully 100% by July.  This goal is much lower on Maslow’s hierarchy than any of my other goals, and thus is automatically the most important.
  • Certification.  I’m already scheduled to take an MCTS exam to help my employer remain in good standing with Microsoft, as well as to improve my knowledge of Microsoft products.  I’m not overly concerned with certification(s) this year.  If I have the opportunity to take more Microsoft exams or pick up some PDUs, I’ll take them, but I’m not going to be worried if I don’t.
  • Android apps.  I will get a handful more of apps into the store this year, whether they be Mono for Android or native Java.  I already have one in the works, and ideas for several more. I’m also going to get some Windows Phone apps in the marketplace.
  • Conferences/sessions.  With the exception of CodeMash, I don’t have any plans for conferences, until–at earliest–after April.  I’d be open to doing local presentations if I’m needed, but that’s about it.  It will be enough of a challenge just to attend CONDG group meetings in the first half of the year.  I would like to definitely make it to GiveCamp this year!
  • Blogging.  I’ve created another blog, one with a much narrower focus than mgroves.com.  It’s called Cross Cutting Concerns, and it’s all about AOP news and information.
  • Business.  Our MonthlySauce.com business really needs to pick up this year.  I will be exploring some creative ways to get exposure on our limited budget.
  • Personal/Internal.  As before, I have a number of personal and internal-to-my-employer goals that I won’t state here.  And I may have another surprise or two up my sleeve this year if all goes well.

That’s it.

Well, it’s not exactly what I expected to create, but one of my goals this year was to get at least two Android apps into the market(s): one free and one paid. Those goals are now accomplished.

My free app has been in the market(s) for a while, and has actually gotten a recent update: Mono Stock Portfolio, which is totally free (and no ads), and was really just a way for me to help learn (and teach) the Mono for Android tool. According to Google, this app actually has a surprisingly large user base: 1080 total installs, and 393 active installs. And I’ve gotten several e-mails from users asking for more features!

The other app, I just threw together this weekend in a sudden fit of whimsy, inspired in no small part by this commercial:

The app is “Yeah Dog!“, which I started creating with Mono for Android, but soon realized that the 5mb+ overhead just didn’t make sense for this app. So I rewrote it, painstakingly, in Java, which wasn’t as unpleasant as I thought it might’ve been (but unpleasant nonetheless). This app will set you back 99 American cents, and is also ad-free.

In the process of creating and publishing Yeah Dog!, I came to find out that I was beaten to market! First, GEICO actually released their own “BroStache” app some time ago, but I discovered that there is a secret “Yeah Dawg” feature in that app. Secondly, some other rascal created his own YeahDawg app (albeit an inferior one!) and published a mere two days before me.

Oh well. Such is the harsh reality of free markets. But in any case, I believe I have enriched myself as a developer, speaker, and businessman throughout the process of creating, publishing, and maintaining these apps, so that alone makes it worth it.

Awaiting Xenu's Orders

I first mentioned Xenu link sleuth way back in March, 2008, as a handy way to find broken links.

It’s worth mentioning a second time, 3+ years later, as I just recently dusted it off again.

This time around, though, I wasn’t looking for broken links or 404′s, but what I was looking to do was to “exercise” an entire site by spidering over it.  The idea being that my site would catch any exceptions and log them, and so by exercising the entire site, I’m essentially doing one big set of tests.

Xenu is such an easy to use tool.  All you need to do is install it and give it a URL to start with, and it will go to town.

I once said that “Multithreading does a lot of things, but I don’t think ‘simplification’ is ever one of them“.  Even with the simplest, most beginner level of no-frills threading, I find this to be true.

As an example, I was writing unit tests for my MonoDroid app that I recently decided to refactor with the MVP pattern (so I could increase test coverage).  There’s only one place in the whole app where I use multiple threads.  When the user clicks on a portfolio, there’s a web service call to get the latest stock prices (and volume, and other stock information).  Because this can take a while, I want to show the user a nice animated “please wait” dialog on the UI while the web service (and other stuff) runs on a background thread.  That all works great, and provides a preferable user experience to a blank screen doing nothing. (Note that I tried doing this without threads and I couldn’t get it to work–this could be a failure on my part).

However, when I got to the part where I’m testing the presenter’s orchestration of the above multi-threaded scenario, my tests started getting inconsistent results. I had also started using MSpec and JustMock at this time, and so I immediately assumed I was using those tools wrong.  However, I should have immediately known it was a race condition, because sometimes my tests would all pass, and sometimes they wouldn’t.   Seems obvious in retrospect.

What would happen is that sometimes my background thread would finish before the test assertions, and sometimes it wouldn’t.  It was a huge relief once I figured that out, but now I have another problem: how do I test it?

My solution seems a little hacky, but it works.  I was reminded of stories of people who wanted to test what would happen to certain parts of code at different times of the day.  I.e. service X should do one thing in the morning, and another thing in the evening.  But you can’t really inject a mock into every place the DateTime class is used.  So, one approach is to simply wrap it in a service and put it behind an interface.  And that’s exactly what I did with my threading code (which is a PostSharp aspect):

Then, when testing, before I do anything else, I set the ThreadingService to be some service that just runs the callback on the main thread, instead of putting it into a worker thread. Like so:

Since my unit tests don’t care about user experience (or even touch the UI implemention), I can now test that the presenter is doing what it’s supposed to. Is this a good general strategy for unit testing threaded code? Probably not. But maybe!

Sorry, I’m getting a little behind myself.  Part 3 of my PostSharp SOLID series went up over a week ago.  Here’s a preview:

Logging and auditing is one of the things that PostSharp is best at. It’s the quintessential example of a cross-cutting concern. Instead of sprinkling logging code all throughout the app, you simply write a logging aspect in one place. You can apply it selectively or on the whole app.

You can get a log a lot of useful information with an aspect

To find out more about logging and auditing, and some advanced information about how PostSharp optimizes itself, check out 5 Ways That Postsharp Can SOLIDify Your Code: Logging and Auditing

The second of my 5 part series on using PostSharp to implement SOLID principles is now live.  Here’s a little preview:

Sometimes there’s just no way to speed up an operation. Maybe it’s dependent on a service that’s on some external web server, or maybe it’s a very processor intensive operation, or maybe it’s fast by itself, but a bunch of concurrent requests would suck up all your resources. There are lots of reasons to use caching. PostSharp itself doesn’t provide a caching framework for you (again, PostSharp isn’t reinventing the wheel, it’s just making it easier to use), but it does provide you with a way to (surprise) reduce boilerplate code, stop repeating yourself, and separate concerns into their own classes.

Suppose I run a car dealership, and I need to see how much my cars are worth. I’ll use an application that looks up the blue book value given a make & model, and year. However, the blue book value (for the purposes of this demonstration) changes often, so I decide to use a web service to look up the blue book value. But, the web service is slow, and I have a lot of cars on the lot and being traded in all the time. Since I can’t make the web service any faster, let’s cache the data that it returns, so I can reduce the number of web service calls.

Since a main feature of PostSharp is intercepting a method before it is actually invoked, it should be clear that we’d start by writing a MethodInterceptionAspect…

To find out how to write a caching aspect, and some of the more advanced bits of knowledge for working with caches, continue reading: 5 Ways That Postsharp Can SOLIDify Your Code: Caching, and keep an eye out for the next three posts.

The first of my 5 part series on using PostSharp to implement SOLID principles is now live.  Here’s a little preview:

How many times have you written something like this:

This is a piece of code that you might write dozens or more times to be able to use a repository to return some data to use in your application. If you’re in a hurry, it’s a quick way to get something that works, and also an easy way to get some lazy loading in place so that the repository doesn’t instantiate until you need it to. Unfortunately, this piece of code incurs technical debt. And the more you use this boilerplate elsewhere in your code, the more technical debt you incur.

There are two things in this code that are incurring the debt: hardwired dependencies and boilerplate code.

To find out how to ‘pay off’ this debt with PostSharp’s help, keep reading: 5 Ways That Postsharp Can SOLIDify Your Code: Lazy Loading of Dependencies, and keep an eye out for the next four posts.

I set a bunch of goals for myself last year, publicly, and while I didn’t meet them all exactly, I think it was a worthwhile exercise, and really helped to focus me throughout the year.  One of the activities that Brian H. Prince suggests in his “Driving Your Career” series is very similar: sit down every year and figure out what your goals are, because they may change from time to time.

I’ll have a number of personal and internal-to-my-employer goals that I won’t list here, so what follows is only a subset of my overall goals set:

  • Read books.  I’ve already purchased way more books than I need to.  Attending the book club that I helped organize last year is practically out of the question due to schedule changes, but among the books I plan to read on my own include: Domain Driven Design, at least one F# book, Beautiful Code, James Bender’s new TDD book, among other non-dev books like Soul of the Lion and Atlas Shrugs.
  • I don’t really have any certification goals, but to keep my PMP I probably need to get some PDUs this year.  Attend PMP user group meetings and sessions, that sort of thing.
  • I will put at least one app into an Android Marketplace, hopefully one free app and one pay app.
  • Conferences and presentations a-go-go: I’ve already got speaking engagements scheduled at two conferences in Louisville and Detroit, not to mention a remote speaking engagement for a college, and probably other events as the year goes on.  I also intend to attend the normal array of events, including Stir Trek, Central Ohio Day of .NET, GiveCamp, etc.  My goal last year was 3 speaking engagements.  At this rate, I’ll quadruple that in this year.
  • User group involvement: as an officer of the local .NET group now, I will definitely be involved in a major way for regular meetings and special events.  I doubt this will involve much speaking, as it will a lot of behinds-the-scenes work, which is totally fine.  I will do my best to help this community grow and improve as much as I can, not only in CONDG, but the community as a whole.
  • Project Euler: while I definitely overachieved on this last year, the amount of time I’ve spent on it in the last quarter has dropped drastically.  I’d like to get at least another 25-30 of these problems knocked out this year.
  • Blogging: I’m nowhere near the volume I used to do in the pre-MBA, pre-children days, but my blog posts are rising back up, in volume certainly, but also in quality (I hope).  This is in major part due to the much more interesting and fulfilling work I’m doing full-time these days.

I have some other surprises up my sleeve too, which I won’t reveal until the appropriate time.  Suffice it to say, I’m very, very busy, but this could really be a red-letter year for me (and my family, of course).

So: keep me honest.  If you see me slacking, or haven’t heard from me in a while, beat me over the head on Twitter, or in a comment here, or in person for that matter.

A project that I’m working on has a number of web pages that need to be tested for performance, and the tool we’re using is Visual Studio Team System 2008.

Previously, I had a single ‘web test’ that sent out a ‘get’ request to every page that needs performance tested.  This works fine, but has room for improvement: it’s difficult for me to make changes en-masse to each of these pages.  For instance, if I want to send out a ‘get’ request before each report that clears various caches before running the perf test, so that each page is running against a ‘cold’ database and web server.  I could put each test in its own webtest, but now I’m essentially copy & pasting everything, and as the number of tests grow that can be a real hassle.

So I took a queue from collegue Mel Grubb who is an expert on using T4 to generate code.  I decided that a T4 template is the best way to maximize flexibility while minimizing work.  To add a T4 template, just create a file with a ‘tt’ extension.  This should work in Visual Studio 2008 (SP1?).  I created a template not dissimilar from this one:

I simply lifted the XML in TestXml from a WebTest that VS built for me (all those test files are just plain old XML).  I plugged in some string.Format stuff where necessary.  I then have a hardcoded dictionary that contains all the information I need to generate individual web tests.  Once I save this template, I’ll have files “BrowserReport1.webtest” and “BrowserSummaryReport.webtest”, etc.  I have to add those files into the project manually, but there are ways of adding those files automatically with T4.  Since this is something of an adhoc situation, I’m not really concerned with that at this point.

Now to run those tests, just go to ‘test view’ in Visual Studio, select the reports you want to run, click the “run selection” button (looks like a ‘play’ symbol) and away you go:

Visual Studio test view

(semi-confidential stuff redacted)

Since I’m looking at performance, I had to add columns for Start Time, End Time, and Duration to the “Test Results” window by right clicking on the header and using “Add/Remove Columns”.

This approach saves me time, because to add a new test, I simply add another entry into that hard-coded dictionary. To make tweaks to all the tests (add/remove/update those cache-buster hits, for instance) I simply make the change in the single template.

I can’t possibly thank and praise everyone who deserves it, but here goes:

Thank you Jim Holmes and the whole CodeMash board for doing all the tough grinding that goes into the delicious CodeMash sausage.  Best dev conference in the world.

Thank you all the amazing speakers, including but not limited to: Shawn Wallace, Jon Kruger, Phil Japikse, Chad Fowler, Josh Holmes, Joe O’Brien, Bill Sempf, everyone! Your hard work results in insightful, inspiring sessions.

Thank you to all the awesome sponsors, including but not limited to: Rich Dudley (ComponentOne), Bart, Tim, and all the Quick Solutions guys, Pillar guys, Sophic/Improving Enterprises guys, Brian Noll and JetBrains, everyone!  You guys have possibly the most thankless jobs at CodeMash–your hard work and efforts are noticed and appreciated.

Thank you to all the random friends & acquaintances (new and old) that I sat down with during meals, cocktail parties, at the bar, in the game room, etc.  Including but not limited to: Arnulfo Wing and the other munchkin guys (Matt Ruma and Johannes), Dean Weber, Seth Petry-Johnson, Alexei Govorine, Kendall Miller, the guys from the MonoDroid open space (Kirk and Jeffrey), Kevin Hazzard, and, well, we would be here all day if I had a better memory.  Some of the best parts of CodeMash are the conversations outside the sessions.

Thank you to the Kalahari staff.  A crowded hotel packed full of nerds has to be challenging sometimes, but the service and friendliness from every staff member is never short of amazing.

Another big thank you to Bill Sempf, who gave me the opportunity to contribute in a small way as a presenter, among a lineup of superstar speakers that I otherwise have no business even being mentioned in the same breath.  Bill is a remarkable man.

That wraps up another stellar CodeMash.  Now I need to get cracking on my personal & professional goals for 2011.