3 ms·
I'm still left wondering whether the code is correct, in that an employee that is paid weekly does not require passing probation to get paid. Is that the correc
by drittich 3y ago
I'm still left wondering whether the code is correct, in that an employee that is paid weekly does not require passing probation to get paid. Is that the correct logic, or is it the (very common) error of forgetting an extra set of parentheses when using OR?
Given that there would probably be more complexity in the real code I would create separate functions expressing the rules for each employee type.
- xmcqdpt2 3y agoExactly. In a better programming language (like Java!) you could simply use sequential filter steps to avoid all those issues, employees .filter(has_passed_probation) .filter(...) .forEach(p -> run_payroll(p, p.salary)) In general I find those kind of examples useless because the real life version tend to be a lot more complex with dependencies all over the place. All the functions in the article are simple by comparison. In general I don't think it's always better to have six small functions split over four files that are required to do X instead of one 40 line function that has all the logic together.
- throw1234651234 3y agoHave fun troubleshooting that. Also, iirc Java just got this in Java 8. Far behind .NET, as usual ;)
- rufus_foreman 3y ago>> Java just got this in Java 8 "just" in this case means as of March 2014.
- klauserc 3y agoI worked on a big Java project where we had to do a lot of list/collection wrangling like that. I found that code using combinator chain/list comprehensions/Streams/LINQ/etc. was significantly less error prone than code with hand-written loops. And that was in a team mostly staffed with junior engineers :)
- xmcqdpt2 3y agoAlso my experience. The only issue is that it's a bit annoying with breakpoints sometimes.
- throw1234651234 3y agoI am not saying use it instead of loops, I am saying don't chain the filters/maps/whatever endlessly. Even if only for the sake of being able to add breakpoints like the other commenter said.
- xmcqdpt2 3y agoWell I picked Java as an example specifically because it is a pedestrian "getting things done" language. I don't do much Windows development.
- Scarblac 3y agoAlso, why does one need to pass probation to get paid? Surely you also get paid before that?
- meling 3y agoRelated to correctness, aren’t employees paid during a probation period?