But such classes always smell to me - particularly if component instances have other aliases. Yes, you can achieve also reduce local readability by passing objects containing buckets of state around. The example model from the article should allow functions to operate on multiple Transaction or AccountRepo instances, for example. And similarly, it bakes in a singleton aspect to the context objects. One issue I had with the Scala feature was how it made refactoring is more fraught - as it's not clear which pieces of code in the 'with' block can be moved elsewhere from just reading the code.Ĭontext objects behave like a form of global variable except their use can be even more confusing as will refer to different things depending on the runtime call stack. Without implicits, you can mentally constrain what effects a line like "x.y(z)" will have on the state of the program. In a larger 'with' block, you cannot tell which invocations will interact with or change the state of a context object without looking at site of the definition of the function.įor me, when reading others' code, being able to construct a mental model of what the effects of a line of code in isolation is a vital property for code to be readable/comprehensible. I hated Scala's implicit feature although I'm not familiar with the recent apparent improvements referenced in the article. I'm really not a fan of implicit context being passed around like this.
0 Comments
Leave a Reply. |