Live data from Hacker News

From first principles: Why I bet on Scala.js

lihaoyi.com

71–80 of 90 posts

Re: From first principles: Why I bet on Scala.js

#71
post #39

Earlier quoted context omitted.

Scala Dotty will maybe have some kind of @infix("+") def add so that if it should be used via a + b it needs the infix else it's only possible todo a.+(b) p.s. I banned scalaz and shapeless on my company so there aren't too much operator noises.

Do you ban cats too and any library of similar ilk? Just wondering, do you have your own libraries that use some of the good stuff? I can't imagine living in a world where I'm banned from using... * Traverse (do you write specialized versions for the cross product of [List, Vector, etc] x [Option, Either, etc] ?) * Validation (how do you collect errors? mutable.Buffer?) * NonEmptyList (I've written my own NonEmptyVec…

* Cross Product is never needed by us.

* Validation? Actually we are on HTTP so mostly a sealed trait structure is enough for us we barly use `Seq(ValidationError)` from Playframework (only class constructs that manually)

* NonEmptyList - I never came across a palce where I needed NonEmptyList?!

* never needed.

Just keep in mind other languages don't have such abstractions as well (maybe haskell has, but I don't know haskell). Some people need these high level abstractions and it's fine if you use it but most things are just syntactic sugar.

The only stupid thing is something like that:

- Future[Option[A1]] - Future[Option[A2]] ... - Future[Option[AN]]

and now I need a `case Some((a1, a2)) =>` without some magic you write a lot of boilerplate.

So a Monad is really something that would be great and probably we will evaluate if we get to use cats.

Edit: Code Snippet:

    val h = (for {
      ph 

        (ph.id, article.id)

    }

    h.value
yes this is something why we consider cats.

Re: From first principles: Why I bet on Scala.js

#72
post #68

Earlier quoted context omitted.

Closure Compiler uses type annotations on variables and functions that give information on null and undefined. These annotations look like {?Object|undefined} (Object may be null or undefined) and {!Object} (object is guaranteed to not be null). In Java, NullPointerExceptions is huge problem. IDEs have plugins to check for this error, but there is no standard solution. Does Scala help in avoiding NullPointerException…

Scala does not have non-nullable types currently (but that might happen in the future), in practice this is not a problem simply because using null is seen as a code smell and basically no Scala library API expects parameters to be null or return null, optional values are usually represented with the standard library class Option: http://www.scala-lang.org/api/2.11.8/#scala.Option

One of the main points of the blog is that Scala.js integrates well with the JavaScript apis and those apis are full of null. A typical loop in the DOM looks like this:

    var node = element.firstChild;
    while (node) {
        // do something
        node = node.nextSibling;
    }
Perhaps those interfaces use the Option class?

Re: From first principles: Why I bet on Scala.js

#73
post #68

Earlier quoted context omitted.

Closure Compiler uses type annotations on variables and functions that give information on null and undefined. These annotations look like {?Object|undefined} (Object may be null or undefined) and {!Object} (object is guaranteed to not be null). In Java, NullPointerExceptions is huge problem. IDEs have plugins to check for this error, but there is no standard solution. Does Scala help in avoiding NullPointerException…

Scala does not have non-nullable types currently (but that might happen in the future), in practice this is not a problem simply because using null is seen as a code smell and basically no Scala library API expects parameters to be null or return null, optional values are usually represented with the standard library class Option: http://www.scala-lang.org/api/2.11.8/#scala.Option

[deleted]

Re: From first principles: Why I bet on Scala.js

#74
post #52
post #42

Earlier quoted context omitted.

By what measure is Scala.js more production ready than ghcjs?

I feel like you've not seriously used each of them. Ghcjs is very interesting, but also very, very early. The ecosystem is tiny, the compiler produces huge and slow builds, the interop is tricky, the semantics imperfect. It may be a very long time before any of those are resolved, too! Compiling a lazy language to Javascript is no simple trick. Luite deserves all the praise in the world for getting it this far... but…

FWIW, this matches my understanding of the situation with Ghcjs, although there's substantial risk that my understanding is dated.

Re: From first principles: Why I bet on Scala.js

#75
post #52
post #42

Earlier quoted context omitted.

By what measure is Scala.js more production ready than ghcjs?

I feel like you've not seriously used each of them. Ghcjs is very interesting, but also very, very early. The ecosystem is tiny, the compiler produces huge and slow builds, the interop is tricky, the semantics imperfect. It may be a very long time before any of those are resolved, too! Compiling a lazy language to Javascript is no simple trick. Luite deserves all the praise in the world for getting it this far... but…

Your hunch is correct, I have not really used either, I'm just generally interested. From a distance, they both appeared to be ambitious and somewhat immature. I'm curious about your comment regarding tricky interop and "imperfect semantics" of ghcjs, could you elaborate? Certainly laziness does make FFI harder, but I wouldn't call that a problem with the semantics.

Re: From first principles: Why I bet on Scala.js

#76
The comments on jsinterop with respect to GWT are stale, GWT has a rich non-JSNI based JsInterop system now, as well as a generator that can read Closure and Typescript files and produce typed Java interfaces and classes for calling external JS. It even converts Java8 lambdas directly into JS functions and the reverse.

Also, the design restrictions to ban runtime reflection in GWT are a codesize decision. Allowing reflective calls basically inhibits optimization and forces the retention of tons of metadata.

The Deferred Binding mechanism is essentially dependency injection before DI and annotation processing existed, because GWT hails from 2007. We now recommend using Dagger2 for DI, and Annotation Processors for code generators, so that the system of compile time reflective calls is all part of the standard tool chain.

In the era of mobile browsers, I think 100k is a bridge too far for a hello world, especially in the developing world, so restrictions to the JRE runtime which allow much greater code pruning are a necessary evil. It hasn't really prevented an enormous amount of code sharing.

For example, Google Inbox shares 70% of its Java code between Web, Android, and iOS (via J2Objc)

Re: From first principles: Why I bet on Scala.js

#77
post #72

Earlier quoted context omitted.

Scala does not have non-nullable types currently (but that might happen in the future), in practice this is not a problem simply because using null is seen as a code smell and basically no Scala library API expects parameters to be null or return null, optional values are usually represented with the standard library class Option: http://www.scala-lang.org/api/2.11.8/#scala.Option

One of the main points of the blog is that Scala.js integrates well with the JavaScript apis and those apis are full of null. A typical loop in the DOM looks like this: var node = element.firstChild; while (node) { // do something node = node.nextSibling; } Perhaps those interfaces use the Option class?

I wrote a small test function. It appears that Scala.js has no default protections against null values from the browser DOM.

  def printNodes(targetNode: dom.Node): Unit = {
    var c = targetNode.firstChild        
    while (c != null) {
      if (c.nodeValue != null) {
        println(c.nodeValue)
      }
      c = c.nextSibling
    }
  }
The return value from firstChild and nextSibling can be null.

Re: From first principles: Why I bet on Scala.js

#78
post #71

Earlier quoted context omitted.

Do you ban cats too and any library of similar ilk? Just wondering, do you have your own libraries that use some of the good stuff? I can't imagine living in a world where I'm banned from using... * Traverse (do you write specialized versions for the cross product of [List, Vector, etc] x [Option, Either, etc] ?) * Validation (how do you collect errors? mutable.Buffer?) * NonEmptyList (I've written my own NonEmptyVec…

* Cross Product is never needed by us. * Validation? Actually we are on HTTP so mostly a sealed trait structure is enough for us we barly use `Seq(ValidationError)` from Playframework (only class constructs that manually) * NonEmptyList - I never came across a palce where I needed NonEmptyList?! * never needed. Just keep in mind other languages don't have such abstractions as well (maybe haskell has, but I don't know…

> * NonEmptyList - I never came across a palce where I needed NonEmptyList?!

Do you ever check the length of a list before applying a computation or dispatch based on a result list?

Re: From first principles: Why I bet on Scala.js

#79
post #35

Earlier quoted context omitted.

As well as GHC JS (not that I'd recommend it over Purescript)

The huge difference is that Scala.js is production-ready, the other ones mentioned aren't.

I'm not sure if Scala.js is production ready, but both Purescript and Elm have been used in production for a few years.

Re: From first principles: Why I bet on Scala.js

#80
post #71

Earlier quoted context omitted.

* Cross Product is never needed by us. * Validation? Actually we are on HTTP so mostly a sealed trait structure is enough for us we barly use `Seq(ValidationError)` from Playframework (only class constructs that manually) * NonEmptyList - I never came across a palce where I needed NonEmptyList?! * never needed. Just keep in mind other languages don't have such abstractions as well (maybe haskell has, but I don't know…

> * NonEmptyList - I never came across a palce where I needed NonEmptyList?! Do you ever check the length of a list before applying a computation or dispatch based on a result list?

Basically we sometimes do. But all of that code is basically coming from either the database where we need to construct a list (which could be empty). Or it's coming from the user.

I guess we have something like 30 occurences of .isEmpty/.nonEmpty in one of our codebases

Post reply on HN