News for hackers. Stuff that matters.
Re:Hands-on Scala Programming by christiansakai on Sunday April 19, 2020 @09:05AM (#22915637)
I work JavaScript/TypeScript day to day, but I like Python syntax and easiness but also like Go's concurrency. Having learned Haskell and Rust in the past, these days I appreciate simpler language.

In what way does Scala have Python's convenience and Go's concurrency? Based on talking to a few people that used Scala in the past they said they wouldn't use it again and they said I probably wouldn't like it.

Re:Hands-on Scala Programming by cinnamonheart on Sunday April 19, 2020 @09:44AM (#22915835)
Scala has a very wide surface area, and it can be as simple or complex as you want it to be.

Written in a certain way, it's that different from writing Python 3 with PEP-484 type annotations. You can easily write Python-like code and just get things done. :)

Concurrency-wise, you can implement any concurrency model you want on top of it, and, personally, I find immutability + Task-like implementations (Monix, ZIO, IO, etc.) easier to understand than CSP, but that's just me. There's also actors & channels & threads & anything else you could want.

What's cool, though, IMO, is that once you need more power than just Pythonic Scala gives you, it has one of the most powerful type systems in the world; you can verify as much as you need to, and refine things over time. It's not a language that hamstrings you once you do need more power.

Scala gets its bad reputation from that huge surface area and flexibility, though. There was a period (2009ish, maybe) where the Scala community was having a field day with its flexibility via custom operators like '<<++>>' and implicit conversions and untyped actors that made it impossible to figure out what was going on. It was like using the worst of Erlang with the worst of Haskell with the worst of Java. I'd say they've matured past that entirely, though; in 2020, it's one of the nicer and more practical languages, ecosystem, & communities IMO. Scala is made for getting things done.

Re:Hands-on Scala Programming by christiansakai on Sunday April 19, 2020 @09:50AM (#22915884)
I think that's the main problem. Everyone writes Scala differently. In Go pretty much everything is quite similar. In JavaScript people also write things differently, like any other language really, but in Scala it is compounded.

Is there a concrete example of the Python-like code vs the more complex ones? I appreciate the help.

I'm thinking what language next should I pick up. It is either OCaml or Scala.

Re:Hands-on Scala Programming by lihaoyi on Sunday April 19, 2020 @09:54AM (#22915915)
> Is there a concrete example of the Python-like code vs the more complex ones? I appreciate the help.

Haha this book is going to be 400 pages of concrete examples. It's not out yet, so you'll have to take my word for it for the next few weeks while the last round of reviews and editing are incorporated into the manuscript. If you're interested, put your email down and I'll let you know when it's ready!

Re:Hands-on Scala Programming by brianyu8 on Sunday April 19, 2020 @12:28PM (#22916898)
I've been wanting to learn more Scala and this book seems perfect! I'm definitely going to buy it when it comes out. The website mentions that there's a PDF download of the free chapters, but I can't seem to actually find it. Do you have a direct link?
Re:Hands-on Scala Programming by christiansakai on Sunday April 19, 2020 @10:08AM (#22916001)
Lol okay. Thanks for the awesome work! I'll put down my email there.
Re:Hands-on Scala Programming by blandflakes on Sunday April 19, 2020 @04:26PM (#22918520)
This isn't helpful for you if you're trying to pick one, but I find OCaml and Scala somewhat complementary for my tastes:

Scala is a pretty great investment for services, big data, etc. It has a robust ecosystem.

However, the compiler is slow, and startup time can be slow (and Graal and Scala Native just aren't options yet), and if I want to make some tool that gets called fast in a loop or deploys as a "small", native binary, OCaml is nice alternative which I prefer to the only other compelling entry in this area, Go.

Re:Hands-on Scala Programming by erik_seaberg on Sunday April 19, 2020 @06:06PM (#22919184)
Experts' code looking like beginners' code is not a good thing! If better learning a language doesn't make your code clearer and more concise, the language isn't pulling its weight.
Re:Hands-on Scala Programming by AzzieElbab on Sunday April 19, 2020 @09:16AM (#22915682)
Scalas echosystem is overloaded with overly complex libraries that take months to learn. Li Haoyi has been trying to change that for years with his to the point open source projects. In my opinion, now is a pretty good time to get into scala with projects from Haoyi, ZIO, quill, akka, and many others that are built on strength of scala itself matured way pass being carbon copies of java or Haskell's equivalents.
Re:Hands-on Scala Programming by christiansakai on Sunday April 19, 2020 @09:52AM (#22915892)
Interesting. Good to know.
Re:Hands-on Scala Programming by nicoburns on Sunday April 19, 2020 @09:15AM (#22915678)
If you like simpler languages, you'll probably hate Scala. It's one of the most complex out there.
Re:Hands-on Scala Programming by walkingolof on Sunday April 19, 2020 @10:53AM (#22916284)
This is one of the most persistent myths about Scala, the language itself is far smaller than, for example, Java, and its standard library is very approachable.
Re:Hands-on Scala Programming by vips7L on Sunday April 19, 2020 @09:50AM (#22915882)
Kotlin is probably a better route if you're considering a non-Java JVM language. Its simple, has easy access to the Java ecosystem, and avoids the complexities of the scala FP purists.
Re:Hands-on Scala Programming by 9q9 on Sunday April 19, 2020 @11:16AM (#22916457)

   avoids the complexities 
   of the scala FP purists.
Are you sure? Have a look at Arrow [1] and similar! I am glad that languages offer pure FP frameworks, so I can use them if I think they are the right tool for the job, and can avoid them otherwise. It's an important software engineering choice which style of programming to use, especially with multi-paradigm languages. But the language should not enforce them!

[1] https://arrow-kt.io/

Re:Hands-on Scala Programming by vips7L on Sunday April 19, 2020 @11:49AM (#22916653)
While Arrow exists I don't think its representative of the community overall.
Re:Hands-on Scala Programming by Psyonic on Sunday April 19, 2020 @12:26PM (#22916891)
Neither is cats in Scala.

Most Scala programmers are probably just maintaining Play apps or using Apache Spark, with no pure FP in sight. The pure FP contingent is just very active and vocal online.

Re:Hands-on Scala Programming by uDontKnowMe on Sunday April 19, 2020 @02:21PM (#22917731)
Unfortunately like you say the pure FP crowd are extremely vocal online and that seeps into the culture of any company that uses Scala. Most of the visible members of the community value and advocate for fp purity and 100% type-safety at any cost, and that has a large effect on who gets attracted to learn Scala in the first place, what they consider to be good or bad code, etc. The resulting culture of firms using Scala ends up being one of pure-fp aspirational, if not pure-fp outright. Anyone who denies the superiority of a pure fp approach is constantly brow-beaten for being such a simpleton.

Every time you dare use something as impure as a mutable object, or a non-const reference (so var instead of val), or even want to look up an item in a collection by index (unsafe operation since it will throw exception if index >= length) you'll have to prepare for a heckling from your team mates. Anyone you might ask help from online will first look down their nose at you for even wanting to do something so despicable, and you'll have to humour them with "well yes oh great FP lords, I know that this is really really bad I know, but I have to for .... reason, please help me anyways!".

Re:Hands-on Scala Programming by Psyonic on Sunday April 19, 2020 @03:14PM (#22918087)
There is definitely some truth in what you’re saying —- especially at startups without a strongly developed internal Scala culture.

I think it’s less of an issue at large companies like Twitter, Asana, Databricks, etc, which overall probably employ most working Scala programmers but not the most vocal.

Re:Hands-on Scala Programming by hocuspocus on Sunday April 19, 2020 @07:56PM (#22919817)
Zalando has probably surpassed Twitter as the biggest Scala shop for a few years now. If you look at Twitter's ecosystem you'll see that while it's mature, the style is very good overall and not so different from modern and opinionated FP libraries. Twitter used to employ people like Travis Brown for instance.

Spark (and Kafka too maybe) are outliers here.

Re:Hands-on Scala Programming by 9q9 on Sunday April 19, 2020 @03:16PM (#22918100)
I agree with your evaluation that parts of the FP community are extremely vocal and extremely smug, and this can and does have a bad effect on a community. This is a problem. Dealing with this problem requires leadership. In particular a project leader typically has to decide (in a Scala context) whether to go FP or imperative, because mixing both is often a problem. Similar to e.g. using message passing or shared memory for communication between threads.

    throw exception 
This is a good example. It is really important to be very clear from Day 1 how to handle errors in a project. One hybrid choice that is popular is: use exceptions for errors that you cannot recover from, use Options for local error handling.
Re:Hands-on Scala Programming by erik_seaberg on Sunday April 19, 2020 @05:52PM (#22919095)
Option does throw away the error. I like Try { expr } a lot, to the point that I retry, give up, and then serialize a Try[T <: Product] into a Row so flaky dependencies don't trash all the output from a big Spark job.
Re:Hands-on Scala Programming by 9q9 on Monday April 20, 2020 @07:21AM (#22922893)
Yes, that's true, if you want to propagate information about the nature of what went wrong locally (e.g. logging) you need to use something richer (e.g. Either).
Re:Hands-on Scala Programming by erik_seaberg on Monday April 20, 2020 @08:38PM (#22930581)
Yeah, Try[T] is basically Either[Throwable, T] with some glue for catching and rethrowing.
Re:Hands-on Scala Programming by AheadOfTime295 on Sunday April 19, 2020 @09:38AM (#22915798)
YMMV. Some features of Scala 2.x have been dropped in Scala 3 (ETA late 2020), others added.

Features we know Scala 3 will have https://dotty.epfl.ch/docs/

A comparison of features across Scala 2.x and Scala 3 is the migration guide https://github.com/scalacenter/scala-3-migration-guide

Re:Hands-on Scala Programming by jpgvm on Sunday April 19, 2020 @09:39AM (#22915803)
On the other hand you may like Kotlin.

It has a lot of what makes Scala good with less of the bits that make it bad.

Re:Hands-on Scala Programming by switchbak on Sunday April 19, 2020 @11:33AM (#22916560)
This is down voted, but for someone wanting to learn a Scala like language, it delivers most of the capability with less complexity and tooling problems.

I still prefer Scala, but found Kotlin to be enjoyable to write as well. Probably a perfect gateway into Scala if that's an eventual goal too.

Re:Hands-on Scala Programming by eismcc on Sunday April 19, 2020 @09:31AM (#22915751)
Agree. It’s a bag of knives. Used scala for many years at Twitter and other places and There’s always a massive combination of tooling and code reviews that eventually hammer the devs into shape.
Re:Hands-on Scala Programming by therealdrag0 on Sunday April 19, 2020 @01:31PM (#22917319)
My anecdote: if I were to go from Java to Go I would have been I impressed with its ease of concurrency, but going from Java to Scala to Go, I was unimpressed. I already had simplicity of concurrency with Scala without feeling primitive like I did with Go.
Re:Hands-on Scala Programming by AzzieElbab on Sunday April 19, 2020 @09:28AM (#22915738)
"In what way does Scala have Python's convenience and Go's concurrency" - I think that is exactly what the book is trying to teach you. There are some pretty good examples in the free chapters
Re:Hands-on Scala Programming by christiansakai on Sunday April 19, 2020 @09:52AM (#22915899)
Oh wow, okay I'll take a look at the book then.
Re:Hands-on Scala Programming by hackerm0nkey on Sunday April 19, 2020 @11:07AM (#22916383)
I think the world needs, "Scala, the Good Parts". Hope this book is it.
Re:Hands-on Scala Programming by dxbydt on Sunday April 19, 2020 @03:20PM (#22918126)
I stand corrected.
Re:Hands-on Scala Programming by nikitaga on Sunday April 19, 2020 @04:08PM (#22918401)
> So you think, hey! I get to use scala.util.Random in javascript instead of javascript's shitty Math.random() ! Woah! That is so beyond awesome.

What? You can certainly use scala.util.Random from scala.js, there are very few Scala features that Scala.js does not actually support, such as blocking (because javascript) and reflection.

> Because this is the scala api that the scalajs folks expose - https://www.scala-js.org/api/scalajs-stubs/latest/#scala.pac.... . So that's fewer than 70 types.

That's not everything that's available in Scala.js, those are just some stubs for smooth cross compiling.

---

Scala.js is certainly not for every project. It's not a better typescript than typescript is. But typescript also isn't the right tool for every project.