Live data from Hacker News

Scala Feels like EJB 2

blog.joda.org

51–60 of 119 posts

Re: Scala Feels like EJB 2

#51

I've been picking up Scala on-and-off for the past few months. "Programming in Scala: Second Edition" is one of the best tech books I've ever read. The authors assume you already know how to program, offer mutable & immutable approaches to nearly everything, anticipate esoteric questions in the footnotes, and even have a good sense of humor. The book also weighs in at 883 pages and I was astonished how much of it I n…

Many people, including experienced Scala developers (e.g. me), find Dispatch hard to use. The BlueEyes HTTP Client is much simpler: val client = new HttpClientXLightWeb client.host("somesite.com").get[ByteChunk]("/some/url") That, plus some imports, is all you need

Thanks. I ended up using scalaj-http, which was much simpler. But it took me a few days to find it. Dispatch does very well SEO-wise for Scala HTTP. The only other option I had come across was using http-client.

Have any good recommendations for JSON parsers? This was another case where I found the common libraries to be rather obtuse.

Re: Scala Feels like EJB 2

#52

Earlier quoted context omitted.

Haskell has typeclasses which would probably correspond to structural typing in Scala. This type signature: Functor f => (a -> b) -> f a -> f b Defines map for any type that implements the type class functor. Lots of types will implement functor and it is easy to implement it yourself.

> Haskell has typeclasses which would probably correspond to structural typing in Scala. Nah, typeclasses are nominative typing but added post-facto (you can define a typeclass instance for a third party's type). Typeclasses are similar to Scala's traits I think (I don't know if you can add traits to a library's types though).

You get typeclasses in Scala via an interaction between traits and implicits. See http://www.sidewayscoding.com/2011/01/introduction-to-type-c... for a super-quick overview and a link to a more comprehensive paper.

Re: Scala Feels like EJB 2

#53
post #48

Earlier quoted context omitted.

What can you express in Scala that you can't express in Java?

You do realize the futility of such questions given Turing completeness, right? It is not about what can be expressed, but about how you express things. You do not need function literals in Scala, but it is sure is more concise and cleaner than anonymous classes in Java. You do not need traits in Scala, but it avoids code duplication or the overhead of wrapper classes or proxies in Java. You do not need case classes…

Ok, so can I express that this method returns a collection of a single type and that collection always contains 10 items?

Re: Scala Feels like EJB 2

#54
post #34

Earlier quoted context omitted.

I'm a Scala newbie, and it did not take me long to actually understand the type signature here. Of course, when I first saw it I was confused, but it's not magical. There are probably map-methods elsewhere, but let's take the map defined on TraversableLike[0]. TraversableLike is a base trait for all kinds of Scala collections (let's just pretend trait is like an interface for now, look it up if you're interested in t…

it did not take me long to actually understand the type signature here Bullshit. You just followed somebody else's public explanation. Not a problem per se, but this doesn't strike me as beginner friendly ... Dr. Brian Beckman also has a great description of monads on Channel9 that doesn't involve category theory. Does that mean that monad comprehensions are also beginner friendly? if you map a collection over a func…

How about acting less aggressive? It certainly dosen't help you to get your point across.

> Here's some Ruby code for you

You just tried very hard to not understand the problem at hand, right?

Because the equivalent Scala code looks like this:

    Array(1,2,3).map(_*2).map(_.toString).toSet
> I can implement all of the above by my own

Sure, if you OK with your code running magnitudes slower than the built-in stuff.

That's probably the main difference between general purpose languages and scripting languages today: General-purpose languages allow you to implement the appropriate data structures yourself, while scripting languages force you to use the built-in stuff.

Re: Scala Feels like EJB 2

#55
post #33

Earlier quoted context omitted.

Are you hinting at Haskell's fmap? The type signature is significantly simpler: fmap :: Functor f => (a -> b) -> f a -> f b

That doesn't capture the type of the original example. BitSet(1, 2, 3).map { _.toString + "!" } // returns Set[String] The Scala code here starts with one Functor (BitSet) and returns a different Functor (Set), depending on the type of the function (in this case, Int => String). If the function had type (Int => Int), it would still return a BitSet. The signature for fmap does not encode this flexibility.

Thanks for explaining. I now understand what the OP meant by "automatic conversions".

Re: Scala Feels like EJB 2

#56

Earlier quoted context omitted.

Scala is not Haskell and in Scala you can only check if a variable contains an Employee or a String. The problem is that such types do not actually contain anything useful about the content within that object, it just says how the object behaves (the messages it responds to). For instance, say you have a String ... well, a String containing what? A name? A regular expression? A number waiting to be converted to float…

The whole point of having an expressive type system is to encode useful properties in it. If a type of String isn't any use to you, give the value a more expressive type . Make a Name type, or a RegEx type, or whatever. Use unboxed types: http://www.chuusai.com/2011/06/09/scala-union-types-curry-howard/ if you don't want to pay an abstraction tax.

Indeed. I think many people seem to miss the fact that types are a language for describing the data in your program.

I also think many people do not understand the benefits of type abstraction, perhaps because many languages do not even offer it without requiring boxing. Even if your RegEx type is a String, not revealing that to client code is wise engineering.

Re: Scala Feels like EJB 2

#57
post #36

Earlier quoted context omitted.

Haskell has no subtyping as far as I know Haskell.

Haskell has typeclasses which would probably correspond to structural typing in Scala. This type signature: Functor f => (a -> b) -> f a -> f b Defines map for any type that implements the type class functor. Lots of types will implement functor and it is easy to implement it yourself.

http://hackerne.ws/item?id=3265598

Re: Scala Feels like EJB 2

#58
post #6

Scala's great, if you have a gorgeous Haskell program and you want to port it to the JVM. Unfortunately, by itself, that may be a niche market. If you want a dynamic language, you have lots of great choices. If you want powerful syntactic abstractions, you have Clojure, Lisp or Racket. You can win big with any of these tools. But some problems benefit from powerful mathematical abstractions, and that's where Haskell…

> How useful is Scala if you don't need to do functional programming with a strong type system?

Functional programming with a strong type system, IMO, has much wider applicability than just the esoteric mathematical abstractions (e.g. Haskell/scalaz) that you're asserting is a niche for Scala.

I can think of many non-scalaz uses of Scala, but even for non-Scala uses, look at Jane Street's evangelism of OCaml (functional + strong type system) for financial systems.

(Note that, personally, while I like the benefits of FP, I admittedly still think in/like aspects of OO, even if just out of habit, so I find Scala's blend particularly nice.)

Re: Scala Feels like EJB 2

#59

Earlier quoted context omitted.

Many people, including experienced Scala developers (e.g. me), find Dispatch hard to use. The BlueEyes HTTP Client is much simpler: val client = new HttpClientXLightWeb client.host("somesite.com").get[ByteChunk]("/some/url") That, plus some imports, is all you need

Thanks. I ended up using scalaj-http, which was much simpler. But it took me a few days to find it. Dispatch does very well SEO-wise for Scala HTTP. The only other option I had come across was using http-client. Have any good recommendations for JSON parsers? This was another case where I found the common libraries to be rather obtuse.

I use BlueEyes here (I'm a big fan of BlueEyes). It's JSON library is based on Lift-JSON. Lift-JSON is fairly commonly used, so perhaps you've run across it already. It's actually fairly simple to use and is one of the few parts of Lift that has decent documentation:

https://github.com/lift/lift/tree/master/framework/lift-base...

Here's a summary:

The JSON AST is pretty straightforward. The JSON DSL works like this:

- A tuple ("key", value) constructs a key/value pair

- ~ joins them together to construct an object

E.g. ("foo", 1) ~ ("bar", "Hi") = {"foo": 1, "bar": "Hi"}

I never actually invoke the parser myself. BlueEyes does it if you change the ByteChunk is my example above to JValue.

Drop me an email (noel at untyped dot com) or tweet (@noelwelsh) or IM or Skype or whatever if you want to discuss more.

Alternatively, I've never used Coda Hale's Jerkson package, but I expect it is of high quality.

Re: Scala Feels like EJB 2

#60

Earlier quoted context omitted.

Many people, including experienced Scala developers (e.g. me), find Dispatch hard to use. The BlueEyes HTTP Client is much simpler: val client = new HttpClientXLightWeb client.host("somesite.com").get[ByteChunk]("/some/url") That, plus some imports, is all you need

Thanks. I ended up using scalaj-http, which was much simpler. But it took me a few days to find it. Dispatch does very well SEO-wise for Scala HTTP. The only other option I had come across was using http-client. Have any good recommendations for JSON parsers? This was another case where I found the common libraries to be rather obtuse.

I don't use lift-the-web-framework, but after looking around at the scala json options, decided on and am so far really liking lift-json's package.

Does any of raw string JSON AST, or maps/lists JSON (...IIRC), or case objects JSON (what I'm using it for, pseudo ORM).

Post reply on HN