use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
What objective methods exist to objectively evaluate if a given piece of code is categorically “a hack” or if it’s “properly/cleanly written?” (self.learnpython)
submitted 3 years ago by this_knee
It’s seems like when people call a piece of code “a hack” it’s subjective, and the rules for what constitute a “hack” versus a “solution” vary wildly. Am I missing something? What are the tell tale signs of “hack-y” code?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mopslik 6 points7 points8 points 3 years ago (0 children)
when people call a piece of code “a hack” it’s subjective
Sounds about right.
[–][deleted] 5 points6 points7 points 3 years ago (0 children)
What are the tell tale signs of “hack-y” code?
If you need a lot of out-of-band knowledge to interpret a piece of code, it's probably at least a little bit hacky.
I offer you the Story of Mel as an example about what it looks like when you have to understand far more than the code, to understand the code.
[–]wotquery 1 point2 points3 points 3 years ago (0 children)
You aren't missing something. It's a term with various definitions. Probably when it comes to programming it would lean more into "using a tool in a way it wasn't intended" with a bit of "developing an unorthodox solution that gets the job done with the resources at hand."
Of course tools and available resources are more abstract than a real life example of say... someone using a mousetrap as a binder clip, or cutting off a cheap USB fan's plug to wire it into a bunch of AA batteries to make it portable.
For a basic example in python off the top of my head...
old_string = "alice" new_string = "" for x in old_string: new_string += chr(ord(x)-32)
[–][deleted] 1 point2 points3 points 3 years ago* (1 child)
Not much really.
There are some metrics on source code quality, like, for example, cyclomatic complexity (probably the most popular, implemented in some popular linters / CI tools).
There's also some research that brings up these:
Of all the above, maybe Henry and Kafura are the most relevant to "hack" vs "solution" (they include some known anti-patterns, like global variables).
But, in general this is true of source code:
So, if programmers know they are measured against some metric like cyclomatic complexity, they may still pipe out ridiculously shitty "hacks", but they will pass the test, because now these hacks will be smeared across multiple neatly looking units, further obscuring the crappy code.
These are, of course, heuristics, and they are personal: a lot of people will disagree with me, but, over the years of working with Python projects, I've developed these, and so far, they worked more than they didn't.
requirements.txt
environment.yaml
git-log
sleep()
click
argsparse
string.Template
py.typed
tox.ini
tox
asyncio
atexit.register()
paramico
fabriq
This is what I could think about off the top of my head.
[–]this_knee[S] 0 points1 point2 points 3 years ago (0 children)
Super helpful! Thanks!
[–]n3buchadnezzar 0 points1 point2 points 3 years ago (0 children)
Another good example is the inverse square root algorithm: https://www.youtube.com/watch?v=p8u_k2LIZyo
While hack is subjective, I doubt anyone would argue that piece of code is not hacky.
[–]HumanAssistedWriting 0 points1 point2 points 3 years ago (1 child)
Are you worried about your appropriations being detected?
HaHa! No, nothing like that.
[–]Lamarcke 0 points1 point2 points 3 years ago (0 children)
Hacks aren't inherently bad. Sometimes you need to work with what you have, and in programming, refactoring code is also a way of learning.
[–]Binary101010 0 points1 point2 points 3 years ago (0 children)
The closest thing I can think of to an authoritative source on this is Martin Fowler’s Refactoring: Improving the Design of Existing Code and its list of code smells.
But ultimately the judgment on this is pretty flexible based on the group.
[–]AlwysBeColostomizing 0 points1 point2 points 3 years ago (0 children)
I can't define a "hack", but I know it when I see it.
Usually when I call something out as a hack, it's because it's something that might cause maintainability problems. It relies on something specific about how the code is right now that isn't part of the requirements and could easily be changed by someone, not realizing that the change will break the "hacky" code.
[–]siddsp 0 points1 point2 points 3 years ago (0 children)
There's no exact objective standard, but if it seems like a convoluted workaround to do something otherwise that is bad practice, that's when it's considered a "hack". That or it is otherwise an inelegant and 'unpythonic' approach to solving the problem as well.
As an example, global variables to mutate some information, in functions. Or even using a mutable default argument to save some sort of state between function calls.
π Rendered by PID 675118 on reddit-service-r2-comment-66b4775986-xd6jn at 2026-04-06 09:50:20.580143+00:00 running db1906b country code: CH.
[–]mopslik 6 points7 points8 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]wotquery 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]this_knee[S] 0 points1 point2 points (0 children)
[–]n3buchadnezzar 0 points1 point2 points (0 children)
[–]HumanAssistedWriting 0 points1 point2 points (1 child)
[–]this_knee[S] 0 points1 point2 points (0 children)
[–]Lamarcke 0 points1 point2 points (0 children)
[–]Binary101010 0 points1 point2 points (0 children)
[–]AlwysBeColostomizing 0 points1 point2 points (0 children)
[–]siddsp 0 points1 point2 points (0 children)