Wednesday, October 1, 2014

Coming Soon To CodeMash: The Cartography of Testing

Last year I had the amazing experience of giving my OOP: You're Doing It Completely Wrong talk to a standing room only crowd at CodeMash (and later at Stir Trek).  It was a crazy experience standing at the side of the room and watching people come in, my reaction going from, "oh this is a good crowd" to "wow, this a big crowd" to "holy crap!!!".  

The idea for the OOP talk came from a question I found myself asking a lot, which was basically, "I know what objects are, but am I using them right"?  Then I went and did a bunch of research and tried to coalesce all that into a coherent presentation of OO.  So when I set out to think of a talk for this year I found myself starting in a similar place, but this time thinking about testing.  The question is basically, "I know what tests are, but am I using them right?"  Testing is such a big and contentious subject that I was pretty nervous to tackle it, but I like the idea that you should give the talk you wish you could attend.  So I wrote it up, and CodeMash accepted it, and here's the abstract for my talk at CodeMash this year!

The Cartography of Testing
Imagine diagramming your application like a map.  The methods might be like cities and the classes like states.  The more coupled two methods or classes are, the closer their cities or states may be to each other.  Let's spread this map out before us and ask, "how do we best deploy our tests across this landscape"?  There are many different kinds of test (unit, acceptance, etc.), each serving a different purpose.  What mix of these will best cover the terrain?  Well positioned tests can give us confidence in our code, document business rules, support refactoring, and make building new features easier.  But poorly positioned tests can just as easily undermine all these goals.  How do you find the right balance and test deployment strategy for your application's landscape?  In this talk, we will look at the trade-offs in the different kinds of tests and survey recommendations for deploying them effectively.

Hope to you see at the Kalahari in January!

Friday, August 22, 2014

Unit Testing Question

Hi there. I have a question for you. I'm looking for some articles/papers/blogs/talks about Unit Testing at the right level of granularity. Could you send me some links?

Let me try to explain what I mean. I've noticed that when you write what I'll call "good OO" (for the sake of simplicity) you tend to end up with individual objects which on their own don't do that much.  Instead the behavior that you care about emerges from the way in which the objects are composed together.  And this poses an interesting problem for unit testing.

If I define a unit as a single object, then I will write tests for each of those little objects and I'll mock/stub/fake out the collaborators.  But since each object doesn't do much this means my tests do not end up describing the behavior of the system that I'm usually concerned with.  These tests might also get in my way during new development or refactoring because the "low level" individual APIs are locked in by the tests.

Alternatively, I could write tests that exercise the full composition of all the objects.  These tests would be closer to describing the "end user" level behavior that I more likely care about.  They are also more robust in the face of change as the lower level API can change without breaking these tests.  But, they can also suffer from Cyclomatic complexity problems because they are testing many levels of objects together.

These last tests can be taken all the way to the edge of the application and written as Acceptance Tests that literally automate the web browser.  Or they can be written like a regular unit test, but the "unit" is at a higher conceptual level, not just a single object.

Finally, these are not mutually exclusive options.  I could write both kinds of tests.

So to loop back, my question for YOU is, have you seen any good resources that discuss this issue and make any recommendations?  If so, I'd love a link, or, share your opinions on the issue.  Thanks!

Wednesday, May 21, 2014

Close old hg branches with powershell

Another silly post combining my two favorite tools: Mercurial and Powershell.

If you use named branches as part of your development workflow you may occasionally forget to close a branch after you merge it back in.  Or you might abandon a branch and never get back to it.  And if you use sub repositories, sometimes it can be impossible to update back to those old revisions...  And even if you don't get an error when you update back, it's still super slow to checkout all those old files just to mark the branch closed.

To address all those issues, I just used this little powershell script:
function closeoldbranch($branchname)
  hg debugsetparent $branchname
  hg branch $branchname
  hg ci --close-branch -m "closes old branch"
I don't recommend that you make a habit of using this technique, but I did just get a lot of use out of it! So enjoy it, but be careful!

Thursday, April 10, 2014

OOP: You're Doing It Completely Wrong

OOP: You're Doing It Completely Wrong (Stir Trek Edition)

This talk, "OOP: You're Doing It Completely Wrong", was first presented at CodeMash in January to a standing room only crowd.  It was the 2nd time I was fortunate enough to present at CodeMash and it was an absolute blast!  The feedback I got was really encouraging and someone suggested I should submit it to other conferences and recommended Stir Trek.  The video above is the recording of the talk as it was given at Stir Trek 2014 in April (to another standing room only crowd!).

Here's the abstract:
Chances are, most of us are primarily writing in Object Oriented Languages. But how many of us are truly doing Object Oriented Programming (OOP)? Objects are a powerful abstraction, but when all we do is write procedural code wrapped in classes we’re not realizing their benefits. That’s the tricky thing about OO, it’s easy to have Objects but still not be doing good OOP. This has led to a plethora of principles and patterns and laws, which are very valuable, but also easy to misunderstand and misapply. In this talk we’ll go back to the foundations of Objects, and take a careful look at what OO is really about and how our principles and patterns fit into the big picture. We’ll see why good OOP is important, and look at the mindset needed to design successful Objects. When we’re done, we’ll have a more nuanced understanding of what good OO is, what it can do for us, and when we should use it.
Between CodeMash and Stir Trek I had the time to really work through and reorganize the details of the talk, so I actually COMPLETELY rewrote it from the ground up for Stir Trek.  And I will admit that I'm really proud of the result.

This talk truly represents my (current) understanding of what makes OO powerful and how we should really think about it.  It's VERY heavy on research and full of quotes and references.  The CodeMash version was even more so.  And that reflects my belief that we, as an industry, need to work on being a bit more scientific, especially when it comes to citing our references.

I hope that you enjoy it, and I'd love to hear your thoughts!

Sunday, April 6, 2014

Visual Studio Shortcuts: The Complete Guide

So I was gonna do this whole series of posts breaking out useful shortcuts into categories in bite sized chunks.  But that didn't happen cause I got bored with it.  But I still think it's really useful.  I have actually stopped using VSVIM and I just use VS's shortcuts now.  The only thing I really miss is vim's hjkl and w and b movement keys (the arrow keys are so far away!).

So, anyway, here's the big list of all the shortcut keys I have found useful and worth practicing.  Each category is roughly sorted by utility.  Hope it helps you too!

Ctrl+L: cuts the current line
Ctrl+del: Join lines
Shift+del: delete line
Ctrl+C with nothing selected: copies current line
Ctrl+F3: search for current select (like VIM *)
Ctrl+Enter; Ctrl+Shift+Enter: insert blank line above/below current line
Ctrl+Shift+W: select word (like VIM viw)
Ctrl+K, S: surround with
Ctrl+E, S: show white space
Ctrl+U: to lower case
Ctrl+Shift+U: to upper case
Ctrl+Shift+down/up: move cursor to next highlighted identifier
Ctrl+Shift+V: cycle clipboard ring
Ctrl+up/down: moves the scrollbar
Intellisense: use capital case to filter by camel case

Ctrl+R, R: rename
Ctrl+R, M: extract method

Ctrl+,: navigate to window
Ctrl+W, L: opens solution explorer
Ctrl+F2: move to navigation bar (the class and method dropdowns)
CUSTOM: Ctrl+W, ctrl+left/right arrow: move window to other tab group **Window.MovetoNextTabGroup/Window.MovetoPreviousTabGroup**
CUSTOM: Ctrl+W, Ctrl+W: switch focus to other tab group **TabGroupJumper.Connect.JumpLeft, requires TabGroupJumper extension**
Ctrl+W, E: opens error window
Ctrl+K, T: opens call hierarchy window (like Find all References, but more)
Ctrl+W, O: opens output window

Ctrl+D, A: opens autos window
Ctrl+D, I: opens immediate window
Ctrl+D, C: opens callstack window

Snippet designer extension: makes it really easy to create snippets
zencoding: comes with the Web Essentials extension, allows you to quickly expand HTML tag structure ex: div.content