Other articles


  1. Is Android's New Build System Production Ready?

    We've been pretty psyched about Android Studio and Gradle ever since it's showcase at Google I/O 2013. Not giving it much thought we dived into when Android Studio was at version 0.2.+. And we backed off even faster. The solution was immature and painful to work with. Since then we've been watching the tooling evolve, but this time with much more skepticism.

    Know your rights, all three of them…

    When introducing automated builds into your workflow, there are at least three things that you can expect of your tools. In essence:

    • They should keep easy things easy, and make hard things possible. You should not be forced to write a custom module to copy files or modify classpath.
    • The builds should be fast, and repeatable.
    • Builds should work same way on developers' machines as they do on CI servers. In other words, the build script should be part of every developers workflow.

    When faced with a project consisting of an android library (which is an actual product), and a demo app (that allows our client to test the library) we decided to give Gradle and Android Studio a second chance.

    Batteries included (to some extent ...

    read more
  2. The fuss with metaclass

    Most of young Python ninjas just after entering the dojo learn that metaclasses are magic. And by magic I mean the good stuff: they spare you work, they spare you tedious configuration, they "just work", when someone gives them to you. With this in mind we happily use them to our benefits, and after some time questions start to arise, and one of them arises quite often: how the hell does all this stuff work?

    Lots of resources on the web state two things:

    • metaclasses are complicated
    • if you are wondering if metaclasses solve your problem, you probably should not use them

    Well, in my personal opinion, both of the above just prove how some crap repeated a lot can become a "common knowledge".

    Metaclasses are one of the simplest mechanisms of Python, and definately are much simpler than inheritance (which you probably consider quite intuitive, don't you?). Yet they should be sometimes avoided, but not due to their complexity, but because of subtle design flaws they can introduce. Want to find out more? Bare with me.

    What the hell is metaprogramming

    Againsit common opinion metaprogramming is posible in every language, dynamic ones just make it much simpler, and ...

    read more
  3. Learn You a Haskell Continued

    It's a long time since I started my work on translation of Learn You a Haskell for Great Good by Miran Lipovaca. And while it's still work in progress, the next chapter just got shipped!

    From Chapter 2 you can learn about types and typeclasses in Haskell. Pretty basic stuff, but definately worth reading if you're just starting the functional ride.

    The Table of contents currently looks like this:

    1. Introduction
    2. Starting Out
    3. Believe the Type

    Wow! Ten more to go!

    As always you are more than welcome to read, share, download and report errors (the more the better)!

    read more
  4. Testproofing your code

    Recently I've been playing quite a lot with Behave, a lovely and fresh BDD framework for Python. If you're looking for a really hype tool to mess around with end-to-end tests and user specs you should give it a try.

    Writing stories and acceptance tests would be super fun if there was no database, external APIs, and no "enviroment" that should be properly mocked out. Database trip times can be kept low by using in-memory SQLite, it's the http layer that becomes a real pain.

    Fortunately I've found a great HTTPretty library that monkey-patches Python's socket module keeping all requests made with popular HTTP libraries in strict isolation from the outside world.

    So far so good... You can monkey patch stuff, mess around with your configuration and keep your tests quite reliable, but why the hell is it so hard?

    Tested code vs Testable code

    It's broken until it's tested, isn't it? True, true, so let's look at some simple example:

    import uuid
    
    class Entity(object):
        """
        Super dull class that only has an id. And by
        accident it can be compared...
        """
    
        def __init__(self)
            self.entity_id = int(uuid.uuid4())
    
        def __cmp__ ...
    read more
  5. Parsing query parameters in rest framework

    It has always bothered me that you have to parse query parameters manually in django-rest-framework views, and there is no generic way to do it.

    The old way

    Basically I used to do it like this:

    class MyView(APIView):
        def get(request):
            count = request.QUERY_PARAMS.get('count', None)
            if count is None:
                return Response(status=status.HTTP_400_BAD_REQUEST)
            try:
                count = int(count)
            except ValueError:
                return Response(status=status.HTTP_400_BAD_REQUEST)
    
            # do your work
    

    This is the most tedious, repetetive and error prone method of parsing query params I can imagine, yet my code is liberally sprinkled with it. Why?

    We'll basically, for some weird reason I kept thinking: hmm... serializers? they're good for POST. After a brief talk with Tom Christie I kept scratching my head and thinking why I did not figure this out myself!

    Serializers are good for any dict

    And they are really well suited for parsing request.QUERY_PARAMS and they save you plenty of lines.

    The superb new way of doing this:

    class MyQueryParamsExpectations(serializers.Serializer)
        count = fields.IntegerField()
    
    class MyView(APIView):
        def get(request):
            qpe = MyQueryParamsExpectations(data=request.QUERY_PARAMS)
            if not qpe.is_valid():
                return Response(
                    data=qpe.errors,
                    status=status.HTTP_400_BAD_REQUEST
                )
            qp = qpe.object
    
            # do ...
    read more
  6. Managing Django settings the right way

    It all starts with SQLite and a single settings file. Managing this kind of configuration is a no brainer. Just drop your apps into your django project folder, update the settings file, grab a coke and enjoy your life. After a few weeks reality starts to kick in.

    The first thing you realize is that SQLite is so ridiculously forgiving that your tests pass on development machine but fail on staging and production boxes. This is a first lession learned, you start to use PostgreSQL whenever possible, even on development machines.

    Then comes the second problem. Django's idea of drop-in apps does not seem like the best idea anymore, and you start to use distribute to manage your applications, because it just seems cleaner to use the same tools for yours and third party tools.

    Then comes the menace of managing configuration.

    Who changed that setting?

    I strongly believe that the number of ideas on how to manage django settings files is even higher than the number of django devs. After a while of working with the framework I can honestly say that I've seen really ugly things and I've done things I'm not really proud ...

    read more
  7. Learn You a Haskell in Polish

    Yeah, that's right, the uber-awesome book Learn You a Haskell for Great Good by Miran Lipovaca just got itself a Polish translator.

    You can already grab the introduction and first chapter dealing with some basic stuff like function calls, lists and tuples. Feel free to proofread it as many times as you want and point as many mistakes as you wish (the more the better!).

    I expect to translate one chapter every 1-2 weeks, so check out for updates. I currently plan on translating 10 first chapters, because I feel like I need some more time to grasp monads, and other hight level stuff. No worries -- they're pretty much covered in the original version of the book.

    read more
  8. FlipIt!

    After reading Learn You A Haskell For Greater Good I kept asking myself a question: Is it possible to write an Android game in a functional manner, with minimum or no state?. While writing a stateless game model was a no-brainer I still cannot find an elegant way of performing nice transitions between states (such as animations). This is why the result is somewhat simple in means of graphic design, but still quite playable.

    Check it out at Google Play!

    read more

Page 1 / 2 »

blogroll

social