Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-12519

Fail-fast pattern for autogenerated getter/setter

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • Qt Creator 3.2.0-rc1
    • Qt Creator 3.1.1, Qt Creator 3.1.2, Qt Creator 3.2.0-beta1, Qt Creator 3.3.0-beta1
    • C/C++/Obj-C++ Support
    • None
    • 3a1f6f9ad78e53129b1fba8be8c644e9f1496e85

    Description

      Currently autogenerated code has the pattern:

      void setStuff(Stuff arg)
      {
          if (m_stuff != arg) {
              m_stuff = arg;
              emit stuffChanged(arg);
          }
      }
      

      Several people argument against this and prefer a fail-fast to avoid unnecesary nesting of brackets. So a pattern of:

      void setStuff(Stuff arg)
      {
          if (m_stuff == arg) 
              return;
      
          m_stuff = arg;
          emit stuffChanged(arg);
      
      }
      

      is cleaner and avoids unnecesary bracket nesting.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            erikv Erik Verbruggen
            desert Ariel Molina R.
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes