Learn me a Haskell

Lately I’ve become interested in functional programming, and Haskell always felt like the thing I should learn, so this week I finally started reading  Learn You a Haskell. So far I’ve been through the first six chapters and they do a great job at indroducing many concepts.

Pattern matching got me hooked. I had read the Patterns chapter in the swift book, and a couple blog posts on the subject, but they always felt like little more than “switch with ranges”. After reading the pattern matching chapter in Learn You a Haskell, suddenly Patterns appeared much more useful, even in Swift.

And then I read some of the concepts around higher order functions, how all functions are curried, how trivial partial application is, and how concise and clear everything reads once you get past the syntax choices. My mind was blown time after time.

xwouu8g

One of those days…

I wake up early, ready to start the week with a fresh mind and debug that issue that drove me crazy on Friday. I pick up from were I left in Xcode, and hit run.

It slowly builds and installs the app on my iPad, then promptly shows the launch screen, then more launch screen. I try again, change some things, reconnect the iPad. One hour later I manage to run the app.

I set a few breakpoints in the debugger to figure out what’s going on. When I hit one, I inspect the call trace and Xcode crashes. Relaunch, debug, inspect, crash again. Repeat 3-4 times.

I yell at the screen, and decide to take a deep breath and walk for a bit to relax. I come back, five minutes later, to a dead mouse that doesn’t seem to work. I change the batteries, I try all the batteries in the house. I clean the contacts. It seems dead.

I try some of those tricks where you shut down your computer, press ctrl-option-shift-power and then start. Nothing. Also, my MacBook Pro won’t even start if the Thunderbolt Ethernet Adapter is plugged in.

I disconnect that, restart, and reconnect. I’m greeted by a couple dialogs asking for permissions, and an app wants to install an update. Nope, not now.

I give up on the Magic Mouse, and go back to the G500 which still works, although it sometimes double-clicks when you click.

I started working 4 hours ago, and so far I got nothing done, for reasons beyond my control.

Some days, I really hate technology.

Fuck Xcode

Two years ago, Brent Simmons introduced ded: a handy little alias to deal with Xcode quirks

alias ded='rm -rf ~/Library/Developer/Xcode/DerivedData'

It has been useful, but since recently it was not enough. Sometimes, Xcode will complain about not being able to use the simulator, even if it’s not running.

Screen Shot 2014-10-15 at 14.02.21

Or things will just fail randomly and often, leading to frustration and anger.

Eventually, ded was not enough, so here’s my replacement:

alias fuckxcode="pkill -9 -i 'ios simulator|xcode' && rm -rf ~/Library/Developer/Xcode/DerivedData && open http://www.calm.com/breathe"

And I’ll quote Brent again on Bugs:

In the old days, programmers spent hours and days and weeks working very hard, and sometimes brilliantly, on difficult things that no one had ever done before.

These days, programmers spend hours and days and weeks working very hard, and usually unsatisfactorily, on getting around bugs in their platform.

Impossible debugging

If your first reaction on witnessing a bug or seeing a bug report is “that’s impossible,” you are plainly wrong. Don’t waste a single neuron on the train of thought that begins “but that can’t happen” because quite clearly it can, and has.

From The Pragmatic Programmer

I should print that and hang it on my wall because some days one needs to be reminded there are no impossible bugs, even when things just don’t make any sense.

Programming sucks

I ran across this question on stack overflow while (still) trying to figure out date parsing. The summary:

Q: I’m trying to get an NSDate object that has 21:00 as the local time[…] The result is 0001-01-02 04:52:58 +0000

A: The problem is that railroad time wasn’t implemented until November 18, 1883. You’re neglecting to set a year so you’re getting a date before that. Prior to the implementation of railroad time, the US time zones weren’t exact hour differences from GMT. I’m not sure exactly what time zone Apple selects for you but whichever it was seems to have been adjusted by 7 minutes and 2 seconds upon the move to PST in 1883.

WTF

And it made me remember an article I read yesterday: Programming Sucks. If you’re not a programmer, you’ll get a glimpse of what it entails. If you are one, you’ll probably laugh. Go read it.