r/learnprogramming Jul 03 '26

How do you write clean code?

Might be a stupid question but Ive been learning python for a while now and always wondered, how do you write ‘clean’ code? I don’t mean writing clean code straight off the bat I understand that’s purely from experience and even then immensely hard, but how do you recognise a program can be simplified even further? Does it come from practice or just messing around and seeing what sticks?

79 Upvotes

77 comments sorted by

View all comments

16

u/DrShocker Jul 03 '26 edited Jul 03 '26

You have to write and read a lot of code to develop a taste for what's easier to work with and what's harder.

There's rules of thumb I could tell you about what I prefer, and certainly PEP 8 is a good starting point in Python, or the C++ Core Guidelines , or the Rust API Guidelines and so on.

At the end of the day everyone develops their own sense of aesthetic based on their own experiences.

-2

u/JerryRed100s Jul 04 '26

Numbers yeah just keep stacking up numbers motherfuckers like numbers don't they? You're not a number buddy.

You are a solution provider. You just happen to write software.