In Scala it's bad practice to use implicit parameters for summoning traits that aren't type classes. Not all traits required via implicit parameters are type classes, usage via "implicit" isn't what defines a type class, the trait's signature is. Stop using "implicit" for DI.
-
Show this thread
-
A lot of the "tagless final" in Scala is basically "passing all OOP dependencies at the call site as implicit parameters", the so called "algebra", in this context a fancy term describing OOP classes w/ state. The things people do to avoid giving plain arguments to functions
4 replies 0 retweets 13 likesShow this thread -
Using implicits for DI is bad b/c reading code requires more context. It's why the Linux kernel has never adopted C++, b/c kernel devs want to reason about pieces of code in isolation, C making everything explicit. Reading code is more important than writing it, always.
2 replies 1 retweet 27 likesShow this thread -
Replying to @alexelcu
But shouldn't that be what context is? It's the things that the reader can take for granted, and every additional explicit parameter that ought to be taken for granted instead has to be present, diluting the parameters that are actually significant to the method.
2 replies 0 retweets 1 like -
Replying to @propensive
Seeing that a method interacts w/ the database, or can potentially fire missiles, is as important at the call-site, as its definition. And if we want context, if we want DI, Scala also has a true and tried way of doing it, which is OOP classes, closures on steroids.
2 replies 0 retweets 2 likes -
Replying to @alexelcu @propensive
Scala is an expressive language, but the aggregate of its features can yield some of the worst code in existence. Whenever I compare Scala APIs to their Java equivalents, I almost always find the Java version easier to read. And no feature was abused more than implicits.
1 reply 0 retweets 6 likes -
Replying to @alexelcu
There's a problem here which is that Java is a language without implicits, so we can read it knowing that all parameters must be explicit. However strict we decide we must be about implicits in Scala, it still permits their usage ("abuse") so we can't reason about it like Java.
1 reply 0 retweets 1 like -
Replying to @propensive @alexelcu
It's quite subjective to call dependency injection with implicits "use" or "abuse", but their design was always to model "context". I think DI fits most definitions of "context".
1 reply 0 retweets 1 like
It might be harder to know what all possible readers of some source code might consider part of the context in which they should read it, I don't think the fact it's harder is a good argument for compromising the code's readability by making everything explicit.
-
-
Replying to @propensive @alexelcu
The thing people do to avoid just allocating and deallocating memory...
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.