ruby, repeat, and runaway recursion: an experiment

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
redpill
Posts: 21
Joined: Fri Jan 08, 2010 10:38 pm

ruby, repeat, and runaway recursion: an experiment

Post by redpill » Sat Apr 17, 2010 1:15 am

Having tried various coding experiments in the past two months in my efforts to learn Rev's syntax, I decided to compare Rev with Ruby. I found an article written by Yukihiro Matsumoto (Ruby's creator) which had a comparison of Ruby, Perl, and Python. One of the snippets of code benchmarks these languages using a "longest word search." http://www.informit.com/articles/articl ... 5&seqNum=2

Cool, I thought! Let's see how Rev compares with file read. This would help me to learn various aspects of Rev coding: reading files, chunk expressions, and LOOPING ( :evil: ).

Here is the Ruby code. I'm not even going to show you what my Rev code (equally simple -- at first) looks like.

Code: Select all

  #!/usr/bin/ruby
 
  len = 0
  words = []
  while line = gets()
    if line.size == len
      words.push line
    elsif line.size > len
      words = [line]
      len = line.size
    end
  end
  for word in words
    print word
  end
Translating this to Rev syntax took all of about 10 minutes. Yes, I know: Some of you Rev guru's can do it in 30 seconds, but I'm a noob.

Of course, one thing led to another: Basically, I asked myself "Can I make it faster? Is there another way to read a file other than line-by-line? Oh, and, what if I add a really cool progress bar?"

:? But, I should have stopped there. Several hours (12+) later, I ended up fighting the repeat construct while trying to update a frickin' progress bar. OK, so why not forget the repeat construct and just use a counter in a recursive command? It worked great -- once. Looks like I discovered runaway recursion -- now what? Back to the repeat construct.

And then there was the send and/or dispatch experiment -- just as horrible within the repeat construct.

So, did I get this thing to work with a scrollbar? YES

What did I learn along the way?
1) Rev syntax is ambiguous and can take weeks to master (Translation: It has a high frustration curve.)
2) Memorize the Rev language Dictionary -- Yes, really.
3) You can ignore how the message path works. NOT!!
3) repeat constructs are BLOCKING -- can anyone point this out in the documentation, as it's not in the Dictionary when you lookup "repeat."
4) DO NOT perform user-interface (screen) updates within a repeat construct.
5) If you DO need to do the above, remember this: mod is your friend! (Look it up. It's in the forums.)
6) Execute your unnecessary and frivolous screen updates within an if .. mod .. end if construct. In other words, don't keep calling any other handler through each repeat iteration -- it will cripple your repeat loop.
7) You can learn patience trying to implement really small, harmless, code snippets!
8) Who needs stinking scrollbars when Rev can read a huge text file almost instantaneously using the URL (file: ...) thingy. (Yes, it consumes memory, but it's very fast and convenient.)
9) Are you sure producing an application is faster than other languages like Ruby, Python, Smalltalk, Visual Basic??? Maybe with a few years of serious Rev coding.
10) And, finally: People write games in Rev?

How will I improve this horrible experiment?
Instead of using a scrollbar, I will see if it is possible to implement an animation. The animation will be started by sending a message to that handler BEFORE starting the repeat construct. Once the repeat ends, I will send another message to stop the animation. Hmm...probably another 12+ hours.

The sad realization of my experiment
I have only brushed the surface of Rev's ambiguity and complexity. I shudder at the thought of experiencing my future efforts to create an internet-capable and SQL database application. But, the strange thing is this: I like the challenge. And that's why I spent more than 12 hours trying to get a stupid scrollbar to work -- nicely. :)

Thanks for reading. Happy Rev'ing.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: ruby, repeat, and runaway recursion: an experiment

Post by FourthWorld » Sat Apr 17, 2010 2:11 am

Your "What did I learn along the way?" is an excellent collection of tips. Good going.

Yeah, RevTalk can be especially hard when you're coming from other languages, especially threaded and OOP languages. It's not the learning, it's the unlearning. :)

Once you get the hang of it, though, I'd be surprised if you didn't find yourself more productive overall with RevTalk than with just about anything else ('cept maybe Lua, but that's a rare bird).

If you ever want to write a "Rev as a second language" article for RevJournal.com I'd be happy to post it. You have a nice writing style, and you're obviously picking up Rev very well. It would be a fun read.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: ruby, repeat, and runaway recursion: an experiment

Post by mwieder » Sat Apr 17, 2010 2:35 am

redpill-

ROTFL. What a great post!

A few things occur to me: keep in mind that you can create standalone executables with rev, while I've yet to come across a good ruby compiler - it's basically an interpreted language. The ruby compilers and the rails compilers seem to keep playing leapfrog as new versions of ruby and/or rails come out, and so they keep being out of sync.

Ruby's interpretative mode is an advantage for writing short scripts to do specific tasks. With rev you'd either have to launch the IDE, create a complete standalone app, or use the engine in cgi mode.

I love ruby's yield command. The dispatch command in rev used in a behavior object comes close, but doesn't have yield's power for ruby.

And I wouldn't necessarily say rev's syntax is ambiguous. Most of the time, anyway. I'd rather say that once you learn the available commands you're allowed a lot of flexibility. And that flexibility can be a double-edged sword.

Post Reply