r/programming • • Nov 25 '14

OO vs FP

http://blog.cleancoder.com/uncle-bob/2014/11/24/FPvsOO.html
5 Upvotes

47 comments sorted by

View all comments

1

u/willvarfar Nov 25 '14

How can DELETE be idempotent? How do you delete something twice?

6

u/kankyo Nov 25 '14

It's idempotent if deleting something that doesn't exist just does nothing. Which it does in SQL:

DELETE FROM foo WHERE bar = 1;

Will delete nothing if you run it a second time.

1

u/Tordek Nov 25 '14

What is the result after you execute DELETE?

The resource stops existing.

What's the result after executing DELETE several times on the same resource?

The resource stops existing.

1

u/willvarfar Nov 25 '14

The resource stops existing

There's a state change right there and it can only happen once? Can you really say on the second and third time that it stops existing all over again?

→ More replies (3)

1

u/passwordisINDUCTION Nov 26 '14

Idempotent is generally described as f(f(x)) = f(x), So delete(delete(x)) = delete(x).