Thursday, November 15, 2012

The Internet is not a black box. Look inside.

The Internet is not a black box. Look inside.:
All too often I see programmers trying to solve their problems on the internet by blindly "flipping switches."
Change something, hit refresh in the browser. "Why is that cached? What's going on?" Change something else, hit refresh in the browser. "What's the deal?"
You may have heard the term "cargo cult programming" where islanders after World War II would wave sticks hoping that planes full of supplies would fly over. They drew a conclusion that the sticks waving caused the planes to come.
Think about abstractions. This is a good reminder for the beginner and the long-time expert. This applies not just to computers but to cars, light bulbs, refrigerators and more.

What are you not seeing? Look underneath.

When coding on the web, remember that effectively NOTHING is hidden from you.
A friend emailed with a question about some CSS files not caching. This is a smart guy with a long question about a confusing behavior in the browser. I asked - as I often ask - what's happening underneath? Did you look inside?
Are you using Fiddler? Did you press F12 in your browser of choice and explore their network tools? Are you using WireShark?
Literally this moment, as I am writing this post, I just noticed that the Twitter box on my blog here doesn't have my latest tweet embedded.
Where's my tweet?
I could hit refresh a bunch of times, google around for vague terms, email a friend, or I could look inside.
I hit F12 in my browser. I look at the Network tab, and sort by Status.
Remember to use the Network Tools in your browser
Hey, suddenly my Twitter API call is a 404. First, that's lame of them. They should have redirected me, but alas, no one respects the permalink anymore. #getoffmylawn
With this single  insight I am now armed with googleable terms. I do a single search for "twitter user timeline json api" and see at the Twitter Developer Center that they've changed the format to included "api." and a version number.
I change my template to call this changed URL https://api.twitter.com/1/statuses/user_timeline/shanselman.json?callback=twitterCallback2&count=10 instead, and hit Refresh in my browser, once.
There's my tweet?
There's my tweet. No joke, this just happened. Good timing, I think.
You decide how deep you want to go down the rabbit hole. I am not expecting everyone to be a neurosurgeon or a professional network engineer but I firmly believe that digging just one layer deeper in all things will enhance your life and your work.
Learn basic HTTP debugging and ALWAYS check your result codes. Even if you are a non-technical blogger, learn how to check for 404s and 301s and 500s and assert your assumptions.
The world - and the internet - is not a black box. Look inside.


© 2012 Scott Hanselman. All rights reserved.


DIGITAL JUICE

No comments:

Post a Comment

Thank's!