A word that fits the concept of "only do something once, and only when it is needed"

I'm a developer, and as part of the development process we'll often 'do something once if it hasn't been done before' in certain parts of our code.

For example, if I require a connection to a database I will connect only if I'm not already connected, I will not try to connect to the database if I am already connected.

I want the word that goes into these blanks:

I am acting or am coding [......] by checking for a connection first prior to connecting.

If I connected to the database twice it would not be [.......].

There is definitely a word for this, but it escapes me.

Apologies for the example, but it's the exact context in which I'd typically use this word. Another example may be only assigning a value to a variable if it hasn't already been assigned a value. Basically, avoiding redundant and unnecessary action by checking it had already been done.

Word It's Not:

  • Efficient/ly, efficiency
  • Optimal, optimisation
  • Concise
  • Singular, single
  • Elegant, elegance

EDIT

Since a bounty of 100 has been assigned, I think it deserves another example:

I will give my variable the value 'A123' if I have not, previously, gave my variable the value 'A123'


If you want to impress the yokels with a real computery-sciencey word, try "idempotent". An idempotent process is one that you can run over and over again, but it will only change things the first time.


There are quite a few relevant programming concepts. Three I find particularly related:

singleton pattern — In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects.

lazy loading — Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program's operation if properly and appropriately used. The opposite of lazy loading is eager loading.

DRY — In software engineering, don't repeat yourself (DRY) is a principle of software development, a principle aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures.

Of these, only DRY would fit into your example sentence in any meaningful way but it doesn't exactly convey what you intend.

The only other term I know that would be related and fits the structure of your examples is "defensively":

I am acting or am coding defensively by checking for a connection first prior to connecting.

If I connected to the database twice it would not be defensively.

This relates to the specific term defensive programming:

defensive programming — Defensive programming is a form of defensive design intended to ensure the continuing function of a piece of software in spite of unforeseeable usage of said software.

In this case, the defensive action is protecting yourself from multiple connections by checking for an existing connection. This avoids unnecessary memory usage, memory leaks and poor performance.


I think you might be looking for the word 'idempotent'

Idempotence (/ˌaɪdɨmˈpoʊtəns/ eye-dəm-poh-təns) is the property of certain operations in mathematics and computer science, that can be applied multiple times without changing the result beyond the initial application.

An idempotent operation functions like a light switch, flipping it up won't change the state of the light if it's already up.


Lazy is the key principle here.

Concepts like lazy initialization, lazy evaluation, and lazy loading represent a common pattern used in resource limited systems (like smart phones, for example) where you don't want the user to encounter long wait times or run out of available memory unless they actually need the product of the lazy operation.

In a smart phone, lazy initialization is used for creating complex objects like views and view controllers. For complex user interfaces with many views and their view controllers, keeping them around is simply too resource consuming, so a common practice would be to create on first use and destroy when not being used (usually only when limited resources are being demanded and with the understanding that it can be re-created if it needs to be used later).

Let me show how your example statements might be worded a little better if lazy is the word you are looking for:

I am acting or am coding lazily by checking for a connection at first use.

If I connected to the database twice it would not conform to the lazy design pattern of initializing at first use (and retaining for later use).

The lazy pattern differs from the singleton pattern, which deals with assuring that only one instance of a particular class is created. A singleton instance may be created lazily, but so can multiple instances (each created on its own first use).

For example, you may have two instances of a database controller for working with two different databases. This does not fit the singleton pattern, but the coding of the database controllers can still fit the lazy pattern.


How about something along the lines of initial. "Initially check for a connection"