The advantage of defining success / unsuccessful function instead of success / success

I read the gearman code man page ( http://manpages.ubuntu.com/manpages/precise/man3/gearman_success.3.html ). They have two functions.

bool gearman_success(gearman_return_t rc) bool gearman_failed(gearman_return_t rc) 

And the code of these functions looks like (libgearman-1.0 / return.h):

 static inline bool gearman_failed(enum gearman_return_t rc) { return rc != GEARMAN_SUCCESS; } static inline bool gearman_success(enum gearman_return_t rc) { return rc == GEARMAN_SUCCESS; } 

Both functions perform almost the same thing. One returns true and the other false. What is the advantage of this code?

Why not just! Gearman_success

Is there any point to coding or something that I don't see here.

+4
source share
1 answer

This code is easier to extend. Suppose you add another value to this enum :

GEARMAN_SUCCESS_BUT_HAD_WARNINGS

With the implementation you're looking at, all you have to do is set up both methods. Without this, you will have to go through all the locations of the GEARMAN_SUCCESS used throughout the code base and make sure that the new enum value is processed correctly.

+1
source

Source: https://habr.com/ru/post/1502838/


All Articles