Operation that can succeed/fail -- return type & naming convention

c#, naming-conventions, return-value

Solution

All builtin methods in .NET that are trying to parse something to something else(e.g. `int.TryParse`) are called `TryParse` and return a `bool` and an `out` parameter.

So maybe:

public static bool TryBuildHouse(T input, out House house)

Problem

What return type is appropriate for a method that can either complete successfully or fail due to its business logic? And based on that return type, what would be the appropriate naming convention? My instinct is that bool is most appropriate for a simple pass/fail. I've researched and found conventions for methods that infer a trait -- i.e. IsValid, HasFoo, ContainsBar, etc. But is that also the proper naming for an action like BuildHouse() or FlyKite() to clearly indicate whether the operation was successful? I've tried it a few ways but each time I keep thinking that it looks weird and there must be a better practice.... ``` bool IsHouseBuilt() bool TryBuildHouse() void BuildHouse(out bool success) PassFailEnum BuildHouse() //seems a little excessive bool IsKiteFlying() bool TryFlyKite() void FlyKite(out bool success) PassFailEnum FlyKite() ```

Original source