-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use enums instead of multiple boolean arguments #624
Conversation
I really like the general idea. These endless boolean args lists deserve to be eliminated, that's for sure.
really better than this?
Why not do this instead?
and call it like
The second example is a bit constructed, but you get the idea. All Another approach I frequently use is passing a struct containing all the args. These can be allocated on the stack and are usually quite cheap. The called routine gets a const ref or ptr->const which is also cheap. Last not least ... would be awesome to have a similar solution in all the other generators as well. Functions with more than five args are a code smell, and we have plenty of them. As always, other opinions are welcome. |
Thanks for the feedback - I was thinking about a struct approach, but because it's not easy to create a struct inline, I avoided that. As you said, flags work, but lose type safety - there's no way to say that If you think the struct approach is better, we can do that, although calls will then probably look like: DeserializeFieldOpts opts
opts.UseTrueType = true;
opts.InContainer = true;
generate_deserialize_field(out, &felem, true, "", opts); I think once we decide on an approach, it should be consistently applied for the other compilers. I'm only really working with Go, so I can only really update the Go generator. |
Multiple boolean arguments in a function call leads to unreadable code. E.g generate_deserialize_field(out, &felem, true, "", false, false, false, true, true); vs generate_deserialize_field(out, &felem, true, "", NOT_IN_CLASS, NO_COERCE_DATA, NOT_IN_KEY, IN_CONTAINER, USE_TRUE_TYPE); The compiler will ensure you cannot pass the wrong type (e.g. NOT_IN_CLASS where IsOptional is required).
I like this notion, the enums make it more readable. If you would be willing to revive it and reapply it against the current master, we can take another look at it. Also a Jira ticket for the change is needed; see https://thrift.apache.org/docs/HowToContribute |
This pull request is being closed due to lack of activity. |
This closes apache#93 This closes apache#326 This closes apache#345 This closes apache#352 This closes apache#353 This closes apache#383 This closes apache#395 This closes apache#413 This closes apache#488 This closes apache#555 This closes apache#624 This closes apache#731 This closes apache#747 This closes apache#756
Multiple boolean arguments in a function call leads to unreadable code.
E.g
vs
The compiler will ensure you cannot pass the wrong type (e.g.
NOT_IN_CLASS
whereIsOptional
is required).There are no functional changes in this patch.