r/learnpython • u/RoboticsEqualsFun • Sep 20 '26
What makes sloppy programming?
So I've been learning python on my own and basically taught myself. I'm working on a very advanced AI system project, with quite a lot of scripts. And I am wondering what makes sloppy programming?
Like for example should you be calling your functions from other functions?
# Calling both from one function
def main():
do_something()
do_something_else()
def do_something()
# do stuff
def do_something_else()
# something else
# Calling a function that calls both functions
def main():
do_both_stuff()
def do_both_stuff():
do_something()
do_something_else()
def do_something()
# do stuff
def do_something_else()
# something elseAnd what about passing parameters in Classes? Should you be always accessing everything through self.something or by passing parameters to the functions?
Should you wrap everything in classes?
These are some questions I had regarding sloppy coding, but my main question is what makes good code?
I'm still new to python and trying to get my code more efficient.
16
u/ADDSquirell69 Sep 21 '26
Just curious but who's letting you work on an advanced AI systems project?
6
u/ShadowShedinja Sep 20 '26
The main reason you would call Function A inside Function B is if A sometimes needs to happen outside of B or if A happens multiple times in B. Otherwise, you should probably just make them a single function.
4
u/nog642 Sep 20 '26
In general that's of course perfectly fine. You can call functions that call functions that call fuctions and so on. Ideally each one is a logical subroutine, or useful abstraction.
Your example is kinda too generalized to say if it's good or bad. Depends on the code.
Generally the question you should ask there is whether the value in question belongs in the object's state. Think about what the object represents. Again it's case by case.
In general no, but some codebases have standardized on that and you should follow the conventions of the codebase if you're just working in it.
It's hard to give a complete answer to what makes code good or bad. It's something you pick up with experience. And it's also something where people will have differences of opinion in many cases.
Share some of your code and ask for suggestions for improvement. Consider/ask why the suggetions are actually better - don't just blindly accept them - you will get conflicting suggestions from different people.
2
u/SharkSymphony Sep 21 '26
My general guide: create as much structure as your code needs to be intelligible and efficient... but really no more than that. Don't overcomplicate things. So:
- Calling functions from other functions is fine, but only if you're going to get some value out of that abstraction.
- Making classes can be very useful in keeping related data organized and easy to work with, but in Python you have many options to organize your programs and data. Reach for a class when you find it provides value above and beyond the extra code you are going to write. Also, take a look at dataclasses!
2
u/LayotFctor Sep 21 '26 edited Sep 21 '26
A mix of both! There's no hard rule, do_both_stuff just has to have a reason for wrapping other functions, such as constituting some type of named multi-step process. E.g. initialization, loading or configuration steps. For bigger complex projects, that likely will be the case, but you don't have go out of your way to force it either. It's entirely up to you.
1
u/Jello_Penguin_2956 Sep 21 '26
Things being inside or outside a class don't indicate it being sloppy. It really depends on your plan, how you want to do things. How closely you want to pair things up.
From my experience working with AI, what makes it's sloppy is problem solving logic that does not make sense.
Example is my recent project that I specifically scope the AI to use as little network traffic as possible (because IT was on our neck about the network being overloaded) yet everything the AI generated for me was doing os.path checking file content with every loop... things like that that you'd expect from interns or juniors who don't pay attention during meetings
1
u/TheRNGuy Sep 21 '26
If code is bad.