CoffeeScript gently reminds me that tabs are not spaces
I recently picked up Trevor Burnham’s CoffeeScript book. So far it’s a great introduction into CoffeeScript and also Node.js, two topics which I wanted to learn more about. I started running through the first examples to see them run. I downloaded the latest node.exe, and found a way to add the CoffeeScript module without NPM. I wrote up a simple test just to make sure it worked:
console.log "Hello World!"
I ran this command to run it:
node %coffee% test.coffee
That worked. Node gladly printed my string, passed through CoffeeScript. Of course there isn’t much that CoffeeScript is doing, but there were no errors.
My next step was to try the first full sample in the book. It’s a buildup of the larger app which the book is building up to. I use Notepad++ for most of my plain text editing. I typed in the code, saved it and ran it.
Error: In prompt.coffee, Parse error on line 14: Unexpected ‘POST_IF’
The function at line 14 looks like this:
promptForTile2 = ->
console.log "Please enter coordinates for the second tile."
inputCallback = (input) ->
if strToCoordinates input
console.log "Swapping tiles...done!"
promptForTile1()
Everything looked correct. I just didn’t get it. Googling for the ‘Unexpected POST_IF’ brings up that it’s a parsing error and most posts have to do with multi-line if statements. I didn’t think that was what I was running into here.
Or was I?
I read through the multi-line if posts and it dawned on me that maybe it was being more helpful then I thought. I went back though my code and re-counted the spaces just to make sure I was consistent. Turns out I wasn’t exactly. Notepad++ was helping me out my automatically starting the next line at the same indention level as the last line. The I ran into was that Notepad++ was inserting a tab instead of 4 spaces when the indention was 4 spaces or more. CoffeeScript didn’t like the tab to start the line after the if statement. It wants spaces, not tabs.
The fix was easy enough. Like all great apps, Notepad++ is flexible. I just had to turn off the option to automatically align the next line. After cleaning out the tabs and changing them to spaces, we were good to go.
Since I didn’t really find anything on Google I thought it might help someone else that runs into this. I’m pretty sure it the kind of thing that only us Windows users will run into, with all of our overly helpful tools.