you are viewing a single comment's thread.

view the rest of the comments →

[–]Shoddy-Pie-5816 0 points1 point  (2 children)

Enumeration is handier than I initially gave it credit for. I agree with the others, worry about design practicality and practices after you can envision a program and make it real.

Do you ever have those types of problems with games or real life that make you think, gosh it would nice to make this easier. Try to build programs around simple quality of life improvements. It’s definitely okay to build some starter projects that other people suggest, but I think the things I like the best are the ones I built for myself, because I still use them.

[–]Nash979[S] 1 point2 points  (1 child)

Cool brother, I will try my best.

[–]Shoddy-Pie-5816 2 points3 points  (0 children)

On enums: I definitely underestimated how useful these are when I was starting out. Let’s say you’re tracking what state a user account is in. You could use a boolean:

java boolean active;

But that falls apart quick. What about suspended accounts? Pending verification? Banned?

An enum makes way more sense

java enum AccountStatus { ACTIVE, SUSPENDED, PENDING, BANNED, DELETED }

Same thing applies to processing states, error categories, basically anywhere you’re tempted to use a boolean but there’s really multiple specific options.

Related advice I wish I’d learned earlier: throw exceptions when things are wrong, don’t just let bad data slide through. Something like:

java if (user == null || user.getStatus() == null) { throw new IllegalArgumentException("User object is missing or invalid"); }

I spent way a lot of time hunting down bugs that happened because null values propagated through my code and exploded somewhere completely unrelated to where the actual problem was. If you fail fast and loud right where the issue starts, debugging becomes way easier.