Exploring Wide Finder

Wow, lots of fairly closed minds here!

I think that any halfway decent developer should be interested in moving outside their C syntax comfort zone and learning other languages. Ruby borrows elements from Smalltalk (e.g. the |goalposts| enclosing local variable declarations) and Perl (e.g. the $1 in regular expressions). Incidentally, Ruby does have a more verbose OO syntax for doing regex if you prefer.

The thing with Ruby is that the language is so flexible and dynamic that you can write cryptic code if you must, or you can write code that reads like an English sentence. Of course it all depends on what you’re used to. My initial reaction to the C# example given earlier was “WTF does CultureInvariant mean”?!

Regarding performance, has everyone forgotten that Java was hideously slow upon release? There are various promising initiatives underway to create a Ruby VM, so expect the performance gap to narrow or disappear altogether. You can even now run Ruby on a JVM using JRuby and access Java classes if you really want to.

Thought Ruby was prettier than that.

Have to agree with Craig – a proper compiler would handle multicore optimizations.

Silly wabbit! The most beautiful code is APL!

http://en.wikipedia.org/wiki/APL_(programming_language)#Examples

I have to chime in with the others. That is not a very readable program. If I knew Ruby I might know what the pipe characters do, but otherwise they are not self-evident.

Of course, I could just be a VB dinosaur.

The code listed is probably not a good example of readability. I doubt as many people would have problems with it if a few simple things were changed such as:

regex = Regexp.new(‘GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)’)

ARGF.each_line do |line|
if regex.match(line)
counts[regex.last_match(1)] += 1
end
end

… and the = operator replaced by the more familiar ternary or a simple if/else. There are too many esoteric Ruby shortcuts for this to be considered ‘readable’ - but that doesn’t mean it’s a problem with Ruby.

I’m no student of programming languages, but I think the other confusing bit of code, the use of blocks, (things between || and the associated do/end or {} code), is a great idea and I would love to see it become more widely used.

The “fad” of cramming as much as possible into as little code as one can has been around a lot longer than Perl golf. As I understand it, the C programmers started it out of necessity, back when memory was truly limited…

a href="http://www.ioccc.org/"http://www.ioccc.org//a

Quoting from posts above:

There’s also a current fad just now with new Ruby afficionados, converts and zealots to see how much they can compress their intent into as few lines as possible using every trick in the book. I find this obfuscates Ruby code as much as it does C#, Perl or any other language that lets you pull of these tricks. You just end up with another blob of ‘write-only’ code.

Just my 2c from current observations.

P.S. Kev: That fad has been around since the invention of Perl. That’s why it’s called Perl Golf. :slight_smile:

Aaron G on June 10, 2008 06:31 AM

Kev on June 10, 2008 06:29 AM

Ruby the most beautiful language? Hah!

In terms of actual visual appeal Erlang is quite nice; pleasingly spikey and compact. I’d love to say that Common Lisp was beautiful, but function/macro names like ‘cadadr’ and ‘destructuring-bind’ ruin it a little. :slight_smile:

A lot of the more exotic languages in this test, btw, are suffering from not having very good bulk IO.

Haven’t you tried C# or VBScript on Excel?

What? No graphical programmers out there? I did the assembly language, BASIC, C++ … but found the love of my life coding in LabVIEW. Talk about beautiful.

I get some grief from a few “real” “seasoned” programmers who think we LabVIEW guys just sit around and “draw pictures” all day. :slight_smile:

I followed TBray’s post on this topic last year. As previous commenters pointed out, WideFinder is more IO bound than CPU-Bound. That’s why a few implementations there resorted to low-level tricks such as mmap to obtain decent numbers. Particularly, Ruby, being weak at IO, sucked a lot.

“naive Ruby implementation” - heh. Funny, but I think it should be native.

My initial reaction to the C# example given earlier was “WTF does CultureInvariant mean”?!

Oh, this is a great feature: Ever searched rtl-Text?
Do the ruby-libs handle different cultures without problems? And does ruby handle the full unicode characterset? Or UTF-8 AND Ansi?
Covers it problems such as wether and i are seen as equivalent?
Ok, ruby is only the language itself, but libs are just as well important.

If you wanna know, which params a method or class needs: Use Intellisense or press F1 :slight_smile:

I have to agree with Mike. If this is actually CPU bound, Gawd help you.

And I think the C# (with some formatting of course) is actually far more readable.

trying to compress your code into fewer and fewer lines / characters has been around longer then programming languages. We used to do it with assembler and machine code. It was a necessary evil when computing power was measure in bytes (not MB or GB, but byte) and kilohertz. Anyone who does it today should be forced to write all of their code in APL, which was unreadable any way.

I love how people complain about .collect, it’s just that Ruby has some different names for things. Personally I think they’re often better. But you can use the ‘traditional’ names if you like:

irb(main):003:0 [1,2,3].map { |i| i2 }
= [1, 4, 9]
irb(main):004:0 [1,2,3].collect { |i| i
2 }
= [1, 4, 9]

Similar idea for inject/reduce, extend/concat, detect/find, etc.

Ruby’s syntax can be a little obtuse at times. The biggest reason people don’t “get” the benefits of ruby is that they haven’t explored the beauty of metaprogramming. If you think laterally about problems, ruby and dynamic languages let you do some amazing things that will be lost on you if you aren’t familiar with metaprogramming or thinking out of the box.

When used correctly, it’s something like “I need to jump REALLY high in this class” and you realize you can turn off gravity locally, in the class. On the flip side, you can also be dumb about it, and turn off gravity globally… With great power comes great responsibility.

http://www.microsoft.com/downloads/details.aspx?familyid=348F73FD-593D-4B3C-B055-694C50D2B0F3displaylang=en

New version of the Paralell Extensions for .Net came out last week

I struggle to understand why people wouldn’t like this ruby code. Maybe, and this is just a guess, they like their intermediate values more explicitly stored?

I mean, Ruby encourages you to keep calling methods on return values until you’re blue in the face:

hash.keys[a…b].collect { …code… }.foo.bar.etc

There are quite a few intermediate values in the above pseudocode that never get a variable name. They’re implicit. Does this bother people? I know that Python would never stand for such a thing. You can get a couple of levels into it but pretty soon you’ll run into a “procedure” (I call them that because they remind me of Pascal) and be forced to store a result in another variable before proceeding.

This code creates a new 10-element array and calls the “each” method on that. Is this bothersome?

keys_by_count[0 … 9].each do |key|
puts "#{counts[key]}: #{key}"
end

For clarification, here’s some equivalent C code:

for (i = 0; i 10; i++) {
key = keys_by_count[i];
printf("%s: %d\n", strhash_get(counts, key), key);
}

P.S. even in this Ruby program, the programmer stopped and regrouped by using the “keys_by_count” variable. It isn’t necessary, but it does clarify the intent of the program. Maybe some commenters would have preferred even more of that sort of thing.

Some units would be nice on those results. Seconds? Minutes? And the format changes on the longer ones, making it harder to grok the difference in time.

Also some of the PRE elements in your HTML aren’t large enough to show anything but the scroll bars, making it impossible to read one-liners, like the format of Tim Bray’s URLs. Well, not impossible, there’s always View Source.

Did anyone actually go and look at the results page? No?
Mixed in the bottom half of the chart are implementations in Perl, PHP, Gawk, OCaml, Erlang and Ruby. In the top half are Perl, Python, Erlang, and JoCaml.

This proves that a programmer can write fast or slow code in any language. Not exactly earth shaking.

It is a nice opportunity to bash Ruby and Ruby developers, those smug bastards!
Here is the point I got from this post, maybe someone would like to comment on it: Multicore is the future. The silicon vendors will keep producing mutlicore chips, run optimized benchmarks and say the performance is amazing. The reality, when running real code on your system, will suck.
What are we, the programmers of the world going to do about it?

Argue about the prettiest language I guess.

Can you do better on the time without exploding either the code size, the code complexity, or the average programmer’s head?

a href="http://blogs.msdn.com/pfxteam/archive/2008/06/04/8573863.aspx"http://blogs.msdn.com/pfxteam/archive/2008/06/04/8573863.aspx/a

See:

for(int y=0; y to
Parallel.For(0, screenHeight, y = /* funcBody */ )