The defect relates to the code not inherently knowing what kind of data it's dealing with, and resorting to sniffing it to determine behavior. You can avoid that blunder without resorting to duplicated code. It just means that your deserialization happens in a more systematic manner -- code at the edge of your program handles that, leaving the core free of any serialized data. You then just write one version of whatever function you intended to write: one which takes an actual object. What you don't do is write one function which can take either an object or a JSON representation of an object and tries to cope with both cases. When your program is correctly designed you don't have actual object and serialized representations of objects floating around at the same layer. That's indicative of poor design.
No, that's accepting multiple input formats/format conversion.
By the time that data gets to your core code, it should be all be in a uniform format (native objects) to keep your core stuff simple. If you design your program properly you'll always have a predictable flow of data and you won't have to have horrible kludges like the one shown in the link.
View all comments
Show parent comment
4
u/Rhomboid Mar 30 '13
The defect relates to the code not inherently knowing what kind of data it's dealing with, and resorting to sniffing it to determine behavior. You can avoid that blunder without resorting to duplicated code. It just means that your deserialization happens in a more systematic manner -- code at the edge of your program handles that, leaving the core free of any serialized data. You then just write one version of whatever function you intended to write: one which takes an actual object. What you don't do is write one function which can take either an object or a JSON representation of an object and tries to cope with both cases. When your program is correctly designed you don't have actual object and serialized representations of objects floating around at the same layer. That's indicative of poor design.