CodeSOD: AAYFN Note

CodeSOD: AAYFN

The provided Ruby code defines a function named bv, which is short for boolean value, and is used to pretty-print boolean values and convert them to strings. The function takes four parameters: prop, tv, fv, and nv, which represent the property name, true value, false value, and null value respectively. The function uses the send method to access a member of the class by name, which is a Ruby idiom that allows for metaprogramming by strings. This approach can lead to potential issues, such as returning "Not Specified" for non-boolean fields, which can be misleading. It is argued that attempting to use the function on a non-boolean field should throw an exception instead. The function's behavior can be surprising, as it will throw an exception if the property does not exist or if the thing being accessed is a function that takes parameters. The Ruby documentation recommends having a good list of allowed boolean values to avoid these issues. However, the use of runtime metaprogramming by passing strings around can still lead to trouble and make the codebase difficult to maintain. The author of the text expresses their dislike for this approach and prefers using C++ templates for metaprogramming, which they find to be simpler and clearer. The author believes that non-trivial Ruby codebases often become unmaintainable due to the use of metaprogramming. Overall, the code and its approach are considered to be problematic and prone to errors.