Mountains

Mountains

Sunday, February 20, 2011

Algorithmic oddities

I don't consider myself an advanced programmer. I would actually call myself a hack. I use code, spit, duct tape, and periodically, jumper wires to do my job. Sadly, sitting around writing code really isn't what I'm paid to do. It's sort of an accessory to the crime.

(I get paid to make an impact...)

I'm working on a not-so-little javascript project to simply our data reporting process. I just found out you can reference variables before they're declared in javascript. The fancy word for that is hoisting. The pre-processor goes through the code and moves all the declarations to the beginning. I think this is the standard way things work... just sometimes (say, Fortran 77), you have to a) declare your variables first b) the pre-processor will often give up if it finds an unreferenced variable. However, it would make a little since to go through the program and figure out if the variable ever gets used first. Although, it will make your code a bit complex for mere mortals (like me) to read.

I feel about the same way as I did when i discovered what a coroutine is. (During a crash course in Lua...) Fun stuff.

Although, unlike coroutines, i do not understand why hoisting is particularly useful.

2 comments:

  1. Humm, I have had a situation like "I know that I want to set x to 7.3213763217 and add 3.14159 to it, but I don't yet know what type I should make it." Unless you want to obfuscate your code or encourage sloppy programming, I can't think of much use for hoisting. It sounds more like a "Because we can" feature. Which means it should be taken out and shot.

    Now if you mean hoisting in regards to a Squeak Cat, well, that is very useful.

    ReplyDelete
  2. Hoisting is freaking awesome if you're a crane.

    I think it's along the "because we can". It makes it so poorly written code will work. That said, by doing it, it discourages good programming. The interpreter should at least throw an caution statement saying that it had to reorganizing things for the reference to be coherent.

    ReplyDelete

Leave a message after the tone...