31

Is the term "iff" (as an abbreviation in "If and only if") commonly understood, when used in software documentation? I thought so, but recently a colleague had not heard about it so I am wondering if I should avoid this term or if I could assume that the general programmer knows it.

Example:

This function returns True iff the value of foo is larger than bar.

I decided to ask here instead of at english.stackexchange.com, because the target audience are programmers.

29
  • 35
    I have nothing against abbreviations, but in this case it is quite easy to miss the double f. I don't think it is practical, and I wouldn't recommend it.
    – freakish
    Commented Nov 18 at 9:25
  • 33
    I this day and age, my first thought would be that it's a typo. Commented Nov 18 at 10:45
  • 24
    @MetalMikester the first word in your comment shows why your thought is right on spot :-) Commented Nov 18 at 12:25
  • 15
    Assuming your function always returns a boolean, you should simplify to "The function returns whether the value of foo is larger than bar.".
    – Bergi
    Commented Nov 18 at 19:34
  • 11
    I have been a professional mathematician for decades, and I prefer writing/reading “if and only if” to “iff”. Shorter doesn't always mean better. Commented Nov 18 at 21:53

15 Answers 15

36

As you noticed, your colleague wasn't familiar with the term, so you can't assume that everybody (or even every software developer) knows it.

I would probably avoid using the term, mostly for two reasons:

  1. this one (not everyone may be familiar, and documentation language should be quickly understandable)
  2. it has a slightly elitist smell to it (this is probably just my personal perception, as I only encountered it in academic contexts)

Using precise language is a good thing, but some verbosity doesn't hurt :-)

16
  • 55
    Reason #3: it looks like a typo. Seriously.
    – Doc Brown
    Commented Nov 18 at 12:02
  • 23
    FWIW I do suspect your reason #2 is just your personal perception, and is not widely shared enough to make it an important reason to avoid using "iff". It's no more elitist than math itself is elitist.
    – David Z
    Commented Nov 18 at 17:28
  • 6
    @DocBrown I recall reading some anecdote where the author had asked their significant other to review a paper they wrote, and the SO said something like "it all looked good except for some minor typos." And, you guessed it, they had 'fixed' all the 'iff' typos.
    – JimmyJames
    Commented Nov 18 at 22:14
  • 14
    Reason #4: iff is assumed for documentation. "The function returns True if foo is larger than bar" → everyone assumes it returns False in any other conditions.
    – Alpha
    Commented Nov 18 at 22:47
  • 7
    Reason #5, I see no functional difference between "if and only if" and just "only if". The former is the kind of fluff I would expect in a college paper of someone trying to meet a word count.
    – Logarr
    Commented Nov 19 at 6:53
28

If your colleague doesn't understand it, take it as a learning opportunity. The idea is not to dumb down things to the lowest common denominator, but to lift everyone up.

Please note that there is a middle ground between "dumbing down" and "being a smartass", So if you are asked about it you just say "that's the abbreviation for if and only if". No word about how everyone should know this.

8
  • 5
    I regret that I have but one upvote to give. I was very surprised to discover that apparently a lot of the programmers here have never heard of "iff" given how useful and common it is. But I agree wholeheartedly with your second point: it's not their fault when no one taught them something before, and the solution is to teach them now.
    – Ray
    Commented Nov 18 at 16:03
  • 7
    @Miss_Understands "you can download believe the common read doesn't. till you're writing for" - what? I can't parse your comment.
    – Bergi
    Commented Nov 18 at 22:18
  • 4
    There are times when I want to read documentation to understand a piece of code, and there are times when I want to learn useful (but inessential) new words. The overlap between these is virtually zero.
    – Sneftel
    Commented Nov 19 at 14:08
  • 4
    @Sneftel I'd say the whole point of documentation is to learn things, which includes not only code but also ways to talk about code. Of course what you don't want is anything that unnecessarily distracts from the information that you're actually searching for, but the nice thing about "iff" is that it has low distraction and confusion potential for those who don't understand it. Meanwhile, for those who do understand it it's a time saver because it makes the statement unambiguous without introducing boilerplate that would make the documentation unwieldier to read than it needs to be. Commented Nov 19 at 14:30
  • 3
    "which includes not only code but also ways to talk about code"... no. If I am reading documentation about a particular piece of code, I only want to learn about that particular piece of code. If I want you to give me an inessential vocabulary lesson, I will ask you for one.
    – Sneftel
    Commented Nov 19 at 17:31
22

Use iff iff the domain is appropriate.

From a dictionary:

iff

(mathematics, logic) Short for if and only if.

A rectangle is a square iff all four of its sides have the same length.

Assuming English text, iff you are writing a text in the domain of mathematics and logic, you may use iff.

That means you should not use the word if you are not writing a text in the domain of mathematics and logic.

This does not cover unrelated meanings in other languages.

13

The term iff for if-and-only-if may be understood in computer science and logic, and also bears an implied symmetry ("and not when not").

It is a useful operational term, with quite expressive power. But it needs always explanation, and the more or less implied exclusion of the negative case (when that is the case) needs also to be explained.

For example, using a foot note with a clear wording could be a solution.

This function returns True iff1 the value of foo is larger than bar.

1 ) if-and-only-iff = necessary and sufficient condition. And not so when bar less or equal to foo.

7
  • 1
    Footnote is a good solution - it explains the term close to its occurrence and does not hamper the reading flow for those who are already familiar with the word. Commented Nov 18 at 11:36
  • 1
    Except you won't write a foot note in a source code. And I'm not sure if any doc generator supports it, I've never seen it.
    – freakish
    Commented Nov 18 at 11:43
  • @freakish: it is unclear whether the OP meant "documentation in source code" or "separate documentation". Maybe they have literate programming in mind - which uses TeX for creating the docs, which is surely capable of adding footnotes ;-). But don't get me wrong, I agree that footnotes are impractical for source code docs.
    – Doc Brown
    Commented Nov 18 at 12:35
  • Thanks in general. Documentation in code has only the room of a popup for a method's javadoc or such. Probably senseless.
    – Joop Eggen
    Commented Nov 18 at 12:56
  • @DocBrown corrected two most evidint typos, though the text still should be formulated differently here and there. Thanks.
    – Joop Eggen
    Commented Nov 18 at 13:13
8

I would avoid using "iff" in documentation for a pragmatic reason: it's entirely too easy to double-tap the 'f' key, turning "if" into "iff", completely changing the meaning of what you wrote. It's a lot harder to accidentally type "if and only if" when you meant to type "if".

(I would consider using it iff the programming language in question has it as a keyword.)

1
  • Are there programming languages that have iff as a keyword? How would it be different from if in source code?
    – gerrit
    Commented Nov 19 at 8:52
7

Documentation should be unambiguous, obvious, and appropriately convey importance to the reader. It's important to know your audience; perhaps your readers are thoroughly digesting the documentation, but in most cases the majority of documentation is skimmed rather than read, and it's easy to misread "iff" as just "if". "if and only if" is a significant statement and "iff" does not do well to convey the weight of the statement to the reader. Also, "iff" strikes me as a notational symbol rather than something you would expect in plain language documentation.

1
  • 3
    It is easy to misread, but also if you misread it as "if" then you will probably still get the correct meaning from it.
    – kaya3
    Commented Nov 18 at 22:53
4

I have two points.

  1. The double 'f' syntax is not common in all programming languages. C# and Java are widely used examples of languages that do not use 'iff'. While 'iff' was taught in several mathematics courses required for my CS degree, those courses may not be required for programming degrees or certificates, and your fellow programmers may not have been exposed to the syntax.

  2. Fully understand what your documentation is doing here:

This function returns True iff the value of foo is larger than bar.

This implies the value of false being the default state prior to the evaluation, and/or the return of false when foo is not larger than bar. Your documentation on this matter should be EXPLICIT. You should both avoid the shorthand, and explicitly include your Else condition.

Here is why I say point 2:

If the documentation is for an end user, e.g. API documentation, they should not have to guess if the returned state is True or False or NULL or guess if the Default state prior to evaluation is NULL or False.

Many readers will have read this and assumed "It's common sense that if something is not true, then it is false." And if you pause a moment longer, you will think of instances where you worked with application code where this is not the case."

If the documentation is for a developer to use in writing the code itself, you need to properly set the expectation of what you want to receive. Implied execution does not convey the entirety of your expectation, and is a great way to get back something that does not meet it.

6
  • 10
    Unless I've misunderstood your first point, I don't think it applies - this question seems entirely unrelated to whether any programming language actually uses iff. (And in fact I'm not familiar with any programming language that uses it, though that shouldn't matter.)
    – David Z
    Commented Nov 18 at 17:24
  • OP is under the assumption it is a common phrase developers would be exposed to. I'm pointing out that a lot of young developers may not have been exposed to it because it is not used, and therefore not taught, in high level language development.
    – Kevin
    Commented Nov 18 at 18:05
  • 3
    @Kevin Few if any languages have the words "tree", "pointer", or "database" in their syntax, but I would still expect a programmer to know what they mean if they appear in the comments. iff describes a property of the algorithm, but isn't a step in it, so it's unlikely to appear in a statement or expression (except perhaps in declarative logic languages like Prolog), but that sort of high-level guarantee is exactly what comments are for.
    – Ray
    Commented Nov 18 at 19:25
  • You are making the same assumption as the OP. Developers are taught, and expected to know, the constructs of trees and pointers, they may not have been taught IFF and instead only know it as IF ELSE. I even provided an example of how IFF is taught in various maths courses, but was not covered in any programming study.
    – Kevin
    Commented Nov 18 at 20:02
  • 1
    @freakish I'm talking about "The double 'f' syntax is not common in all programming languages" (emphasis added).
    – Ray
    Commented Nov 19 at 15:26
4

Mathematical formalism is for the code; documentation should communicate clearly and precisely. In the given example, think about what you intend with the extra 'f'. The implication is: when foo isn't larger than bar, the function won't return True. Okay, but documentation is primarily about what the code will do, not about what it won't do.

Generally, if a function is returning a boolean, the natural assumption is that both True and False return values are possible, and that False is returned whenever True isn't. One doesn't expect, for example, the function to raise exceptions unless those cases are explicitly called out. So if that's what you mean, then say it. Common styles may range from:

Returns: foo > bar

This function returns a boolean indicating whether foo is greater than bar.

Any of these will be more concise than explaining what "iff" means.

On the other hand, if the function does something else in the other cases, you should say that, instead. Simply leaving it at "it doesn't return True in those cases" will lead the reader to guess, probably wrongly.

3

This function returns True iff the value of foo is larger than bar.

Do you actually mean this function returns (the result of the expression) foo > bar? it's not immediately clear: perhaps the function sometime does not return, or sometimes returns a value that is neither true nor false.

My take is leave the language of mathematical logic on the shelf, and use the langauge your audience, the programmer, will be most familiar with. Mixing languages leads to confusion. For exampls do "functions" in the programming language satisfy the mathematical definition of a function?

3
  • 1
    In your example, the problem is not the use of "iff", but the fact that there are no additional requirements about what-if-not-iff ... So if one extreme is bad, the other extreme is not inherently good either. Just to clarify: "This function returns True if-and-only-if the value of foo is larger than bar." is equally bad from the point-of-view of "perhaps the function sometime does not return, or sometimes returns a value that is neither true nor false".
    – virolino
    Commented Nov 20 at 8:42
  • 1
    So "This function returns True iff the value of foo is larger than bar, if it returns at all, and if it returns a Boolean value" ;-)
    – U. Windl
    Commented Nov 20 at 12:29
  • I'm guessing OP thought iff was saving words. in some languages there are more than two boolean values
    – Jasen
    Commented Nov 20 at 20:19
1

Many others here have stated that "iff" looks like a typo, yet none of them has suggested this approach: Make it so that it does not look like a typo.

This function returns True iff the value of foo is larger than bar.

This function returns `True` <i>iff</i> the value of `foo` is larger than `bar`.

(Note that *this syntax* renders as <em> (emphasis) rather than <i> (idiomatic text). Use that iff <i> is not a choice.)

Italicizing a word does not magically make the reader understand it, however, so an explanation of some kind is still necessary.

6
  • 1
    How does that make it clear it’s not a typo? One might also use emphasis if the case is notable but not exclusive. Commented Nov 19 at 6:54
  • @MisterMiyagi Two things: First, <i> does not mean emphasis; second, I never said italicizing make it clear that "iff" is not a typo (only less so). I also noted that an explanation is still necessary.
    – InSync
    Commented Nov 19 at 6:57
  • 2
    Well then how does that make it so that it does not look like a typo? Commented Nov 19 at 7:14
  • Maybe it depends on IDE, or keyboard but then wouldn't it be easier to just type "if and only if"?
    – Piro
    Commented Nov 19 at 7:28
  • @MisterMiyagi If something looks different from the rest, it is intuitively understood as having received extra attention and would thus less likely to be an error. This might work for one person but not another; if you don't feel that way, fair enough.
    – InSync
    Commented Nov 19 at 7:36
1

I think any good documentation should explain the concepts it uses:

  • Explain (or provide a reference for) formal syntax notation being used
  • Explain the meaning of symbols being used
  • Explain abbreviations and acronyms being used
  • Explain any keywords that may not be universally understood (like "iff", but you could also think of "implies")

Also I think the use of "iff" is justified to use (but see above) if the documentation is very formal (rather rare these days); still it could be spelled out ("if, and only if").

2
  • 1
    Where do you stop that? Commented Nov 20 at 10:53
  • Depend on the audience of the documentation, naturally. And it's a matter of taste. Actually I found an example in ECMA-367: "5.7 Validity: “if and only if” rules"
    – U. Windl
    Commented Nov 20 at 12:22
-1

SURPRISE! Most readers aren't as educated as you are. It's the smart man's burden. And it can be shocking.

Think about it. The ONLY place anyone could ever encounter the term IFF is in a class on formal logic. It's just not part of the general vocabulary. Your fellow programmer didn't even understand it.

Smart people make the same mistake that stupid people do, which is why I call it The Universal Human Mistake: assuming that everyone else has the same knowledge and intent and motivation as you do.

I make the same mistake myself. It's universal. I assume everybody tells the truth when they say something, and that they want to know the truth when they ask me a question. But I once had a boss who was a compulsive liar. He explained that some people in the organization were "our enemies" and he always assumed everyone else was scheming and lying.

In fact, that's when I came up With the idea Of The Universal Human Mistake.

4
  • 7
    "The ONLY place anyone could ever encounter the term IFF is in a class on formal logic." That's not true. It is quite common in every branch of math. And the second half of the answer isn't related to the question at all.
    – freakish
    Commented Nov 19 at 6:28
  • @freakish Sure, the term may be in a user manual. But without having been exposed to it in a class or in a book, the reader is unlikely to understand it. It's not a factual issue; it's a writing style issue. Commented Nov 19 at 7:56
  • 1
    The vast majority of mathematics is not formal logic, and most mathematicians do not study formal logic. When I studied mathematics, formal logic wasn't taught until an optional third-year module which probably less than 25% of the cohort opted in for (lectures were on Saturdays at 9AM!). But the word "iff" would have been used in practically every module all the way through the whole course, starting on the first day. It may seem like a minor distinction, but it's the basis for your answer, so it matters that it's not literally true. And hyperbole doesn't go down well here.
    – kaya3
    Commented Nov 19 at 17:14
  • 1
    The distinction I refer to is the one between "mathematics" and "formal logic", as the purpose of my comment was to point that distinction out. I apologise if that was unclear, but I also don't think my consistent use of the past tense was unclear enough to suggest that I am still a student. Also it's a bit weird to suggest that I might not have encountered the word "iff" in a course which I said used that word consistently all the way through. Anyway, your primary claim, "The ONLY place anyone could ever encounter the term IFF is in a class on formal logic", is objectively wrong.
    – kaya3
    Commented Nov 20 at 19:11
-1

There are already several good answers (thank you all for contributing), but there is some detail I did not yet see anywhere.

Any documentation is not written for the experts (except for occasional reference), but for the people which have (and ideally they want too) to learn. So using "iff" should be more than appropriate.

However, there is a small catch - no one can learn anything if that anything is cryptic and not explained.

So what I would do is something like this:

  1. Explain "iff" at the beginning of the document in the "Definitions and abbreviations" section, specifying at least one reliable source (e.g., a dictionary).
  2. Spell "iff" with capital letters as IFF for a triple purpose: a) to make it obvious that the spelling is not a mistake, b) to draw the attention that there are 2 F's there actually - which carries a lot of important information and c) to make it obvious that, etymologically, the word is actually an abbreviation.

Without the clarifications above, anyone can infer or assume anything, which beats the purpose of writing the said documentation.

You are of course welcome to find other ways to transfer knowledge to the readers of your document, if you do not fully agree with my way.

10
  • 1
    "IFF" looks like an initialism to me, not the short form actually meant. Commented Nov 20 at 8:58
  • @MisterMiyagi: There are exceptions to the rule, indeed. But since there is no definitive non-modifiable list of all initialisms, we can create initialisms of our own, if there is no risk of ambiguity. So if the documentation is not about file formats on Amiga, and is not about military / combat / competition stuff, then IFF can stand for iff. Or you can find another way, as I already wrote in the answer.
    – virolino
    Commented Nov 20 at 9:04
  • " Or you can find another way, as I already wrote in the answer." I am still looking for one that works in isolation without presupposing the knowledge that iff is a "word". Even the variations with defining it on first use / glossary requires people to actually read those first. Perhaps linking to a glossary would do? Commented Nov 20 at 9:17
  • @MisterMiyagi: and what is the difference between "link" and "specifying at least one reliable source (e.g., a dictionary)" ?
    – virolino
    Commented Nov 20 at 10:38
  • 1
    If "iff" absolutely must be used and cannot be replaced by the more usual English terms, then using capitals, bold, italics, or some other form of emphasis feels a good idea for a term which is so easily taken to be a typo. It makes it a little clearer that this is a deliberate usage, particularly after the second or third instance, and it hints to the user that they can look in the definitions section. It should definitely be defined, either on first use with a pointer from the index, or in a definitions section, as it's not a safe assumption that every reader will have encountered the term. Commented Nov 21 at 3:34
-2

The very rare times I want to use if-and-only-if in a computer program comment, I use the 3-character sequence <=> (or if that jumps out as an operator, <==>). It's a real logic symbol, which officially means the same thing as IFF (Wikipedia logical equivalence), but it more obviously indicates "I'm using a logic symbol". Briefly, if-and-only-if means a=>b and b=>a which is shortened to a<=>b and they both mean "both true or both false".

But I mean "very rare". Possibly very, very rare. For one thing, consider OP's "returns true if foo greater than bar". We wouldn't want to use iff or <=>, even if everyone knew it, since it's implied. If there were other ways to return true, we would have listed them. Saying things that are implied is confusing. Put another way, this is like adding "otherwise returns false".

For another, we rarely want to know IF vs. IFF. Say we're about to write a comment "restarts if idle for more than 20 seconds", but realize if-and-only-if is more accurate and write that. We've now told readers that there's currently no other way of restarting. We've let someone working on restart() know they can safely assume 20 seconds of inactivity. I don't think that's useful.

The few times I actually use <=> is explaining my logic. As a fake example "NOTE: amazingly, edges*2>=vertexes <=> maze can be solved!". I'm telling myself two things: checking for enough edges is a quick way to know the maze is usable; and checking for not enough edges is a quick way to know the maze isn't.

8
  • 2
    While the 3-character "spaceship operator" sequence "<=>" looks similar to "⇔", it's heavily overridden in computing contexts. It means "three way comparison" in several programming languages, or "null-safe equality check" in SQL dialects. Math markup in prose is generally an anti-pattern, as symbol sequences are typically opaque to the non-cognoscenti: so "iff" is trivially searchable, but "⇔" is not. Overall, I'd consider "iff" far more likely to be unambiguous and colloquially known to those reading an English computer manual, but I'd recommend "if and only if" for most cases. Commented Nov 20 at 3:02
  • A reader could think I meant to suggest the single-character double-arrow symbol. I can fix that. Thanks. Commented Nov 20 at 16:03
  • But the spaceship operator doesn't ever mean iff in computing contexts, so far as I can tell. It means "3-way comparison", or "null-safe comparison"; a comparator, not a conditional operator. Your line "It's a real logic symbol, which officially means the same thing as IFF" does not appear to be correct, or at least, your link does not seem to support the claim you're making that it's ever used or understood to mean "IFF" by anyone other than yourself. Commented Nov 21 at 3:30
  • @DewiMorgan Ah! You think I'm one of those naive folks who "helpfully" propose a solution they just made up! You think I hastily misread a Wikipedia article. No. I learned <=> in the same computer logic class I learned IFF, and have seen it since used interchangeably. I assure you that if you make truth tables, IFF and <=> work out to be identical. Commented Nov 21 at 18:33
  • I can see this working out very badly in things like Javadoc comments, which are (approximately) HTML. Commented Nov 21 at 22:09
-3

If and only if means something. Use it when that’s what you mean.

This is the age of google. It’s not that hard to look something up. So don't feel like you have to explain what it is. Explain why you need it.

However, don’t use this because you want to show off. Use it when it’s important.

I’d rather you made me think than made me guess.

As for the abbreviation, "iff", like all abbreviations it's considered wise to spell it out on first use. Like you did when you asked this question.

9
  • 7
    While it's true that it's not hard to look something up, when reading I don't want to spend my time looking stuff up on Google. In this specific case, seeing "iff" I'd be more inclined to think it's a typo. Commented Nov 18 at 10:46
  • @MetalMikester better now? Commented Nov 18 at 11:04
  • 1
    @MetalMikester In that case you would ask and you would learn something.
    – gnasher729
    Commented Nov 18 at 12:40
  • 4
    @MetalMikester Meanwhile, all the other readers would think it's a typo. And then later in the text, they become very confused.. That's not good writing. Write for your audience. Commented Nov 19 at 3:36
  • 3
    FWIW, I tried looking"iff" up for fun and it took me quite a while to realise my input had been automatically changed to "if". After correcting it, google brought up a flower shop and research institute. Then I gave up. Commented Nov 19 at 7:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.