September 22, 2005
Reusable Code, Encapsulable Complexity, and CSS
This week we started talking about building reusable code blocks: functions, classes, etc. One of the primary advantages of doing so is that you can make one change to one line of code, and have that change deployed everywhere throughout your program. For instance, if you have a Ball class that creates a green ball, and you have 30 instances of that green ball in your program, you can change the color of all the balls just by changing one line of code in the class definition.
It had never occurred to me until yesterday afternoon how, in this respect, stylesheets are able to do exactly the same thing. I can change the background color of every single page of my site by changing just one line of the CSS file.
I don't know if CSS was developed specifically for this one-to-many power, or if it was developed to be able to semantically divide the web form from content, but it struck me as an astonishing parallel between two things that really aren't very similar.
Maybe it's part of human nature that we inherently seek to optimize. Maybe our brains do this thing all the time where they store "masters" for different kinds of information and the brain is able to change its definition of the master once and every other memory we have that is related to that master is changed.
Yes, that actually sounds like it is a good description of the way we think. If I told you the sun is actually a disc, not a sphere, and that it was about 4 inches across and alwyas about 2 feet out of reach, you could change your definition of sun (if you believed me), and every memory you had of tanning on a beach would be affected, without having to go through all of those beach memories.
At least, I think that's what's going on.
Posted September 22, 2005 01:14 PM. Categories: Week 3 | Permalink
Trackback Pings
TrackBack URL for this entry:
http://itp.nyu.edu/~cf831/cgi-bin/mt/mt-tb.cgi/6
