Live data from Hacker News

Scala Feels like EJB 2

blog.joda.org

101–110 of 119 posts

Re: Scala Feels like EJB 2

#101

Could someone explain to me what are entreprise javabeans and how they are used - in easy to understand language

They were an early Java attempt to "save" programmers from the complexities of writing actual systems by adding all sorts of abstractions and supporting server software. They were an abomination, used mainly by "enterprise" shops that were willing to spend money on everything but programmers who knew what they were doing.

As far as I could tell, they were a classic example of the architecture astronaut's tendency to inflict blue-sky designs on others before actually using them in the real world. They sounded great in the marketing brochures, but were hideous in practice, both for development and run-time use.

The EJB3 transition he mentions came about because EJB as a product was getting its ass kicked by Hibernate and related open-source, field-tested software. Eventually they just threw out EJB2 and said, "Hey, EJB3 is a bold, innovative approach that just happens to look exactly like Hibernate."

Re: Scala Feels like EJB 2

#102
post #96
post #81

Earlier quoted context omitted.

Heh to a Java programmer, the answer would be - everything. Here are my thoughts on it. - I get val myList is some sort of list... - Seems to be a list of Strings. But what is ::? - Nil means list is nullable. Wait is one of the parts of list 'myList(println)' (looks a bit like Smalltalk)? - Why is println the argument and not the method? Is that syntax correct?! Compare same thing in Fantom. Note ; is only used as a…

The :: is Scala's cons operator, the Nil means end-of-list. It's actually much more common in Scala to create a list like so: val nn = List("Jim","Bob") This creates the same list that the example using :: did. It doesn't need to be explicitly terminated with Nil.

What does cons operator mean? Concatenation? Constructor? Other than hello world I haven't done much Scala.

Re: Scala Feels like EJB 2

#103

i used scala for a few months. it sounded very promising, java without the verbosity. but in the end i decided to stop using it. The biggest problem for me was readabilty. Scala is the first language that i've learned where at first i couldn't just read code and immediately guess what it does. I think the prime reason for this is that scala permits operator overloading; more than that, in fact, almost every character…

>I think the prime reason for this is that scala permits operator overloading; more than that, in fact, almost every character can be an identifier.

I've been toying with the idea of trying scala for a serious project for a few months, and this part scares me. It's so obviously a bad idea it makes me wonder what other dumb things are in there.

Re: Scala Feels like EJB 2

#104
post #95

Earlier quoted context omitted.

Not so. What if something fails database validation so you want to display it in the form with an error? This can lead to attacks where a malicious user gives the victim a specially crafted URL that inserts a script into their page, then when they access the URL the script executes inside their browser with their session. For this reason any user input needs to be escaped whenever it is rendered in HTML as well. If y…

Data from the database is just as unsafe as data from URL parameters which is why escaping of data must be done in the presentation layer. This is basically the same thing as SQL queries. You have a template like this (most of the HTML omitted). "> Where username and user_type are variables containing data fetched from the database. This template is then compiled to something like the blow. Strings literals of the HT…

This makes sense. You're totally right about the database. I've run into that issue before, but I had forgotten.

Your example is similar to the approach that Yesod, a Haskell web-framework, takes. The templating language, Hamlet, will accept many types, such as Text or String, but ultimately everything gets translated into RepHTML before being rendered to a real HTML string that is sent to the client. Whenever you give the template a value it automatically runs the appropriate conversion function based on type to generate something safe for display on the page.

The only way to get from a String to RepHTML is either to use the proper escaping function (usually done automatically) or use a special function to do an unsafe conversion, forcing you to explicitly state that a conversion is safe.

The type system is one of the tools used to guarantee that these things get sanitized. You can generate RepHTML in other places, such as through a widget, or other helper functions, and it knows at that point that you properly escaped it. Without the type system you could run into issues when a function generates HTML (sanitized) and then the final template re-sanitizes it. It would be very awkward to do things like layout templates if things are getting sanitized many times.

Re: Scala Feels like EJB 2

#105
post #62

Earlier quoted context omitted.

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.

Shouldn't that be as simple as func bar() [10]foo with var a [8]foo = bar giving an error like cannot use bar() (type [10]foo) as type [8]foo in assignment Is it necessary to use Peano arithmetic to specify a simple type in a general purpose programming language?

That is not a simple type. And people who still remember the original Pascal will know that you do not want to encourage people to make the size part of the collection type. And it doesn't buy you much if you cannot prove at compile time that the type you use to index into the collecton cannot overflow the collection bounds. Use Ada if you need that.

But if you want you can also encode the sizes in binary or decimal numbers: http://apocalisp.wordpress.com/2010/06/24/type-level-program... http://www.ict.kth.se/forsyde/files/tutorial/apas03.html

Re: Scala Feels like EJB 2

#106
post #82
post #14

Having dipped my toes in Scala, and written some Clojure, it seems to me: If Java is CVS, then Scala is Subversion and Clojure is git.

And what people want is Mercurial -> ?.

Sorry, I should have explained.

Scala feels very much like "Java done right". Scala solves a lot of problems with Java and is better in every respect. In the same way, Subversion solved a lot of problems with CVS and is very much "CVS done right".

But the opportunity that was missed was that, just at the Subversion developers never asked themselves "Is centralized version control the right way to do things?", I feel that the Scala developers equally were so focused on fixing the myriad of problems with Java, they never took the step back and asked themselves "Is imperative/mutable state/exposing-Java's-warts-for-compatibility the right way to do things?" Of course, they've built a much better Java, but it feels that they've been so focused on the trees that they've not seen the wood [1].

[1] For non-native English speakers the idiom is http://idioms.thefreedictionary.com/cant+see+the+wood+for+th...

Re: Scala Feels like EJB 2

#107
post #79

It's unfortunate that there a number of very smart people from the Haskell community that are trying to mold Scala in Haskell's image that also appear to be very prominent and active in the community. Other than having some negative effect on Scala's public image, however, there's nothing wrong with what they are doing. People work on open source projects that interest them, and it is an interesting exercise for some…

After struggling through using sbt and Maven/Ivy I can say it is categorically worse than what I have used in other languages including ruby-gem python-pip clojure-leiningen (a jvm language) and node-npm. When I say worse I mean doing what the majority of developers want from a module system: easily install modules, not provide a complicated mess of configuration and versions. This isn't to say scala couldn't adopt a…

Could you go into more detail about what problems you had with sbt? What you describe doesn't really match up with my experience. If you want to use it simply to compile Scala code you can just do 'sbt compile' in the directory containing the Scala files. If you want to add dependencies you just create a file called 'build.sbt' and add lines like:

  libraryDependencies += "org.scala-tools" %% "scala-stm" % "0.3"
Although this may not be clear since sbt presents 2 configuration methods, a simple one (as seen above) and a complex one.

Re: Scala Feels like EJB 2

#108
post #7

So Scala is to Java what C++ was to C

Umm, I'd say Scala is to Java what C# was to Java. It cleared some things at expense of come other things. Overall it's pretty cool language (I rarely use :P).

Re: Scala Feels like EJB 2

#109
post #102
post #96

Earlier quoted context omitted.

The :: is Scala's cons operator, the Nil means end-of-list. It's actually much more common in Scala to create a list like so: val nn = List("Jim","Bob") This creates the same list that the example using :: did. It doesn't need to be explicitly terminated with Nil.

What does cons operator mean? Concatenation? Constructor? Other than hello world I haven't done much Scala.

Cons is short for construct and comes from Lisp which has weird names for things; things like car and cdr.

It means construct a new list.

A cons A (or A :: B) means create a new list with A before B, where B can be a list item or a list itself and A is a list item.

The :: operator is right associative so "Jim" :: "Bob" :: Nil actually works like ("Jim" :: ("Bob" :: Nil) ) (Actually all operators that end in : are right associative in Scala.)

For more see: http://en.wikipedia.org/wiki/Cons

Post reply on HN