File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ruby and the fly likes Ruby: the new Perl ? (syntax sugar that kills, too many ways to write stuff) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Ruby: the new Perl ? (syntax sugar that kills, too many ways to write stuff)" Watch "Ruby: the new Perl ? (syntax sugar that kills, too many ways to write stuff)" New topic
Author

Ruby: the new Perl ? (syntax sugar that kills, too many ways to write stuff)

Thomas Queste
Greenhorn

Joined: Mar 08, 2006
Posts: 15
Hi David,

After reading some Ruby tutorials, the main idea of Ruby I had was : "Hey, there are so many ways to write that stuff. How can anyone maintain it ?!".
I encountered the same "problem" doing some Perl programming (Ok, Perl make be cool but did you look at those one liners...).

So, my question is : Do you really think that the language improvements won't make Ruby the new Perl ? (added complexity, less maintainable, useless syntax sugar, expressiveness as a drawback, not and advantage...)

I am a Java guy and Java has the advantage of being "poor" (no closures for example...) but the advantage is the simplicity. The language itself is really simple, no the OO principle of course.

Regards,

Tom

PS: I really hope to have a look at your book if it can help me to understand what all those Ruby things mean
J Alexander
Greenhorn

Joined: Feb 20, 2008
Posts: 4
What kills Perl for me are the unorganized modules, having to compile some modules, and "you can't just drop a jar" type of approach to setup. I don't want platform dependent code.

Perl didn't always behave like I expected, but Ruby has been pretty consistent. It is easy to 'accidentally' discover some obscure behaviour in Perl. I think you have to try harder to find that in Ruby.

Ruby is more fun to read - methods being called that were not defined and dynamic behaviour. But it's all based on convention, right!? And Ruby has JRuby, which works well on the JVM.

-Jason
Michael Sullivan
Ranch Hand

Joined: Dec 26, 2003
Posts: 235
I'm going to agree with J. Alexander here, Ruby is a lot easier to read than Perl because of it's expressiveness.

I will challenge whether Java as a language is simple. I find it complex in some areas, very verbose, and that it gets in my way far too often. There are some good books out there that compare Java directly to Ruby, two that I recall right off the top of my head are:

From Java To Ruby
Rails for Java Developers

Both take on how Java and Ruby compare, and the second compares Java web frameworks to Rails. However, both distinctly point out how much simpler Ruby can be (vs. Java) for the developer - a main tenant of the Ruby language (whereas Java is built for the compiler first, and the developer second).

Just my .02
Thomas Queste
Greenhorn

Joined: Mar 08, 2006
Posts: 15
First, thanks for your replies.

The main focus of my question was more related to the syntax of the Ruby language.
Apparently, the syntax evolves in each version of the Ruby and sometimes there are many way to do the same thing (method synonyms for example).

I think that adding "syntax sugar" is a way to increase the complexity for newcomers and make the language worse step by step.

I don't know much how Ruby has evolved. Are you pretty confident of the evolution of the language ? Will it always be as simple as now, and not too expressive ?

Thanks for your thinking,

Tom
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
API is another thing but Ruby's syntax hasn't seen that many drastic changes or additions - it's been relatively stable. It may be true that Ruby has more "method aliases" than, say, the Java API but it hasn't bothered me. By the way, can you think of an example of an alias (in Ruby) that you'd remove from the core API? The only one that comes to mind is Array#indexes / Array#indices and that's already marked as deprecated (in favor of Array#values_at).


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
David Black
author
Greenhorn

Joined: Aug 16, 2009
Posts: 13
Hi Tom --

For whatever reason, I've never been bothered by the ability to do things in more than one way, whether in Perl or Ruby. I kind of enjoy it :-) I did a lot of Perl for several years, and I always thought it was incredibly cool. I then fell in love with Ruby (that's the most accurate way to put it, even if somewhat non-technical) and haven't used Perl for a long time.

I think that here and there it's possible that something might be a little too sugary for my taste, or a bit line-noise-ish, or whatever. But overall, I continue to feel that Ruby has the extraordinary ability to be very concise and very clear at the same time. I've always said that the longer you work on a Ruby program, the more code disappears from the screen -- and the more clear the program becomes.

It's certainly true that you can write obscure or cryptic code in Ruby. I suppose there was a brief period when I sort of wanted to convince myself that the language simply wouldn't allow it, but that's too idealistic and definitely not true. There's never been a culture of it in Ruby (the JAPH type of thing), but it certainly can be done.

One thing I wonder about languages -- and libraries and frameworks too, as they evolve -- is the extent to which the new stuff is built on old stuff that the people who have been around a while know about, but newcomers don't, and whether that makes it harder to get up to speed. I think there are a few things like that in Ruby -- like doing this:

array.map(&:upcase)

instead of

array.map {|s| s.upcase }

The former makes sense once you know that Symbol#to_proc exists, and that & forces a call to it, and so on. But I don't think I would have wanted to learn it first.

And as a trainer and mentor, I do tend to encourage people to understand the more elemental parts of the language, rather than just learn the more composite ones and never quite get the hang of what's underneath.


Ruby training coming up in September! David A. Black and Erik Kastner team up for fast-paced, four-day Ruby intro, in New Jersey, September 14-17. See http://rubyurl.com/vmzN or contact David.
Thomas Queste
Greenhorn

Joined: Mar 08, 2006
Posts: 15
Yes, I agree with learning the more elemental parts of the language.

Thanks all for your replies.

Tom
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

not too expressive

Is it possible to be "too expressive"?
Michael Sullivan
Ranch Hand

Joined: Dec 26, 2003
Posts: 235
That comment caught me as well, since the more expressive my code is - the less documentation (code comments) I produce, while the production of test cases increases.
Thomas Queste
Greenhorn

Joined: Mar 08, 2006
Posts: 15
Hi,

Sorry, I see that using "too expressive" was not the right way of telling it (you know now that English is not my mother tongue ).

The main idea was : when a language's syntax evolved from version to another, adding more and more sugar, won't it be unreadable in a near future ?

I heard that the Ruby language itself has evolved and continues to evolve a lot, adding more and more to the language (new operators maybe, many ways of doing the same thing).
I fear that the language will stop being readable if you don't have a very good knowledge of all that stuff.
So the language will be harder and harder to learn and to use.

David, you cited : array.map(&:upcase) versus array.map {|s| s.upcase } .
From a beginner's point of view (mine ), it should exist only one way to write that code, no ?
(I know that it may be useful in certain condition to use one or the other syntax, but, hey, I do have to know each if I want to be able to read that code).

I hope that language syntax will stabilize and that the language will be kept simple and smart.
(Maybe the whole idea is because I am a newbie and then I don't know Ruby well enough to emit this idea).

I kindly appreciate your feedback.
I am learning Ruby, step by step and any suggestions and opinions are welcome.

Thanks,

Tom
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Thomas wrote: David, you cited : array.map(&:upcase) versus array.map {|s| s.upcase } .
From a beginner's point of view (mine ), it should exist only one way to write that code, no ?

I don't believe so, really. I mean, if you want a "semantically pure" language, you're going to be limited to a very few choices (Scheme comes to mind). There are almost always going to be multiple ways to accomplish the same functionality. Even Java, which is pretty limited in capability, might have a number of ways to represent identical functionality: an old-style for loop, a new-style one, Commons Collection's Transformers, Google's collections equivalent, a home-brew solution, etc.

While technically living at a different level (the two for loops are language constructs, the two collections things are APIs) you still have to understand the differences, advantages, use-cases, etc. so the cognitive overhead is basically the same thing.

Languages are *always* going to evolve, and that generally implies there will be changes on some level: syntactic, API, usage patterns, etc.
Thomas Queste
Greenhorn

Joined: Mar 08, 2006
Posts: 15
Yes, you are right. I understand well. You make it pretty clear and gave a good opinion of this subject.

Thanks,
Tom

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ruby: the new Perl ? (syntax sugar that kills, too many ways to write stuff)
 
Similar Threads
What are your ideas of Python and Ruby?
Ruby Best Practices: large teams, performance, deployment, and more...
Why Ruby?
Beginning Ruby - Questions
Ruby vs other scripting languages