Heard It All Before

by casperOne 27. January 2009 13:17

While on the subject of Microsoft building on others ideas (to put it mildly), this blog post has been sitting in my browser waiting for me to comment in on a blog post:

http://blogs.msdn.com/vbertocci/archive/2009/01/09/microsoft-tags.aspx

Can anyone say QR Codes?  Or their prevalence in Japan for that matter?

Not surprisingly, when I posted a comment to that effect, it never showed up.  I’m guessing it was not a fault of the technology here, and active moderation on the part of the poster.

Shame.

On a side note, these things look horrible.  Not to say that QR Codes are pretty, but they just seem to have a better aesthetic than these.  I can’t help but think some sort of failed modernist expression here.

The concept is cool though (I can use it on my iPhone, that’s good enough for me), but cell-phone culture here in the States just isn’t the same here as it is in Japan.  When I was in Japan, QR Codes were ubiquitous, but here, Microsoft faces an uphill battle in getting this to catch on.  Ugliness aside, it’s one I hope they win.

Tags: , ,

technology

New, Var, the Chicken and the Egg

by casperOne 27. January 2009 12:16

Eric Lippert's most recent blog entry proposed an interesting suggestion for enhancing the C# language:

If our goal is to remove the redundancy, I would therefore prefer to remove it the other way. Make this legal:

private static readonly Dictionary<TokenKind, string> niceNames = new()...

That is, state the type unambiguously in the declaration and then have the "new" operator be smart about figuring out what type it is constructing based on what type it is being assigned to. This would be much the same as how the lambda operator is smart about figuring out what its body means based on what it is being assigned to.

I can't tell you how much I love this.  While I absolutely love the var keyword in C#, there is a massive potential for abuse here.  It is too easy to use it to obfuscate code and use it in situations where you don’t need it (you need it when generating an anonymous type, most often for projections in LINQ).

I love it so much that I’ve already suggested it to Microsoft at least a year ago.

Last year, at the MVP Global Summit, I proposed this idea to Mads Torgersenafter his presentation on possible future enhancements to the C# language.  This conversation resulted in a very long email that was sent to Mads on the subject, which I had hoped would result in its distribution inside Microsoft for discussion.

I even made a suggestion through the Microsoft Connect site, elaborating on the language feature, as well as it’s impact (or lack thereof on existing code).  The suggestion can be found here:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=388649

Addtionally, I posted the link in the microsoft.public.dotnet.csharp newsgroup, asking for comments on the recommendation as well.  The full thread can be found here:

http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/f8ab748deca4737

Needless to say, I’m a bit frustrated about the situation, given that there is no reference to the email, or the suggestion, both of which predated his blog post.

Of course, I’m completely cognizant of the fact ideas are a spontaneous thing and that the same ones can sprout anywhere.

However, what is frustrating to me is that this idea is coming from a person in the organization and on the team in that organization that I submitted the idea to, and that kind of coincidence is suspicious, at best.

Oh, and I will post the full details of the idea at a later date.

Tags: , , ,

programming

Don't Cry Over Spilled Milk

by casperOne 21. January 2009 17:16

I couldn’t help but think of this while I was making green-tea ice cream yesterday.  As I pulled the container of cream and half-and-half from the fridge, the top slid from the container.

Being the dumbass that I am, and having only grabbed the top of the container, the rest proceeded to spill all over my kitchen floor.

I then had the thought that I wish I could get the milk back into the container, which is when I was reminded of how profound the statement in the title truly is.

I’m still a dumbass though.

Tags: ,

personal

Hail to the Chief

by casperOne 21. January 2009 17:12

Yesterday, like so many others, I tuned in to witness a momentous occasion in in my nations politics and history, the swearing in of America’s 44th President.  While his taking of the oath started off rocky, I feel it came off without a hitch.

Of greater import was the inaugual address:

John F. Kennedy’s inaugural addresshas its place as one of (if not the) best inauguration speeches of all time, and this speech will do nothing to displace it.  By all means, it is historic and it will be remembered, but more so because of it’s association with the man behind it and his singular accomplishment.

It’s the combination of the man and the speech, however, which makes it truly moving.  There were many times that I bordered on tearing, but refrained, sitting right next to my boss while watching.  Invoked were grand images of America in its past, as well as a vision of its future, while tempering Americans for the tough times ahead.

I couldn’t help but think that America got a little bigger on this day, that some people that typically felt disenfranchised by the system now felt that they had a place in it (let’s be honest, race-relations are still not what they should be in this country, and that’s what we are talking about here).  It felt like more of us were in this together, and that when America emerges, it will not only be triumphant, but together.

At first I didn’t feel this effect of enhanced inclusion.  After all, as a white, heterosexual male with Judeo-Christian beliefs, there is no one that the system is more unjustly in favor for (it should be said that this isn’t because of outright bias in the system but because of those that choose to corrupt it for their own discriminating ends).

That was until I took a look at the official site of the White House.  As with everything else from the previous administration, the new administration’s website went live when President Obama took his oath.  Taking a look at the site, I was stunned at how ambitious the agenda is.  I would stop short, but not too short, of calling it all-encompassing.

While the typical policy points are included here, the fact that there is an agenda for technology, as well as an impressive use of it on the website (there’s a blog!) was overwhelming.

It’s at that point where I felt that this inclusion wasn’t just about those that didn’t feel included before, but for everyone, for all Americans, which is what we have been and need to continue striving for.

Tags: , , , ,

politics

Anger Management

by casperOne 19. January 2009 03:18

A recent post in the Shoryuken forums brought up an interesting aspect of competition, as well as in life (although I wonder if those reading and responding are aware that what is discussed there has broader applications).

"Dealing with Anger" is a question about how to handle the negative feelings that arise from losing, and asks for ways that one might control our reactions in the process.

I was pretty surprised with the number of earnest answers. In crafting my own answer, I realized that there is a lot of good that can be had from what I have learned/am trying to learn (we are all works in progress, no?) and bears reiteration here.

For a very long time, when I would compete against other people, if I was to lose, my reasoning for the loss was always external to me (i.e. the tactic used was "cheap", for example). I would become very angry, and in my mind I was justified because the universe had committed an egregious error against me.

I would subsequently carry this anger into my interactions with the people closest to me and to my shame, it would lead me to treat those people without the respect that they deserve from me, for reasons that had nothing to do with them. It is shameful behavior, at the least.

For me, quantification is a wonderful thing, and computers enable me to do that to a great deal. I can measure many things, and with all of that data, I can track progress over time. The flip side of that is that I can also track failure as well (this is why I don't play poker online anymore, btw).

That's where the Super Street Fighter II Turbo HD Remix comes in. There is a ranked mode, which allows me to see how many matches I have won and lost, as well as my ranking (which uses a calculation that I swear I don't understand completely to this day).

While I was able to see that I would win anywhere from 70 to 75% of my matches, those matches that I did lose would enrage me. Sure, I might go on ten-game win streaks, but then I would turn it around and lose ten. Of course, all of those losses were never my fault.

Unfortuantely, this lead to some poor behavior on my part, and all over a game, no less.

The first thing that had to change was my sense of responsibility (which, outside of competitive situations, is pretty strong). I had to stop shifting the blame to external sources to myself. If I lost at something, it was my fault. I didn't know how to counter my opponent, I didn't know the appropriate responses.

Admittedly, this is the most difficult change to make. It requires humility and an ability to look past the delusions that I allowed myself to get sucked into, namely, that I had reached the pinnacle of my development. And that's really what it is. I was never in the place that I thought I was in, it was just an illusion that allowed me to remain ignorant.

In making that realization, in being honest with myself about my ability, a path (or a number of them) became apparent. There was plenty of room to grow, and in order to grow, I had to be able to learn from my losses, something that my anger didn't allow for. I simply can't learn anything if I was too blinded by my anger.

So, I had to get rid of it.

Ok, so it's not that easy, but in being able to identify the issue, it makes it that much easier to address it, and then move on from there.

Tags: , ,

personal

Where Does One Find a Leather Hippo?

by casperOne 16. January 2009 20:49

Park Avenue in New York City, of course:

I'd totally get this if I had the money.

Tags: ,

personal

On Fame, Immortality and Teaching

by casperOne 15. January 2009 01:05

Listening to the latest episode of the Street Fighter Podcast got me thinking on a few things.  In it there is a discussion between Ryan Gutierrez (a.k.a. gootecks) and Mike Ross regarding an upcoming project from Mike.

What Mike wants to do is create a series of video shorts (no doubt due to today's attention-lacking viewing audience) to tell the story behind, as he calls it, “those geeks you see playing Street Fighter IV”.  He wants to show you that playing the game is not the only thing that these players are all about.  They have families, friends and interests outside of the game.  But of course there are the equally compelling stories within that community for (and any competitive community in general).  There are allies, rivals, drama, and all the strange, wondrous and absurd events that can occur whenever people interact.

Ultimately, this is just another reality series, and as we all know I abhor reality series with a passion.  As with all things, there are exceptions, even notable ones.  It’s because most of these series capitalize on the worst aspects of humanity that become apparent in high-pressure situations.

But I digress.  As I said, there are notable exceptions.  I love “Top Chef”.  Yes, Padma Lakshmi is a goddess in every sense of the word, and one of the primary draws, but at the same time the drama due to personality clashes are kept to a minimum (the promos pretty much expose all of it, if any) and leave you for the most part with high-level competition which is then critiqued at a very high level.

Underneath all that commercial, consumerist glory lies a lesson to be taught and knowledge to be taken away (I challenge you to tell me what you learned from “Flavor of Love” or “Rock of Love”, entertaining as they might be).

Case in point.  I had a box of donuts that was absolutely inedible.  The donuts were dense and nasty, somewhere between bread and cake with a glaze that just wouldn’t set.  Solution?  Make bread pudding from them with a custard enhanced with lemon and orange zest and a hint of cardamom.  It’s quite nice, I assure you.

It was also done in Top Chef, Season One.

There was no recipe or guide, just a general concept that I was able to take away from the show which, using established fundamentals, allowed me to extend my repertoire just a little bit more.

In the end, I believe this is what Mike is trying to do, and he deserves recognition for it.  He wants to teach people outside the community about the community itself, and in the process attract more people to it.

(An interesting side note to this is that Mike came from the Marvel vs. Capcom community, which tends to be tight-lipped when it comes to sharing things about the game, while the Street Fighter community tends to be more open.  That being said, it’s interesting that Mike is reluctant to reveal much about his E. Honda play during the podcast.  To be fair though, Ryan has interviewed other Street Fighter players reluctant to delve into detailed aspects of their gameplay.)

What’s also great is that he had this conversation with Ryan, who on the “about” page of his blog states:

I’m interested in your ideas about how to reach more people with the podcast, how to help more people get better at 3rd Strike and am also available for one-on-one coaching.

Ryan desires to teach as well, and it’s apparent throughout his podcasts and his blog postings.  His postings are obviously tailored to those who are looking to disseminate information, and he consistently asks detailed questions of top-ranked players to try and expand the knowledge base of the community as a whole.

I don’t play 3rd Strike , but I find myself voraciously taking in his posts and podcasts with meticulous detail (I am more a Super Street Fighter II Turbo HD Remix person, who will be transitioning to Street Fighter IV when it is released for consoles, but there is great discussion about the mindset of playing on a competitive level which runs through most of the Capcom fighters) because more knowledge is always a good thing.  In assimilating some of the knowledge he is trying to spread, I’m always going to be able to find things to apply to my game.

The problem that exists is that there is nothing along the lines of a structured curriculum for advancing (“leveling up”) one’s skill level.  You’ve always had to “climb the mountain” so-to-speak (even though it’s been made easier in recent years because of the Internet, which enabled things like the Shoryuken site and forums, allowing for the collaboration and archiving of information, as well as YouTube videos which allow for people to witness the execution of that information).

People like Ryan and Mike are trying to change that.

Ryan started to develop his “from scrubs to winners’ clubs”, which strikes me as an experiment of sorts, with the desire to expand it if it is successful.  From what I can tell, he is taking a non-top-ranked player, and determining if a structured learning experience (instead of “climbing the mountain”) can be successful in producing a top-ranked player.

The initial subject in this experiment is John Rog, and the established goal is to place in the top five at AI with three months of training.  The results are pretty evident:

While John placed in the top eight, it’s still a vast improvement, and shows that structured learning will work in this competitive environment.

Congratulations to both John and Ryan, with wishes for continued success.

So what does that have to do with me?

I want to do what Ryan and Mike are doing.  I want to contribute and I want people to gain from that knowledge.  It’s not completely altruistic though.  I desire fame, and I desire immortality, and teaching is a very good way of doing both.

When I was young, surprisingly, I was not the most popular child.  It’s nothing that I have issue with today, but it’s definitely something that has impacted me to this day.  Simply put, I find myself desiring attention, and I would let a lack of attention affect me in negative ways.

Needless to say, I’ve grown past that, but this desire for attention has transformed subtly into a desire for fame, specifically in the things I am passionate about.  Cooking, Street Fighter, baseball, etc, etc.

I do realize that there are limitations to my ability, and I will never get the all fame I desire.  Take baseball, for example.  I’m never going to play for the New York Yankees.  So what do I do? I  adapt.  If I can’t play for my favorite team (or one of the other 29 lesser teams), then I would find my way to the baseball diamond another way.  Umpiring.  Assuming I had the financial security to do so, I would quit my job and go to an accredited institution to lean to umpire (there is one that I know of) and then put the time in until I am tenured enough to work on the major league level.  No, I wouldn’t be the star of the game (nor do I want to be, unlike Joe West), but I would have a unique experience and perspective that I would cherish always, as well as be woven into the fabric of every game that I participated in.

What very much applies in this particular instance is rooted in the saying “those that can’t do, teach”.

There is also the death of my father to consider here.

As children, we believe that we are invulnerable.  It’s why as a child I rode my BMX bikes off ramps over garbage cans and why today I see children 1/3 my age flying off ramps and rails I’d never consider while snowboarding.

When he passed away, I realized that nothing (myself, the people and things I love) will be forever and that my time here is limited.  Because of that, immortality is more and more attractive to me.  Unfortunately, the means just isn’t there yet to allow my physical form to last forever.

But aspects of me can survive long after I am gone.  It’s one of the many reasons why I wish to have children in a timely manner.  Not only is a child literally part of me, but I can imbue them with lessons and ideals, and take pride in the contribution I’ve left to the world.

That’s for the future though.

So for now, I do things like contribute to the Shoryuken forums, contribute to newsgroups (for which I have been awarded the Microsoft Most Valuable Professional Award) and places like stackoverflow.com, write a blog, etc, etc.

Yes, there is an unexpected personal gain that I get from all of this, but over the years, I’ve come to appreciate the satisfaction that is inherent in doing something for which there is no expected gain in return.  It also falls in line with my desire to produce more than I consume.  Considering that I’ve spent the majority of my life taking from the universe, it only seems right that I begin to give something back.

Fortunately, it becomes a perpetual cycle, feeding itself, I end up learning more, so I can teach more, which enables me to learn more, and so on, and so on.

Tags: , , , , ,

personal

The Most Wonderous Place on Earth

by casperOne 8. January 2009 17:24

The New York Times has impressed me of late.  In an age where print publications are going the way of the dinosaur, the Times has managed to show that it can adapt to ever-evolving technology.  Whether it be the Windows Presentation Foundation reader from a few years ago to their current iPhone reader application, they have shown that they can deliver content through in new ways and through new mediums.

But what’s most compelling about what they are doing the interactive features on their website, which go above and beyond anything that you will get in print (and even on most websites).  For example, just check out any of the interactive features at the 2008 election site.

However, it’s this one that stands out the most to me, the embodiment of heaven on earth:

http://www.nytimes.com/interactive/2008/12/22/nyregion/20081222-rooms-pano.html

Tags:

food

A Better Implementation Pattern for IDisposable

by casperOne 4. January 2009 19:18

During the first few years of programming in .NET, I sheepishly followed the Design Guidelines for Class Library Developers in regards to implementing IDisposable in my class libraries.

On the face of things, the recommendation is solid. A base class exposing IDisposable looks like this:

// Design pattern for a base class.
public class Base : IDisposable
{
    //Implement IDisposable.
    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool disposing)
    {
        if (disposing)
        {
            // Free other state (managed objects).
        }
        // Free your own state (unmanaged objects).
        // Set large fields to null.
    }

    // Use C# destructor syntax for finalization code.
    ~Base()
    {
        // Simply call Dispose(false).
        Dispose(false);
    }
}

So what’s going on here?

First, a non-virtual method is exposed on the class so derived classes don’t have the opportunity to muck up cleanup code.

Next, a protected virtual override of Dispose handles the disposal of unmanaged resources/large objects as well as any other state that needs to be managed (if not called from the finalizer, then any references to other IDisposable implementations have their Dispose methods called as well).  This allows for base classes to be able to hook into the cleanup code without burdening it with the details of implementing the finalizer or the method on IDisposable:

// Design pattern for a derived class. 
public class Derived : Base
{
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            // Release managed resources. 
        }
        // Release unmanaged resources. 
        // Set large fields to null. 
        // Call Dispose on your base class. 
        base.Dispose(disposing);
    }
    // The derived class does not have a Finalize method 
    // or a Dispose method with parameters because it inherits 
    // them from the base class. 
}

(Both code samples were copied from “Implementing Finalize and Dispose to Clean Up Unmanaged Resources”)

Last, the finalizer calls the same protected virtual overload of Dispose, indicating that it should only clean up unmanaged resources and large objects (not references that implement IDisposable).

The effect here is twofold.  The first is that calling Dispose has the effect of freeing any state that needs freeing at a determined point in time (usually when you are done with the resource).

The second is that if you forget to call Dispose, the garbage collector will do it for you.

The problem lies with the statement “if you forget to call Dispose.”

Pop quiz, how many of the following errors in code would be tolerated in a production environment:

  • Not hooking up an event handler for an event that code needs to react to
  • Not calling Monitor.Exit (unlikely, but a possibility if not using the lock statement or calling TryEnter) after a call to Monitor.Enter/Monitor.TryEnter
  • Not throwing an exception when an error occurs (one that is worthy of an exception, that is)
  • Not synchronizing access to a resource that is accessed by multiple threads of execution

In any of these cases, this would be considered a bug and fixed.

But why is this a bug?

If the finalizer executes (remember, the object is removed from the finalization queue if Dispose is called) then that means that the instance did not have the Dispose method called on it.  In this case, you have circumvented the entire reason for implementing IDisposable in the first place, which is to make the developer aware that attention needs to be paid to instances of the implementing type.

Microsoft exacerbates the situation with the current guidelines because it actually obfuscates the issue.  With the recommendation, if Dispose is never called then the resource is eventually freed up at some indeterminate point of time in the future.

That recommendation ends up placing this on the same level as the race-condition bug noted in the last bullet point .  Your app might run very smoothly for the most part, but at random times, you have exceptions that you can’t trace (because the resource in question is corrupted and leads to states in your application that you aren’t prepared for most likely).

In the case of not calling Dispose, this will most likely manifest itself in the form of starvation of the resource managed by the IDisposable implementation at random times (sockets, database connections, etc., etc.) and even then, if at all, depending on the usage pattern of your app.  You might never see the exception, but then (at a critical moment, of course) your app fails, and you haven’t the faintest reason why.

So what can I do to prevent this?

The bad news is that outside of your code, not much.  You have to live with the fact that everything in the framework and most other library code written follows this guideline.  If you miss cleaning up one of these resources and you run into an intermittent problem involving a resource that isn’t cleaned up properly, a great deal of painful debugging awaits you.

To add to that, I haven’t seen many static-analysis tools that catch this either.

Quite simply, there isn’t a definite way to catch this at compile-time (or to be more specific, without running code).

What about inside my code?

That is a different story.  You can simply throw an exception in the finalizer.

You are surely thinking now “woah, that’s a massively bad idea”.  Well, yes, it is.  You are going to hose your app in a major way either during the garbage collection that occurs with the IDisposable implementation which hasn’t had Dispose called on it, or on exit of the app.

But that’s the point.

Surely you aren’t going to deliver your app without running it at least once, right?  And if you are in a more formalized software development environment, you are going to run it through all sorts of unit tests, quality assurance tests, and so on.

So even if you can’t catch the error at compile time, you can catch it much earlier, and hopefully, before your app ships (assuming you have proper test coverage of your app).

Here is the code sample.  For all intents and purposes, the derived class remains the same:

// Design pattern for a derived class.
public class Derived : Base
{
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            // Release managed resources.
        }
        // Release unmanaged resources.
        // Set large fields to null.
        // Call Dispose on your base class.
        base.Dispose(disposing);
    }
    // The derived class does not have a Finalize method
    // or a Dispose method with parameters because it inherits
    // them from the base class.
}

The changes come in the base class:

// A better design pattern for a base class.
public class Base : IDisposable
{
    // Implement IDisposable.
    // This remains the same, this instance should not be finalized if Dispose is called.
    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool disposing)
    {
        if (disposing)
        {
            // Free other state (managed objects).
        }
        // Free your own state (unmanaged objects).
        // Set large fields to null.
    }

    // The change is here, you want to throw your exception if you do not call Dispose.
    ~Base()
    {
        // Throw an exception.
throw new InvalidOperationException("Dispose method not called."); } }

Things to note:

  • The public overload of Dispose is the same.
  • The protected overload has not been changed, but only to make it easier for those that already have Dispose implementations following the original guideline.  Ideally, it would be changed to a method with no parameter (since only true will ever be passed here, there is no point in having it, as well as the conditional with the check against the parameter) and renamed (since it would conflict with the public Dispose method).  Do NOT refactor the public method into a virtual method, as that would give derived classes the ability to screw things up.
  • The exception is thrown in the finalizer.  I’d recommend resource strings for localization purposes of course.

Tags: , ,

programming