Wednesday, August 16. 2006RubyTrackbacks
Trackback specific URI for this entry
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
i also like the python syntax better - looks easier to understand. the ruby example looks a bit like perl code ;)
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.
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!
Und in .NET? Natürlich auch
"test".Length Was soll das beweisen?
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.
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 ;-)
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. |
About meYou can find my web page with links to my work as a journalist at https://hboeck.de/.
You may also find my newsletter about climate change and decarbonization technologies interesting. Hanno Böck mail: hanno@hboeck.de Hanno on Mastodon Impressum Show tagged entries |