I suppose enough people would have named it valid token without thinking on it, that it can be hard to tell sometimes. I would agree though, the is prefix is a must.
Aside from throwing Exception instead of something more meaningful, this is perfectly common and fine.
void or throw is rather common for validation. I'd rather say that returning a boolean from a validation method is the least favorable way unless you are sure your validation checks exactly one constraint (e.g. implements javax.validation.ConstraintValidator), otherwise the validator will discard information that might be of interest to the caller (e.g. for determining the correct error code or message that is presented to the user).
44
u/mathimaz Sep 14 '21
I would throw a custom exception type instead of system.exception. But other than that, it's not an uncommon practice.
27
u/[deleted] Sep 14 '21
The function is called validateToken not isTokenValid
I don't know why would you expect it to return a boolean
10
u/missingdays Sep 14 '21
Real badcode here is the singleton implementation of the SessionDao
5
u/hurtl2305 Sep 14 '21
Aside from throwing
Exceptioninstead of something more meaningful, this is perfectly common and fine.void or throw is rather common for validation. I'd rather say that returning a boolean from a validation method is the least favorable way unless you are sure your validation checks exactly one constraint (e.g. implements
javax.validation.ConstraintValidator), otherwise the validator will discard information that might be of interest to the caller (e.g. for determining the correct error code or message that is presented to the user).5
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 14 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
4
u/AlFasGD Sep 14 '21
Exception-driven programming, an exceptional paradigm
1
u/[deleted] Sep 15 '21
I dont understand what is bad about this?