by tunesmith · 8y ago · 0 comments
Dog d = new Dog("fido"); d = alterDog(d);
public Dog alterDog(Dog d) { d.name="arfybark"; return d; }
It's not quite a pure function since it changes it in place, but at least the parameters and return types reflect the method. I ran across a term for this practice in the past but don't remember what it's called.
That syntax loosely implies that removing the second d assignment would allow me to create new-but-altered dogs with alterDog(Dog), which isn't the case. If I wanted to use assignments like that, I would try to go fully immutable with factory methods that help me make slightly different, new dogs on the fly, and return them.