|
|
|
|
|
by jfoutz
3499 days ago
|
|
In this case, it's unfortunate that there's no, "will this name create a valid person object?" predicate. much much better to filter the names, then make the objects. In this case, as long as append is O(1), i think the imperative version has a big benefit, it avoids building the name size list of persons. If you've got a billion names and 2 valid person objects, the imperative version is a big win. Of course that predicate i mentioned is the right way to go though. I think the right way to do it is with a fold. But that's not built in, so hard to expect of novices. I see what you're saying about mutation, i guess i have a higher tolerance for mutating stuff that you have the only reference to. I'm not really sure doing a += [validPerson] is much of a win. (but i think would be the right answer in a fold) |
|
No "object" is made if the name can't create a "valid person object", it'll return a stack-allocated null/nothing value. That pattern is also much better for concurrency issues.
> much much better to filter the names, then make the objects.
You're just duplicating the validation logic (or worse, the "objects creation" assumes it's given valid names and does no checks)