The Daily WTF
Follow
CodeSOD: An Array of Parameters
The provided code snippet demonstrates a problematic coding practice where an ArrayList is used to pass multiple parameters into a method. The method expects the ArrayList to contain specific data types and values in a predetermined order. This approach sacrifices compile-time type checking for the potential of runtime errors. The justification for this design was to accommodate potential future changes to the underlying database without altering the method's signature. However, this bypasses standard language features like optional arguments, which would offer a safer and more maintainable solution. The developer incorrectly believed that passing an ArrayList in this manner made the code more flexible. This pattern of using ArrayLists as parameter bags is prevalent throughout the codebase. The alternative of optional parameters would have provided compile-time safety and clearer intent. The current implementation relies on implicit assumptions about data order and type, leading to brittle code. This practice is considered an anti-pattern in software development.