Ghost In The Machine

The big application I’ll be working on for my job will be extremely expansive and far too large and complex for all of the components to be embedded. To prepare for this, I started playing with the ModuleLoader class on Friday. I had a working understanding of it by the end of the day on Friday. My demo app wasn’t complete, but it was loading external modules into memory. I didn’t have time to continue experimenting until yesterday evening.

Instead of continuing with my tiny little playground app, I decided to start working on something a little more real world and expansive. My plan was to use Beau Scott’s example and re-write it my own way. That’s how I do a lot of my early learning of anything.  I went about writing up an example module and then went on to start writing the code to load it.

That’s when everything started getting weird.

My code wasn’t working. Surely, I just forgot to declare the var keyword (I can’t tell you how many times I forget to do that), or forgot an import statement or something. Everything seemed OK. I toggled back and forth comparing code against my original test file. Everything seemed fine. Nevertheless, I kept getting errors saying that moduleLoader.url was a read-only property. Huh? Double-checking the documentation, I confirmed that it was a read-write property – ignoring the fact that I had set the property in my original test file.

Knowing that I had a working example was what was confusing me the most. If I didn’t have any working code, I’d just chalk it up to my own bad code. I decided to copy and paste the working code into my new file. Surely, that would get me back on track. No. My working code suddenly no longer worked – but it continued working in my original test file.

At this point, I just went to bed – my mind racing trying to figure out what was wrong.

This morning, I made sure to clean the apps and rebuild them. No joy. That new file just wouldn’t work no matter what. I decided to copy the non-working code into a new file.

It worked.

I compared project settings. Nothing was different. My code was fine. There was nothing wrong with it. It seems that at some point, somehow, the Sunday night file just got corrupted.

I immediately flashed back to a JavaScript issue my friend Roger and I once ran into. It’s been so long (at least 10 years), that I no longer remember what we were working  on, but it didn’t work. A piece that we had done many times before just wasn’t working this time and we had no idea why.  After hours of chasing our tails, we decided to just re-write it. We re-wrote it word-for-word – and it worked. Now we were really confused. We set out comparing the code line by line – and discovered that the difference between them was a single extra white space character at the end of a line. But JavaScript isn’t white-space dependent, so surely that couldn’t be it, could it? We removed the extra space, saved and reloaded. It worked. We closed the files, and sought out beer.

You can leave a response, or trackback from your own site.

Leave a Reply