Monday, January 22, 2007

A Favor

Pat Maddox wrote a post called "Java People Must Be Stupid," and unfortunately, his irony blew up in his face. The point of his post isn't really that Java people are stupid -- it's that Java people coming to Ruby often seem to arrive with the crippling assumption that their fellow programmers are stupid.

What worries Java immigrants to Ruby is that Ruby doesn't have any of the protection mechanisms Java has, and the protection mechanisms it does have are easily circumvented. Pat's point is basically, "let it go, don't be afraid," but his phrasing put him right in the middle of a language war.

Anyway, I posted a comment there, and Reg Braithwaite asked me to post it on my own blog, so he could link to it without including all the shrapnel and debris from the language war, so here we go:

It’s not really stupid people, it’s people who’ve accepted a stupid idea. Java’s design is based on the idea that a language can prevent misuse by making bad things hard to do. It’s defensive thinking. Java people are caught up in this paradigm; that’s where these questions come from.

It might be more accurate to say that Java people are smarter than they give themselves credit for.

The thing is, telling people they’re stupid, when their problem is an equal mix of bad ideas and defensive thinking, that’s not the most persuasive argument available.

I think the only compelling argument, from a Java perspective, at least, in terms of Java people I’ve talked to, is that nobody ever actually accesses the stuff inside Rails which, if it were inside Java, would be hidden. The door isn’t locked, but still nobody goes in.

In any OOP language you do want to keep client programmers only using the API, not the internals of the objects the API is made of. That’s a good design principle. Java makes it happen by building a fort, locking everything down, the theory being they can’t steal it if it’s nailed to the floor. Their goal is legitimate, but their way of achieving it is kind of paranoid. Ruby’s got the same goal, but a radically different approach to achieving it. It doesn’t enforce any kind of security, but makes it easy to build such elegant APIs that entering the “forbidden zone” never even occurs to people, because it just isn’t necessary.

It’s like the opposite of thinking defensively isn’t thinking offensively; the opposite of thinking defensively is thinking creatively.

29 comments:

  1. Has anybody mentioned how difficult it is to read the thin white on black text?

    ReplyDelete
  2. Sorry, Isaac, I am planning to redesign this thing, currently it's just using a stock Blogger template.

    ReplyDelete
  3. I've been writing Java code since 1999, and while I like that the compiler will tell me when my code is provably wrong, I don't like having to give it information to achieve that.

    That's why I think the Haskell type system is superior, although it is certainly harder to get to grips with. I haven't got completely comfortable with it yet, perhaps my opinion will change. I might need a strict imperative language with type inference.

    Having programmed in Java for so long, I've refined how I write it. I keep interfaces small, one method where possible, preferring static methods that operate on minimal objects, over instance methods.

    Scala's mixins would allow me to treat those statics as instance methods without changing the object's code, which is good.

    I don't care much for private methods/fields - rather than use private I make anonymous implementations of interfaces.

    One of the ideas of defensive programming is that you can defend against yourself; you're not assuming that you are an idiot, but that you will approach the code without the context that you had while writing it.

    In that situation, extra (visible) methods on objects are just noise, obscuring the signal. In the Java APIs, JButton is a good example; it has many many methods, most of which are just implementation details inherited from superclasses.

    It is possible to write defensive code creatively; a little Haskell use persuades me of that.

    It's all about the developer experience though. Ruby seems attractive because it gets out of your way and lets you code (I don't know this, I'm just assuming that it's in the same arena as Lisp).

    I hope a statically typed language can do the same someday.

    ReplyDelete
  4. re:Has anybody mentioned how difficult it is to read the thin white on black text?

    If you do ctrl-A, it magically goes to black on white.

    ReplyDelete
  5. "It doesn’t enforce any kind of security, but makes it easy to build such elegant APIs that entering the “forbidden zone” never even occurs to people, because it just isn’t necessary."

    Errr... I guess you don't work in the finance industry then. What you say is fine in many situations, what what if need that security/protection against misuse?

    In an everyday situation, it is often more important to be able to demonstrate from a compliance POV that your code takes appropriate steps to prevent misuse, than there being much risk of it.

    I don't want to plug some 3rd party API into my financial applications (like an API from a bank), which could possibly route through my code and send them back the trading algorithms I use. I want to lock down what they can do, which is easy enough in Java though isolation, tightly-written API's and the SecurityManager mechanism.

    I guess this is a reason why Java would live on in the finance world...

    ReplyDelete
  6. its nice to see somebody not using "linux arguments"

    ReplyDelete
  7. I love Linux. However, it is a shame that some people in the community put a cushion around their ears when a feature is needed they they don't use, and then try to generalise about it. Just because they don't use it, doesn't mean it is absolutely vital for enterprise development.

    ReplyDelete
  8. <a href="http://phenonline.tlg.pl">Phentermine</a>July 29, 2007 at 8:58:00 AM PDT

    Good design!

    ReplyDelete
  9. <a href="http://phentermine1.eamped.com">Phentermine</a>August 17, 2007 at 11:23:00 AM PDT

    Thanks for interesting article.

    ReplyDelete
  10. <a href="http://drugscenterhere.com">ShopMan</a>August 25, 2007 at 11:16:00 PM PDT

    I like articles like this. Thanks!

    ReplyDelete
  11. <a href="http://buy-viagra2007.blogspot.com">Buy Viagra</a>September 2, 2007 at 2:57:00 AM PDT

    very good!

    ReplyDelete
  12. <a href="http://courses.cvcc.vccs.edu/ENG112_GROSS/_Chat_Room/000008fd.htm">Anonimous</a>September 9, 2007 at 9:41:00 AM PDT

    Well done. Keep up the great work. Best regards!

    ReplyDelete
  13. <a href="http://buy4soma.eamped.com">Anonimous</a>September 10, 2007 at 12:22:00 PM PDT

    I like it a lot! Nice site, I will bookmark!

    ReplyDelete
  14. <a href="http://m2.aol.com/rth5gr/index.html">Anonymous</a>September 11, 2007 at 11:41:00 AM PDT

    Thanks to author! I like articles like this, very interesting.

    ReplyDelete
  15. <a href="http://paydayadvisors.org">PaydayLoans</a>October 30, 2007 at 9:36:00 AM PDT

    qKlE98 You have a talant! Write more!

    ReplyDelete
  16. <a href="http://tes.uab.es/MISS/portal_memberdata/portraits/twkgxziok">Auto insurance company</a>October 30, 2007 at 7:32:00 PM PDT

    IKE1j3 Wonderful blog.

    ReplyDelete
  17. <a href="http://hydrocodone.99k.org/index.php">Hydrocodone</a>November 1, 2007 at 8:48:00 PM PDT

    CyDkt3 The best blog you have!

    ReplyDelete
  18. <a href="http://users2.titanichost.com/buyviagra/269.html">shannons car insurance australia</a>November 2, 2007 at 10:18:00 AM PDT

    ZOjC0g Please write anything else!

    ReplyDelete
  19. <a href="http://free.7host07.com/nmcfgy/471.html">amador county winery tour</a>November 2, 2007 at 11:11:00 AM PDT

    actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.

    ReplyDelete
  20. <a href="http://fioricet.clanteam.com/?pharma=156">compare fioricet prices</a>November 2, 2007 at 11:59:00 AM PDT

    Nice Article.

    ReplyDelete
  21. <a href="http://celebrex.zxq.net/?pharma=664">celebrex commercial</a>November 2, 2007 at 12:51:00 PM PDT

    Wonderful blog.

    ReplyDelete
  22. <a href="http://m1.aol.com/BrettHead14/476.html">contact accounts payable for affinity insurance</a>November 2, 2007 at 1:56:00 PM PDT

    Nice Article.

    ReplyDelete
  23. <a href="http://users2.titanichost.com/buyviagra/index10.html">carisoprodol amp phentermine diet pills</a>November 3, 2007 at 3:30:00 AM PDT

    Nice Article.

    ReplyDelete
  24. <a href="http://tramadol.newsit.es/naproxen-tramadol-contraindication.html">naproxen tramadol contra</a>November 3, 2007 at 8:06:00 AM PDT

    actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.

    ReplyDelete
  25. <a href="http://xanax.newsit.es/larger-xanax.html">larger xanax</a>November 3, 2007 at 9:08:00 AM PDT

    Nice Article.

    ReplyDelete
  26. <a href="http://xanax.newsit.es/equilivualnt-of-xanax-and-clonepin.html">equilivualnt of xanax and c</a>November 3, 2007 at 10:12:00 AM PDT

    Magnific!

    ReplyDelete
  27. <a href="http://phentermine.whdot.com/index13.html">xenical hgh phentermine qu it smoking</a>November 3, 2007 at 11:01:00 AM PDT

    Thanks to author.

    ReplyDelete
  28. <a href="users2.titanichost.com/amalopra">JohnBraun</a>November 4, 2007 at 1:06:00 AM PDT

    a90vDj write more, thanks.

    ReplyDelete

Note: Only a member of this blog may post a comment.