by oflordal on 8/10/14, 4:38 PM with 12 comments
by aurelianito on 8/10/14, 9:35 PM
by lyinsteve on 8/10/14, 6:54 PM
typedef struct APIError {
int code;
char *description;
};
/**
* Returns NULL and fills the error parameter if creation was unsuccessful.
*/
Something APICreateSomething(bool param1, int param2, APIError *error);
So common execution would be: APIError error;
Something something = APICreateSomething(true, 3, &error);
if (error) {
// handle error...
}
And if the user passed in NULL for the error parameter, then that's their problem, and they won't get error information.by neilunadkat12 on 8/10/14, 7:03 PM
void createSomething(bool param1,int param2, Something something, success: function (something) {}, error: function (error){});
Of course this would be in those languages that support passing of functions as params.
by Strilanc on 8/10/14, 6:33 PM
Style "E" is also known as an error monad, and has a lot of advantages when writing functional-style code. For example, you can use the usual List.map on a function that returns an error monad but not on one that has out parameters or throws exceptions.
by adamnemecek on 8/10/14, 8:04 PM
[0] https://github.com/llvm-mirror/llvm/blob/eee7a7a8362afddab3f...
by fndrplayer13 on 8/10/14, 6:27 PM
by dfbrown on 8/10/14, 9:00 PM
by th0br0 on 8/10/14, 7:34 PM