News for hackers. Stuff that matters.
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 :)