Archive for December, 2010

Wish List

Sunday, December 26th, 2010

What follows is a general list of items I want. My friends and family can use it for birthdays and Christmases.
I’ll keep it up-to-date as I think of new things, or as I get them.

  1. Tim Minchin is a refreshing mix of comedy, intelligence, emotion, and offensiveness.
  2. I’d really love a 160-lumen 1-watt version of the flashlight I have now, but it seems nearly impossible to find something like that.
  3. Black liquorice! There are so many different kinds.
  4. Instruments, including violin, flute, and theremin. These can all be rather expensive, so I really don’t expect them. I’ve also got a thrifty flute for practicing, so that’s good enough for now.

Object Oriented Programming in JavaScript

Tuesday, December 14th, 2010

(From A Student View)

When an institute is teaching programming to new students, it’s a common theme to play around with Java before going on to other languages. It’s easy to learn, has all the Object-Oriented goodies instructors want, and is fairly ubiquitous.

With the current snafu that is Oracle circling around Java and all the rest of Sun’s old open-source projects, I decided I would try my hand at emulating those same principles using JavaScript; an open, simple, ubiquitous technology.

As it turns out, the resemblances end with those adjectives. JavaScript was never really meant to do the things we’re making it do now. It’s possible to do most things in most languages, but the verbosity of the code needed to perform a specific action tells you what it’s made to do, and what’s been tacked on as an after-thought.

So, from a student’s point of view, how does it matter which language they’re using? Which is easier to learn, or simpler?


  • Requires each class to be in its own file. It can be tedious, but it can also make it easier to manage.
  • Each file has one class. Each class has a constructor (sometimes overloaded), and zero or more methods. The structure is fairly simple.
  • Besides the keywords, not much is being used. If you don’t import anything, there are very few class names already taken.
  • It’s made to work with the console, or to display a GUI.
  • Inheritance is an important part of Java, and all you need is one keyword and the class name to inherit.


  • Everything can go everywhere, and the syntax can go different ways. This freedom can be devastating to those who are learning.
  • Objects are functions, and functions can go within functions, and what are closures, anyway? Where and how you create variables influence how you can access that variable later in the program (private, public, hidden, privileged, for either fields or functions).
  • The global scope is chock full of different classes and attributes and functions.
  • It’s not meant to do anything on its own. You have to teach students HTML and DOM manipulation at the same time, and programs have to output in HTML.
  • Inheritance is handled through the prototype chain, which has to be explicitly set after an object function is created. You have to set the prototype of that class to a new instance of the parent class, and then you have to set that prototype’s constructor back to the constructor of the current class (to ward off some edge cases).

I’ve made a sort of console window out of HTML. It overwrites the document.write(), prompt(), and confirm() methods to output to a <pre> element. The latter two also pause execution by opening an invisible modal dialogue that is closed when the Enter key is pressed, which enables synchronous user input.

It’s a cludge, but you can run any JS code in there that acts like a console Java program.

Later: GUIs.

In short, You can do Object-Oriented programming in JavaScript, but it’s not something you should be teaching students in their first semesters, and the complexity and power of it don’t lend well to simple instruction.

I’m going to keep playing around with this, to see if I can get something simpler out of it. I just got the ‘instanceof’ keyword working, so I can start chipping away at what I need to get a ‘true’ out of that.


Friday, December 3rd, 2010

I use Explorer to browse.

No, I’m not talking about the internet. Explorer.exe is the file browser that comes with Windows, and which manages your taskbar and other windows. If you’re a Windows user, you use it every day whenever you open a folder. Mac and Linux have their own file browsers, as do different operating systems on different CPU architectures.

Anyway, I’ve recently noticed that I browse differently than other people do. I open My Computer (or whichever folder on my desktop), then click through the folders leading to my destination. I know the file structure intimately, and can tell you where certain files are. When I get to the files I want (executables, text, web pages, program code, whatever), I execute them, view them, zip them, or open them in a program. Any time I’m working with files, I’ll be in that directory. Any time I want to move or copy files, I’ll have both directories open.

Lately, I’ve been helping students who focus on the programs themselves and use the ‘Open…’ dialogue to open files. It’s a completely different way of thinking that drives me silly, especially when they eventually need to browse through folders. Especially in crappier (i.e. Java-based) programs with a miserly Open dialogue that doesn’t let you copy or move files, or select more than one file,or right-click on files.

It’s just one of those differences that you never notice until you meet it.