Home > geekery, python, wtf > Python: You’re Doing It Wrong

Python: You’re Doing It Wrong

November 25th, 2008

A coworker just showed me this little gem–a maintenance script that’s got no author attribution and isn’t in source control, so whoever has perpetrated this crime against all that’s good and holy remains anonymous and (for the moment) safe from our wrath. I’m so completely taken aback by this–I… I don’t know what to say. I just have to share.

#!/usr/bin/env python
import os,sys
C=os.chdir
S=os.system
M=os.mkdir
J=os.path.join
A=os.path.abspath
D=os.path.dirname
E=os.path.exists
W=sys.stdout.write
V=sys.argv
X=sys.exit
ERR=lambda m:W(m+"\n")
PRNT=lambda m:W(m+"\n")
assert len(V)==2,"you must provide a sandbox name"
SB=V[1]
H=A(D(__file__))
SBD=J(D(H),SB)
C(SBD)
PST=J(SBD,'bin/paster')
VAR=J(SBD,'var')
ETC=J(SBD,'etc')
S("mkdir -p "+VAR)
PRNT("restarting "+SB)
CMD=";".join(['source %s'%J(SBD,'bin/activate'),PST+" serve --daemon --pid-file=%s/sandbox.pid --log-file=%s/sandbox.log %s/sandbox.ini start"%(VAR,VAR,ETC)])
PRNT(CMD)
S(CMD)
PRNT("All done!")
X(0)

Weep for us.

Similar Posts:

geekery, python, wtf , , ,

  1. November 25th, 2008 at 12:49 | #1

    I wept, then wept some more. I wish for that code to rot in the deepest pit of /dev/null. It pains me, really.

  2. November 25th, 2008 at 13:07 | #2

    S=submit.to
    D=”The Daily WTF”
    U=URI
    L=”thedailywtf.com”
    N=now()
    S(D(U(L)),N)

    Okay, so not knowing Python, I made up the notation at the end. Still: do it!

  3. Robert
    November 25th, 2008 at 13:38 | #3

    All I can say is “wow”.

  4. November 25th, 2008 at 14:21 | #4

    That’s appalling. And now AM stock is down 3% ;)

    Seriously, though, I don’t think I’ve ever seen such bad python.

  5. November 25th, 2008 at 14:35 | #5

    I remember seeing some C code way back where the author had defined one capital letter macros for common things, like R for return, and so on. Maybe the same guy, but unfortunately I can’t remember what that C code was. Nevertheless, worthy of a submission to Daily WTF.

    #include <stdio.h>
    
    #define R(x) return(x)
    #define M main
    #define P printf
    
    int M(void) {
      P("Hello World!\n");
      R(0);
    }
    
  6. jesse noller
    November 25th, 2008 at 15:03 | #6

    Needs more lambdas!

  7. Brandon Corfman
    November 25th, 2008 at 16:39 | #7

    LOL. That really hit my funny bone.

    You can fix it with a little search and replace, but you would lose all the humor.

  8. November 25th, 2008 at 16:48 | #8

    I wish I could say it is mine, but it lacks my trademark style of putting blank lines between nearly every statement. Plus I would almost certainly arrange all those one-letter aliases to spell out something vulgar.

    I suspect one of the many fine temporary contractors wrote that code. You don’t write shit that awesome when you’re on salary.

  9. Nick Barendt
    November 25th, 2008 at 17:00 | #9

    Wait, that doesn’t qualify as a DSL? :-)

  10. Jay P
    November 25th, 2008 at 17:24 | #10

    You just broke my brain.

  11. MrDotOne
    November 25th, 2008 at 18:26 | #11

    Looks like Martin’s work ;-)

  12. November 25th, 2008 at 19:03 | #12

    Wow … I’m appalled and intrigued at the same time.

    Maybe this was created by some kind of Python code minimizer script, that somebody wrote in anticipation of the time when browsers will support Python natively? ;)

  13. November 25th, 2008 at 21:18 | #13

    prototype for Python obfuscator. Good!

  14. November 25th, 2008 at 23:25 | #14

    reminds me of an old joke:
    A: (complaining) Most Unix commands are cryptic 2- or 3-character commands
    B: That’s why I have 1-character aliases for the most common ones I use

    all I see is someone doing a little bit of creative aliasing. Even without knowing Python I can see that he’s not using the M “macro” anywhere, and “S” is only used once, so if you comment that out you know what he’s doing anyway.

    I did about 10 years of COBOL (both dev and maint) before switching to Perl, so I can understand the pain of gratutious verbosity.

    If I met this guy I’d shake him by the hand and buy him a beer.

    PS: Am I saying that just to piss off my pythonista friend who sent me this link? Only I and my shrink would know… :-)

  15. El Hack
    November 26th, 2008 at 05:18 | #15

    I have seen similar before in KSH.
    He(She) is doing it again in Python… ARRGH!

  16. November 26th, 2008 at 05:44 | #16

    It be better if you write new code and show how it should have been done.

  17. November 26th, 2008 at 14:59 | #17

    XD!!! Funny! It makes you want to ask “If you hate python so much, why code in it at all?”

  18. pv
    November 26th, 2008 at 17:26 | #18

    Hm. I think it’s the handiwork of a troll. :) Certainly it’s not a Python beginner. Consider that this fellow:

    1. understands functions and methods are first-class, and can be bound to a different name.

    2. knows about lambda.

    3. knows about assert.

    4. knows about __file__.

    Taking a step back, as others noted, it’s not like keystrokes are saved, since most aliases are used only one. On the other hand, actually spelling out something rude would be a touch obvious, gauche.

    Thanks for sharing, either way.

  19. Nathen
    November 30th, 2008 at 11:27 | #19

    I think it might be interesting to ponder what language this person normally thinks in, My guess is for COBOL or FORTRAN ( probably FORTRAN ).

  20. November 30th, 2008 at 14:08 | #20

    It looks like MUMPS

  21. StephenThorne
    December 1st, 2008 at 00:34 | #21

    Clearly this person is doing it wrong.

    S(“mkdir -p “+VAR)

    should be:

    M(VAR)

  22. Daniel
    January 5th, 2009 at 12:29 | #22

    Hey, it has a nice MUMPSish feeling to it!

  23. January 6th, 2009 at 22:16 | #23

    Clearly TRWTF is that he sends errors and normal output both to stdout, when he should be sending ERR to stderr… ;)

    D

  1. November 27th, 2008 at 02:38 | #1