Assumed Sorting or Assorted Assumptions?



  • A sensor sends some data via the network to a software where the data get visualized. Sometimes, a package of data may contain data of more than one timestamp (but that timestamp is part of each record).

    For visualization purposes, data must be added in the order of the timestamp (oldest first). David knew that and wrote:

     // oldest snippet first
     for (int i = _readResult.SnippetDatas.Count - 1; i >= 0; i--)
    

    Since the transport layer in between had some issues (David's code, well, ...), he built a new transport layer. But now the data arrived already in the required order - and his code re-ordered them the other way round.

    Comes Kevin, who was tasked with a cleanup. Bernie could point him to that line, and ask him to have a closer look at it. Kevin could fix eventually it (after Bernie had to show proof that the order was wrong in current context - a line of logging was enough for him to detect that, but Kevin...):

    foreach (ISnippetData<ushort, uint> snippetData in _readResult.SnippetDatas)
    

    It works. Now. With that specific context.
    And if someone would fix the old transport layer, or write a better one, or ...

    Well, it works NOW is all what is required for a smart software developer. He assumes that a current situation will always stay as it is and will never change. Why should he prepare for a different sort order?

    Could be as easy as this:

    foreach (ISnippetData<ushort, uint> snippetData in _readResult.SnippetDatas.OrderBy(_x => _x.TimeStamp))
    

    Of course, neither Kevin nor David like writing tests. There they would have to think about their assumptions...


Log in to reply