A programmer shared a code snippet from a .NET Framework to .NET Core migration project.
The code features a CustomerController with an action method that processes a Customer object.
Inside the method, a condition checks customer.someProperty to decide which overloaded UpsertSomething method to call.
The UpsertSomething method is called with a very long list of parameters, many of which are null or default boolean values.
The author points out that the two calls to UpsertSomething are almost identical, differing only in one boolean parameter.
This suggests that the if/else statement was unnecessary.
Instead, the value of customer.someProperty could have been passed directly as an argument to a single UpsertSomething call.
The author highlights this as a prime example of less-than-ideal coding practices.
The provided snippet is representative of the broader codebase encountered during the migration.
The post serves as an example of how code complexity can sometimes be avoided with simpler design choices.
CustomerControllerwith an action method that processes aCustomerobject. Inside the method, a condition checkscustomer.somePropertyto decide which overloadedUpsertSomethingmethod to call. TheUpsertSomethingmethod is called with a very long list of parameters, many of which are null or default boolean values. The author points out that the two calls toUpsertSomethingare almost identical, differing only in one boolean parameter. This suggests that theif/elsestatement was unnecessary. Instead, the value ofcustomer.somePropertycould have been passed directly as an argument to a singleUpsertSomethingcall. The author highlights this as a prime example of less-than-ideal coding practices. The provided snippet is representative of the broader codebase encountered during the migration. The post serves as an example of how code complexity can sometimes be avoided with simpler design choices.