Adam and Jerod talk with Katrina Owen – Panelist on Ruby Rogues, Instructor at Jumpstart Lab and creator of Exercism.io, an open source platform for crowd-sourced code reviews on daily practice problems.
Now that the Mac App store is open, everyone is wondering what they can get away with. Apple has added some interesting restrictions that applications must be compiled with XCode. There are tons of languages for which this is not exactly normal, and so people have been curious to see what kinds of things will actually make it in. In particular, the Ruby community has been pretty excited about building apps with MacRuby, since it fits the bill.
Well, I just heard about another oddball case, and it’s been successful: Jinjing Wang created an application called ClippingDetector, and he’s made a GitHub repo showing how he did it. Now, this isn’t the code for the ClippingDetector app itself, it’s Apple’s famed Currency Converter example. However, it does show how to use XCode together with a custom Python script that makes all of the magic happen.
I’m excited to see all kinds of programming languages being used for desktop Mac development; while I enjoy Objective-C, sometimes it can be a bit unwieldy. It’s also cool to have a real, working example of something when you’re attempting to do something new and interesting.
Yes, you heard me right. Yesterday, the Snap framework had its 0.3 release. If you haven’t heard of Haskell before, you’re in for a treat.
I’ll try to keep this short. Haskell is a functional programming language. This makes it a bit different than the procedural or object oriented languages you’re probably used to. The syntax looks much more like math notation than code:
f :: Int -> Int f x = x + 1
This reads “f is a function that takes an Int and returns an Int, and f of x is equal to x + 1.” For more about Haskell, check out Haskell.org. I could talk forever about how interesting and different Haskell is.
Enough about that. Let’s get back to Snap. To install Snap, use
cabal, the Haskell package manager:
$ cabal install snap
Next, make a directory and create a project:
$ mkdir hello-snap $ cd hello-snap $ snap init
This gives you a directory with a
.cabal file and a source directory. Then try this:
$ cabal install $ hello-snap -p 8000 $ curl 'http://localhost:8000/'; echo
This’ll compile your website (yes, you read that correctly, Haskell is compiled), start a server on port 8000, and then request the homepage.
That’s all fine and dandy, but what’s the code look like? Well, if you look at the handler in
Site.hs, you’ll find this:
site :: Application () site = route [ ("/", index) , ("/echo/:stuff", echo) ] <|> fileServe "resources/static"
While the syntax may be foreign, you can get the gist of it: We route ‘/’ to index, and anything starting with ‘/echo/’ to an echo handler. Otherwise, serve a file from the
What about one of these handlers? Here’s the
echo :: Application () echo = do message <- decodedParam "stuff" heistLocal (bindString "message" message) $ render "echo" where decodedParam p = fromMaybe "" <$> getParam p
Don’t be scared! It’s easy. Repeat after me:
echo is an
Application. When it’s called, we first decode the “stuff” parameter and bind it to
message. We then use a Heist template and bind the “message” string inside to our
message we created from the parameter, passing that along and using it to render the “echo” template. Oh, and that
decodedParam method that we used to set up the
message earlier gets the parameter we asked for, (
p) and yields either it or an empty string. You can find a much more thorough explanation of this in the documentation, which is excellent.
So what’s new in v0.3? There are three big improvements, as far as I’m concerned:
- SSL support
- “Development Mode”, which means you don’t need to recompile your site every time you change your code. This is a big benefit to getting things done quickly.
- an extensions mechanism for writing reusable components.