(Programming)

Post Thumbnail

Patterns Schmatterns: But Don’t Forget the Fun

July 3, 2010 @ 23:58:36

Courtesy of SeanMonstar, I now know to guard myself against Criminal Overengineering.

The most insidious cause of overengineering is over-generalizing. We will over-generalize anything given half a chance. Writing code to work with a list of students? Well, we might want to work with teachers and the general public someday, better add a base People class and subclass Student from that. Or Person and then EducationPerson and then Student. Yes, that’s better, right?

We have to stop championing each ridiculous feat of overengineering and call it what it is. It’s not ‘future-proof’, because we can’t see the future. It’s not robust, it’s hard to read. Applying a generic solution to a single case isn’t good programming, it’s criminal overengineering because like it or not somebody, somewhere will pay for it.

He mentions fear as a motivator; the worry that your code won’t stand up against the unforeseen use-case. He also describes the sense of productivity it engenders. In other words, “look at all this code I just cranked out”.

And while I agree with everything he says, I do have a small point of contention: He doesn’t account for the fun factor. This must be the exception to the rule. The one time it is okay to shoot way high.

I mean, isn’t it fun to create these beasts? To take a simple problem and abstract it out to this giant chain of inheritance and interfaces and abstractions? I’m serious here. I’m sure there exist the coders who enjoy nothing more than filling in a function stub with one return statement, mumbling “done” to themselves, and then moving on to the next task at hand. But aren’t most of us the kind who enjoy the creating and building of these…things?

So yeah, while absorbing the fluorescent rays of a cubicle sun, make sure not to “makes things harder than they are” (to quote my dad) too often. But try to find an excuse every now and again to exercise those creative muscles and think larger than the simple problem at hand. That’s what I say.

Post Thumbnail

The ReadyAgain jQuery Plugin: Re-executing Ready

June 9, 2010 @ 16:21:50

I’ve been wanting to become better acquainted with the Mecurial revision control system (see Hg Init for more info). There’s also been a jQuery related issue I’ve been wanting to investigate. So I made the jump and

1. Created a plugin
2. Created a repository for that plugin at BitBucket

ReadyAgain at BitBucket

The ReadyAgain jQuery Plugin

Prior to version 1.4, the array of functions saved by jQuery for execution when the DOM is ready (i.e. those functions added by $(document).ready(function...)) was an accessible property of jQuery. This meant that you could reference the array directly using something like $.readyList. Now, however, that array has been hidden within an anonymous, self-executing function (the deepest, darkest well of data hiding in javascript, here’s a bit of a primer). So re-executing all of the ready functions by grabbing a copy of that array becomes impossible.

The ReadyAgain plugin is my attempt to solve that issue. The specifics can be seen by looking at the code, but the basic concept is to override jQuery.ready to intercept each function as its added, and to save it within our own internal array.

Public Code

So the initial commit of the code is there and I’ve typed up a page on the Wiki with some examples. I hope that people use it and maybe even contribute to it. It would certainly be something fun for me to be a part of and from which to learn.

↓↓(show more)↓↓

Post Thumbnail

Miter Box Slider

May 24, 2010 @ 09:19:20

I submitted a jQuery plugin to CodeCanyon before this past weekend started, and this morning I received an “it’s been accepted” email. If you’re not already familiar with it, CodeCanyon is a marketplace for code. It allows anyone to submit a piece of code to sell. If accepted, they set the price and take a cut of any profits. It’s part of the larger Envato marketplace, which includes areas for selling things like site designs and audio clips.

Miter Box Slider is my submission. It’s a jQuery ’slider’ plugin (i.e. when there’s a slideshow display of images at websites). What’s awesome about it is that it provides the ability to create truly unique animation transitions. With other sliders you’ll see a set of predefined transition effects, but with Miter Box, you create the transitions. It’s actually very powerful. One of the largest issues I had developing it was that I would often end up just playing with it. It’s a fun tool for experimenting.

Regardless of whether other people decide to use it, I really am pretty proud of it. Remember that those who run the site review the code and set the price? Right now, mine is the highest priced (one of only two at that price) item in the javascript section of code. I don’t know everything that goes into that price point, but I will say that I think it’s an indication of the power my plugin offers.

If you’ve got a site, or create sites, and are looking for some way to spice up the way you display your images, check out the Miter Box demo.

Absolute Positioning and the Canvas Element

June 1, 2009 @ 22:27:46 5 Comments

I’ve been working on a personal “hobby time” project lately using John Resig’s port of Processing (a Java thing) to Processing.js (a javascript thing).

I was at one of those lulls where, instead of worrying about the code, I started playing with the layout. My <canvas> element is sitting inside a <div>, whose “positioning” property I changed to absolute. After this edit, the top-left corner of my <canvas> was no longer (0,0). It had changed to the (x,y) coordinate of the <canvas> element on the page.

Of course, the above conclusion was only reached after a bunch of “W.T.F is going on? Why T.F. is everything broken?”. After some other debugging routes, it dawned on me what might have happened. So I set the frame rate to 1, and used Firebug to log the mouseX and mouseY as I moved the mouse around. Sure enough, my positioning of “top: 200; left:200;” was reflected in Firebug’s console output showing coordinates near those values while hovering around the top left corner. Commenting out the style sheet’s absolute positioning returned the console output to the (0,0) area code.

So this is a defect, right? I can’t imagine that’s how it’s supposed to work. Anyway, consider this a heads-up if you decide to embark on a little processing.js play.

Wordpress, jQuery and ‘noConflict’

September 5, 2008 @ 21:31:19 3 Comments

I’ve been working on a plugin for Wordpress and have, until now, been using Mootools. I decided that I should try and simplify things by using jQuery, since it is already included with Wordpress.

So let me take you through my links and hopefully summarize what I’ve learned. First though, let me say, I’m assuming that you already know what it means to hook into the Wordpress application flow by adding “actions”. If not, read up.
↓↓(show more)↓↓

LOLCode Has Me LOL’ing OMG DOOD

September 1, 2008 @ 23:04:07

Not only is LOLCode funny, but it’s effin real. Here are the specs and here are some implementations.

But who cares. It’s just plain funny. I mean, I’ve read the two front page examples (very bottom of the home page) at least twenty times and it still manages to entertain.

COUNT!!1

HAI
CAN HAS STDIO?
I HAS A VAR
IM IN YR LOOP
	UP VAR!!1
	VISIBLE VAR
	IZ VAR BIGGER THAN 10? KTHXBYE
IM OUTTA YR LOOP
KTHXBYE

GeSHi (used by WP-Syntax) needs to get up in that piece so my blog can have syntactically correct formatting of LOLCode.

Heads-Up Regarding the CodeIgniter Video Tutorial

August 23, 2008 @ 16:13:49 6 Comments

I’ve finally gotten around to working through the second video tutorial for CodeIgniter. It’s centered around creating a blog in about 20 minutes (it continues from the shorter, “Hello World” intro tutorial…so if you haven’t already, I’d start from there).

There’s a small error I didn’t notice (but should have). It had me stumped for a bit but, as is most always the case, the solution was painfully obvious.
↓↓(show more)↓↓

Reading Lines Using Java

August 21, 2008 @ 20:41:29 2 Comments

Every year or so, for whatever reason, I end-up trying to read text files line by line using Java. I always start out thinking regular expressions, and it always starts to look unnecessarily convoluted.

Three or four years ago I came across BufferedReader and, whatdya know, its got the function readLine. Of course, each time I start anew, I forget the lessons I’ve previously learned. Then, when the code’s starting to look rough, I remember “Oh yeah, there’s a really easy way to do this.” So I find the old code and voilà.

I realize this is simple stuff. It’s just one of those things that’s worth putting out there for the occasional search result that might help someone out .

/* Note that I've left out exception handling. */
 
ArrayList<String> lines = new ArrayList<String>();
File file = new File("C:\path\to\file.txt");
 
BufferedReader reader = new BufferedReader(new FileReader(file));
 
String line;
while((line = bufferedReader.readLine()) != null)
     lines.add(line);			
 
bufferedReader.close();

Firebug’s Future

August 12, 2008 @ 17:17:09

Firebug is a fantastic tool. It works as an add-on to Firefox and can be used for all sorts of fun stuff. It is a javascript debugger (breakpoints, variables and watch expressions). It can also be used to “inspect” whatever web page you happen to be visiting (hover over areas of the page to see its corresponding HTML and CSS). It’ll even profile the javascript.

The original author, Joe Hewitt, open sourced Firebug sometime last year and back in mid-July, John Resig (a well-known javascript guru and Mozilla employee) announced that he was taking over its development. Today he laid out his initial plans:

  • Improve the knowledge of Firebug that we have
  • Build a runnable set of test cases to prevent regressions
  • Track the state of Firebug performance
  • Audit and Improve

I can’t wait to see how Firebug evolves now that Resig has reign.

Available Online: When Print Has No Space for Content

August 9, 2008 @ 22:17:59 1 Comment

Dr. Dobb’s Journal is a pretty well-known magazine geared towards software engineers, and they’ve been at it for more than thirty years. The articles are generally pretty hit or miss for my taste. I was just reading the August 2008 print edition, specifically Disentangling Concepts in Object-Oriented Systems. It’s pretty meh in my opinion, but that’s neither here nor there. The problem I found is something I’ve come across before in this magazine, but this time it was just plain absurd.
↓↓(show more)↓↓

Do More to Do Better

August 4, 2008 @ 18:29:35

Coding Horror, a blog that I’ve started reading regularly, has some fantastic advice on how to improve your skills (regardless of the domain): Quantity Always Trumps Quality.

When it comes to software, the same rule applies. If you aren’t building, you aren’t learning. Rather than agonizing over whether you’re building the right thing, just build it. And if that one doesn’t work, keep building until you get one that does.

This is advice that I sincerely need to start following. I tend to have the debilitating problem of starting to work on an idea but never completing it because of constant tweaks and muddles and experiments and refinements ad nauseam. With an approach like that, your results are always incomplete. And when you feel like you can never complete something, you tend to move on to something else (i.e. quit).

When I used to create and record music, it was the same thing. The difference, however, was that there was always something to show for the effort, even if I wasn’t totally satisfied. No matter my perceived flaws, there was still a piece of recorded music I could share with others. But when the code isn’t finished, or the design still “in-flux”, it’s pretty difficult to call it a day and let the beast loose on the world.

I hereby resolve to…oh who am I kidding.

Friendly Reminder – mod_rewrite needs AllowOverride All

February 17, 2008 @ 02:15:56

Running Wordpress locally and not sure why the permalink or category pages are resulting in 404 errors?

It’s more than likely due to mod_rewrite not being allowed to do its job. If you don’t know anything about mod_rewrite, here is a nice howto. Also, of course, is Apache’s own documentation.

In a nutshell, the redirects created by Wordpress in your .htaccess need the authority to send a page request elsewheres. Open httpd.conf and make sure that you have AllowOverride set to All.
↓↓(show more)↓↓