Here is a little example of code I’ve been faced with (not written by me), that struck me. Although the syntax is correct (it is javascript), it took me a little while to actually understand what is going on.
Here is the code:
someObject: function(data) { return data.json ? data.json.stateObject ? data.json.stateObject : {} : {}; },
And here is how I refactored it.
someObject: function(data) { if (data.json) { if (data.json.stateObject) { return data.json.stateObject; } } return {}; }
So I mentioned brianpower in a while ago. Michael Feathers though calls such a thing “forming a mental model“. Which is exactly what I meant. You also hear this in the scene of Usability; the less your mental model matches with the actual object you use (expectations), the less likely you’ll probably understand it, let alone *use it*.
So tell me, which one is easier to understand? And how much impact do you think this has?