Well, I mean... regexis the type. I get that this code won't confuse anyone, but it's as type-named as string or bytes or num and as uninformative as data or object.
publicboolverifyPasswordFormat(stringpassword){// 2-7 lowercase chars, then 3-4 digitsreturnnewRegex(@"[a-z]{2,7}[1-9]{3,4}").IsMatch(password);}
the above is probably ideal in terms of readability, but if you have to for example hoist the Regex in a particular language to avoid recompilation, would this be a close second?
Some will say yes, because "it's good to declare things that do one job, and will be replaced rather than modified".
But personally, I'd end up with
// 2-7 lowercase chars, then 3-4 digitsstaticRegexpasswordRegex=newRegex(@"[a-z]{2,7}[1-9]{3,4}");publicboolverifyPasswordFormat(stringpassword){returnpasswordRegex.IsMatch(password);}
Yes, it has a type in its name. But in a wider scope like that it might be a boon and not a sin, as that still reflects its "role" in the code, and is not an implementation detail of how the role is accomplished. You could replace that with "Pattern" but I think that's purely harmful.
And of course I renamed the function.
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.
Well, I mean...
regex
is the type. I get that this code won't confuse anyone, but it's as type-named asstring
orbytes
ornum
and as uninformative asdata
orobject
.the above is probably ideal in terms of readability, but if you have to for example hoist the
Regex
in a particular language to avoid recompilation, would this be a close second?Some will say yes, because "it's good to declare things that do one job, and will be replaced rather than modified".
But personally, I'd end up with
Yes, it has a type in its name. But in a wider scope like that it might be a boon and not a sin, as that still reflects its "role" in the code, and is not an implementation detail of how the role is accomplished. You could replace that with "Pattern" but I think that's purely harmful.
And of course I renamed the function.