News for hackers. Stuff that matters.
Re:Context should go away for Go 2 by crowcountry on Tuesday January 21, 2025 @04:52AM (#42778202)
Scala has implicit contextual parameters: https://docs.scala-lang.org/tour/implicit-parameters.html.
Re:Context should go away for Go 2 by agumonkey on Tuesday January 21, 2025 @05:16AM (#42778384)
I've always been curious about how this feature ends up in day to day operations and long term projects. You're happy with it ?
Re:Context should go away for Go 2 by kloop on Tuesday January 21, 2025 @08:26AM (#42779851)
As a veteran of a large scala project (which was re-written in go, so I'm not unbiased), no. I was generally not happy.

This was scala 2, so implicit resolution lookup was a big chunk of the problem. There's nothing at the call site that tells you what is happening. But even when it wasn't hidden in a companion object somewhere, it was still difficult because every import change had to be scrutinized as it could cause large changes in behavior (this caused a non-zero number of production issues).

They work well for anything you would use environment variables for, but a chunk of the ecosystem likes to use them for handlers (the signature being a Functor generally), which was painful

Re:Context should go away for Go 2 by lmm on Tuesday January 21, 2025 @09:06AM (#42780188)
> There's nothing at the call site that tells you what is happening.

A decent IDE highlights it at the call site.

It's definitely an abusable feature, but I find it very useful. In most other languages you end up having to have completely invisible parameters (e.g. database session bound to the thread) because it would be too cumbersome to pass them explicitly. In Scala you have a middle ground option between completely explicit and completely invisible.

Re:Context should go away for Go 2 by agumonkey on Tuesday January 21, 2025 @11:14AM (#42781773)
yeah that's what i thought, but maybe scala implicit param not being perfect will help finding a better linguistic trait (maybe they should enforce purity on these parameters)
Re:Context should go away for Go 2 by lmm on Tuesday January 21, 2025 @08:12PM (#42787437)
IMO it is perfect, or at least better than anything else that's been found so far.

"Purity" means different things in different contexts. Ultimately you can give programmers more tools, but you can't get away from relying on their good judgement.

Re:Context should go away for Go 2 by kloop on Tuesday January 21, 2025 @03:33PM (#42784879)
I'm not sure what you consider a decent scala ide, but it was a problem with IntelliJ in several of our code bases, and I'd have to crawl the implicit resolution path.

I eventually opted to desugaring the scala completely, but we were already on the way out of scala by that point

Re:Context should go away for Go 2 by lmm on Tuesday January 21, 2025 @07:21PM (#42787048)
> it was a problem with IntelliJ in several of our code bases

It shouldn't be, unless you were using macros (always officially experimental) or something - I was always primarily an Eclipse guy but IntelliJ worked well. Did you not get the green underline?

Re:Context should go away for Go 2 by kloop on Wednesday January 29, 2025 @08:28AM (#42864666)
We weren't using macros, but one of our major dependencies was (geotrellis).

Didn't seem to matter how close to geotrellis we were though. That being said, I'm willing to buy that it confused IntelliJ enough that it gave up on entire packages

Either way, we ported a couple of the abstractions from there to go and just used that. The build times plus getting away from sbt have been enough of a win to keep us on go, and that's before we get to the memory reduction on in-memory rasters

Re:Context should go away for Go 2 by lmm on Wednesday February 05, 2025 @10:11PM (#42958543)
Oh SBT is awful and I can see why drags down the reputation of the whole language. I stick to Maven and I don't understand why other people don't do the same.
Re:Context should go away for Go 2 by agumonkey on Tuesday January 21, 2025 @09:03AM (#42780154)
thanks a lot for your answer
Re:Context should go away for Go 2 by xmodem on Tuesday January 21, 2025 @08:30AM (#42779884)
Not OP, but I briefly seconded to a team that used Scala at a big tech co and I was often frustrated by this feature specifically. They had a lot of code that consumed implicit parameters that I was trying to call from contexts they were not available.

Then again I guess it's better than a production outage because the thread-local you didn't know was a requirement wasn't available.

Re:Context should go away for Go 2 by segfaltnh on Tuesday January 21, 2025 @07:43AM (#42779472)
Scala has everything, and therefore nothing.