Dynamic

Custom Interfaces vs Duck Typing

Developers should learn and use custom interfaces when building modular applications that require clear separation of concerns, such as in microservices architectures or plugin-based systems meets developers should learn duck typing when working in dynamically-typed languages to write more generic and reusable code that focuses on what objects can do rather than what they are. Here's our take.

🧊Nice Pick

Custom Interfaces

Developers should learn and use custom interfaces when building modular applications that require clear separation of concerns, such as in microservices architectures or plugin-based systems

Custom Interfaces

Nice Pick

Developers should learn and use custom interfaces when building modular applications that require clear separation of concerns, such as in microservices architectures or plugin-based systems

Pros

  • +They are essential for implementing design patterns like Strategy or Adapter, and for creating testable code through dependency injection, as interfaces allow mocking or stubbing in unit tests
  • +Related to: object-oriented-programming, design-patterns

Cons

  • -Specific tradeoffs depend on your use case

Duck Typing

Developers should learn duck typing when working in dynamically-typed languages to write more generic and reusable code that focuses on what objects can do rather than what they are

Pros

  • +It's particularly useful for creating flexible APIs, implementing design patterns like strategy or adapter, and handling diverse data structures in a uniform way, such as iterating over collections regardless of their specific type
  • +Related to: dynamic-typing, polymorphism

Cons

  • -Specific tradeoffs depend on your use case

The Verdict

Use Custom Interfaces if: You want they are essential for implementing design patterns like strategy or adapter, and for creating testable code through dependency injection, as interfaces allow mocking or stubbing in unit tests and can live with specific tradeoffs depend on your use case.

Use Duck Typing if: You prioritize it's particularly useful for creating flexible apis, implementing design patterns like strategy or adapter, and handling diverse data structures in a uniform way, such as iterating over collections regardless of their specific type over what Custom Interfaces offers.

🧊
The Bottom Line
Custom Interfaces wins

Developers should learn and use custom interfaces when building modular applications that require clear separation of concerns, such as in microservices architectures or plugin-based systems

Related Comparisons

Disagree with our pick? nice@nicepick.dev