Debugging Is Sexy Good Times

I love me some JSON. The problem with it is that it's not too human readable when you need to see what it's returning. Sure you could litter your code with alerts or console.debug (if you are using Firebug and Firefox to figure out what values are you getting back.

But if you've got the Firefox/Firebug setup (and why don't you if you don't?) then you can just use the Firebug console to display the JSON data. Say for instance you have the following data returned from your service (but imagine it's a bazillion lines long):

{"SomeObject":{"Attrib1":"foo",
               "Attrib2":"bar",
               "SubObject": {"SubAttrib1":"bar"}
              }
}

Just wrap that in an eval function, plug it into the console and you get back a nice little tree of your data in the DOM view.

console screencap

Now isn't that sexy?

Add a comment
Category: programming Tags:

Welcome

Hello and welcome to sethmason.com. This site is basically an experiment to set up a site that's a resume of sorts. It will feature articles about technology that reflect my depth of knowledge.

The site itself is set up using TextPattern. Normally, I would eat my own dog food and use a Java based content management system but I wanted to give PHP and Textile a test. So far, I'm impressed.

For more information about myself, check out my about page. And feel free to leave a comment.

Add a comment
Category: personal Tags:

Writing Tests For Fun And Profit

Learning a new programming language historically starts off with the classic “Hello World” example. I've probably written a variation on that a bazillion times. From there you take more steps into advanced parts of the language. If you are smart, you save your example programs to refer back to them later. But there's a better way. And that better way is to write test cases that exercise the capabilities of the language you are trying to learn. This also works for new libraries within a language you are trying to learn.

The advantages of writing test cases are plentiful. It gets you writing actual code which helps you remember, they can be usually be run easily, they serve as an extra source of documentation about what you are trying to do (e.g. “How do I use gsub again? Oh yeah, it's in that string test I wrote?”) and finally writing tests is fun.

An Example

After ignoring it for way too long, I recently started trying out the Yahoo! User Interface Library. It's a JavaScript library with scads of useful utilities for buidling web applications. So, I pulled up the documentation and started writing a tests based on what's documented. Since it's JavaScript, I used JsUnit since I'm used to JUnit on the Java side of things. And voila we have our first test:

<html>
    <head>
    <title>Test Yahoo</title>
    <script type="text/javascript" 
        src="jsUnitCore.js"></script>
    <script type="text/javascript" 
        src="yahoo.js"></script>
    <script type="text/javascript">
    <!--
        function testIsArray() {
            assertTrue(YAHOO.lang.isArray([1,2]));
        }
    //-->
    </script>
</head>
<body>
    A test document.
</body>
</html>

(I know it's very simple but I just wanted to get a feel for the first method in the global library and type it so my brain remembered it.)

So, now I drop the test file into my test runner and here we have the results:

It's all green!

Can't you just feel your brain expanding with the possibilities?

Add a comment
Category: programming Tags:

© Seth Mason

Themed using aboutwilson

Powered by Pelican