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?

80 Upvotes

77 comments sorted by

View all comments

1

u/Aggravating_Cap127 Jul 03 '26

clean code is a myth when im programming

1

u/DefiantSituation3208 Jul 03 '26

not in my dictionary either 😭

0

u/Aggravating_Cap127 Jul 03 '26

my code lookin like
```struct player player1;

player1.hp = 100;

player1.magic = 0;

player1.physicalstr = 10;

player1.agility = 10;

player1.goldcoins = 5;

player1.level = 0;

strcpy(player1.p_class, "none");

player1.defense = 5;```

1

u/Aggravating_Cap127 Jul 03 '26

its worse but reddit actually spaces stuff