The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Accidentally obfuscated code

Last post 05-05-2008 8:43 PM by Eternal Density. 14 replies.
Page 1 of 1 (15 items)
Sort Posts: Previous Next
  • 05-02-2008 11:14 AM

    Accidentally obfuscated code

    Code is as follows:

    interpretedData={'location 1':{},'location 2':{},'location 3':{},'location 4':{},'location 5':{},'location 6':{}}
    
    # interpretedData gets further initialized elsewhere.
    
    
    # SetData is called with one parameter (data) by a C++ application.
    def SetData(data, d_list=interpretedData):
        # data[0] is the name
        # data[1] is the location
        # data[2] is the amount left
        d_list[str(data[1])][str(data[0])]=str(data[2])
        interpretedData=d_list
        global interpretedData
    

    I ran into this gem today. It's a wonderful mindfuck, that took me a few minutes of staring before I realized why it worked in the way that it did work. I'll leave the simplified SetData() function as an exercise for all your entertainment. :)

    A cookie for the person who explains why it essentially is a double mindfuck.

    Filed under: , , ,
  • 05-02-2008 11:48 AM In reply to

    • dlikhten
    • Top 25 Contributor
    • Joined on 09-27-2007
    • New York Citeyah
    • Posts 670

    Re: Accidentally obfuscated code

    interperetedData is set to d_list which is already interperetedData?

    It unnecessarily does not have 3 paramaters, instead of having a f-ed up way to pass an array. The data needs to be cast to a string, is it not a string, is it arbitrary?

    data[1] is a constant "location" data[0] is an integer with a space prefix?

     

    Code is like a box of chocolates. You never know who stuck a turd in there and why.
    The Stupidest Man On Earth
    SSDS Bug: Program should not start up
  • 05-02-2008 11:51 AM In reply to

    Re: Accidentally obfuscated code

    The global statement being after the assignment is a mistake, and Python will warn you of this, like so:

    <stdin>:8: SyntaxWarning: name 'interpretedData' is assigned to before global declaration

    If interpretedData is never assigned to a different object and the d_list argument is *really* never used, then it can be simplified to this:

    def SetData(data):
    interpretedData[str(data[1])][str(data[0])]=str(data[2])
    Otherwise, you can't make any other changes without modifying its behavior.
  • 05-02-2008 11:59 AM In reply to

    Re: Accidentally obfuscated code

    FUCKING EDIT TIME LIMITS

    Let's just pretend the forum software isn't utter shit, and this is what my post says now:

    The Real WTF:

    The global statement being after the assignment is a mistake, and Python will warn you of this, like so:

    <stdin>:8: SyntaxWarning: name 'interpretedData' is assigned to before global declaration

    If the d_list argument is *really* never used, then it can be simplified to this:

    def SetData(data):
    interpretedData[str(data[1])][str(data[0])]=str(data[2])
    Otherwise, you can't make any other changes without modifying its behavior.
  • 05-02-2008 12:16 PM In reply to

    Re: Accidentally obfuscated code

    Funny, I thought I knew that about global and was pretty sure it had to be right after the def, but couldn't find it in the docs (docs say 'has to be in same code block') so I left it where it was. I merely changed some variable names around. 'The Real WTF' indeed gave the correct simplification.

    About the meaning of the indices [0..2], they don't really matter too much. I'm not sure why I left those comments in... extra obfuscation perhaps. The actual code isn't mine, and while the use of str() isn't the wtf, the person who wrote it both misunderstood assignments as well as a common problem with default parameters in Python. I'd hope I won't have to explain -how- they were misunderstood.. and at the same time actually managed to produce working code.

  • 05-02-2008 12:27 PM In reply to

    Re: Accidentally obfuscated code

    The Real WTF:

    FUCKING EDIT TIME LIMITS

    Let's just pretend the forum software isn't utter shit, and this is what my post says now:

     

    Some of us just proofread our posts before we click submit.  Not dlikhten, but some of us.  If it were up to me, there'd be no edit ability at all and people might actually stop to think before they posted.

    < pstorer> Bans don't mean shit on the forum. It's like being on the Sex Offender List. You can still entice kids into your van with candy.

    Want more? Go the IRC channel #TDWTFMafia on irc.slashnet.org.
  • 05-02-2008 12:38 PM In reply to

    Re: Accidentally obfuscated code

    morbiuswilters:
    If it were up to me, there'd be no edit ability at all and people might actually stop to think before they posted.
    A better system would force people to use preview by only having the post button showup on the preview page.
    irc://irc.slashnet.org/#TDWTF
    [12:15:49] <Duplication_Prevention_Bot> Human test subjects are illegal! I didn't sign an EULA for this.


  • 05-02-2008 12:42 PM In reply to

    Re: Accidentally obfuscated code

    Lingerance:
    A better system would force people to use preview by only having the post button showup on the preview page.
     

    Except that would penalize those of us who actually read before we post.

    I prefer questioning the intelligence of people who post dlikhten-speak. Much more fun.

    Filed under:
  • 05-02-2008 7:54 PM In reply to

    Re: Accidentally obfuscated code

    dlikhten:
    It unnecessarily does not have 3 paramaters, instead of having a f-ed up way to pass an array.
     

        def SetData((data_name, data_location, data_amount_left), d_list=interpretedData):
    ...
    Filed under:
  • 05-05-2008 2:23 PM In reply to

    Re: Accidentally obfuscated code

    Lingerance:
    morbiuswilters:
    If it were up to me, there'd be no edit ability at all and people might actually stop to think before they posted.
    A better system would force people to use preview by only having the post button showup on the preview page.
    Clicking the "Preview" tab on some versions of Safari not only fails to actually show a preview, but totally disables the "reply" page. I wouldn't be surprised to find that this is the case in other browsers as well.
  • 05-05-2008 2:26 PM In reply to

    Re: Accidentally obfuscated code

     

    Carnildo:
    Clicking the "Preview" tab on some versions of Safari not only fails to actually show a preview, but totally disables the "reply" page. I wouldn't be surprised to find that this is the case in other browsers as well.

    Works fine. FF3b5

    Filed under:
  • 05-05-2008 2:52 PM In reply to

    Re: Accidentally obfuscated code

    Carnildo:
    Clicking the "Preview" tab on some versions of Safari not only fails to actually show a preview, but totally disables the "reply" page. I wouldn't be surprised to find that this is the case in other browsers as well.

    Safari?  Really??  Why aren't you using a real browser like FF?  You might as well complain that your solar calculator can't make phone calls.

    < pstorer> Bans don't mean shit on the forum. It's like being on the Sex Offender List. You can still entice kids into your van with candy.

    Want more? Go the IRC channel #TDWTFMafia on irc.slashnet.org.
  • 05-05-2008 3:54 PM In reply to

    • dlikhten
    • Top 25 Contributor
    • Joined on 09-27-2007
    • New York Citeyah
    • Posts 670

    Re: Accidentally obfuscated code

    morbiuswilters:

    Carnildo:
    Clicking the "Preview" tab on some versions of Safari not only fails to actually show a preview, but totally disables the "reply" page. I wouldn't be surprised to find that this is the case in other browsers as well.

    Safari?  Really??  Why aren't you using a real browser like FF?  You might as well complain that your solar calculator can't make phone calls.

     

    I do, but noone listens.

    Code is like a box of chocolates. You never know who stuck a turd in there and why.
    The Stupidest Man On Earth
    SSDS Bug: Program should not start up
  • 05-05-2008 3:55 PM In reply to

    Re: Accidentally obfuscated code

    Yep, I remember back before the upgrade when everyone was afraid to preview because it usually didn't let you post afterward.
  • 05-05-2008 8:43 PM In reply to

    Re: Accidentally obfuscated code

    dlikhten:
    I do, but noone listens.
    Oh!  So that's why my calculator has been making weird noises for the last few years...

    300 posts! This is Spar... dang I just lost the game.
    Legendary Thread
    lolwtf: Instead of comfy chair, package contained bobcat. Would not buy again.
    curtmack: It's like Godwin's Law, but instead of Hitler it's xkcd references.
    morbiuswilters: Right, but the Holocaust wasn't nearly as bad as xkcd.
Page 1 of 1 (15 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems