top | item 3773985

How not to write Python: Part 1 (Courtesy of Adobe)

40 points| linoox2424 | 14 years ago |voxel.dl.sourceforge.net | reply

15 comments

order
[+] mturmon|14 years ago|reply
The ugliest, deeply-nested part is just a machine-generated classification tree (e.g., http://en.wikipedia.org/wiki/Decision_tree_learning).

Notice how all the leaf nodes (ends of if/then branches) do only one thing: set isDirty to 0 or 1.

And, all the if/then conditions are just thresholds of one variable against a constant threshold.

The later part seems to be exceptions to the above tree. I've never heard of this, but it seems like what they used:

http://weka.sourceforge.net/doc/weka/classifiers/rules/Ridor...

[+] loeg|14 years ago|reply
"How not to write a HN headline"
[+] bri3d|14 years ago|reply
From the description of the project: "The tool was developed using models resultant from running the J48, J48 Graft, PART, and Ridor machine-learning algorithms on a dataset of approximately 100,000 malicious programs and 16,000 clean programs."

This is just machine-generated J48Graft code. Amusing, but not as terrible as it appears at first blush.

[+] dhconnelly|14 years ago|reply
Regarding the title of this submission: as demonstrated by the other comments here, it's good to have some context before you make snarky remarks about the work of others.
[+] evanmoran|14 years ago|reply
Automated code should be beautiful too. How can you debug what you generate if is so ugly? I would even say there is less of an excuse since 100% was written by you and you can easily rewrite all of it at once.
[+] emilv|14 years ago|reply
1) Use unit tests.

2) It isn't that ugly! If you know what the code is supposed to do (which should be clear from documentation or just the purpose of the program) and it fails in some cases, take that failing case and go through the if-else statements manually.

If this is machine-generated code the real program is the one outputting this script. The big machine-generated statements are just data from that program. That program may be much better structured.

[+] Rinzai|14 years ago|reply
Honestly, this looks like automatically generated code.
[+] pjscott|14 years ago|reply
Specifically, it looks like someone created a decision tree using Weka's J48graft class, then translated it automatically to Python code.
[+] jefe78|14 years ago|reply
Ouch...my brain hurt after reading parts of that. I believe it was generated code, but if not...that poor dev!
[+] th0ma5|14 years ago|reply
heh. this has to be some kind of output of a translator. if someone or some group was directed to make a file like this, we need a new name for design by committee :D
[+] cpcloud|14 years ago|reply
LOL. I sometimes wish I was able to write teh codez dis gud.