Pages

Thursday, October 14, 2010

Code obfuscation

From http://twitter.com/cedrickrier/status/27248865483

dict = {}
        for object in result:
            k2 = {}
            for id,fnct in result[object].items():
                k2.setdefault(tuple(fnct), [])
                k2[tuple(fnct)].append(id)
            for fnct,id in k2.items():
                dict.setdefault(fncts[fnct[0]][4],[])
                dict[fncts[fnct[0]][4]].append((fncts[fnct[0]][4],object,id,map(lambda x: fncts[x][1], fnct)))

http://bazaar.launchpad.net/~openerp/openobject-server/trunk/annotate/head:/bin/osv/orm.py#L3777

Code obfuscation...

6 comments:

  1. Hi,

    Could you comment this code ?

    http://pastie.org/1222060

    Thanks

    ReplyDelete
  2. Better but 80 cols but naturally OpenERP doesn't respect it... But better...

    ReplyDelete
  3. The OpenERP Developer: I'm one of those developers who does not like the 80 cols limit:
    - With 19:10 >19" monitors becoming more popular each day, a lot more than 80 columns per line fit on screen.
    - 80 columns per line is fine if you use a language that only allows you 8 characters per name, but on modern languages you may have "self-describing" names like "account_move_facade" or "customer_manager_proxy.change_password()", that use a lot of space.

    So, for me breaking the 80 cols per line is better than having obfuscated hard to read code :)

    Anyway, as you stated: There is still a lot of obfuscated code in OpenERP that needs some refactoring (like Stephane just did) and comments, lots of comments.

    ReplyDelete
  4. Agree with NeoPlus about the rule of 80 columns.

    About the code and the refactoring, we make some improvements but it's hard because we don't have time but a merge proposal is welcome.

    ReplyDelete
  5. I am in favor of the 80 cols limit beacause it forces you to write concise and thus understandable code. The example you're giving has a len() of 40 and should probably be on its own line.

    ReplyDelete
  6. For me <80 columns are very well for Python code because of:
    * Copy fits into email without line break
    * Can have three editor windows in a row
    * Can code on a terminal without X
    * Avoiding JAVA-Style in Python

    For XML I prefer <120 columns if needed, but trying to keep the <80 if possible.

    ReplyDelete