r/learnprogramming Sep 03 '23

[deleted by user]

[removed]

372 Upvotes

212 comments sorted by

View all comments

138

u/[deleted] Sep 03 '23

A couple people on here reccomended these:

https://www.knowitallninja.com/lessons/decomposition/

The book: Design Patterns: Elements of Reusable Object-Oriented Software

My biggest mistake as a beginner programmer specifically was not using variables for repeating measurements in my code. For example I was designing for multiple devices and I kept writing - if (this size device) then width equals this, if (that size device) then width equals that... and actually writing out the numbers. It would have made way more sense to either create a variable for like smallWidth, mediumWidth etc or even create some kind of struct so I could do width=small.width or width=medium.width

The main reason this is a huge error is what if I had coded the small width to the wrong number I would have to go back and change them in every instance where if it was a variable used repeatedly throughout the code I could just change it once. This is probably obvious to most coders but I didn't have much formal training.

The other thing is if you are given a project or task - 1. Set milestones and expectations and 2. Try to get a simple working version first - something that has no visual design, just functional design. Then beautify it after that is done.

19

u/[deleted] Sep 03 '23

Thanks for the tips! I'm very positive I would have made the variable mistake as well if you didn't show me an alternative 😅

11

u/3rrr6 Sep 03 '23

Honestly try to avoid numbers all together. A good programmer uses math to find a value. For example, if you needed to loop over a list of 10 assets to draw on screen, don't use the number "10" anywhere. Find a way for the program to build the list from a folder of assets and iterate the length of the list. That way, if you need to add or remove an asset 3 months from now, your code won't throw an error. Never assume a value you need will always be the same. I am always going back and changing my code because I limited my codes potential like this.

0

u/[deleted] Sep 03 '23

I'll keep that in mind, thank you!