One thing I noticed: Your version does not seem to allow for a length
check on a simple string. I believe the original did that, although I
have no idea why anyone would want to use this validation type for
that type of check, so perhaps it's best to leave it out in this
version.
Bob
> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/validatethis-dev/-/5u_iI_iSa50J.
> To post to this group, send email to validate...@googlegroups.com.
> To unsubscribe from this group, send email to
> validatethis-d...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/validatethis-dev?hl=en.
>
--
Bob Silverberg
www.silverwareconsulting.com
This sounds like a good idea to me!
- sent by a little green robot powered device
if (isSimpleValue(theVal)) {
if (listLen(theVal) gt 1) {
theSize = listLen(theVal);
} else if (listLen(theVal) lte 1) {
if (isRangeCheck) {
theSize = len(theVal);
} else {
theSize = 1;
}
}
If the simple string is not a list with more than one element, then
the length of the string itself is used as theSize. The extra logic
around isRangeCheck is something that doesn't make sense to me, and I
think we need to do away with, but the fact remains that there is some
logic in here to check the length of a string that isn't a list.
Having said that, I really do not see any reason to keep this in here,
as there are other validators to do that, and I don't think the length
of a string can really be considered to be a check of CollectionSize.
Adam, if you are reading this please feel free to chime in with the
logic behind this original version.
Thanks,
Bob
> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/validatethis-dev/-/rErP85bfLvsJ.
Imagine if you had a list of id's that looked like this: 8,9,10,11
When running that value, you would get a resulting theSize value of 4
However if first 3 items were removed from the list and it was now just: 11
Well then the resulting theSize value would be 2 which is the same as passing 10,11. That I think is a bug in itself.
As always if there is a valid reason for this behavior, I'm all ears.
-Greg
Cheers,
Bob
> --
> You received this message because you are subscribed to the Google Groups "ValidateThis-dev" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/validatethis-dev/-/wSVvBVk_DDgJ.
What do you think?
Bob
> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/validatethis-dev/-/BbA5aTexb4gJ.
I think I agree with both of you on the empty array/struct thing. It
really depends on the context and why you are asking the question.
I also agree that the current implementation of the logic can be
improved, but I'm not in favour of defactoring (if I can coin a term
which I've never heard before), i.e., taking code that has been
encapsulated in a method and breaking it out and repeating it all over
the place. That isn't the solution, imo.
The point of that code is to allow an SRV to have optionality - to
allow the rule to be ignored if the property has not been populated
and is not required. So maybe we need to think of a different way of
indicating that in the SRVs and also reconsider the actual
implementation. I envision some way of saying "hey, this SRV should
be optional if the property hasn't been populated" that we would put
right in the SRV, and then have it implemented in the base SRV. This
is basically what is being done now, expect that now it is done via a
call to shouldTest() in an if statement, so it's a bit difficult to
decipher. Having just written all that, I'm not sure it's actually so
terrible at all, but yes, it could be a bit easier to follow.
Because shouldTest() is in the base SRV, it is overridable, so if the
logic for a particular SRV needs to be different than the standard one
can always put a shouldTest() method in the SRV itself.
Regarding whether an empty array and empty struct should be considered
as having a value, as I said I think it comes down to context. Does
anyone want to volunteer to look through the existing SRVs and see
which ones can validly operate on an array or struct and then we can
evaluate it on a case by case basis?
Thanks,
Bob
> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/validatethis-dev/-/kssl-CrPUOEJ.