Live data from Hacker News

Scala Feels like EJB 2

blog.joda.org

61–70 of 119 posts

Re: Scala Feels like EJB 2

#61

Earlier quoted context omitted.

The list of features were meant to just illustrate that Scala is not some programming fad, it is strictly more expressive than Java and based on solid programming language principles. Although,I agree the code may not be easy to understand for everyone in the beginning but with effort and training I believe every programmer can learn enough of it to be more productive.

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

For instance you can implement a library providing Units of Measurements such that you can track the correct type through computations, e.g:

    val time: Time[Int] = 15 s
    val length: Length[Int] = 450 m
    val speed: Speed[Int] = time / length
The type annotations are of course completely optional.

The interesting thing is that while the implementation is quite complex, the actual user has a very simple interface to develop against.

So while you can write complex code in Scala, Scala allows you to keep the complexity in the library-side, while it would bleed into the use-site in Java (use-site generics, anyone?).

Java can't do that. In fact, they already failed twice with it.

Re: Scala Feels like EJB 2

#62
post #48

Earlier quoted context omitted.

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?

Yes, you can do that by using types indexed by a number.

See https://apocalisp.wordpress.com/2010/06/16/type-level-progra... for one take on this.

Re: Scala Feels like EJB 2

#63

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

It's been a long time since I touched Scala — and I never used it for web stuff at the time anyway — but is this really typical?

It's mostly an absurd comparison (equivalent to Fibonacci or something), and a tangent besides, but in Clojure:

    (slurp "http://somesite.com/some/url")
That gives me the response as a string. If I want a binary stream:

    (clojure.java.io/input-stream "http://somesite.com/some/url")
The same functions work for URLs, URIs, Files, and strings that describe them.

Re: Scala Feels like EJB 2

#64
post #54

Earlier quoted context omitted.

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'…

The issue discussed here is the implementation and signature of "map", a trivial function that anybody should be able to understand and implement without a sweat.

     Sure, if you OK with your code running magnitudes 
     slower than the built-in stuff
     ...
     scripting languages force you to use the built-in stuff
These 2 sentences don't compile.

You should also realize that the speed of the JVM has nothing to do with the static-ness of the language. The bytecode is in fact dynamic ... the only instances where certain assumptions where made based on Java (the language) being:

1) classes are immutable and can't be garbage collected unless you destroy the corresponding class loader

2) the method dispatching done cannot be overridden (so when calling a method on an implicit object, you also have to specify the interface where that method is defined) ... but this has nothing to do with the inner-workings of the JVM and is being addressed with the work done on InvokeDynamic

Really, if you're worrying about "scripting" specific behavior sneaking in on you, stealing away precious CPU cycles or RAM bytes, then you should stay away from the JVM.

Re: Scala Feels like EJB 2

#65
post #15
post #10

Earlier quoted context omitted.

I don't see how Haskell or Scala are better in mathematical abstractions. I guess it would be equally easier (or even much easier) to abstract away this kind of thing in clojure, you could generate all the checking that you would get in Haskell/Scala. The only real diffrence I see is the compiletime checking, right?

Yeah, the big advantage of Haskell (and Scala) for abstract mathematical code is the compile-time type checking. Normally, I'm extremely happy with dynamic languages, because I make maybe 2 type bugs a year. I mean, it's not that hard to remember whether a variable contains an Employee or a String, and that's all you need for some programs. But when you're designing a library, and a variable contains the free module…

I'm genuinely surprised that you make only two typing bugs per year. I make about 2 per minute, and I consider myself a good programmer. My higher frequency may be in part because my style of coding relies heavily on the typing system: I recompile after about every line of code I type, and make sure my code always type-checks, so maybe I'm not as carefully planning my programming as somebody who's accustomed to dynamically typed languages. Nevertheless, I find it hard to believe that you don't trip up when you create deeply nested loops/recursion. If you don't, what's the trick?

Re: Scala Feels like EJB 2

#67
post #2

There are those who say scala is complicated, and there are those who actually learn it and once they do they love it more than anything out there. So yeah, I love scala.

This could be caused by any of these widely known cognitive biases: - http://en.wikipedia.org/wiki/Commitment_bias - http://en.wikipedia.org/wiki/Endowment_effect - http://en.wikipedia.org/wiki/Sunk_costs - http://en.wikipedia.org/wiki/Herd_behavior [edit: also, you're inferring the experience of people from the complaints that they make. that means that you are automatically dismissing anyone who makes certain kinds…

> .... widely known ..

Yeah right.

Might I suggest you read more about

- https://en.wikipedia.org/wiki/Cherry_picking_(fallacy)

- https://en.wikipedia.org/wiki/Wikipedia:Neutral_point_of_vie...

Rather pointing out that humanity is flawed. Why don't you try to practice living by virtue and show others the right way ?

It's more honorable than finger pointing from a high horse.

Re: Scala Feels like EJB 2

#68

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

It's been a long time since I touched Scala — and I never used it for web stuff at the time anyway — but is this really typical? It's mostly an absurd comparison (equivalent to Fibonacci or something), and a tangent besides, but in Clojure: (slurp "http://somesite.com/some/url") That gives me the response as a string. If I want a binary stream: (clojure.java.io/input-stream "http://somesite.com/some/url") The same fu…

Do you think the code is hard to read?

BlueEyes is a framework for writing high performance web services. For it's use cases you care whether you're getting or putting. Thus it is explicit. Similarly, you care about performance, and so don't want to parse strings if you can help it -- thus you set the host once rather than parsing a URL.

For a pure ease-of-use library Dispatch is probably the best, if you can figure out the syntax (see earlier discussion). In Dispatch you can write something like

  url("http://somesite.com/some/url") >>> System.out
I forget how you read into a string. Probably change >>> to >>@!#$$T%^@#$% or similar.

Re: Scala Feels like EJB 2

#69
post #2

There are those who say scala is complicated, and there are those who actually learn it and once they do they love it more than anything out there. So yeah, I love scala.

This could be caused by any of these widely known cognitive biases: - http://en.wikipedia.org/wiki/Commitment_bias - http://en.wikipedia.org/wiki/Endowment_effect - http://en.wikipedia.org/wiki/Sunk_costs - http://en.wikipedia.org/wiki/Herd_behavior [edit: also, you're inferring the experience of people from the complaints that they make. that means that you are automatically dismissing anyone who makes certain kinds…

[deleted]

Re: Scala Feels like EJB 2

#70

Earlier quoted context omitted.

It's been a long time since I touched Scala — and I never used it for web stuff at the time anyway — but is this really typical? It's mostly an absurd comparison (equivalent to Fibonacci or something), and a tangent besides, but in Clojure: (slurp "http://somesite.com/some/url") That gives me the response as a string. If I want a binary stream: (clojure.java.io/input-stream "http://somesite.com/some/url") The same fu…

Do you think the code is hard to read? BlueEyes is a framework for writing high performance web services. For it's use cases you care whether you're getting or putting. Thus it is explicit. Similarly, you care about performance, and so don't want to parse strings if you can help it -- thus you set the host once rather than parsing a URL. For a pure ease-of-use library Dispatch is probably the best, if you can figure…

No, I don't take (much) issue with your example's readability, I just thought you were offering a typical snippet for the easy path for "I need to perform a GET".

Of course, more involved interactions require an API with more knobs. Clojure has a number of options, including touching the JDK's HTTP client API, or using a wrapper around something more grounded like clj-http[1] / Apache HTTPComponents.

[1] https://github.com/dakrone/clj-http

Post reply on HN