Naming wise, I like the second one. But if it was purely my choice I would not make a function to name in the first place and have the constructor do the validation during instantiation.
For high level objects that take arbitrary input, like an Email or URL, yes. Other things it's not always necessary because the type system ensures everything else is in order
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Naming wise, I like the second one. But if it was purely my choice I would not make a function to name in the first place and have the constructor do the validation during instantiation.
Does this mean that you will have to create a class and do validation in the constructor for everything in your code that needs validation?
For high level objects that take arbitrary input, like an Email or URL, yes. Other things it's not always necessary because the type system ensures everything else is in order