SLotD: Pushing the model

Software Lesson of the Day for 16/10/2024:

Sometimes you will try something and it works. And then you extend it a bit. And then a bit more. And it stops working and/or doing what you want.

Consider the possibility that the fact it initially worked was just a false signal, and that actually you should never have done it that way at all. Because the model or pattern for doing $thing$ is actually somewhat different — and whether you approve of that pattern or not, and whether you like deleting superficially working code or not, that’s the way you have to do it. Because we rarely write software nowadays without what we write having to fit into a more or less opinionated container. So make sure you actually understand the pattern, not simply what you want it to be.

(This post is brought to you by trying to implement an Android ViewPager with hard-coded child elements in the layout xml. No matter how hard you try, you can never defeat the PagerAdapter‘s beliefs about page instantiation and caching.)

West

“I was headed out down a long bone-white road, straight as a string  and smooth as glass and glittering and wavering in the heat and humming under the tires like a plucked nerve. I was doing seventy-five but I never seemed to catch up with the pool that seemed to be over the road just this side of the horizon. Then, after a while, the sun was in my eyes, for I was driving west. So I pulled the sun screen down and squinted and put the throttle to the floor. And kept on moving west. For West is where we all plan to go someday. It is where you go when the land gives out and the old-field pines encroach. It is where you go when you get the letter saying: ‘Flee, all is discovered.’ It is where you go when you look down at the blade in your hand and see the blood on it. It is where you go when you are told that you are a bubble on the tide of empire. It is where you go to grow up with the country. It is where you go to spend your old age. Or it is just where you go.”

— from All the King’s Men by Robert Penn Warren

SLotD: Serialise/Deserialise is Copy

Software Lesson of the Day for 2/12/2022. Rather than waste all that time writing a perfect universal .net object copy library that copes with every possible variation of nested reference types, value types, fields, properties, statics, and twenty-plus years of special cases and regret and technical debt baked into the framework… just serialise your damn source object to json and de-serialise it back out again. And then be on your way.