I’m a computer programmer. When we test programs, we often use a function called “assert” to check if the program produces the conditions we expect.

For example, this test will fail if the + produces an incorrect result:

assert( 2 + 3 ).equals(5)

Another meaning of “assert” in programming is “check, and take action, if necessary”. For instance, the procedure assertDataPresent() may check if the data has already been loaded. If it hasn’t, the function would try to do so, so that in either case the data is present after the procedure is executed.

Which of these meanings is the more common one in regular English? Can “assert” even be used in these ways outside programming?

  • stravanasu@lemmy.caM
    link
    fedilink
    English
    arrow-up
    5
    ·
    edit-2
    1 year ago

    According to the Cambridge dictionary and to the Merriam-Webster dictionary, “assert” means “to say that something is certainly true”. The Oxford dictionary gives a similar definition among others:

    III. To declare, state.

    7 trans. To declare formally and distinctly, to state positively, aver, affirm.

    So to me it sounds strange to use it as “to check”. I haven’t seen a definition similar to “to check” in the three dictionaries above. I didn’t know it was used this way in programming.

    Edit: my understanding of the programming term was wrong, see other comments.

    • Skyhighatrist@lemmy.ca
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      1 year ago

      Assert is used in programming to test a condition and cause a crash if it fails. They are used for conditions that are unrecoverable and should never happen. Then you have unit test assertions as in the example op gave. Those fail if the asserted fact isn’t what you expected. The third way, as in the assertDataPresent() example, the implication is that whatever you are asserting must be true. Usually in a method like assertDataPresent() it will make certain that the data is present. i.e. it would add it if it wasn’t already there. That’s how I’ve mostly seen it used in programming. So under that usage, it is actually closer to the english definition, because it’s not just checking, it’s ensuring that after the assertion that whatever was being asserted is true.

      • stravanasu@lemmy.caM
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 year ago

        Thank you, I see, it isn’t just a check as I understood. Then the meaning does make sense.

  • Skyhighatrist@lemmy.ca
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    Your third example is the one that is closest to the English definition of assert. Used that way it’s not about the check, it’s about ensuring that whatever being asserted is true after the assertion.

    • galilette
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      1 year ago

      This. It’s about explicitly stating the assumptions that will be crucial to the rest of the proof/work/program/whatever, so there will be no misunderstanding going forward. In other words, defining the boundary of the problem to be considered.