Hacker News new | ask | show | jobs
by lopatin 493 days ago
I only allow myself to use Scala these days if follow some rules: no sbt (just Maven) and no Scala libraries (just Java ones). I never used fancy stuff like Cats anyways. Curious to hear who actually does, and for what.
6 comments

This thread is interesting; so many tools and libraries referenced that I am not familiar with at all. I think some of us are writing very different languages.

I've used Scala my entire career at multiple companies, and Typelevel has been the default at all of them. I'm not even entirely sure where Scala ends and Cats begins, so it's hard to identify what's "fancy", let alone justify it. I do like IO, and monad transformers. I think neither of those are native. Flat code tends to be maintainable.

From my perspective, fully baked frameworks and ORMs are what's "fancy" (a readability nightmare). I don't know if it's a cultural thing, but Scala codebases that go hard on FP tend not to introduce these, which I appreciate. Pick your poison I guess.

I use ZIO (https://zio.dev) and nothing really like it exists on any platform.

You can wrap any computation in a single ZIO object e.g. normal, callback, future, promise etc. Which you can then chain together in different ways e.g. run them in parallel, sequentially, race them against each other and kill the loser, schedule in elaborate ways, run with a timeout and then run another if it’s exceeded etc.

And it will execute this either using normal or virtual threads i.e. fibers without locks so it’s extremely fast.

But the incredible part is that it does all of this whilst seamlessly handling every type of error. Which if you’ve ever written complex concurrent code is extremely hard to get right.

Now I feel curious about what do you build that makes that much use of parallel computations, races and killing the loser, etc?
EffectTS? :)
Not even close.
This might be a bit of a shameless plug, but because you ask :)

Regarding no sbt, I would highly recommend to have a look at the mill build tool https://mill-build.org. I personally find it very pleasant to use as a replacement for sbt, mostly because of the following points:

- it uses regular Scala code to define a build

- it isn't DSL-heavy like sbt, which means it's A) easy to debug by simple searching, and B) anyone unfamiliar can get a vague idea of what's going on at a first glance

- it is designed around a generic task graph and isn't centered around the JVM world (disclaimer: I'm helping with development, and recently first-class support for Python and JavaScript projects was added)

I use cats so that I can write custom effect/wrapper types for e.g. "must happen in database transaction" or "has audit log" or "requires this level of access". (I'd also flag up the free monad, which is like a generic version of the command pattern - you just write your leaf action types and you get a command object for, well, free). Essentially, anything that you might think of using an annotation/AOP pointcut/reflection for, in Scala you can do it with plain old refactor-safe code and have it checked at compile time rather than runtime.
I don't really mind sbt, but we migrated off maven a while back for gradle for java projects. There are some crazy sbt build scripts but it's fairly easy to keep things sane, but maybe the fact that sbt builds can look so different is an issue.

I really like the simplicity of the com-lihaoyi ecosystem but I also enjoy cats/fs2 and friends on occasion.

sbt is way better than what it used to be, also, check-out scala-cli which is very nice.