5 ms·
I started scala with Akka Http and magnet pattern[1] is the most convoluted, disgusting abuse of any language feature i've encountered. I really dislike implici
by dominotw 9y ago
I started scala with Akka Http and magnet pattern[1] is the most convoluted, disgusting abuse of any language feature i've encountered. I really dislike implicits, implicit conversions ect, doesn't matter how awesome features it enables you to use.
Can implicit fans explain to me how I am supposed to navigate to the correct overloaded method in Magnet pattern? Even IDE's like intellij Idea have no idea what to navigate to. If its so hard of an IDE to figure out, how are humans supposed to deal with this.
http://spray.io/blog/2012-12-13-the-magnet-pattern/ http://spray.io/blog/2012-12-13-the-magnet-pattern/
- s4vi0r 9y agoIf you have to write that kind of code for work you're probably out of luck, but if you're comfortable with FP and have some control over your stack I'd suggest the typelevel stack. I didn't know what the magnet pattern was until you just said so, and it seems like an awful idea relying on implicit abuse on the level of the cake pattern - something which has been discouraged for the last 4 years now. Implicits are great, and allow you to do some really amazing things, but you have to be careful not to abuse them or risk making your code take forever to compile and be impossible to debug.
- MrBuddyCasino 9y agoAnd I thought I was the only only to go "wtf" when I first read about the magnet pattern. They claimed it to be "elegant", but it really is only "clever" in the worst possible way and makes it hard to reason about the code. I've got a theory that the type of people doing overly complex Java enterprise (see EJB 2.1) 15 years ago haven't vanished, they're just doing Scala now.
- doikor 9y agoMagnet pattern is purely about making the code you write nicer to look at. (for spray it had more reasons to exist but for akka-http it is purely a usability problem) Basically it allows you to write def f[T](fMagnet: FMagnet[T]): X => Y f(t) { x => // ... } instead of def f[T](t: T)(implicit tc: TC[T]): X => Y f(t).apply { x => // ... } so just about removing one ".apply" (see https://github.com/akka/akka-http/issues/100 https://github.com/akka/akka-http/issues/100 where i copy pasted the code bits from) But yeah first time I read up on the magnet pattern it was a wtf moment.