News for hackers. Stuff that matters.
Re:How (not) to write Factorial in Java by endtime on Wednesday January 26, 2011 @11:54AM (#2143866)
>It’s obscuring the purpose of the code–replacing a two or three line utility (max!) with dozens or even hundreds of lines of self-important masturbatory Java bullshit.

I'm not trying to troll, but are there any Java programmers who don't write code like this? I've never seen "real" Java code, which is to say production code, but every time I had to work with Java in school it was pretty much described by the above quote; and what's more, the libraries I had to interact with often made me feel like I was forced to do the same thing.

Re:How (not) to write Factorial in Java by coliveira on Wednesday January 26, 2011 @11:58AM (#2143879)
That is the big problem of Java: the libraries. They require programmers to use these patterns, even when it makes no sense.
Re:How (not) to write Factorial in Java by giberson on Wednesday January 26, 2011 @12:09PM (#2143924)
Libraries don't require you to use them. You are free write your own solution [that makes sense].
Re:How (not) to write Factorial in Java by steveklabnik on Wednesday January 26, 2011 @04:06PM (#2145140)
And also making it really easy to say "bye bye" and move to a language that has sane libraries.
Re:How (not) to write Factorial in Java by meadowsp on Thursday January 27, 2011 @11:03AM (#2148291)
Could you point me towards a comparison of an insane java library and the sane equivalent in a different language?
Re:How (not) to write Factorial in Java by steveklabnik on Thursday January 27, 2011 @11:21AM (#2148365)
Hello world in Swing: (from here: http://www.java2s.com/Code/Java/Swing-JFC/HelloWorldSwing.ht... )

    import javax.swing.JFrame; 
    import javax.swing.JLabel;

    public class HelloWorldSwing {
      public static void main(String[] args) {
        JFrame frame = new JFrame("HelloWorldSwing");
        final JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
        frame.setVisible(true);
      }
    }
Hello world in Shoes:

    Shoes.app do
      para "Hello, world"
    end
Hello world for Hibernate: (from here: http://www.javaworld.com/javaworld/jw-10-2004/jw-1018-hibern...)

    package hello;
    public class Message {
       private Long id;
       private String text;
       private Message nextMessage;
       private Message() {}
       public Message(String text) {
          this.text = text;
       }
       public Long getId() {
          return id;
       }
       private void setId(Long id) {
          this.id = id;
       }
       public String getText() {
          return text;
       }
       public void setText(String text) {
          this.text = text;
       }
       public Message getNextMessage() {
          return nextMessage;
       }
       public void setNextMessage(Message nextMessage) {
          this.nextMessage = nextMessage;
       }
    }

    Session session = getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    Message message = new Message("Hello World");
    session.save(message);
    tx.commit();
    session.close();
The equivalent in ActiveRecord:

    class Message < ActiveRecord::Base
    end

    message = Message.new(:text => "Hello, world")
    message.save
You have to set up your schema in both, so I've left that out.

These are just the first two that came to my head. I ditched Java so long ago that I'm sure a few hundred more have come up.