Re:Why bad scientific code beats code following “best practi...
by tigershark on Sunday August 28, 2016 @05:44PM
(#12378696)
In my experience, in quite big projects, people had a tendency to mutate objects in the wrong place and in the wrong reasons.
A field encapsulated in a getter without setter certainly helps.
[ Parent
| on HN ]
Re:Why bad scientific code beats code following “best practi...
by qwertyuiop924 on Sunday August 28, 2016 @09:09PM
(#12379385)
But if it has to be able to be mutated in some cases, you're stuck. This is a place where Scheme's parameterize may be useful: Define a closure with the setter in scope, and write it so that when it's called with a lambda as an arg, it will raise an error unless those certain conditions are met, in which case, it will use parameterize to make the setter available in the lambda's scope. Or I suppose it could pass it in, which would be slightly simpler...
Re:Why bad scientific code beats code following “best practi...
by chopin on Sunday August 28, 2016 @05:59PM
(#12378740)
That would be a final field. But generally I agree with you and its by far the pattern I use most.
Re:Why bad scientific code beats code following “best practi...
by kuschku on Sunday August 28, 2016 @07:51PM
(#12379132)
The issue is, for example, if you have for example a class encapsulating a bunch of flags, and allowing the user to either set each flag seperately, or a bitfield representing all of it.
In C, you might be able to do some magic, but in Java, you’ll need setters and getters there – you can’t even do final fields there.
Luckily, in C#, you can just use accessors, and maybe in Java with Lombok, too.