Pigsflew.com Realization of a Dream

21Feb/110

A Little Trip

This week in the War on Sloth:

So I didn't do as much productive hobbies this week, though I did learn the chords to the main theme from Legend of the Seeker (the show somewhat loosely based on the Sword of Truth novels by Terry Goodkind) on the guitar, and later on piano.

Really, I spent my time here:
Harper's Ferry WV

This year, since leaving taking a 10 day vacation out of the country isn't an option given the craziness going on at work, Mikah and I decided to take a jaunt out to West Virginia to celebrate Valentine's day with a weekend at a nice B&B. Mikah found us the Hillbrook Inn in Charles Town, a place which is exactly as it looks in the photos--remote, secluded, gorgeous. We spent most of Saturday wandering around Harper's Ferry, even exploring a Flea Market.

We were there only two nights, and I wish we could have been there longer, but I feel greatly refreshed, and am glad to have had the time to reset myself.

I did briefly stop at Micro Center and took a look at books for getting myself into a new development skill. I've been talking and talking about several things, including 3d game development, and mobile app development, specifically for webOS. Game development is very different from my actual development path, and it would almost certainly take a long time to learn to use the tools of that particular trade; therefore I decided a few weeks back to work on making an app for webOS. Now I'm running into some rough patches with that, because, while I can easily get through the various tutorials I've found and get some pretty pictures displaying on the screen, I don't actually know certain best practices for code organization and, well, mainly, how to fetch new information from an outside server.

This is certainly something that, with a little more time and patience, I could learn from the documentation and from reading through more examples, but to assist me on the path, I was thinking of buying a book on webOS development. Unfortunately, Micro Center only had one which had very low ratings online, so I left it. I'll just have to keep looking, and reading.

12Feb/110

The War on Sloth Begins

I think I had a pretty successful first week in the War on Sloth--despite having a particularly rough week at work (60 hours!) I managed to get in some music, a bit of drawing, and a personal coding project that I think is rather nifty. As I said, I'm going to be scatter-shot for a while as I figure it all out. If things at work calm down, maybe I'll keep it diverse and start doing a post per pursuit, but for now each one is relatively small.

For music, I sat down at the piano long enough to learn the introduction to Ben Folds' "Still Fighting It". It will take a bit more time to commit the whole song to memory, but the song is fairly simple, short, and calm--which is a good recipe for a song I can pick up fast and feel good about playing for others. Didn't spend any appreciable time on the guitar, but this is a good start.

I also spent a bit of time playing with Inkscape and drew a new pig. Here's the old one for comparison:

The Old Pig

Phlox, the Phlying Pig

And here's the new one:

The New Pig

Phlox, the Phlying Pig

I still like the old one better (it's just a better drawing to start), but I like the new one's open eyes and more comic-like lines. I need a sharper version of Phlox for an icon anyway, for upcoming projects.

This is the biggest thing I've started: I'm making a Palm webOS app. There's a few of them that I have in mind, so my plan is to start with a very simple app and work my way up to more awesome ones after I get the gist of how webOS development really works. So I pulled down the Palm SDK and started tinkering. So far, I've got very little that I want to show off, but I've learned a lot! So we'll see what I can come up with for next week.

Until then, what's your free time like?
Adrian

25Jun/100

OOP and Fitting JS into CSS/HTML, a Thought Experiment

Recently I've been thinking about how website design could be cleaner and clearer. My brain is wired for Java and OOP development, so I couldn't help but think that maybe an actual object oriented approach would be far better than what exists now --functional manipulators of a single DOM object.

We already have this idea of "classes", thanks to CSS and how it interacts with HTML. Future specs of javascript (and many current js libraries) already include a getElementsByClass function that work with this as well as the getElementsById that already exists.

So we're already to an extent treating these elements as "instances" (with a unique ID in the DOM) of one or more "Classes". So why doesn't the Javascript conform to this?

What I'd love to see is for something like this:

HTML:

<div id="article-1" class="article">
<h3>Article Header</h3>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
</div>
<div id="article-2" class="article">
<h3>Article Header</h3>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
</div>

Nothing new there.

new CSS:

.article {
  h2 {
    padding-bottom:10px;
    border-bottom: 1px solid black;
  }
  p {
    padding: 5px;
  }
}

See what I did there? It's actually not that far a stretch. Typically this would be done by using ".article h2" and ".article p". This format mostly just allows for greater clarity in the CSS--at a glance--for what your style really expects elements to look like. Let's face it, styling has a dependancy on content--you can't theme a webpage unless you have some vague idea of what's going to be represented.

The next part is where I get serious:

Javascript:

class article {
  var header = this.getElementsByTagName("h3")[0]; // We expect only one of these
  var paragraphs = this.getElementsByTagName("p");
  var hidden = false;

  function onContentReady() {
    this.header.addlistener('onClick',this.hideShowContent);
  }
  function hideShowContent() {
    for ( var i in paragraphs)
    {
      if (this.hidden) { paragraphs[i].style.display = ''; }
      else { paragraphs[i].style.display = 'none'; }
    }
    this.hidden=!this.hidden;
  }
}

You get the idea, I think. Your non-class CSS defines what to do with elements occurring outside of classes, and gives styles that will cascade into classes unless overridden. Your non-class Javascript would include basic functionality used in many classes, and some of your classes might even require helper javascript classes that would be pulled in at need, and only once. (say, a date picker class that is required by several parent classes).

You could even separate your class-based js and css out, storing them locally, and providing "glue" in your base-level javascript, so that whenever the browser loaded a class it had not already seen in the DOM, it would look at that glue, and go and fetch the necessary JS and CSS if necessary.

This means that unless there's an Article on the page, you'd never load the Article css and javascript. The javascript and CSS would never be loaded more than once.

Clearly, my example is not incredibly good--the idea could probably use a lot more work, but what strikes me as funny is that when I look at it this way, it seems like it's almost meant to be. Javascript/ECMAScript is constantly improving and is at this point a full-fledged programming language in its own right, albeit one without a canonical interpreter. HTML and CSS specs are constantly improving as well, but there is a divide sharply between the two. I wonder if perhaps Javascript not being under the purview of the W3C has something to do with how separate it is from the HTML/CSS setup, and why they don't seem to be converging, aware of each other, toward something cleaner.

Filed under: Geekdom No Comments