I haven't explored Ruby much, but as I read through each of the features touted the article, one thing that came to mind was how similar many of them are to Perl both in syntax and in usefulness. (Background: generally I use Java at work and LAMP(erl) for managing my own websites.) So let's do a little closer comparison of the three languages. If any Ruby experts want to jump in and correct anything, I'd be interested in hearing it.
Fast moving objects: All constructors essentially similar, using new classname(params) or some permutation thereof. Ruby has C++ style default values. In Perl you have to remember to bless(), but only in the constructor.
RubyBeans: Ruby definitely has the most compact property notation. Java is verbose but predictable. Perl is weird, with $obj->{prop} syntax or the use of tie(), and read vs. read-write isn't as easy to do.
Collections: Perl and Ruby both define lists with [...] and have [n] and [m..n] accessor syntax. Java, well...
Iteration: collection.each { |var| do something with var... } looks a lot like foreach $var (@collection) { do something... }. With Java 5, at least you have for (var in collection) { do something... }
. But this is probably the most important operation that needs a compact syntax!
Yes, yes, yes: Ruby has a while() construct, but the author claims that it's not much used due to the.each syntax. Not so sure I agree - I find while is best for looping when the termination status is calculated in some way.
Conditionally yours: postfix if statements - first saw it in Perl and hotly debated ever since. But it's no worse than the "optional braces" that derives from C. Perl and Ruby both have unless.
Polymorphism and Mixins: Match up those method names! Perl and Ruby are again similar. Ruby has mixins, Perl has @ISA. Ruby seems slightly more elegant, but the end result is pretty much the same - I don't how there's more than one sensible way to do OO in a dynamically typed language (no, I haven't seen Smalltalk).
Regex: var =~/expr/ in both Perl and Ruby. I don't know whether Ruby has regex flags to compare with Perl. Java 4 regex package has a completely different syntax but is pretty compact and easy to use, though.
Syntactically, Ruby seems to be much closer to Perl than Java - this feels like a apples-and-oranges article. I know Java and Perl both compile to bytecode, both approach native speed in practice, and both have a extensive set of libraries. I would only assume that Ruby is the same.
I'm sure I'm missing many of the intermediate-to-advanced features of Ruby, but what would make me choose Ruby over Perl? Anyone else feel like diving in?
Boo hoo hoo! I keep hearing everyone complain about how bad Java sucks, but I'm afraid you just can't convince me of that. You have to use the right JVM of course - last time I tried the Sun JDK is was horribly slow and bloated. I've switched to the IBM's JDK 1.3 and it works GREAT. The JIT compiler really does a job on number crunching or straight-up data structure manipulation. Just for kicks, I tried implementing a B-Tree algorithm in Java and got near-native performance while manipulating trees with >1e6 strings. I'll agree that Swing feels a little poky, but really, it's not much more so than X.
And don't get me started about the language. I'll admit, I came from a procedural world, and haven't used any of the languages that OO purists always yammer about. Maybe I don't know what I'm missing. But I think Java, overall, is an elegant language and Java code is the easiest to maintain of any I've seen. Of course, the two biggest changes Java needs now are the elimination of primitive types (or transparent casting to and from corresponding object types), and templated collections. Both these could be implemented in the compiler with no change to the JVM or bytecode.
HashMap<Integer> map = new HashMap<Integer>
int x = 1;
map.put("ONE", x);
System.out.println(map.get("ONE") + 2); // Prints "3" // Before, you needed // map.put("ONE", new Integer(x)); // System.out.println(((Integer)map.get("ONE")).intVa lue() + 2);
Also, you can't disparage the huge number of "libraries" that come with Java. You have collection classes, a very flexible widget set, network comm libraries from simple (Socket) to complex (HttpURLConnection), a database connectivity library, yadda, yadda, yadda. Yes, these are all available for free for C/C++ too, but they're a big part of the value of Java.
Stupid disclaimer: No, I don't work for Sun. But I do like Java on Linux and I can finally do Java development on my favorite platform without having to go get a snack every time I compile a source file.
Programming in almost any language forces a precision of thought not usually found in "human" languages. Even though the words themselves are borrowed (or made up), the constructs and concepts that are being described are well, different.
I guess a lot of the currently popular computer languages could be compared to "dialects" of C - all somewhat derived from it, and mutually intelligible. It was easy to pick up Java when I already knew C++. Then you have things like Scheme, or COBOL, or M4 that aren't necessarily immediate to understand.
"Language shapes thought" is the essence of the Sapir-Whorf hypothesis (still debated in linguistic circles AFAIK). A good question is how much it goes back and forth between the two. I learned to program in 6502 assembler (well, BASIC too, but is wasn't good for much), and using that "language" definitely shaped part of how I think. But now after 15 yrs I haven't gotten around to figuring out functional languages - different way of thinking. I've heard people complaining about not "getting" functional languages on other postings. So I guess there's something to it. It's all pretty interesting. I'm starting to ramble a bit now, huh?
Ehm, excuse me but doesn't the phrase "comparing apples to oranges" come to mind here? I mean how the hell can you compare two forces with completely [different] causes? It is just as absurd as saying that 1 gram is more than 1 coulomb. Gravity is related to mass, and electromagnetic forces on charge. How can someone compare the mass of the earth with the charge in the atoms in a magnet? They are totally different things.
It's true that mass and charge have different units, but what we're talking about here is forces. Mass + gravity == a force, and Charge + EM == a force. Those two forces certainly have the same units!
Dimensions do not have a size. Objects have sizes in a set of dimensions.
True if the dimension is infinite and unbounded. Not true if the dimension is wrapped in on itself (as string theory speculates), therefore finite and unbounded. Consider an infinitely large sheet of paper. It's meaningless to ask "what is the width of the sheet?" unless "infinite" is an acceptable answer. But when the sheet is rolled up into a long tube, it's perfectly meaningful to ask "what's the radius of the tube?" Of course, the unit of measurement is always arbitrary anyway, but if you consider two rolled-up dimensions you can use their ratio as a quantitative measure independent of whether you use feet, millimeter, parsecs or whatever.
I haven't explored Ruby much, but as I read through each of the features touted the article, one thing that came to mind was how similar many of them are to Perl both in syntax and in usefulness. (Background: generally I use Java at work and LAMP(erl) for managing my own websites.) So let's do a little closer comparison of the three languages. If any Ruby experts want to jump in and correct anything, I'd be interested in hearing it.
Syntactically, Ruby seems to be much closer to Perl than Java - this feels like a apples-and-oranges article. I know Java and Perl both compile to bytecode, both approach native speed in practice, and both have a extensive set of libraries. I would only assume that Ruby is the same.
I'm sure I'm missing many of the intermediate-to-advanced features of Ruby, but what would make me choose Ruby over Perl? Anyone else feel like diving in?
Boo hoo hoo! I keep hearing everyone complain about how bad Java sucks, but I'm afraid you just can't convince me of that. You have to use the right JVM of course - last time I tried the Sun JDK is was horribly slow and bloated. I've switched to the IBM's JDK 1.3 and it works GREAT. The JIT compiler really does a job on number crunching or straight-up data structure manipulation. Just for kicks, I tried implementing a B-Tree algorithm in Java and got near-native performance while manipulating trees with >1e6 strings. I'll agree that Swing feels a little poky, but really, it's not much more so than X.
And don't get me started about the language. I'll admit, I came from a procedural world, and haven't used any of the languages that OO purists always yammer about. Maybe I don't know what I'm missing. But I think Java, overall, is an elegant language and Java code is the easiest to maintain of any I've seen. Of course, the two biggest changes Java needs now are the elimination of primitive types (or transparent casting to and from corresponding object types), and templated collections. Both these could be implemented in the compiler with no change to the JVM or bytecode.
HashMap<Integer> map = new HashMap<Integer>
// Prints "3"
// Before, you needed
// map.put("ONE", new Integer(x));
// System.out.println(((Integer)map.get("ONE")).intVa lue() + 2);
int x = 1;
map.put("ONE", x);
System.out.println(map.get("ONE") + 2);
Also, you can't disparage the huge number of "libraries" that come with Java. You have collection classes, a very flexible widget set, network comm libraries from simple (Socket) to complex (HttpURLConnection), a database connectivity library, yadda, yadda, yadda. Yes, these are all available for free for C/C++ too, but they're a big part of the value of Java.
Stupid disclaimer: No, I don't work for Sun. But I do like Java on Linux and I can finally do Java development on my favorite platform without having to go get a snack every time I compile a source file.
Programming in almost any language forces a precision of thought not usually found in "human" languages. Even though the words themselves are borrowed (or made up), the constructs and concepts that are being described are well, different.
I guess a lot of the currently popular computer languages could be compared to "dialects" of C - all somewhat derived from it, and mutually intelligible. It was easy to pick up Java when I already knew C++. Then you have things like Scheme, or COBOL, or M4 that aren't necessarily immediate to understand.
"Language shapes thought" is the essence of the Sapir-Whorf hypothesis (still debated in linguistic circles AFAIK). A good question is how much it goes back and forth between the two. I learned to program in 6502 assembler (well, BASIC too, but is wasn't good for much), and using that "language" definitely shaped part of how I think. But now after 15 yrs I haven't gotten around to figuring out functional languages - different way of thinking. I've heard people complaining about not "getting" functional languages on other postings. So I guess there's something to it. It's all pretty interesting. I'm starting to ramble a bit now, huh?
Ehm, excuse me but doesn't the phrase "comparing apples to oranges" come to mind here? I mean how the hell can you compare two forces with completely [different] causes? It is just as absurd as saying that 1 gram is more than 1 coulomb. Gravity is related to mass, and electromagnetic forces on charge. How can someone compare the mass of the earth with the charge in the atoms in a magnet? They are totally different things.
It's true that mass and charge have different units, but what we're talking about here is forces. Mass + gravity == a force, and Charge + EM == a force. Those two forces certainly have the same units!
Dimensions do not have a size. Objects have sizes in a set of dimensions.
True if the dimension is infinite and unbounded. Not true if the dimension is wrapped in on itself (as string theory speculates), therefore finite and unbounded. Consider an infinitely large sheet of paper. It's meaningless to ask "what is the width of the sheet?" unless "infinite" is an acceptable answer. But when the sheet is rolled up into a long tube, it's perfectly meaningful to ask "what's the radius of the tube?" Of course, the unit of measurement is always arbitrary anyway, but if you consider two rolled-up dimensions you can use their ratio as a quantitative measure independent of whether you use feet, millimeter, parsecs or whatever.