Design

Magic Conventions

What makes an awesome framework? A lot of things obviously, but one particular thing is how much magic it does.

I was amazed at the magic going on in Rails the first time I looked at it. ActiveRecord automatically knew which tables my classes mapped to! It automatically gave me handy functions, (ar.foo for regular attributes and ar.foo? for booleans, for instance). Specifying (basic) validations was a piece of cake. Adding relations to other tables was also super easy. It also automatically located the ID column of my tables.

Constant Arguments

I just started thinking, why do pretty much all languages define arguments as regular variables instead of constants? The way I see it, the most common feature should be the default behavior, and how often do you need to (or more importantly, “should you”!) change the value of an argument variable? I can’t think of a single time that I’ve done so with a good reason. With some languages (like the simple Scheme interpreter, %scheme, we’ve implemented reading our SICP-based course) it’s simply easier to omit the use of constants altogether. We did it

Unfortunate Syntax Rules

There are two things with the JavaScript syntax that really bothers me. What they have in common is that they force you to remember to add superfluous characters to your code. This makes it really easy to forget to add them, and this may cause syntax errors or bugs.

Sound familiar? Probably. First of all I’m thinking of the fact that array and object literal values need to be comma separated. It makes sense, [1, 2, 3] looks good when you write it on one line. But take a look at the multi-line version:

  1. var a = [
  2. 1,
  3. 2,
  4. 3
  5. ];

Creating Conventions using Meta Conventions

I’ve been working on [Cactus JS][] for a while now, and parts of it are finally available to the public! Now that other people might become interested in contributing, decisions have to be made about pretty much everything thinkable.

Coding conventions are what I’m thinking the most about right now. I follow very strict conventions when I code myself, and whenever there isn’t an existing convention I make one up. Since JavaScript is such a dynamic language, there are a lot of ways to do things. If the

PHP and Abstraction

I’ve been working with PHP lately. Certain circles have really been giving this language a beating for quite some time. When the uproar started (how over dramatically phrased of me) I was quick to join them. What are some of the arguments put forth? Here’s a few off the top of my head, it might be added that these really are true statements:

  • Inconsistencies in the STD library.
  • STD library bloat (“This perl function does what 13 PHP functions do!”)
  • Poor support for OOP.
  • It was called Personal Home Page, after all (I’m not sure if I’ve

Reflections on Prototypical Inheritance

JavaScript is an object-oriented language. It uses prototypical inheritance instead of the more common class based inheritance, but luckily it—being the flexible language it is—allows one to utilize both methods of inheritance. But why even allow for both when you usually work with class based models? Well, I can’t speak for the people responsible for making that decision, but I will give you some of my thoughts on the subject.

Now then, what is prototypical inheritance? Douglas Crockford described it so well when he tried to defend it

State and Proxy: Substitution Proxy

I was reading the State pattern in GoF and there was one issue they addressed that I think I have a better solution for.

A quick reminder if you don’t remember the pattern: Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. The example GoF gives is a TCPConnection class that is composed of a TCPState, the TCPstate will behave differently depending on the current state of the connection (such as throwing an exception if close() is called when the state is already

Syndicate content