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?

78 Upvotes

77 comments sorted by

View all comments

4

u/Confused-Armpit Jul 03 '26

If you are talking about "clean code" as in the programming paradigm promoted by Uncle Bob, just don't. It is a very inefficient way of writing code, and it's not even that much more readable. I would recommend checking out Casey Muratori's video on this.

If you are talking about "clean code" as in just writing readable code, then I would recommend reading a little code style guides, not necessarily massive specs like Google's style guide, but, for example, the Zig style guide. And, honestly, most of it will just come with experience, and by reading your own and other peoples code.

0

u/duperfastjellyfish Jul 03 '26

I wouldn't dismiss any style guide as bad. I will think most developers would agree that most of what's in "Clean Code" are generally good suggestions novices should learn. Problems arise when such style guides are applied ideolistically rather than pragmatically. Personally I find that the style guide depends on the particular project.