"Context bounds are a convenient Scala shorthand. For example: def printList[T: Ordering](list: List[T]): Unit = println(list.sorted) Here, [T: Ordering] is a context bound, which under the hood is equivalent to: def printList[T](list: List[T])(using ord: Ordering[T]): Unit = println(list.sorted) Context bounds are neat for small, simple cases. But in large applications, overusing them can lead to implicit chaos: def complexFunction[A: Foo: Bar: Baz](a: A)(using logger: Logger) = ... Now you have four or more implicit dependencies, scattered across scopes"
"Scala's implicit system (now given/ using) can be abused: given Logger with ...given Database with ...def saveUser(user: User)(using db: Database, logger: Logger) = ... If you start chaining these across many layers: Functions start to have hidden dependencies Debugging becomes hard if the wrong instance is in scope New developers struggle to figure out what gets injected Implicit hell is like passing secret ingredients between chefs in a kitchen without labels. The dish might turn out fine,"
Scala given/using and context bounds provide compile-time safety and concise dependency injection mechanisms. Overusing context bounds scatters implicit requirements across scopes and obscures how dependencies are wired. Chaining given instances across many layers creates hidden dependencies, complicates debugging, and raises onboarding costs. Prefer explicit using parameter lists for complex services and reserve context bounds for small, utility cases. Consider established DI frameworks like Spring when centralized configuration, clearer explicit wiring, or team conventions improve clarity and maintainability. Discipline, clear APIs, and intentional design choices prevent implicit chaos and improve long-term code health.
Read at Medium
Unable to calculate read time
Collection
[
|
...
]