Ruby

Hanno's Blog

Wednesday, August 16. 2006

Ruby


Trackbacks

No Trackbacks

Comments
Display comments as (Linear | Threaded)

Ruby is my favourite programming language since I discovered it 2 years ago, I'm glad you also like it.

There's also the find module which does the same:

require 'find'
Find.find('.') do |file|
...
end
#1 Robin on 2006-08-16 15:35 (Reply)
That does not look "simple" to me, albeit the XML-like structure...
#2 Anonymous on 2006-08-17 00:31 (Reply)
Same in python:
import os

for files in os.walk('.'):
#3 Alex (Homepage) on 2006-08-17 13:58 (Reply)
i also like the python syntax better - looks easier to understand. the ruby example looks a bit like perl code ;)
#3.1 thp (Homepage) on 2006-08-18 11:39 (Reply)
100% ack.

I think a good programming language should mostly be readable by every programmer even if he does not know the language. Ruby does have so many ugly constructs that look like what one can do in perl and that are not really consistent with what a programmer expects. Ruby is far away from being self-explaining, just like Perl. We don't need another write-only-Language! :)

I like Python for its clean and easily readable syntax.
#3.1.1 Bernd (Homepage) on 2006-08-20 08:08 (Reply)
Ruby:
"test".length

Python:
len("test")

But that's not the point. The comfort of ruby lays in its rich inspection implementation. Every fscking class provides a method "methods", which returns a list of methods. You will never stuck with the »what was the name of the method«-question, you just take a look. You start irb, write "File.methods.sort" and get a sorted list of methods. Comparing Ruby with Perl is not fair and reputable, Perl lacks a clear syntax, which ruby does have. The concept of Perl is to program with side-effects, the concept of ruby is to forbid side-effects. And, in relation to Python, Ruby comes with a straight OOP-implemenation. While in Python you have constructs like "for x in list", in Ruby you will never use functional statements, the method each is a block-function of every list and provides a foreach-like construct. Also Ruby provides much more patterns, a singletons, different server-types. And the modules are all built on each other. GServer, a simple multi-connection TCP-server implemenation is based on sockets, tcp, network and so on. Give Ruby a month and you're going to love it!
#3.1.1.1 Lars Strojny (Homepage) on 2006-08-21 15:03 (Reply)
Und in .NET? Natürlich auch

"test".Length

Was soll das beweisen?
#3.1.1.1.1 Uwe Keim (Homepage) on 2006-08-26 19:16 (Reply)
Die Frage ist, wie sehr ziehen sich Konzepte durch. Man kann sich z.B. überlegen, eine funktionale Sprache zu designen, die immer function(haystack, needle) umsetzt, oder man macht's einfach gemischt, wie in PHP und zwingt dadurch Leute zum Lesen der Dokumentation auch wenn sie die Funktion kennen. in Ruby weiß ich, dass die Stringfunktionen immer eine Methode des Strings selbst sind. In Python gibt es da teilweise Mischmasch.
#3.1.1.1.1.1 Lars Strojny (Homepage) on 2006-08-26 19:42 (Reply)
The example of Hanno is a classical beginner example, utilizing "Find" is much more sensible here. But I don't know why "for files in os.walk(".")" should be intuitive. os? walk? Never heard about that. But "find" is a daily-used util. Naming the things as expected is a good idea ;-)
#3.2 Lars Strojny (Homepage) on 2006-08-21 15:06 (Reply)
The really good thing with os.walk is that is does not actually expand all the files and dirs at once: it is a generator.
When doing Dir["/**/*"] you have to wait for it to walk ;-) on all files and then have a big structure in memory.
Though, it is possible to do the generator thing in ruby: you just have to reimplement Python's os.walk.
#3.2.1 max paine on 2007-02-27 11:17 (Reply)

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 

About

This blog is written by Hanno Böck. Unless noted otherwise, its content is licensed as CC0.

You can find my web page with links to my work as a journalist here.

I am also publishing a newsletter about climate change and decarbonization technologies.

The blog uses the free software Serendipity and is hosted at schokokeks.org.

Hanno on Mastodon | Contact / Imprint | Privacy / Datenschutz