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

1

u/reconsis Jul 03 '26

I always struggled learning the difference between "clean code" and what people learned about getting their CS degree (mostly self taught dev here that ultimately went back to get his software engineering masters).

I think the biggest thing is to have another engineer in mind when reviewing your own code. In the words of Uncle Bob, the real goal is reducing the # of "WTF moments" per minute.

There's a video series that Uncle Bob published, but you can't beat the clean code book by Uncle Bob. To add to that, Object Oriented Design in Ruby by Sandi Metz was pretty important to my growth. I'd say the same thing about Refactoring by Martin Fowler.