Get rid of "if obj.hasElement(field) then obj[field]" antipattern

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Server Programmability
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      This is an antipattern because it makes us go through the BSON object twice:

      if (obj.hasElement(elemName)) {
         elem = obj["elemName"]
         doStuff(elem);
      }
      

      Instead it should be:

      elem = obj["elemName"]
      if (!elem.eoo()) {
         doStuff(elem);
      }
      

      We do this in several places in our codebase, such as here, here, here, etc.

      While some of the examples I listed are not on the hot path, it would help if we got rid of this idiom altogether so that it stops spreading.

      See comments for more info.

              Assignee:
              Unassigned
              Reporter:
              Vishnu Kaushik
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated: