20150530

PaaS and static typing

I have mentioned Google App Engine - "Google App Engine is a Platform as a Service (PaaS) offering that lets you build and run applications on Google’s infrastructure."

You can build apps in Python, Java, PHP or Go. PHP sucks, Go is not that popular as the other three candidates, Java has a runtime penalty, and Python is a dynamic language.

What do I mean by runtime penalty? First, we need to know how GAE works: each time a client sends an HTTP request to the app server, an instance of the code is spawned to provide a response. For Python, this doesn't require a lot: just fire up the interpreter, interpret the script, and you are good. But for Java, this means you have to fire up the VM, and then run the Java code. The catch is, if there were no requests in the last 30 seconds, the VM shuts down, so next time it has to be started again. (Also, there is no way a free app could have a background process running indefinately. Task Queue and Cron is the closest you can have - or Background processes in the Module API, but I forgot why I ruled it out, and I'm lazy to check it again.)

In itself, this wouldn't be a big problem for my game, but combined with my hatred for Java, this is enought to not choose this. So this leaves my Python. I thought that maybe I just oversensitively annoyed by dynamic typing - it might not be that bad. I was wrong.

When I create a module in Haskell, the compiler spits out a thesis on why I should feel bad about myself - in the form of error messages, of course. Two points to mention: a) it is fast, b) if I fix those errors, I can be 90% sure my code works as it is intended. This is very different from working with Python: you write a syntactically correct code, and that's it - nobody's there to defend you from yourself, so you have to test everything in order to be sure that you will not shoot yourself in the foot. I usually write a few lines of Python code, then start the game, while watching the logs from Google App Engine Launcher, only to find my code just tried to call some method on the None object, because I forgot to check if the object is None. (Fore the record: there is no Null object in Haskell - if you want a Nullable type, you have Maybe - but it has to be said explicitly in the type signature (you use type signatures, right? RIGHT????), so when you work with a function that can have a Nullable object, you are aware of it, because the type checker makes sure. Bothersome in the short run, but you will thank for it every day after you wrote the script.)

I was patient with myself, kept telling "this is not so wrong, you just have to have discipline, and everything is good". Well, after years coding in Haskell, I have everything but discipline. It is so comfortable to know that there is a typechecker to cover my back that I'm happily rummaging through the codebase and creating a mess that I hope will work. (And I have the courage to call myself a "programmer".)

After a week, I gave up. I can't do it. I'm a lousy coder, I need my typechecker, I need my functional language, and I need my Haskell. So I'm now searching for something like GAE but for Haskell. I know that at FPCenter, I have a Haskell IDE on the cloud, and a free server that is ideal for testing, I just need to find some PaaS that is sized for my wallet. (I don't have $100 for a server at Amazon EC2.) I love GAE, but I hate the languages it lets me use.

On the bright side, I have learnt a lot from GAE: I learn how to use the NDB/Datastore, how to use the Tast Queue, how to use POST and GET requests, learnt about what the cron is good for, and I'm thankful for all of these.

No comments:

Post a Comment