Hacker News new | past | comments | ask | show | jobs | submit login

Having written massive amounts of both Scala and TS, I'd say the #1 issue Scala has the the impossibility to understand a simple variable reference.

If I see `A`, the search space to understand where that comes from is quite large for most Scala.




I’m a professional Scala dev, what exactly do you mean? Structural sharing instead of copying? Implicits?


    package mypackage

    import shapeless._
    import anorm._
    import mything.MyObject._
    import com.seriouscompany.Foo

    object MyThing {
      val a = new A()
    }
What does A refer to? Where does it come from?

One of the 15 files in the anorm package? Does it come from one of the 40 files in the shapeless package? What about mything.MyObject and the dozen mixin traits that it has?

Alright, let me clone the repo, startup my 4GB IDE, wait 15 minutes for it to download JARs and index eveything and then I can get an answer to where `A` is defined.

Scala wildcard imports are very common in practice, but even if I eschew them, there still another 50 files in the mypackage package that could contain its definition.

---

The same thing can happen in TS with globals, but those are rather few.


Anecdotally, this is a non-issue depending on the tools you use. IntelliJ IDEA and Metals both have Go To Definition support.


Well, I bet it comes from either shapeless or anorm or mything.MyObject. Moreover, how is this different from literally any other programming language? Also, I would venture to guess that almost all programmers regardless of the language or editor/IDE they are using have some sort of jump to definition function they use all the time. At least with Scala I can actually see the source of the definition reliably, which is more than you can say about C or C++ (headers don't count).


JavaScript or TypeScript don't have the problem (except for globals, but those are usually few and far between).

Python doesn't have this problem (unless you use wildcard imports, which is often recommend against [1]).

Java does not have this problem, except for protected/internal classes which have only local use anyway (yes there are wildcard imports, but they are rather rare [2]).

Go has this problem for files in the same package, but not from other packages.

C and C++ are far from a hallmark of readability. Though there is at least a common C++ practice to at least always use the fully qualified name [3].

Ruby shares this issue.

---

What makes Scala worse is that wildcard imports are strongly encouraged by libraries and in very frequently found practice, for things such as implicits whose whole purpose is to not be explicitly named.

Plus in Scala, object, classes, fields, methods...all of these can be imported into the scope. So in practice this becomes a more common problem.

[1] https://stackoverflow.com/questions/3615125/should-wildcard-...

[2] https://stackoverflow.com/questions/147454/why-using-a-wild-...

[3] https://stackoverflow.com/questions/1452721/why-is-using-nam...


How can you say "_____ doesn't have this problem (unless you use wildcard imports" when all of the languages you listed allow wildcard imports? (Or just dump all their garbage symbols in a global namespace.)


Like I said, in practical terms, this turns out to be a much bigger issue for a random selection of Scala than a random selection of Java/TypeScript/Python.

Just like every language has an untyped/unsafe method of operation. But some languages use that sparingly; others have that for the whole language.


> for things such as implicits whose whole purpose is to not be explicitly named.

Now that's an interesting perspective on a language that seems too magic. A whole ecosystem of objects who must not be named!


Implicits allow for a kind of flexibility and power that is absent from pretty much every other language. Allowing functions to implicitly introspect their caller’s context is incredibly useful. The only languages that can even half way do this kind of things without crazy dynamic introspection/reflection are those that support dynamically scopped variables (such as Common Lisp). And even that isn’t as powerful.


I have been writing Scala professionally for 6 years now. I must say this is a problem I have never seen anybody face or discuss anywhere whatsoever.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: