News for hackers. Stuff that matters.
Re:Evolving Java Without Changing the Language by axod on Wednesday October 21, 2009 @06:14PM (#895756)
>> "Well, I know it prevents me from writing good code."

Right, but everyone is different. It depends on how you think and your personal taste. Some people look at 'public void foo()' and apparently recoil in horror. I look at significant whitespace, or foo => |something| etc type syntaxes and recoil in horror.

Lots of people also claim that no one can be productive writing in pure assembly language, and while that may be true for many programmers, it's certainly not true for everyone.

I don't think you can really say which language 'smart people' use. Obviously there's a lisp/functional bias here on HN, but I'd be very surprised if 'smart people' congregate toward any one particular language.

I still think good programmers are defined by the code they write, rather than which language they choose to write it in.

Re:Evolving Java Without Changing the Language by jrockway on Wednesday October 21, 2009 @06:43PM (#895805)
The examples that you list above don't really matter. Whitespace, "public static void main", sigils on variable names, and so on may look weird when you aren't used to them, but they don't detract from the programming experience.

What matters is how many tokens you need to say something simple. Say you have a list of words, and you want to sort it by length. That's one line of code in Perl, Python, Ruby, Common Lisp, Haskell, etc. It is not one line of code in Java.

When every simple concept in your program requires a new class with a new file, it just becomes unmanageable, even with the best tools. That's why I can't be productive in Java. (Java also doesn't allow quick hacks; private is private, so fuck you. This means that prototypes have to be "as good as" the real implementation, which simply means that you don't prototype. The resulting software sucks accordingly.)

But anyway, I know you have a pretty good app written in Java. I would like to hear more about how you deal with it sometime.

Re:Evolving Java Without Changing the Language by axod on Wednesday October 21, 2009 @06:51PM (#895823)
I think foo => |something| does detract from the programming experience. Special characters that have different meanings depending on context are a PITA. Also you're unable to show the code to a programmer unfamiliar with the syntax, without having to explain each character.

I don't really subscribe to the "Less tokens to say something = always better". As long as it's easy to see what's happening... I do agree collections, and specifically sorting is one area Java is slightly lacking, but it's not a big deal really.

Hopefully I'll release the comet server open source sometime. It's similar to tornado in functionality, but slightly smaller codebase. I think it'd surprise a few people about how you can write Java code if you choose to.

Re:Evolving Java Without Changing the Language by jrockway on Wednesday October 21, 2009 @09:47PM (#896052)
Also you're unable to show the code to a programmer unfamiliar with the syntax, without having to explain each character.

Yeah, well, you're also unable to show French to an English speaker without having to explain the grammar rules and define each word. To use a language, you have to learn it. To read a language, you have to learn it. (Reading is the harder of the two. When you are programming or speaking, you can say things the way you want to. When you are reading or listening, you have to understand the other person's way of speaking.)

Less tokens to say something != always better

I definitely agree with you there. Regular expressions are a good example of this -- way too much optimization for typeability at the expense of readability. It is much easier to read an expression when you have a little bit more verbosity; in the regex domain there are things like rx (Emacs Lisp) or Parsec / PArrows (Haskell). Easy to read, not too hard to write (is "\w+" much harder to type than "(many words)"? no.)

But it is also possible to be too verbose. If you just want to say:

    my @sorted = sort (length $a <=> length $b) @list
you really don't want to have to write:

   // file SortableByLength.java
   public interface SortableByLength implements Sortable, HasLength {}

   // your app code
   List sorted;
   Sorter sorter = new Sorter<SortableByLength>();
   sorted = sorter.customSort( list,
       new SortFunction {
           public Ordering compare(SortableByLength a, SortableByLength b){
               return a.length().compareTo(b.length());
           };
       }
    );
By the time you have written that, you have forgotten what you were actually trying to program. (Upon proofreading this, I realize that the sorters could all be specialized to a concrete type, and that would save a bit of typing. But when you factor out the anonymous class, you will want it to be generic.)

It also worth noting that the extra typing there is not to get type safety; I can get the same type safety with a lot less typing in Haskell:

    sorted = sortBy f list
         where f :: (HasLength a, Sortable a) => a -> a -> Ordering
               f x y = compare (length x) (length y)
Re:Evolving Java Without Changing the Language by axod on Thursday October 22, 2009 @04:46AM (#896401)
Thanks for the examples, and I completely agree about regexps... Personally though, I would be more worried about typos, potential bugs or misunderstandings with the Haskel. For me, the Haskel is too close to regexp land.

If you look at the Java code you've pasted, there's not really anywhere you could typo a character or 2, and it still compile. You'd have to typo a lot, or completely write it in the wrong way for it not to work. It's absolutely explicit and clear what it's doing.

With the Haskel code, you could mistype or misread a single character, and it'd completely change the meaning of the code.

I agree it's more verbose than the Haskel example, but also IMHO more solid/safe.

Re:Evolving Java Without Changing the Language by wiggles on Thursday October 22, 2009 @12:54PM (#897082)
Have you ever written any ML/Haskell?

It's nearly impossible to get past the type system unless your code is correct, especially for small chunks of code.

Re:Evolving Java Without Changing the Language by jrockway on Thursday October 22, 2009 @01:46PM (#897255)
No, he is right; however, Java has the exact problem.

The place where this code will screw up is in the logic of the comparison routine. It will be difficult for the types of x and y (or a and b in the Java example) to be wrong, but it is easy to say:

    compare (length x) (length x)
or

    compare (length y) (length x)
instead of

    compare (length x) (length y)
Your tests will catch this, though.