Better HN
topnewbestaskshowjobs
Log inSign up

sideeffffect

318 karma · joined Jan 5, 2019 (7y ago) · 168 submissions

Submissions

comment 1y ago · link · parent

> Shapeless breaks everything so casually.

Thank goodness that Shapeless is not needed in Scala 3. The good parts have been integrated into the language itself and so it's reliable and faster.

> Jetbrains had completely abandoned Scala

Thankfully not at all. Gets regular releases, Scala 3 support is improving with each. They're also welcoming to PRs, if you have spotted a bug that needs fixing. (The codebase of the Scala plugin is in Scala, so that makes it easy for the community to contribute.)

comment 1y ago · link · parent

Java has certainly improved. Kudos to its stewards.

But I think it still has many rough edges -- things that are awkward (or outright impossible) to do in Java and Scala is great. It doesn't have to be advanced features, like meta-programmig/macros. Here are some example that I think are not anything esoteric:

* Just the mere fact that Scala has immutable/persistent collections improves how and what programs people write.

* Scala also has good infrastructure to deal with "modifying" data model graphs in a persistent/immutable way. Think deeply nested case classes and sealed traits. You have the copy method, lens libraries, etc. Java does have records and sealed interfaces, but all the rest of the machinery to work with them is still missing.

* To generalize the points above, Scala is immutable-first language, with all the positives that come with it. Java, still not so much (even though they are moving in that direction, e.g. `record`s).

* Another weird thing in Java is how it deals with variance. In Scala, I find it easy to comprehend, in comparison.

* Scala is expression oriented. Ifs, trys, etc -- all of them are expression. You can bound the result of these expressions to a variable. Not the case in Java, which makes it annoying to work with. You have to fist make the variable null or something and then make sure it gets assigned within of the body of the if/try/... Just a bad experience :(

Than there is a matter of culture:

* Java libraries like to return (and expect to be passed) a `null`. Scala culture embraces `Option` from its standard library.

* While Java does have support for checked exceptions, which I think is a very good idea in theory, in practice its implementation is underwhelming (e.g. not possible to abstract over) and so libraries don't use it as much. With Scala you can return an `Either`. Or with new Scala 3, we may soon have powerful capability system to, among others, allow throwing "checked" exceptions. That's the Capture Checking https://docs.scala-lang.org/scala3/reference/experimental/cc... research.

* This may be even more personal opinion that others, but I find Java libraries more difficult to use that Scala ones. With Scala, you just follow the types and you create and work with the objects that the library gives you in an intuitive way. With Java, the types don't help you as much. You have to read the documentation thoroughly, to make sure you're calling the right methods on the right objects, in the right order. Because the types don't help you, you can't be sure you doing it correctly, because every other way compiles too.

comment 1y ago · link · parent

Very interesting. Have you already investigated where is Mill's overhead spent? What can be optimized in Mill to get its time closer to just invoking the javac? Do you already have a plan?

comment 1y ago · link · parent

Why is it

./mill common.compile

and

./mill clean common

but not

./mill common.clean

?

comment 2y ago · link · parent

I see. But no hope is lost! You can always lean on Scala. It runs fine on any Java >= 8 and it's great. Unless you intentionally used is badly (but you could say that about any language).

comment 2y ago · link · parent

> Java is generally fine enough, but it's a little annoying when I have to do whacky workarounds with wrapper classes to get something that would be done in three lines

This is a weird take, given that Java has had ADTs for years

Records https://en.wikipedia.org/wiki/Java_version_history#Java_16

Sealed classes https://en.wikipedia.org/wiki/Java_version_history#Java_17

And pattern matching for almost a year https://en.wikipedia.org/wiki/Java_version_history#Java_21

Otherwise big agree on how delightful to work with F# is.

comment 2y ago · link · parent

People are already working on this

https://leandojo.org/

https://machine-learning-for-theorem-proving.github.io/

https://www.youtube.com/watch?v=P5ew0BrRm_I

https://paperswithcode.com/task/automated-theorem-proving

https://old.reddit.com/r/math/comments/11mb9lx/future_of_aut...

https://github.com/RiccardoBiosas/LeanGPT

comment 2y ago · link · parent

I don't mean to be snarky in any way. I think this is actually great development.

But isn't this just good old inversion of control, modularity with maybe some inspiration from Functional Programming. Or even more generally, good Software architecture and engineering?

Anyway, I'm very happy to see this, the more code is architected this way, the better for all our industry.

comment 2y ago · link · parent

Regarding 3), you probably meant the Prague Castle, not Karlštejn, right? Karlštejn is far from Prague.

comment 2y ago · link · parent

In Scala 3, implicits live on under a different name. They're called _given_s. But they're reduced to just one use case: propagating a context through (and deriving one given form others). And Type Classes are subsumed under this use case.

The other use cases have been essentially removed:

* Extension methods are now its own feature, relying on completely different mechanism * Automatic conversions have been severely curbed and de-emphasized, although they are still there, but much more explicit

comment 2y ago · link · parent

> [Odersky's] work is not focused on simplicity as Wirth's was - I wonder if he tried hard to adopt Wirth's simplicity mantra or not

I would beg to differ. I think he's very much aiming at simplicity. Btw, the essence of Scala really is simple. Take for example DOT (Dependent Object Types is the theoretical calculus Scala is based on), it is simple

https://www.scala-lang.org/blog/2016/02/03/essence-of-scala....

as video https://www.youtube.com/watch?v=bZEWNKzhBoU

Or take his emphasis on simplicity in practical software engineering: https://www.youtube.com/watch?v=-qf8yteuxPs&pp=ygUObWFydGluI...

Than there is the question of practical concerns with Scala, like fitting onto the JVM, interoperability with Java, superficial features for programmer comfort (or lack thereof) and the tendency of some people to use the most powerful features for the simplest of problems that inevitably lead to messy codebases. And that certainly makes things complicated.

> the notion of "object-functional" itself, as a hybrid concept, lacks simplicity

I think this is misunderstanding about what Scala is all about. Scala is not supposed to be 50% functional and 50% object-oriented. It's supposed to be both 100% functional and 100% object-oriented (aka having powerful module system) _at the same time_. It's supposed to be a concrete proof that this dichotomy (FP vs OOP) is false and you can have both in the same language with the same features.

This is contrary to other languages which may have support for FP and OOP but have _separate_ support for each, like SML, OCaml or F#. Scala is in this tradition, but different, it supports FP and OOP with one set of features. And from this point of view it is _simpler_. Whether people find it _easy_ is another question.

comment 3y ago · link · parent

There are even libraries for that!

https://github.com/dirs-dev/directories-rs

comment 3y ago · link · parent

I think he shows the performance of running JRuby on top of GraalVM. GraalVM uses Graal (the JIT compiler) in place of C2 (the JIT from HotSpot).

But TruffleRuby is something different. It is another Ruby implementation (just like JRuby is a Ruby implementation) using the Truffle framework. And Truffle framework requires to be run on GraalVM.

comment 3y ago · link · parent

It even supports Scala (Scala Native, that is)

https://github.com/lolgab/snunit

comment 3y ago · link · parent

This seems to be missing persistent collections, like immutable Map, Set or Vector/Sequence. Those are very important when doing FP in practice.

Is there some other established Go library that contains these collections/containers?

comment 3y ago · link · parent

Not true. They're is GraalPython, which is for Python 3 and supports also native code extensions.

https://github.com/oracle/graalpython

comment 3y ago · link · parent

We need Copyright very much, it's the only way to enforce the so called Copyleft:

https://en.wikipedia.org/wiki/Copyleft

comment 3y ago · link · parent

GC is by no way a solved thing. Let alone in Java! Consider these developments:

* Distilling the Real Cost of Production Garbage Collectors

https://twitter.com/stevemblackburn/status/15196411576216576...

https://www.youtube.com/watch?v=OUZt0mo1xic

https://old.reddit.com/r/java/comments/udtdke/the_real_cost_...

https://old.reddit.com/r/ProgrammingLanguages/comments/udt2p...

https://news.ycombinator.com/item?id=31192261

* Low-latency, high-throughput garbage collection

https://twitter.com/stevemblackburn/status/15183861337467289...

https://www.youtube.com/watch?v=1TLmawuxHfY

https://old.reddit.com/r/ProgrammingLanguages/comments/ubp2d...

https://old.reddit.com/r/java/comments/ubgyva/lxr_a_new_java...

https://news.ycombinator.com/item?id=31153434

comment 3y ago · link · parent

It's been like this in the academia (Mathematics in particular) since ever.

Also, some people say that it makes for easier (less ambiguous?) parsing.

But the -> part is a bit weird. It "shouldn't" be

    def factorial(x: int) -> int:
but it "should" be

    def factorial(x: int): int =
Maybe it's that way because of Python?

comment 3y ago · link · parent

The history of that ticket is really mind-blowing https://bugs.chromium.org/p/chromium/issues/detail?id=6606

comment 3y ago · link · parent

> Constant matters

Not in these exercises. They're focused on algorithms and their asymptotic complexity.

comment 3y ago · link · parent

Oh, I see. Nice!

I'm afraid we don't have anything like ST in any Scala library that I know of :(

comment 3y ago · link · parent

> But what does he mean by "Objects" and "Classes"?

To be hones, I'm not sure.

> Everything good about objects that a pure functional programmer would want is captured by first-class modules.

I just know that in the talk I linked above, Odersky mentions 1ML, that it converts modules into SystemF (extended Lambda calculus, but you probably already know that) and that he feels this attempt is force fitting where some (important?) things get lost in the conversion.

From 2:56 to 4:55

> The internal mutable state

That is very strongly discouraged in the Scala community.

> subtyping

Yep, that is embraced quite a bit.

> inheritance

Used to some extend but still generally discouraged even though not as strongly as mutable state.

> ... relationships are much less useful

How can you say that subtyping is not useful? In Scala it is one of they key ingredients for modularity. You have signatures (aka interfaces or traits) and than you have multiple implementations (modules, objects, classes as partial abstractions) which you can swap one for each other. That is possible because they form these subtyping relationships. A side note: Scala code which embraces subtyping has better type inference.

> But please do take a good look at Haskell too, if only just for interest.

I don't want to make an impression that I want to offend the Haskell community. Haskell is where I learned FP and the languages is a great success in many regards. Over Scala it has many advantages, like better syntax, better type inference, better control over memory layout, better optimized which turns even advanced idioms into efficient code, etc.

But it also has some downsides compared to Scala. It is lazy which makes debugging more complicated. It doesn't have any satisfactory modularity story (last time I was around there was Backpack, but it hasn't caught on AFAIK). And Scala has all the advantages that come with the JVM and Java interoperability: great debugging, profiling, introspection, telemetry, etc, great IDE, huge gallery of libraries, etc. I'm a software engineer and all these things are _very_ important to me. Compiling to efficient JavaScript with Scala.js is also nice.

> Many leading Scala programmers ended up moving to Haskell, in order to get deeper into FP.

Sure, if you want to write Haskell programs, you'll have much better time in Haskell than with Scala. There were people like that, and so they eventually left. But note that you can be deep in Pure FP in other languages, like Scala or PureScript, Haskell is not the only game in town, each comes with its pros and cons.

That being said, with Haskell, Pure FP is built right into the language. With Scala, while easily possible, Pure FP is built on top of the language with library(-ies) and that comes with some disadvantages.

comment 3y ago · link · parent

> Odersky's "values" primarily appear to be whatever will appease the masses, which is why Scala started with curly braces and OOP.

I would agree that Odersky wants Scala to be popular and wants to accommodate even programming novices. For example Python (and a little bit Haskell and F#) proved significant whitespace to be popular, so Scala 3 now has it. In times of XML's popularity, on Wadler's suggestion, XML literals were added to Scala. Today AFAIK using XML literals is now popular in many frontend/browser frameworks/languages (although XML literals have been dropped from Scala 3).

But that doesn't mean that Scala design is unprincipled. On the contrary, there are 3 pillars that make Scala what it is, all working together in a unified and coherent manner:

* Modularity (objects, interfaces, etc, sometimes called OOP)

* Functional programming (ADTs, pattern matching, preferring immutability, higher order functions, ...)

* Meta-programming (Scala 3 features powerful Macro system, AFAIK inspired from MetaOCaml)

> Folks are moving on from OOP. Scala is in danger of building what people once wanted, but don't want any more.

More and more languages are becoming more and more like Scala:

* Rich type system instead of unityped

* type inference vs having to manually annotate everything

* higher order functions instead of not having them

* preferring immutability instead of mutation everywhere

* ADTs, pattern matching instead of "OOP style" modelling

* module system (sometimes also called OOP) instead of non-modularity

* strict instead of lazy

* ...

It's interesting to see such convergence. New languages are more like Scala now than before. And already existing languages, even though starting are more different, are getting closer to Scala by adding more features. That is to say, Scala is not magical or prophetical, not even original (most, if not all, individual feature was done before in other language), but it's just ahead of the others with combining these features.

https://news.ycombinator.com/item?id=26101435

https://old.reddit.com/r/scala/comments/lerd3t/from_first_pr...

> 1ML paper

I will definitely check it out. Thanks for the suggestion. A quick research suggest that 1ML can't model objects and classes (in the OOP lingo), as per slide 6 in https://www.slideshare.net/Odersky/from-dot-to-dotty https://skillsmatter.com/skillscasts/8866-from-dot-to-dotty

In the meantime, I will continue enjoying Scala that allows me to do Pure FP in a modular fashion while getting paid for it because of its huge (relatively speaking) job market :)

comment 3y ago · link · parent

> Scala is really an object-oriented language, first and foremost

You're technically correct, which is the best kind of correct. Scala is not based on the Lambda calculus. The DOT calculus (which is what Scala is theoretically built upon) is based on objects.

Yet, at the same time

> please do not judge functional programming based on how it looks in Scala

based on my research into the labour market, I would guess that Scala is the programming language where most of the Functional Programming takes place, both in the general sense and also in the Pure FP sense. It is more widely used than Haskell, F#, Clojure, Elixir, Erlang, OCaml, Racket, etc.

And it works rather nicely in my opinion. There are still areas that I'd like to see improved, of course, like the for-comprehension, but I'm already quite content.

> effects to be controlled, checked and reasoned about

Definitely! We have so called Functional Effect System libraries for that in Scala. Not just one, but two: Cats Effect and ZIO. Check them out. I would recommend anybody using Scala do use either of those.

comment 3y ago · link · parent

And you can do it with a state monad in Scala too.

But Odersky's point is that (at least in Scala) it is even simpler (and thus should be preferred) to do it with raw (but still local!) mutation.

https://www.youtube.com/watch?v=QRcD9Zc7eq4&t=943s

comment 3y ago · link · parent

Totally agree that these paradigms are badly defined. See my other comment where I explain it more https://news.ycombinator.com/item?id=34217547

My point here was that all "OOP" languages (that I know) allow you, with all their "OOP feautres", to work with objects which actually don't contain any mutable state.

I'll let you be the judge whether it is still "OOP", but I know from experience that it's very practical for Software Engineering.

comment 3y ago · link · parent

Here's the recording of the talk

KEYNOTE Simply Scala Martin Odersky

https://www.youtube.com/watch?v=QRcD9Zc7eq4

comment 3y ago · link · parent

> though I'm not sure they have precise definitions

Of course they don't. These "paradigms" like OOP or FP are just human made up terms _without any basis in theory_. Sometimes they can be practically useful when communicating with other humans, like we do now. But more and more people are starting to realize how meaningless/nonsensical these categorizations are (and always have been): FP vs OOP, compiled vs interpreted, static vs dynamic, etc. We might as well categorize languages based on the colour of their mascot.

See this for more https://old.reddit.com/r/ProgrammingLanguages/duplicates/6xt...

The closest thing to the definition of an FP language that I was able to come up with is "based on the Lambda calculus". Haskell is, Scheme is, F# is. But e.g. Scala isn't, it's fundamental building block isn't functions but objects. But many people do consider Scala to be an FP language.

So let's all be aware of the limitations of these (pseudo-)concepts.

comment 3y ago · link · parent

There's nothing anti-functional in bundling related functions into an object.

On the contrary, this helps with modularity, which is a good thing. You can then swap out the object for another object with the same interface, but where the functions (methods) have different implementations.

123456