lowering impedance of TDD with python mock

So after my post about gaeunit a few weeks ago I've since completely thrown out what I was doing there and moved to vanilla python unit tests. I ended up making this move for a few reasons.

 1. I was never running my tests.
  • GAEUnit was nice, but slow. Even when running tests in parallel I still had to go through the process of opening the browser, navigating to the right place and letting the tests run. Compare this to ctrl-f9 and seeing the following:  


 2. AND I love seeing code coverage numbers and while it might actually be possible with GAEUnit, it wasn't this easy...


In the end it was relatively simple once I started employing mocking to deal with sessions and realized that I could actually issue real request objects to my handlers with relative ease... 

    webObReq = Request.blank(url)
    webApReq = webapp.Request(webObReq.environ)
    handler.initialize(webApReq, webapp.Response())

For the mocking I eventually decided to go with this framework:
 
It has so far been fine for my needs and at least my handlers have almost achieved 100% coverage. The syntax is a little foreign compared to Moq, but hasn't been a blocker to me actually getting work done so I'd recommend it.  

Engineering Management (link)

Great article(s) on some of the management principles in the engineering group at Facebook from Yishan Wong who was at Facebook through some very interesting growth times. I found reading this to be inspirational so posting for posterity...

http://algeri-wong.com/yishan/engineering-management.html

I just quit my job....

Ha! No I didn't. But starting on the premise that I had and I had already saved a bunch of cash and decided to finally become my own boss, what would I do first?

For me this is hypothetical, but for my good friend who's about to make the leap out of full time employment to self employment it is very very real. And so I will live vicariously and imagine what I'd do.

The Goal:

  • build a business that can at a minimum support me before my year of savings has run out so that I can continue to build said business long enough affect real change and or make loads of cash 
My Challenges:
  • I have enough money to sustain myself for the year, or to invest and sustain myself for less
  • I love to program. I love to program, and specifically solve technical problems, so much that I focus on it to the detriment of other tasks. (like writing business plans, talking to users or bathing)
  • I have a set of real technical hurdles to clear in order to have anything of value
My Assets:
  • A good idea
  • Mad programming skills
  • Friends in medium places



(caveat that this is an hour's worth of dumping thoughts based on a few conversations and some latent thought) ;-)

My first steps: 
  • Set some very high level goals (these can change)
    • Month 1 initial Product Plan is ready (see below)
    • Month 1 website is up, domain is secured (even if a teaser)
    • Month 2 delivering live usable software with weekly updates for the remainder of the year
    • Month 3 gut check milestone - pull the plug or keep going?
    • Month 4 gut check milestone - go alone or go big? do I need more money?
    • Month 5 gut check milestone - pull the plug or keep going?
    • Month 6 target - engaged user community is built and driving the backlog (uservoice)
    • Month 6 target - marketing (adsense? viral? user communities?)
    • Month 8 target - earn my first dollar
    • Months 9  gut check - is this a venture someone would buy? should I start talking to those people?
    • months 10-11 - rinse and repeat, drive drive drive
    • Month 12 - profit! 
  • Make a workspace
    • Seclusion, powerful machine, dual monitors, natural lighting, huge whiteboard, music and snacks
    • block reddit.com from this network
    • have a laptop available for games, surfing etc - try however possible to keep these separate
  • Make a development environment
  • Start building! 
  • For at least two days a week early on, or maybe a couple hours a day in the beginning besides building I would ALSO do the following....  (Product Plan)
    • Write myself a short Vision and Scope document which would include:
      • The elevator pitch, preferably in a single sentence which I would then post on a wall in my workspace
      • The high level guiding principles for the need I'm trying to solve, how I'll translate that into some revenue (not overly specific), who I'm targeting, who my competitors may be and what the biggest risks are. 
      • I would do this loosely, but I would do it. Just the act of looking and solidifying my direction would be motivating. 
    • Build a backlog of features, ideally written in the style of "As a <<user>> I want <<to do something>> so that <<some value>>" 
    • Make a persona or two or three based on the largest value user segments
    • Pick one persona who I can deliver something of value to
    • Prioritize my backlog with this user type in mind, and work backwards to find the minimum viable product that could actually be used by a user. This is my first milestone. 
    • Look for ways to accelerate getting to revenue sooner. 
    • Look around for ways to extend the 12 months without too much distraction (grants etc)
  • Network network network. A lot of my milestones might be easier with help. Socialize that I'm up to something even if I'm not giving away the secret sauce. 
  • Force myself to join some local developer user groups that align to my technology choices
    • force myself to attend some tech talks and socialize with other technologists
    • guarantee that at least some evenings are spent away from my work
  • Refer to my 12 month road-map on a weekly basis. (Monday morning when I'm slow)
    • Change it whenever
    • Where will I deploy? How will I deploy? I only have two months before it needs to be live in some form so figure that out. 
    • Will finding my initial target user be difficult? Start hunting early
    • What questions will I need to ask in order to answer my gut check milestones? Ask those early.
    • Are there components I should look to buy or rent rather than build? How do those align to my backlog?
    • How could I accelerate delivery of features? Can some things be outsourced? Should my backlog be altered to allow my investment decision in month four?
    • What else might I need to make a go big decision in month four? Do I need a more formal business plan? Do I need to incorporate?
  • Continue to build like mad!!
  • Profit!!  

welcome criticism, be open to review and invest in process

TLDR:
  1. External audit and review is important
    and can have value not easily measured
  2. Be open to investing in processes even
    if you think those processes are already
    optimal
When someone asks you why you aren't better at what you do, how do you react? Is your impulse to defend yourself? Do you look for comparables? Do you start to question yourself or your team? Can you begin to break down what exists today and imagine it built up in a new form?

I work for people who are largely from a non-technical background. These same people are investing eight digit figures in our teams and products. Naturally they need to know that those dollars are being spent wisely, efficiently... maximized.

For myself, facing this question and having been so recently embedded in those same teams being questioned, I admit my impulse is to defend my compatriots. I have a lot of trust in the people I've been in the trenches with and to a lesser degree trust in the process we've put in place there (which is in a word scrum). This defensive impulse is well intentioned, but in my mind definitely the wrong place to start.  Of course I need to defend my peeps, but at the same time I need to be completely open to inspection, evaluation and change. (left brain fighting right brain)

The inspection and change is taking the form of the following:

  1. A few day audit by a high priced and well networked consultant with a ton of experience in software
  2. Scrum Training for our whole team
  3. A week long more technically focused audit and coaching session

I was reticent about any of these at first, concerned that we were wasting money on a problem that could be tracked down to an inability on my part to assure my employers of the quality of our group. Despite my internal struggle with the idea of subjecting my teams to external audit, and the spending, and the potential for fallout, I acted as best as I could to be open and welcome to the idea, knowing full well that anything else can be  suicide for the group. Before I understood the value in these exercises I already had a sense for the political dangers in what closing myself off to them would mean.

It's a few weeks later now and we've already largely completed numbers 1 and 2. I have to say I'm pretty happy about the value for the money and the impact on us. For 1, it has been somewhat shocking to see the informal chat like approach the contractor has taken with us but it really has been somewhat shallow. Honestly what are you going to learn in a couple days anyway? My guess is that it's all going to be about structure, alignment of views and ultimately focus for the company. Very high level stuff. Despite the shallow nature of the actual time spent with this guy though, there was a very focused frenzy of activity to prepare for what we thought the audit would look like. In particular the questions ahead of our interviews and requests for particular types of documentation had me seeing our knowledge and goal management in a completely new light. The todo's that I have as a result of preparing to be audited are immensely valuable. Another less tangible benefit was socializing the idea of the audit itself. I don't necessarily want us to feel complacent, and having someone external come look at you is a good way to fight that.

The biggest surprise for me has been the training however. And maybe we were just lucky, but the scrum training we had was fantastic and had so many positive side-effects that I didn't anticipate. Here are a few examples...

1. The value of common terminology. Simply having the same vocabulary does wonders for conversations around process and expectations. Not that we're 100% of the way there, but it really does make a huge difference in day to day conversations across our larger team and product management.
2. Bottom-up process improvement. The teams know best, and the learnings and suggestions coming from the people who are on the team are invaluable. The training really gave the team a collective voice to management that may have been lacking.
3. Hope/Change/Inspiration. Maybe these are separate points, but they are very related. Introspection and seeing the potential for positive change leads to hope which leads to inspiration. People were positively jacked coming out of the training sessions and very eager to put into action the incremental changes they discovered through the process.
4. Socializing.  The group had basically two uninterrupted days together to socialize and work together on something other than the daily grind. Everyone got a little closer as a result and had this common vision they could work towards on leaving. So hard to measure, but very important.

What's really amazing about the impact of the this is that the training was on a process we were already using. And in fact at the end of the day there was very little genuinely new learning. It was all small incremental change and having everyone look at the problems with fresh perspective and a critical eye.

I think for me this highlights what would be my biggest challenges in running a business which is an openness to spend money. It's true of my house (in which I've only invested the bare minimum) and it would be true of my company I fear. Dr. Deming had a critical phrase for an accounting centric decision making process that I always loved  "managing by the visible numbers only". As much as that resonated with me when I read his book a decade ago, I still catch myself getting caught up in the visible numbers and missing the value that comes from investments like this training and audit.

In any case, next time the external questions swirl around I'll definitely be a lot more open to what I may not know.

blogquotes version b02.1

New release of blogquotes is out, with the biggest change being a switch from exclusive reliance on google accounts for login to leveraging a cool service at http://www.janrain.com/ that gives me a simple way of integrating authentication from a bunch of different sources. So you no longer need to be a google user to use blogquotes!  


Note that if you were previously using google to login this should just work albeit with a slightly different UI. And if you find other methods to be more preferable they should also "just work" provided that you use the same email address for those services. Note the logout button at the top of the page which will tell you what email or ID you've logged in with. So for example if I login with facebook all my old quotes are there, but if I login with blogger which doesn't use the same email address I get nothing and am essentially starting fresh. 

enhancement : support for Facebook, Google, Windows Live ID (includes hotmail), Blogger, Wordpress and LiveJournal logins  (have yet to validate Wordpress + LiveJournal) 
bugfix : javascript remote inclusion could still barf on some unicode, added clientside utf-8 handling

In the background I've also made a number of restructuring changes to the code which should help me release changes faster.  


Please leave comments on this post if you are having trouble getting access or for some reason can't see the quotes you've already entered. (no data has been deleted!) 



Unicode woes and Python unit testing in GAE

One of the really cool aspects of deploying to Google's cloud offering (GAE) versus the more machine oriented Microsoft Azure and Amazon EC2 approaches are that you really are only dealing with computing resources. You deploy your app not to any particular server, but to the cloud itself. Despite the very real challenges in distributing work across data centers I am still filled with visions of automagical propagation and distribution and unlimited elastic computing. Beautiful. Anyway I was inspecting the logs and was SHOCKED to discover that there have been close to a thousand quotes added to system by 37 users. THIRTY SEVEN USERS!! Now, these are small numbers I know, but given the only publicity I've ever given this has been the two posts on this blog I was absolutely amazed to find that people had not only managed to find the app but were able to use it! (It's quite ugly)

There is nothing quite as motivating as having users.

So I started looking at log files and discovered that I am actually throwing errors for at least some of those users who are not English speaking and are using Unicode characters. Oops. You'd think I'd know better by now.   See : The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

In most cases for these bugs it just meant calls to unicode(var) rather than str(var) . So for example when parsing url variables starting with the example provided here by Google and adding my own processing of an array of arguments to a method like so...


  def update_field(self, fieldName, *args):
    strings = [str(arg) for arg in args]
    ....
    return

and then calling that code with a unicode character such as ''–" would produce an error that looked like this...

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 0: ordinal not in range(128)

the same code as above corrected is below. There were a few variants on this but this is a good example of a function where user defined input dictated a change to accommodate.


  def update_field(self, fieldName, *args):
    strings = [unicode(arg) for arg in args]
    ....
    return

So in the course of digging in and finding/fixing these bugs I also recognized I was far overdue for some unit testing. So starting with the premise that I needed a way to reproduce the issue in the lab and write a failing test for this bug I went in search of the best method to do so. Python actually has [pretty good unit test support] built-in but I was also looking for something that would work in the context of GAE. It doesn't take much looking before stumbling on GAEUnit, which is a useful extension that provides some scaffolding for tests that will run within GAE. The major negative to this is that your tests are part of your application, but I don't have a problem with that as it's easy to secure them to administrator access only but for some people it's a block.

The next issue I ran into with this was the fact that the python SDK for GAE doesn't include a method for testing content behind authentication. So whereas in Java you can say this :

private final LocalServiceTestHelper helper =
        new LocalServiceTestHelper(new LocalUserServiceTestConfig())
            .setEnvIsAdmin(true).setEnvIsLoggedIn(true);    

    public void testIsAdmin() {
        UserService userService = UserServiceFactory.getUserService();
        assertTrue(userService.isUserAdmin());
    }


But today there is no equivalent for that in python. I wasted a few hours trying to work around this issue before deciding to just login before I run tests. My login lasts for hours so this isn't much of a constraint. In the long run I plan to drop Google's authentication any and move to janrain/rpx to allow users to login using whatever they like. That will mean abandoning or at least shimming the infrastructure provided by GAE, but has the additional benefit of reducing my applications direct dependency on Google. Once I have my own definition of Session and session provider I can of course mock it out and control it a lot easier.

Here's the test, no asserts but if there is a problem we'll see an exception


  def test_unicode_to_json_error(self):
      badQuote = q.Quote(quote='hi there ' + u"\u2013")
      result = badQuote.jsonSafe()
      simplejson.dumps(result)


So one error-type in the log file later I've spent a couple days, done a bunch of refactoring and have produced no new functionality... but I do have this!



Of course then, after all that I STILL ran into an error with the JavaScript, for which I have yet to add unit testing for. Sigh. I'll have to choose between qUnit which I've used before and YUI-test which is probably better aligned to the rest of my application.

The JavaScript portion of this bug was basically because I was calling unescape() on a url-encoded variable. URL encoding though only supports 8-bit characters and doesn't truly allow unicode, so my unicode characters became three ascii characters which could include control characters or other undesired results. There seems to be a lot of people standardizing on UTF-8 within url-encoded variables but it's purely a convention at this point.  Thankfully I found this pre-written code on webtoolkit.info that knows how to do the look ahead at the next three characters in order to handle UTF-8 input properly.

Now I hope it's safe to say that  blogquotes can handle unicode! (and has some unit tests to boot!)

Blogquotes version b01.2

Didn't expect to get more released this weekend or I would have combined these posts, but another quick release of blogquotes, the following are added :

- enhancement : quotes table is sortable by either "who" or "quote" 
- enhancement : click to edit on any cell in the table for convenient fixes 
- bugfix : missing robots.txt

In the background I've also added analytics to the header so I can get a sense of how much traffic the site is seeing.

The table features have both been things I've felt missing and which were remarkably easy to add since I'm just leveraging the Yahoo User Interface library YUI for major widgets like the table. Lots of low hanging fruit now that the guts are in place.

Blogquotes version b01.1

A new version of blogquotes has been published this morning. Not a lot of new features, but at least the wheels are turning again and some annoying bugs have been addressed.

- bugfix: adding quotes with some types of punctuation caused page errors
- bugfix: unicode characters in quotes caused errors when pulling those quotes out for includes
- bugfix: hitting enter on the "who" input field caused a page error, now hitting enter is equivalent to clicking "Add"
- enhancement: updated to a new faster version of the YUI data table
- enhancement: moved quote entry form above the quote table to avoid scrolling down when adding to an already long list
- enhancement: adding a quote will blank out the form and put focus back to the quote textbox
enhancementmore obvious navigation in left column for moving between managing and including quotes
enhancementminor cosmetic improvements (title bar, fonts, spacing etc)
enhancementnew welcome page that includes more than the word "Login"
- degredation : banner ad now in right column (sorry... appengine ultimately is not free and I'm worried about potential rising costs)

Please comment on this post if you use blogquotes and want to see specific features.

curiosity killed the addictive gamer in me

I can see it now. Homeless, slightly demented and jabbering about inane details of imaginary characters. This will be my life in six months from now after suffering through a debilitating addiction.  An addiction to the ridiculous time suck that is world of warcraft (aka world of walking). I'm almost embarrassed to admit that I have now played through the 10 day free trial (damn you free trial!) and have *paid* to play for another month. What happened?! How could I go from so jealously guarding my time to pissing it away into the ethereal fantasy world that is the "world" of warcraft?

And yet.... And yet, I am completely fascinated. I've read a few articles about professors studying the economics of  the game, and about the staggering number of people (11 million?) who play the game but never really understood the allure. In fact, just the idea of playing games "online" is largely unappealing to me. And by online I mean amongst hoards of teenage kids and angry shut-ins throwing slang at each other. I mean internet gaming, the kind where you show up and get completely slaughtered before you even know what's going on.  LAN gaming on the other hand, with a room full of people you knew and could taunt... that's a different story. How old am I?

I got to witness my young (11) cousin not too long ago playing on his XBox. It was eye opening to see the way his generation has adopted online anonymous gaming in a way that I have yet to really get to. Jump online, form casual alliances, piss some people off, play basically completely ad-hoc and move on to the next one. It's social too, with banter and chat being casually tossed around. I still didn't really get it though. (Is this just the introverted programmer in me?)

[time passes]

I started writing this post in December, and after five months of not playing the game I am all of a sudden well into this thing now. I had to stop playing after the holidays were over just to get back into work, and once I stopped I stopped. Course all it took was to login again after a stressful week at work and I was back at it.  No different than any other game I suppose except that this game has no ending. I really can see how this game could destroy school, relationships, careers. Thank god I already have a family.

And I have to say after a few weeks the social elements are starting to be far less baffling to me. I still find that given constraints with kids in the house and limited time windows I rarely have the opportunity to commit to a game socially, (very poor form to just turn off the game midstream like I do when I play alone) but having now run a few quests both with planned partnerships and adhoc allegiances I am starting to really get the appeal.  It's amazing too the diversity of people online (teens to doctors, moms to executives), and you have an ability to really choose who of that diverse group you actually interact with for the most part. The game includes two main modes of play, either player vs player or player vs environment. Both are collaborative, but PvE is primarily groups of humans versus AI and bosses.  I may yet play PvP but I fear that's where you really lose control over your experience. I don't relish the thought of being ambushed by a group of players who's sole purpose is to run around finding people to annoy/destroy/humiliate.  And even when playing against the environment you still have arenas in which you can pit yourself against other players which honestly is enough for me.

Biggest distraction for me so far? The remote auction house on my iPhone. I can be walking to a meeting and purchase or sell gear for my toon, check out upgrades etc. It's insane.  I lament the thought of what these hours amount to in terms of lost productivity to global economies. ;-)

Anyway this is way off topic but I'm cleaning up old posts and thought I'd get it out.  For the record I can't yet say I'd ever recommend playing to my real-life friends, but these MMORPG worlds are insanely rich and engaging, not to mention wildly popular.

Flying at the right altitude - advice to a slightly younger me

No posts in five months! Almost exactly the same time I've been in a new position at work. 
Disturbing trends, this completely predates just the last six months.... 
I've moved from being a team lead to being the head of our R&D group. I now have as many teams (7) as I did people to think about, and a whole new world of politics, strategy and planning. With a group of this size HR issues seem to be at least a weekly occurrence and I am now fully and completely on the manager's schedule.   

However now that I've somewhat got my sea legs in this position I am increasingly allowing myself to get back into technical issues where I think I can add value. "Where I think I can add value" is the whole challenge here though. I have literally not opened visual studio in five months of running around like a chicken with my head cut off. How often does having the boss swoop  in and give their less informed perspective do more harm than good? Impossible to answer without knowing the boss in question of course, but surely there are ground rules some sage masters can teach me. 

I have to say I really enjoy looking at things from this altitude, in that you really can see patterns in development across teams, opportunities for reuse or better design across teams, efficiencies to be gained etc. It all can be very fun, but at the same time I worry about losing relevance, and I worry about sidetracking teams. Even worse is the feeling that by interfering I actually hurt the autonomy and self-sufficiency of these teams by interfering (which almost outweighs the fear of divergent or  teams).

Here are some things I think I would tell the me of six months ago:  (advice to a new executive)
  1. Don't stop the old routine completely.  I actually think a lot of my comfort these days is precisely because I'm getting back to things like my reader and blogger. Just imagine how nice it would be if I could do the occasional code review or bug fix! (unlikely) My life has gotten decidedly more stressful (father died, promotion, second child all within the last six months) and my routine has out of nowhere incorporated quite a bit of gaming all of sudden. (COD2 MW, WoW) Good stress releases but I need to get myself back into creating rather than just consuming things.  
  2. Embrace the manager's schedule, but respect the maker's schedule. It's a very tricky thing not to let your new found schedule dictate awkward length and times for meetings with the people who are there to actually do the development. Resist the urge and find ways to be more effective with meetings. It is SO easy to forget the real costs around this.  
  3. Don't seek consensus on every decision. It can work on a team of seven or eight to drive for consensus and try to win minds but on much larger teams you're going to have to get used to making some calls without the comfort of knowing you have everyone on board. Of course reasonable efforts still need to be made but it becomes about key people and finding the influence in the group. 
  4. Be open and give status frequently. Still one I struggle to do properly but it really is key. I am trying right now to really focus on problems at the request of my boss, but don't forget to acknowledge the wins as well. The more open you are about the warts the easier it is to excise them. In my opinion, maybe counter intuitively, more shit should flow up and more sunshine down. (though that's an easy one to over generalize)
  5. Trust and trusting your gut. Not really anything new to the position, but the frequency with which I've run into this has gone through the roof. You often just know the right course of action. Waiting to find out the hard way (or expensive way) that you were right can be painful.  Trusting yourself is only second to trusting your people. Trust your gut on your people, make sure you have the right people and put that trust in them. 
  6. There will be a lot of water sprayed at your back, be the duck.  Or, in other words, find a way to regain your slack