When use exclamation (!) mark in names of functions

2015-06-19 tags template

On site clojure-style-guide we can read:

The names of functions/macros that are not safe in STM transactions should end with an exclamation mark (e.g. reset!).

But what does it really mean? Anything what has a non-idempotent side effect.

Idempotent operation is the one that has no additional effect if it is called more than once with the same input parameters.

Make it simple:

(create-user! ...)
(create-user-only-if-not-exist ...)

Why do we need that? Functions in STM transactions can be run many times, because of some conflicts. So using function create-user! you will add the same user many times, but function create-user-only-if-not-exist will add him only once, even if it will be run many times.

So, if you see

(create-user! ...)
expect it will has additional effects if you run it more than once with the same input.

But if you see

(create-user ...)
expect it wouldn't have additional effects even if you run this many times with the same input.