Monthly Archives: October 2014

The most creative abuse of C#…

My coworker JSR has, by presenting on the topic, staked out the position of Lead C# Expert where I work.  So it is with no small amount of relish that I enjoy finding code samples that either stump him or make him want to gag.  In a blog post I found what is perhaps the most “creative abuse” of C# I’ve ever seen.  The scenario is this: I have a variable of the type Animal, and among it’s various subclasses in the program is the type Dog and I want to run some logic on an instance of animal, but only if it’s a Dog… and I only want to run it once. Here’s one possibility:

for (Dog dog = animal as Dog; dog != null; dog = null) {
//put your “only if it’s a dog” code here

Admittedly, this is a hack, and an ugly one at that… but it works perfectly fine. It’s also a case of code that is so obtuse as to be incomprehensible to junior developers, and probably more than a few seasoned ones as well. The more sane way to accomplish the same in only one more line of code is this:

Dog dog = animal as Dog;
if (dog != null) {
//put your “only if it’s a dog” code here

But hey, if saving a single line of code is worth making your logic unreadable the feel free to use the for() construct above. More on this manner of code abuse at:

Cory Made Me Do It!!!

Tonight I had the good fortune to attend Cory House‘s “How to become an outlier” talk.  I’ve heard this talk before but in a way it was totally new.  Perhaps I wasn’t paying attention the last time I heard it or perhaps the act of taking notes forces you to remember more, but I feel very motivated and energized and happy about being a programmer — more so than I was earlier this week.  Among the advice Cory gave: programmers need to blog! Okay fine… even though this is a content-free post I’m going to blog and make an informal commitment to blog every other week or when I find something of use or interest on twitter or hacker news (sorry — I just can’t do Reddit, even if Mr. House thinks there’s something of value there). So if you’ve been waiting for me to blog again you can thank Cory — he made me do this again!

I would be remiss if I didn’t express my thanks to Melissa Green (or Greene?) for organizing the VML Speaker Series.  I’m really impressed by what I saw of the VML office, and being an aviation geek I question how much work I would get done if I had a view of runway, apron, and approach to KMKC… I look forward to December’s installment!