What are your ideas of Python and Ruby?

I am quite familiar with Python and I really like the language (but haven't looked at the backwards-incompatible 3.0 version yet.) What I really like about it is its clean syntax and simple yet powerful OO implementation, and the fact that it is extremely high level and reflexive. I was tempted to look into Ruby, but then somehow I ran into a few comments which liken its syntax to Perl (in the sense that there are many different syntactic ways to do something.) On the other hand, I keep hearing how Ruby is truly a more elegant language than Python (although I haven't found satisfactory explanations as to how that is so.) I was wondering what experiences and insights some of you guys could offer.

Thanks,

Ruben

All code in my posts, unless a source is explicitly mentioned, is my own.

I must admit I haven't use neither Python nor Ruby for real life projects. But my impression of Ruby (and other dynamic languages) is similar to yours. There are often many ways to achieve a goal. Moreover there is a lot of magic going on behind the scenes with reflection, meta programming and so on. This is really nice to say and may be quite good when you create a prototype or you make an application from scratch.

But I think MOST programmers will definitely misuse all these nice features and you will end up with a completely non-understandble code base if you can't control that everybody works very disciplined. Maintainability and readable code is in my opinion absolutely missing in all those nice examples which try to make the shortes "Hello World" program even shorter. Of course it is arguable if this is a problem of the programming language or the programmer but practice often shows that it's even hard to understand most code written in more straight forward languages.

What I find a really good compromise is the approach in Scala where it's allowed to leave out some redundant information like braces or type definitions where they can be inferred by the compiler. The code is still readable enough for other developers in contrast to some funny tricks in dynamic languages.

This is of course just my opinion. Maybe someone can REALLY convince me of the advantages of Groovy, Ruby, Python etc. :-)

I've never heard anybody say that Ruby is more "elegant" than Python. They're both very nice, capable languages. I tend to prefer Ruby (perhaps due to my Lisp and Smalltalk background?) but appreciate Python's cleanliness.

The "static v. dynamic" debate is a completely separate issue, and only rarely worth arguing about. I have zero comprehension regarding people that completely disregard an entire set of tools because it doesn't fit their particular model of how programming "should" be done. The straight-jackets that Java makes me wear would quickly send me over the edge if it was the only language I worked with. The levels of abstraction Java can represent is really a step down from many other languages.

Even if I *didn't* work with other languages, to dismiss out-of-hand the lessons they teach about other approaches and paradigms is really a disservice.

Funny tricks in dynamic languages? You want "funny tricks" check out how many Java libraries get their work done... there's a reason many of the best libraries Java developers use *all the time* are dependent on things like ASM, CGLib, and so on.

I have zero comprehension regarding people that completely disregard an entire set of tools because it doesn't fit their particular model of how programming "should" be done.

I don't disregard dynamic languages although my post indeed may look like I would. Moreover I didn't want to arouse just one more discussion of static vs. dynamic typing. I know that this is pointless. And I didn't want to promote Java as the one and only valid programming language. Sorry if you got this impression from my post!

Of course I see many of the weaknesses Java and other similar (static) typed language have. On the other hand I clearly see the advantages you can gain with dynamic languages like Python, Ruby, Groovy and others.

I have read about and experimented only with Ruby and Groovy and I think it's really nice how easy you can do many, many things that would take you lots of lines of code in Java for example. Also the shorter and concise code you get from this is definitely a big advantage. Not to speak of the capabilities Java simply doesn't offer you like closures, meta programming and all these things.

In contrast where I see problems (and that is what I really wanted to state with my post) is when you have to deal with code written in those dynamic languages possibly by someone other than you.
On the one hand I often face the same difficulties Ruben pointed out with the different ways you can do this or that. This starts for me even with braces you can or can not include in every place. It's nice to have the choice to leave out or explicitly put in such details but for me it makes the code less readable and confusing. Of course you have the same problem in a weaker form in Java, too.
On the other hand the dynamic vs. static problem still lasts. At least for me. I don't care if a language is statically or dynamically typed and I don't want to prefer one of these types of languages. It's just my personal experience that it makes the code harder to read and understand for me if all the type information at development time is missing because this (maybe redundant) information still serves as a kind of documentation for me. Regarding maintainability of an existing system I personally think the shortest solution isn't always the best no matter what kind of programming language you use.

Obviously dynamic languages aren't that popular just because of the shortest possible hello world examples I'm pretty sure like with many other things you have to come to a certain point of understanding to really see the advantages. Perhaps you, David, can give me some good advices how to master the typical problems one has when beginning with dynamic languages coming from static languages like Java! As many discussions show I'm definitely not the only one who has problems to understand the advantages of Ruby or Python for real projects. And I'd be very happy to see where and how all those new languages could make my life as software developer easier.

Anyway as I stated I try to understand and use dynamic languages additionally to Java. And as I pointed out I like the concepts in Scala which I think give you a lot advantages in contrast to Java by mixing many good ideas of object oriented and functional programming. I hope that should be enough to show that I'm not one of those closed-minded programmers who only love what they are already familiar with and don't care of anything new to them!

And sorry, sorry that this discussion has become a bit off-topic. At least it's slightly related to Python and Ruby

I use Python once in a while, but there are many things I don't like about it. I think it is considerably less elegant than Ruby, though it is more elegant than Java and especially C++.

The enforced indentations make programming a pain, the lack of common and useful, although they are nothing more then syntactic sugar, functionality such as switch is a headache. It is an odd thing that its data structures don't know its own size. The lack of abstract classes and private members makes writing libraries problematic(you can't really guarantee anything and any changes is liable to break lots of code), its difficulty in telling the difference between variable names and functions is laughable(ie len =len(someArray)). But it does have lots going for it as well. having to type self.variableName makes me laugh and cry at the same time. The one thing I absolutely love is the ability to save huge values easily, but Ruby does this as well. That saved me the last few months since I have been writing scripts to directly read file partitions, something java would be terrible at, Ruby would be good at it. Its use lambas and its sort of built in support for design by contract are two other big pluses for the language. Why None instead of nil or null???

Ruby is simply elegant in its structure and syntax. It is considerably easier to write clean and readable Ruby than it is to do the same in Python(It is not quite as horrible as Perl or Lisp, but close). Its biggest legitimate knock is performance, but Ruby 2.0 should address that problem. Closures just flat out rocks, and the common libraries available for Ruby make life easy, especially ActiveSupport. Its time and date functionality just can't be beat. I get a kick out of the fact that even nil is an object.

Both are well worth learning.

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra

Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032

posted Jun 11, 2009 20:10:16

0

Marco Ehrentreich wrote:Hi Ruben,

I must admit I haven't use neither Python nor Ruby for real life projects. But my impression of Ruby (and other dynamic languages) is similar to yours. There are often many ways to achieve a goal. Moreover there is a lot of magic going on behind the scenes with reflection, meta programming and so on. This is really nice to say and may be quite good when you create a prototype or you make an application from scratch.

But I think MOST programmers will definitely misuse all these nice features and you will end up with a completely non-understandble code base if you can't control that everybody works very disciplined. Maintainability and readable code is in my opinion absolutely missing in all those nice examples which try to make the shortes "Hello World" program even shorter. Of course it is arguable if this is a problem of the programming language or the programmer but practice often shows that it's even hard to understand most code written in more straight forward languages.

What I find a really good compromise is the approach in Scala where it's allowed to leave out some redundant information like braces or type definitions where they can be inferred by the compiler. The code is still readable enough for other developers in contrast to some funny tricks in dynamic languages.

This is of course just my opinion. Maybe someone can REALLY convince me of the advantages of Groovy, Ruby, Python etc. :-)

Marco

Hi Marco,

Sorry for the late reply. I am mostly familiar with Python and Java, and I think that they have very different philosophies. I think that with Java there is more redundancy, which probably means that in most cases it's more difficult to make code less readable. You can do many things in Python which are amazing though, since you basically have full freedom in customizing class creation at runtime. I'm not saying this something every language should have, just that it's one example where you can appreciate the difference in approach of each language.