Re:The Modern Java Ecosystem (for the Sinatra or web.py lover)
by waffle_ss on Friday December 02, 2011 @12:25PM
(#3304773)
In Ruby, everything evaluates to true except false and nil. Also, the last statement executed is your return value. Therefore your first function could be written as
[ Parent
| on HN ]
Re:The Modern Java Ecosystem (for the Sinatra or web.py lover)
by pacala on Friday December 02, 2011 @01:14PM
(#3305004)
I have no idea what the annotations mean, but if we use exceptions for transmitting error conditions, then there is no point having a true | exception function.
public void deleteStudent(int uid) {
if (STUDENTS.remove(uid) == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
}
Re:The Modern Java Ecosystem (for the Sinatra or web.py lover)
by smanek on Friday December 02, 2011 @12:29PM
(#3304786)
I love it!
And that is the reason I still write in Python or Lisp when I don't need something (Hadoop, Lucene, etc) from the JVM ;-)
Re:The Modern Java Ecosystem (for the Sinatra or web.py lover)
by jblomo on Friday December 02, 2011 @01:40PM
(#3305105)
If you need something from the JVM and want to write Lisp, use Clojure. Checkout Hadoop extensions in Clojure at https://github.com/jblomo/oddjob .
Re:The Modern Java Ecosystem (for the Sinatra or web.py lover)
by jeltz on Friday December 02, 2011 @01:30PM
(#3305065)
In that case it is preferable to use "or" over "||" since then you do not have to worry so much about operator precedence because "or" has about the weakest of all operators. This means in this case that you can skip the explicit ".new" for the exception.
def delete_student(uid)
STUDENTS.remove(uid) or raise WebApplicationException, Response.Status.NOT_FOUND
end
Re:The Modern Java Ecosystem (for the Sinatra or web.py lover)
by mbell on Friday December 02, 2011 @01:18PM
(#3305014)
I seem to remember this same feature causing lots of headache in C in the form of subtle bugs mostly the result of this being used in awkward ways.
Personally I'd rather have a distinct boolean value to test for, the java version is much more explicit as to exactly what its doing.