Author Archives: Martin Cron

My continuing love affair with ReSharper: Indicating Recursive Calls

I generally believe that comments should be about “why is this code doing this” instead of “what is this code doing” because if you feel you need comments to explain what your code is doing, it could probably be refactored to be more readable and/or intention revealing.

One exception that I’ve often made is for recursive calls. I generally write a comment indicating that the method is about to call itself and why. This may be left over from my first CS class at the University where I had some kind of mental block around recursion, I don’t know.

So, I was delighted to see ReSharper give a little visual indication of a recursive call in the margin.

Recursive Picture

This useful when doing recursion on purpose (this example was using reflection to populate test data into properties, I would recurse when a property was a complex type), but it’s even more useful if you do recursion on accident, as in this public property returning itself below.

 Bad Recursion

Guilt as a Code Smell

One of the best things about working for Velocity Partners is that I get a chance to do presentations/brown bag seminars for their other clients/prosepective clients. I like to think that as I’m a hands-on developer who actually works with this stuff every day, I have different credibility from the full time trainers/presenters/coaches/pundits.  Note: I don’t want to disparage the full-time trainers that I know and respect, their credibility comes from the fact that they were hands-on coders for a long time, and have more time to do the reading/research/writing that someone working on deadlines may or may not have.

I’m currently putting together a presentation on Refactoring, and how that relates to the other agile tools and techniques (where “agile” simply means “modern development practices that work”). While looking for examples, I’ve been re-reading Martin Fowler’s great Refactoring book.  One thing that struck me was the focus on “getting the inheritance hierarchy right” which, after living in the design patterns (favor composition over inheritance) realm for the last few years, felt kind of odd to me.

Meanwhile, in my “day job” I’ve been working on a well encapsulated, generics-based .NET client for a family of REST-y XML services.  After making one major component, I found that I had to make another major component that does much the same thing. So, I created a new abstract base class and made both my existing component and the new component concrete derived classes of the base class. As I needed functionality for the new class, I generalized it and moved it up to the abstract class (using the protected modifier, of course) so I could use it in the other derived class.

It was working pretty well. I had very little code duplication and ReSharper is particularly good at the “Pull Members Up” refactoring, but I was starting to feel a little guilt about not doing things in a “pattern oriented way”. Sure, you could never use the two concrete components interchangably, so there was a violation of LSP, but I can be cool with that. The abstract class didn’t have any public methods on it, so there’s no danger of someone trying to couple to its publically-exposed interface.

After, I figured out where my guilt was coming from. It’s a coupling/testability problem. As the concrete types are tightly coupled to their base types, I couldn’t ever substitute a different type to handle that functionality. This is particularly important as the base type was all about making external (HTTP) service calls, so it was impossible for me to test any of the types in isolation.

The solution: it’s pretty obvious, but I just moved the functionality of the abstract base class into a service class with an interface. Now my two components (formerly derived classes) just have an instance typed to that interface. I can test all three parts in isolation (Q: How do you test an abstract class in isolation? A: You can’t) and I can re-use the same functionality across additional components in the project, further reducing duplication.

So, what I’m saying is: take your guilt seriously. If you have a bad gut feel about a design, it might very well be bad.  It’s just like any of the code smells in the original Refactoring book. It doesn’t necessarily mean that there’s a problem, but it’s worth looking at.

But, at the same time, I’m not going to beat myself up over my interim design. It was a good, easy stepping stone to a more optimal design. This is the sort of thing that Scott Bain’s new book Emergent Design: The Evolutionary Nature of Professional Software Development is about. I’ve only skimmed it so far (I’m working on a new presentation, after all) but I know Scott, and I know his approach to the subject. From what I’ve read so far, it seems to be the right text for the professional programmer who wants to move beyond “just getting it working” to the level of “getting it working well”.  I wish that I could have read it years ago.

(Relatively) Simple Party Photo Booth Project

One of coolest things about digital photography is the instant feedback loop of seeing what the picture looks like. One of the downsides is that your subjects know this, and often want to get the immediate “how did it turn out” feedback. When I was taking the party invitation pictures, Ethan kept tripping over the flash sync cable trying to get a peek at how the pictures looked. My wireless flash setup is arriving any day now, but that still solves only part of the problem.

Mostly inspired by John Harrington’s far cooler (and more expensive/elaborate) party photo booth rig, I set up a simple one for my Son’s 6th birthday party.

For the setup, I put the camera (Canon Digital Rebel XT) on a tripod with the video out (simple RCA plug) piped into my TV. I set the camera “preview display” mode to “hold” so the camera would send a video signal of the last picture taken until the next one was snapped. The video output is not great (my TV reported the signal as 480i), but it’s enough to give you a sense of the lighting and facial expressions.

For lighting, I setup the Vivitar 285HV with shoot-through umbrella camera right as my main lighting. I had a couple of Sunpak DS-20 cheap optical slave flashes floating around the room to give some extra light, which provided some really interesting medium-tone shadows and edge definition.

The backdrop is a combination blue/green screen that I got when I was working at PlayStream, making server-side software that would integrate with a video blogging app from SeriousMagic (now Adobe) which did the background subsitution in real-time. Other than making a few “this is Martin Cron, reporting live from the White House…” fake newscasts, I hadn’t used it much. It’s held to a ceiling beam with bungee cords hooked to a pair of 3M command clips, which mount easily and remove cleanly without having to use any tools.

This whole thing was triggered from the RC-1 remote control, which I set to a two-second delay which worked out well for a couple of reasons. One, the video output would go blank for those two seconds, which would get the kids to stop looking at themselves on the TV and instead look at the lens. Also, the delay insured that the flash (1/4 power) would have enough time to cycle. Most importantly, it gave enough time to get the remote control itself out of frame, as it has to be line-of-sight with the camera.

Lastly, I set up a simple “prop table” out of frame for the kids to pose with hats, safety goggles, sunglasses, etc.

The cool thing about this setup is that it could be replicated pretty cheaply. The video output cable comes with the camera. The RC-1 is around 30 bucks. While I used diffused off-camera flash, you could do it with available light or (perish the thought) on-camera flash. Instead of a fairly exotic backdrop (blue/green screen), you could just line the kids up against a blank wall.

The most important thing is, of course, that the kids (all around six years old) had a great time and I got some good pictures out of it. I’ll be able to send back prints of the best pictures with the thank you notes.

I, for one, welcome our new pediatric overlords

From January 2000 until a few weeks ago, I lived (and worked, when I was a freelance consultant) in a townhouse-style condo in Seattle in the Laurelon Terrace complex. I sold it to Children’s Hospital in January to allow them to tear it down and turn it into more condos. It was a good time for me to leave, our family had outgrown the small townhouse, and we had a guaranteed buyer in a down housing market.

This, of course, is why nothing gets done in Seattle. If you tear down a beloved institution (such as Ballard’s Sunset Bowl) to build more condos, people complain bitterly. If you tear down condos to build more beloved insitution (Children’s hospital), people complain bitterly. You think I’m joking about complaining bitterly. Check out the tone of the posts at childrensaction.com. Hell, people even complain bitterly about parking lots being turned into condos. Really.

I’m sad to leave (some parts) of the Laurelon community behind. There’s a lot to be said for shared-space medium density. Getting to know your neighbors, hanging out in the courtyard and and parking lots.

The other parts that I’m not as sad to leave behind? The constantly rising HOA dues brought on by years of neglecting upkeep. The HOA board, generally staffed by misanthropic busybodies whose default response to any idea is “no”. The neighbors who would blur the lines between personal and shared property. Hey, that’s MY bucket you’re using!

I looked into contemporary townhouses, but they are both antisocial and anti-family. Antisocial in that they all seem to be built with an ethic of minimizing shared property/interactions (why have one usable yard used by four families when you could have four unusably tiny yards each used by one family?) Anti-family in the ubiquitous “two bedrooms on the 3rd floor, one bedroom in the basement” floor-plan. You can’t put a small kid all the way down in the basement next to the garage, calling those rooms “bedrooms” isn’t particularly honest.

Note that the bedroom count inflation problem isn’t limited to townhouses. I toured a lot of 3BR houses that were actually “2BR + crappy basement closet”.  In fact, our 3BR home was listed as a 4BR even though it only has three usable bedrooms. Oh well, at least we have a space to store our boxes as we unpack.

More Typeface Snobbery

I saw this on 37 signals and thought it was the funniest thing I’ve seen in some time.

http://goodiebag.tv/episodes/06_trajan_is_the_movie_font.htm

 

More on becoming a Java Developer

There’s an excellent SDET whom I worked with around a year ago who shares many of my software interests (Lean/Agile/TDD/Design Patterns, etc.) as well as some some non-software interests (photography, left-handedness).  Even though we haven’t been on the same project for a while, we sometimes get together to have design discussions. We’ve found it helpful for both of us to have an audience who is outside our immediate projects to give us honest feedback.  His test code is better than most people’s production code, and my production code is getting more and more testable.

Anyway, after one of these discussions, I mentioned that I was working with Spring, something that the development group uses extensively for Java projects, not as much with the C# projects.

“What, you’re working with Java now?” he asked.

“Yes, I’m becoming bilingual.” I said.

“That’s not bilingual, that’s ecumenical!

He has a point, many people have such a religious zeal around their choice of technology that it clouds their vision. Personally, I think that learning Java has done a lot to make me a better C# developer because the contrast stands out and I think to myself “why are things this way in this language?” and “wow, anonymous classes are pretty handy for endo-testing” and “while I miss the get/set property accessor syntax, I see and understand why Java folks don’t like it.”

College Botany and the Java Ecosystem

When I was a student at the University of Washington, vaguely interested in plant life, I decided to sign up for a botany class on top of an already busy schedule. “How hard could it be?” I thought, after all, I did very well in biology class in high school.

Big mistake.

Botany is hard, and not for the reasons you might expect. A first-year botany student learns more new words than a first-year foreign language student. Why is that? Because you have to learn all the different words to tell different parts of different kinds of plants apart. There’s a small amount of logically figuring stuff out (which I enjoy greatly) but it’s mostly rote memorization (which I enjoy not so much).

For the last few years, I’ve been working in the C#/.NET ecosystem, where most of the day-to-day tools and technologies are pretty clearly defined and packaged by Microsoft. Sure, you need source control, nUnit, ReSharper, and CruiseControl, but that’s about it.

I’ve just finished my first week as a developer working on a Java project. My first impression: the entire ecosystem is huge. I’ve had to learn about a billion new words. Maven, Pom, Jmx, Spring, JBoss, JDK, ClassPath, VM Parameters, Jetty, TeamCity, beans, WARs, JARs, SARs, EE/SE/ME, etc. Well, maybe it’s not as many new words as I tried to learn in botany, but it felt like a lot to me this week.

But it has been good. The core languages between C# and Java are almost exactly the same, with the distinctions being really interesting. The Pragmatic Programmers suggest learning a new programming language every year, and I understand why. Even if I don’t keep at this whole Java thing long-term, I’ll come out of it a better C# developer.

Actually, this would make two new languages this year, if you’re willing to count scratch.

The best thing about this learning experience is that IntelliJ has the generally same keyboard shortcuts at Visual Studio with ReSharper (of course). When I saw that hitting ALT+F7 (find usages) on a setter method will show me the spot in the spring config xml where that value was set declaratively, I almost cried with joy.

Maybe it’s just me.

This is probably just me over-reacting as a grammar geek. That, and a person who cares a lot about my dev tools.

I just read the phrase “Integrated IDE” and it really felt wrong to my ears.  Someone who doesn’t know what IDE stands for is less likely to be impressed by an integrated one.  No, “Integrated DE” doesn’t work, either.