3

I'm designing some programming code, and the language is an important piece of making it easy for readers of the design to understand the context and intent of the code.

In particular, I'm looking for a negative complement to the word when in the context below.

When

Reading the code in the positive with "when", it would be interpreted along the lines of the following:

"when" condition -> wait until the condition becomes true/is satisfied then do something

e.g.

"when" true -> do something

"when" false -> wait

The word "when" describes to the reader both the waiting and conditional triggering (once) of an action upon a condition being met.

When negative

The complement is a mystery word/portmanteau "X", ought to describe the same but with the conditional logically inverted:

"X" true -> wait

"X" false -> do something

Options

Here are some possible options for what X might be, for thought:

  • whenNot
  • whenNoLonger
  • untilNot

Example

So for an example, suppose there's a condition "temperature", that's either hot or cold, and we want to trigger when it is not cold, here's my best thought on how they'd be roughly written/interpreted to/from English:

The temperature, "whenNot" cold, we do something
The temperature, "whenNoLonger" cold, we do something
The temperature, "untilNot" cold, we do something

The one that strikes me as the most appropriate innate description is whenNoLonger, but a simpler, shorter alternative would be ideal.

Do any good succinct alternatives come to mind?

Edit Adding on the helpful comments I've garnered some ideas.

One option may be heretofore or hitherto, adverbs meaning essentially "before this time; until now." So "the temperature, before this time cold, we now do something". It's old englishy but otherwise seems apt.

One might also use thus far but there's no guarantee that the condition of "not cold" is not immediately met (i.e. "thus far" presumes or might indicate a history of state, that may not actually be known)

  • 4
    I'm actually starting to believe this is an XY-problem. You are looking for a negation of "when", but you describe having implemented "when" to mean "until". Fixing that, you are looking at "Until" and a negative form, which could be "UntilNot". – oerkelens Apr 1 '17 at 14:59
  • 2
    But when doesn't mean until. Look at my example. When it rains, you open an umbrella. Until it rains, we will continue to enjoy our picnic in the park. They have opposite time senses. – Dan Bron Apr 1 '17 at 15:00
  • 1
    I'm afraid this is becoming too much of a programming question, but that when in jQuery_ is a delegate - nobody is waiting for anything, it just gets executed when that query finishes. That is very different from "waiting until some condition is true or false". – oerkelens Apr 1 '17 at 15:06
  • 1
    I may be missing your point. I don't see a need for any additional syntax for until vs. when. The word until embeds the notion of a duration, of waiting. When rain, open umbrella, Until rain, picnic. – Dan Bron Apr 1 '17 at 15:06
  • 3
    Then after rain? – Dan Bron Apr 1 '17 at 15:09
6

A common word for when not is unless.

unless conjunction Except if (used to introduce the case in which a statement being made is not true or valid) ‘unless you have a photographic memory, repetition is vital’ - ODO

The phrase "when X (is true), do Y" says to do Y when X holds. For example, "when it rains, use an umbrella" says to use an umbrella when it rains.

The phrase "unless X (is true), do Y" says to do Y when X doesn't hold. The parallel example, "unless it rains, use an umbrella" says to use an umbrella when it's not raining.

Note that if you're looking for the rule to execute upon the termination of a condition, as opposed to just the negation of the condition, use @Dan Bron's suggestion: after.

|improve this answer|||||
  • I would never infer any waiting to happen is X is not true - intuitively, I would expect execution to continue, just not executing whatever jumbled form of "IF" you are trying to implement :) – oerkelens Apr 1 '17 at 14:56
  • Thanks @Lawrence. The problem with unless is that it does not innately indicate that there's waiting. I.e. when is not just describing the conditional (as in if x/unless x) but the delay when = if not x then wait for x then do. Using unless would ordinarily indicate that the do y would never be called. – Brian M. Hunt Apr 1 '17 at 14:56
  • 1
    @BrianM.Hunt When has the opposite property. Taking the umbrella example, the ordinary (English) sense has no 'wait' associated with the case that it's not raining. That is, if it's sunny and you require that when it rains, use an umbrella, the sense isn't wait until it rains - it's just don't use an umbrella (equivalent to your "never be called" behaviour). The use of unless is an exact complement. So if you add waiting to when not, it would be consistent to add waiting to unless not. – Lawrence Apr 1 '17 at 15:02
  • @oerkelens I think you're making the same objection as Brian in his (later) comment. Please see my reply to him. – Lawrence Apr 1 '17 at 15:03
  • @BrianM.Hunt Instead of the bare when vs unless, you might want to consider block when vs block unless, where block has the standard programming meaning of suspending execution. – Lawrence Apr 1 '17 at 15:09
3

The commonly used alternative for this is while, with an empty body, meaning that while some condition is true, you just keep re-evaluation that condition. How you phrase the condition is entirely up to you - it's usually considered a good idea to not use negative condition- or boolean-names, so "ItsTooCold" would often be preferred to "ItsNotYetWarmeEnough". Think of negating that last one: if (NOT ItsNotYetWarmEnough).

while (ItIsTooCold); // <-- this line keeps repeating until "ItsTooCold" returns false.

//Do whatever you want to do when the temperature is high enough.
|improve this answer|||||
  • 1
    Thanks. It's not phrasing the conditional (over which we have no control) but the operation of waiting until the conditional is (not) met. – Brian M. Hunt Apr 1 '17 at 14:53
  • There's definitely an ambiguity there, but in the context of the design it's clearly asynchronous, and so distinct from the immediate if/if not alternatives. But I take your point. – Brian M. Hunt Apr 1 '17 at 14:58
2

Ruby actually has exactly this:

  • if -- run the following block once if condition is true.
  • while -- run the following block while the condition remains true.
  • unless -- run the following block once if condition is false (if's complement).
  • until -- run the following block while the condition remains false (while's complement).

Honorable mention: Ruby also has when, but it's used more in a switch-case sort of statement (literally just case-when instead of switch-case).


I know this is on english SE and not programmingSE, but please consider whether you should add a feature like this, not just whether you can. It's not clearly a benefit in Ruby...while it does make nice things like this possible:

fail ArgumentError unless param > 0

it also allows antipatterns like this possible:

unless foo
    # something
else
    # something else
end

I think unless-else blocks are widely considered an antipattern. And in any case, for me personally, I almost always have to mentally convert an unless or an until back to a if ! or while ! -- it's just easier to reason about.

|improve this answer|||||
  • This would be exactly the thought provoking stuff that furthers the conversation 😀 – Brian M. Hunt Apr 1 '17 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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