Live data from Hacker News

Scala Feels like EJB 2

blog.joda.org

91–100 of 119 posts

Re: Scala Feels like EJB 2

#91
post #56

Earlier quoted context omitted.

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.

My favorite example is dealing with user input on the web. Everything from the data passed by the user's browser to the data stored in the database is just a string of bytes. You could go about representing this as a string, but really there are different types of strings, specifically there are sanitized and unsanitized strings. The database should only ever receive sanitized strings and all input from the user is a…

That is a poor example since you should not normally have to code like this when handling user input on the web.

You must escape all user input you send to the database, and this is normally done by your database driver by using parametrized queries (be they prepared or not). And when the data is retrieved from the database you generally do not have to unescape anything, especially not since the returned data is not SQL strings but in whatever binary protocol is used and is unescaped (if necessary) by your driver.

So what your code should look like is something like:

  db.execute("INSERT INTO foo (a, b) VALUES ($1, $2)", a, b)
So for the database you just have two types. Queries and data. Data should always be treated as unsafe while queries is the special class that could help out if you do a lot of manual query building.

Re: Scala Feels like EJB 2

#92
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…

Kotlin also seems to be addressing the issue of modules (http://confluence.jetbrains.net/display/Kotlin/Modules+and+C...)

Re: Scala Feels like EJB 2

#93
post #62

Earlier quoted context omitted.

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.

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?

Re: Scala Feels like EJB 2

#94
post #91

Earlier quoted context omitted.

My favorite example is dealing with user input on the web. Everything from the data passed by the user's browser to the data stored in the database is just a string of bytes. You could go about representing this as a string, but really there are different types of strings, specifically there are sanitized and unsanitized strings. The database should only ever receive sanitized strings and all input from the user is a…

That is a poor example since you should not normally have to code like this when handling user input on the web. You must escape all user input you send to the database, and this is normally done by your database driver by using parametrized queries (be they prepared or not). And when the data is retrieved from the database you generally do not have to unescape anything, especially not since the returned data is not…

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 you got it from the DB it should be safe, but if you got it from the url parameters it isn't.

Re: Scala Feels like EJB 2

#95
post #91

Earlier quoted context omitted.

That is a poor example since you should not normally have to code like this when handling user input on the web. You must escape all user input you send to the database, and this is normally done by your database driver by using parametrized queries (be they prepared or not). And when the data is retrieved from the database you generally do not have to unescape anything, especially not since the returned data is not…

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 HTML-safe type start with s", and concatetnation to the output buffer is
  out " "
So to implement your own templating language and and template helper functions this is a useful concept. But query building should be in the database layer and HTML building in the presentation layer. People using the database should not have to know of or care about that the data might at some point be displayed in a HTML page.

Re: Scala Feels like EJB 2

#96
post #81

Scala is awesome, when combined with AKKA it's even better. We're much more efficient then we ever were in Java. Also, ops doesn't know it's not java since they can use all the same jvm tools. val myList = "Jim" :: "Bob" :: Nil myList(println) what's hard about that?

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.

Re: Scala Feels like EJB 2

#97

Most of the comments here talk about how whatever useful can be done in Scala can be done in some other language. That is not the point, Scala is a good language because - Compatible with JVM - Strong type system - Linear Typing - Substructal Types - Local Type inference - Concurrency constructs built in as actors (Akka) - Integration of OO and functional paradigms - Supports Higher Order Programming - defn-site Vari…

Is it easy for programmers of all abilities to understand and use? Will I still understand my own code in 9 months time? I think that their is more to being a good language than a list of features.

> Is it easy for programmers of all abilities to understand and use?

I am working with two guys right now who have less than 8 months of programming experience.

They are not having a problem with scala. They can do useful work in it.

What they have a problem with is all the other stuff that you just have to learn about building systems.

Re: Scala Feels like EJB 2

#98
post #75

Earlier quoted context omitted.

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…

Seeing that you still don't grok the basics discussed here, this is probably my last answer to you. You still fail to understand that the `map` (and other methods) are far more flexible in Scala, making them play well with sub-typing and inheritance (and in fact with stuff like `String` and arrays which don't implement any collection methods at all). With your examlpe above, what result collection type would you get…

You have a reading comprehension deficiency.

The example above was made by me, on purpose to explain the difference, which I did.

On the JVM - I've implemented dozens of parsers and simple compilers, I did a lot of bytecode manipulation. I know my bytecodes, I know very well the challenges involved.

Your oppinion is based on gospel and the authors of Clojure or JRuby dissagree with you ;)

Re: Scala Feels like EJB 2

#99

Scala is awesome, when combined with AKKA it's even better. We're much more efficient then we ever were in Java. Also, ops doesn't know it's not java since they can use all the same jvm tools. val myList = "Jim" :: "Bob" :: Nil myList(println) what's hard about that?

Apparently everything since that statement doesn't compile

Re: Scala Feels like EJB 2

#100

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

Or just do a:

  val source = scala.io.Source.fromURL("http://news.ycombinator.com/item?id=3264849")
Post reply on HN