News for hackers. Stuff that matters.
Re:Why isn't Java used for modern web application development? by latch on Sunday June 10, 2012 @05:11AM (#4090583)
My complaint isn't about client-side rendering. It's about _anything_ that involves getting in JSON or outputting JSON. It's essentially being able to easily bind json to objects on the way in, and being able to use respond_to and to_json on the way out.
Re:Why isn't Java used for modern web application development? by fizx on Sunday June 10, 2012 @05:53AM (#4090657)
You're stuck in 2007. People doing modern java use:

    @Path("/hello")
    @Produces(MediaType.APPLICATION_JSON)
    class HelloController {
      class Greeting {
        public Greeting(String name) {
          this.content = "Hello, " + name;
        }
        public final String content;
      }

      @GET
      public Greeting greet(@PathParam("name") String name) {
        return new Greeting(name);
      }
    }

    > curl http://localhost:8080/hello?name=me
    {"content": "Hello, me"}
Re:Why isn't Java used for modern web application development? by latch on Sunday June 10, 2012 @06:08AM (#4090686)
I'm not sure if you are being sarcastic, but you do realize that's a lot of code for something so simple, right?

  get '/hello/:name' do
    content_type :json
    {:content => "Hello, #{params[:name]}"}.to_json
  end
Re:Why isn't Java used for modern web application development? by mibbitier on Sunday June 10, 2012 @08:16AM (#4090850)
I think you mean "characters". Rather than code.

"public static void main()" isn't a lot of code. It's three keywords, and one identifier. You may consider it a lot of characters, but it's pretty rare that a programmers bottleneck is speed of typing.

I wish people would stop confusing "number of characters" with "amount of code".

And FWIW, I find your example far harder to decipher. I have to know what => means, # means, what : means, etc etc etc.

Add to that, in your example, if you typo one of those characters, your code may well still run, but will fail. With Java, if you typo a single character, it's more likely the code just won't compile.

We could all code in regular expressions or something akin to that, maybe perl one liners. But "number of characters" isn't a good aim. Readable, maintainable, well written code is.

Re:Why isn't Java used for modern web application development? by latch on Sunday June 10, 2012 @09:07AM (#4090940)
The last part of your comment is just language bias. symbols and hashes are fundamental to ruby. Why would I use string concatenation like my parent, when the language support string interpolation. It's as unclear to you as generics or annotations might be to someone who didn't know Java. Surely you see that?

I think you are being pedantic about characters vs code. But, for what it's worth, I disagree. You are having to create 2 classes, define a field, a constructor and use four framework specific annotation. I consider all of that code (made up of characters).

Both versions should be unit tested. The unit test might be more important in the Ruby version, but so too will it be easier to write.

Re:Why isn't Java used for modern web application development? by mibbitier on Sunday June 10, 2012 @09:31AM (#4090990)
I grew up reading assembly code listings. Being able to read code is a really really important skill IMHO. Something like Java is very very easy to read. It's mainly keyword based, rather than special character based. I'd much rather read a 1,000 line Java program, than a 100 line <concise language> program.

The other point I'd make is that Java is probably about as verbose as english is. But we all manage, using English. We don't moan on and on that talking, writing, reading is so inefficient and we should all switch to something better. English also has odd grammar and spelling rules which are inconsistent and plain stupid sometimes. Yet, English works pretty well for what we use it for. Communicating.

Re:Why isn't Java used for modern web application development? by pi18n on Sunday June 10, 2012 @10:49AM (#4091178)
You'd much rather read a Java program because you are already biased towards it. Yes it's easy to read, but you need to acknowledge that many other skilled developers would find it easier to read Python, or Ruby, and indeed would rather read 1,000 lines of the same over 100 lines of Java. Otherwise you are simply being willfully ignorant.

Why is Java considered inefficient and English not? Maybe because we don't need to create a new class for every concept in English. Yours is a pretty poor analogy; English vocabulary is extensive but it is not inherently verbose.

Anyway I am only writing not to say you are wrong, but rather, since other people are arguing with you reasonably and you are dismissing them without consideration, your argumentation is wrong.

Re:Why isn't Java used for modern web application development? by mibbitier on Sunday June 10, 2012 @11:53AM (#4091358)
> "You'd much rather read a Java program because you are already biased towards it."

No. I'd rather read "int foo; bar.printLn()" than "%foo => &bar :print"

Less special characters. More words.

Each to their own though.

Re:Why isn't Java used for modern web application development? by koide on Sunday June 10, 2012 @05:00PM (#4092180)
So you'd also rather read

"An unordered tuple Z going from a1 to an is a defined as for every x in Z then x is a1 or x is a2 ... or x is an"

than

"An unordered tuple Z (a1,...,an) is defined as [x : x = a1 v x = a2 v ... x = an]"?

I take that as not being (or not wanting to be) familiar with the language you are reading. If you'll read Ruby, at least browse a manual to know what {} and # mean.

Re:Why isn't Java used for modern web application development? by pi18n on Sunday June 10, 2012 @10:53PM (#4093005)
The psuedo-Ruby code posted there is characteristic of someone who is having a knee-jerk reaction against something they don't understand. The person we are arguing against is obviously a Java zealot that will never consider using another language, so as long as he's going to accept that different people like different languages I think that's good enough for today.
Re:Why isn't Java used for modern web application development? by pi18n on Sunday June 10, 2012 @10:46PM (#4092992)
> Each to their own though.

I'll agree with that wholeheartedly.

Re:Why isn't Java used for modern web application development? by Silhouette on Sunday June 10, 2012 @10:41AM (#4091162)
The other point I'd make is that Java is probably about as verbose as english is. But we all manage, using English. We don't moan on and on that talking, writing, reading is so inefficient and we should all switch to something better.

You've made this argument in multiple posts now, so I'm just going to point out here that people doing science and engineering use formal, mathematical notations precisely because they do offer more precise and concise ways of expressing the necessary technical concepts.

There are plenty of reasons to criticise some of those notations with hindsight, but "not being English" is not among them.

Re:Why isn't Java used for modern web application development? by mythz on Sunday June 10, 2012 @10:10AM (#4091082)
This is just a sad Stokholm defence - against languages that threatens your sacred cow - which is understandable since the Java code example got pwned.

So rather than defending the code example on merit, you dive into pedantic nit-picking territory. I used to be defensive about my choice language as well, till I matured and realized holding onto sacred cows just hurts your ability to learn from others doing it better and being more productive; and just clouds your ability to choose the right tool for the job.

More code = more code, to read, to decipher, that hides intent, that adds complexity, that can have bugs and can go wrong. Code-size is codes worst enemy.

I don't even know Ruby, but it's implementation is vastly more readable and would look a lot closer to what the perfect DSL would look like for this task, than the Java example.

Re:Why isn't Java used for modern web application development? by zootm on Sunday June 10, 2012 @11:03AM (#4091223)
The sibling comments point out some good points about your general critique, but it's worth noting your code isn't really "equivalent"; almost everything you chopped was a datatype declaration, which isn't required in Java any more than in Ruby:

      @GET
      public Map<String,String> greet(@PathParam("name") String name) {
        return singletonMap( "content", "Hello, " + name );
      }
I like both of these systems, and Java is undeniably the more verbose language, but this framework really isn't an egregious example of that.
Re:Why isn't Java used for modern web application development? by gizmogwai on Sunday June 10, 2012 @06:50AM (#4090740)
I'm not sure if you are being sarcastic, but you do realize that your version is entirely static while the other one is ready for future evolutions?

By changing a single line, the java version can also produce XML or text response. By changing two lines, it can also respond to POST requests.

And that's just the top of the iceberg. Oh, and in the ends, it's way faster than Node, Ruby, Python and most of the dynamic languages.

Re:Why isn't Java used for modern web application development? by latch on Sunday June 10, 2012 @09:10AM (#4090947)
And when those changes are made, I can change my version to:

   response = {:content => "Hello, #{params[:name]}"}
   respond_to do |wants|
      wants.json { response.to_json } 
      wants.xml { response.to_xml }
   end
Re:Why isn't Java used for modern web application development? by fizx on Sunday June 10, 2012 @04:06PM (#4092039)
I've been trying to ignore this particular flame-war, but your example is doing fundamentally less, because it's not binding objects to json (which was what you originally asked for).

I actually cannot write your example easily in Sinatra/Ruby/etc, without making my object either a Hash or an ORM subclass, customizing serialization, or pulling in uncommon libraries.

Here's your complete example, in reasonable Ruby. It's longer than the Java.

    class Greeting < Struct.new(:content)
      def content
        "Hello, #{super.content}"
      end
  
      def to_xml
        {:content => content}.to_xml
      end

      def to_json
        {:content => content}.to_json
      end
    end

    get '/hello' do

      response = { :content => Greeting.new(params[:name]) }

      respond_to do |wants|
        wants.json { response.to_json } 
        wants.xml { response.to_xml }
      end
    end
If I create an imaginary library that does exactly what we'd want here, it'd look like the following. It's marginally shorter than the java, but hard to argue anything about it being fundamentally better.

    class Greeting 
      include JsonObject
      field :content
      def content
        "Hello, #{@content}"
      end
    end

    get '/hello' do

      response = { :content => Greeting.new(params[:name]) }

      respond_to do |wants|
        wants.json { response.to_json } 
        wants.xml { response.to_xml }
      end
    end
Re:Why isn't Java used for modern web application development? by Retric on Sunday June 10, 2012 @08:30AM (#4090868)
That's a funny complaint when evaluating 4 lines of code one of which is end.

Java makes the assumption that you need a lot of boilerplate code, so being able to make changes easily seems like a big deal. Other languages avoid that boilerplate and can make the changes just as easily for free.

Re:Why isn't Java used for modern web application development? by thebluesky on Monday June 11, 2012 @03:55AM (#4093607)
Making changes to a complex system is a "big deal" in any language. Pretty (and compact) syntax doesn't help much, especially when the refactoring tools are weak.
Re:Why isn't Java used for modern web application development? by masklinn on Sunday June 10, 2012 @11:35AM (#4091315)
> By changing two lines, it can also respond to POST requests.

That's twice as many lines you need to replace as in Sinatra:

    get '/hello/:name' do
to

    route :get, :post '/hello/:name' do
Re:Why isn't Java used for modern web application development? by pi18n on Sunday June 10, 2012 @10:53AM (#4091190)
> By changing two lines, it can also respond to POST requests.

If you think this is a feature, you might actually like Sinatra/Ruby :)

Re:Why isn't Java used for modern web application development? by swah on Sunday June 10, 2012 @05:39PM (#4092302)
Its fine code once the design its settled, but while you're changing the schema, the backend java code and the frontend javascript, having to change all those classes gets tedious.