|
Accidentally obfuscated code
-
05-02-2008 11:14
|
|
-
worstje


- Joined on 05-02-2008
- Posts 2
|
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.
|
|
-
-
dlikhten


- Joined on 09-27-2007
- New York Citeyah
- Posts 669
|
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 EarthSSDS Bug: Program should not start up
|
|
-
-
The Real WTF


- Joined on 08-23-2006
- Posts 21
|
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.
|
|
-
-
The Real WTF


- Joined on 08-23-2006
- Posts 21
|
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.
|
|
-
-
worstje


- Joined on 05-02-2008
- Posts 2
|
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.
|
|
-
-
morbiuswilters


- Joined on 01-15-2008
- Cambridge, MA
- Posts 2,342
|
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.
|
|
-
-
Lingerance


- Joined on 07-24-2007
- Posts 834
|
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.
|
|
-
-
MasterPlanSoftware


- Joined on 11-10-2006
- Posts 20
|
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.
Yes, I have been banned. Thanks to all for a good time.
Tired of incompetent moderation? Wondering where all the clever discussion went? Try irc.slashnet.org #TDWTFMafia. We don't ban or kick and everyone is welcome.*
*Stupid people will be mocked mercilessly and encouraged to commit suicide, however.
|
|
-
-
SpComb


- Joined on 05-04-2006
- Posts 81
|
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): ...
|
|
-
-
Carnildo


- Joined on 03-30-2005
- Posts 593
|
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.
|
|
-
-
MasterPlanSoftware


- Joined on 11-10-2006
- Posts 20
|
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
Yes, I have been banned. Thanks to all for a good time.
Tired of incompetent moderation? Wondering where all the clever discussion went? Try irc.slashnet.org #TDWTFMafia. We don't ban or kick and everyone is welcome.*
*Stupid people will be mocked mercilessly and encouraged to commit suicide, however.
|
|
-
-
morbiuswilters


- Joined on 01-15-2008
- Cambridge, MA
- Posts 2,342
|
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.
|
|
-
-
dlikhten


- Joined on 09-27-2007
- New York Citeyah
- Posts 669
|
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 EarthSSDS Bug: Program should not start up
|
|
-
-
Cap'n Steve


- Joined on 09-07-2006
- Posts 456
|
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.
|
|
-
-
Eternal Density


- Joined on 03-25-2007
- Posts 283
|
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...
Legendary ThreadYes my avatar is a fictional character, get over it. (Before she chokes you with her mind.)
|
|
Page 1 of 1 (15 items)
|
|
|