this post was submitted on 21 Oct 2024
86 points (86.4% liked)
Programming
17538 readers
67 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Or
I would argue that the validate routines be their own classes; ie
UserInputValidator
,UserPasswordValidator
, etc. They should conform to a common interface with avalid()
method that throws when invalid. (I’m on mobile and typed enough already).“Self-documenting” does not mean “write less code”. In fact, it means the opposite; it means be more verbose. The trick is to find that happy balance where you write just enough code to make it clear what’s going on (that does not mean you write long identifier names (e.g.,
getUserByEmail(email)
vs.getUser(email)
or betterfetchUser(email)
).Be consistent:
get*
andset*
should be reserved for working on an instance of an objectis*
orhas*
for Boolean returnsfetchUser()
,validate()
,create()
UserService.createUser()
valid
vsisValid
const
unless you absolutely have to reassign its direct value; I.e., objects and arrays should beconst
unless you use the assignment operator after initializationif {}
statements. Short-circuiting is cutesy and all, but it makes code more complex to read.{}
to create small groups of related code. You’re not penalized for the white space because it gets compiled away anyway.There is so much more, but this should be a good primer.
Oof found the Java developer. No thanks.