Posts Tagged ‘Programming’

This is by far, the most frustrating error I’ve had the unfortunate luck to run into…and it all seems so simple in retrospect. If you’ve ever set a color using the style.color method in javascript, you may have encountered a compatibility problem where it works in Firefox and Safari, but not in Internet Explorer (this is not a bash IE blog post, by the way).

The Error

If you’re using Scriptaculous, like I am in Ruby on Rails:

1
 $('item_id').style.color = '#09SF0C';

or if you’re using the document object:

1
document.getElementById('item_id').style.color = '#09SF0C';

The action will result in an error in an ‘Invalid Object’ error in Internet Explorer. Safari and Firefox will do their best, but not consistently.

The Solution

I thought, at first, that it was a coding issue where IE would treat style.color differently then the other browsers (although I could find no evidence to support that assumption), so I edited the code and tried every different combination setting the color style, but to no avail.

It turns out that no browser really likes this color #09SF0C (which is a green by the way). So, after two hours of ridiculous code editing, I started playing with the color and found a new green (#336633) that all browsers liked just fine. Code works, color changes. In retrospect, it’s all so simple…and I feel pretty bad that I didn’t think of it in the first 15 minutes. The least I could do is save someone a couple of hours. Use one of the hex colors here.

- Chris

We live in a changing world, that much is true. What I’ve found recently is not only that the environment changes around us, but our perception of the environment changes around us just as quickly. I think this is an important and prescient idea. Almost everything I know, or think I know, is probably wrong. There may be some odd facts, like New Jersey Devils Left Winger, Zach Parise has scored 41 goals so far this season, that will hold true many years from now. On the whole, though, I’m probably going to be proven wrong about a number of things I think are iron clad ideas. It’s a humbling and energizing realization.

Merging Galaxies

You may be asking yourself what triggered these thoughts (and if you’re not, I’m going to say it anyway). If you’ve read my blog before, you’ve probably seen references to Scientific American…mostly because I’m a subscriber…but also because I love almost all things scientific. The most recent issue has a leader article called Does Dark Energy Exist?. The basic premise: astrophysicists have been trying to explain what makes up most of the universe. To do so, they have created and are trying to prove a theory that a mysterious dark energy has contributed to the expansion of our homogenous universe. The article offers a different theory that explains the expansion of our universe. In short, (read the article for the entire treatise), our universe is inhomogeneous, that pockets of the universe are expanding at different speeds which accounts for our observational data.

Granted, this isn’t necessarily earth shattering news to most people, nor may you care very much about dark energy. The interesting point here is that for over a decade, cosmologists have considered the universe homogenous and filled with dark energy. Now the opposite may be true. In short, a lot of stuff they know about the universe may indeed be wrong (It’s not proven yet, just a theory).

Peripateia and Anagnorisis

That brings me to programming. In general, programming is ephemeral and guided by the best ideas of the day. If you’ve worked as a programmer for longer than a couple of years, you’ve probably migrated from one general design pattern or language to another. And in every migration, you’ve thought to yourself, “this is the one I’ve been waiting for.” Case in point: Ruby on Rails.

I was looking at the source code from one of our old .NET applications. We built that system using the Table Data Gateway pattern. More or less, the TDG pattern utilizes a gateway class that contains all necessary SQL code for a specific entity. All of your other code then interacts with the gateway class to perform the CRUD operations that you’ve outlined in the class. On top of the gateway, we constructed additional classes which wrapped each entity and provided any necessary business logic. Then using the .NET (version 1.2) code behind classes we created all the sweet, sweet presentation code.

Lately, we’ve moved to the MVC architecture for all applications. The separation of concerns has improved the speed and cleanliness of our code. In short, our code smells a lot less. The MVC architecture makes a lot of sense (especially because we’re doing a lot of ROR work), but it also fully encapsulates the entire architectural idea for a system. Previously, we relied on the governing structures of the .NET framework, but the move to a more language agnostic framework makes it easier for us to transition from one language to another very quickly. To be fair, TDG is only one part of a larger architectural pattern, but it fueled the overall architectural ideas that governed our .NET architecture.

All this hullabaloo and exposition is to make one point, MVC will probably give way to some other architecture in the ensuing years. We may all move to the PAC pattern (doubtful I know) or the Reflection pattern. This is the thing I like the most about programming. It seems like no matter how hard I try, I’ll always be wrong about something and I’ll have to rethink everything I’m doing sooner or later. The nice thing, even when I change my approach to programming, the stuff I wrote 6 years ago will keep chugging along with it’s old patterns. The poor astrophysicists will have to rethink almost everything if dark energy doesn’t exist.

Another inspiration: Mike Rowe on being wrong

Event Clipboard