If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Why I felt in love with Ruby
6 posts
• Page 1 of 1
Why I felt in love with Ruby
I started programming back in the days when oop was just a wish. Since then, I worked with a lot of oop-oriented languages, but Ruby is the first that really fascinates me for its ease of use. Let's have a look at this (its not the full code, just an excerpt):
This is so close to the way human beings think, that I currently can't imagine any other language doing it better. Besides, these 3 lines of code represent what would have been dozens of code lines 20 years ago. But what is happening here?
A string input is said to be looped for each line of text, additionly giving an index. An array is told to store each line seperately. But that line of text is heavily altered. First, it gets rid of any control signs (like CR, LF, etc.) using chomp. Then that result line is split into single words using split with space as seperator. Those single words are now looped and each of them changed to start with a capital letter. And lastly all of them are joined together again, again using space as seperator. See? I can't even describe it as short as its written in Ruby while still instantly recognizable.
Awesome!
- Code: Select all
@example.each_line.with_index do |s, i|
@value[i * 4 + 2] = s.chomp.split(" ").each {|s| s.capitalize!}.join " "
end
This is so close to the way human beings think, that I currently can't imagine any other language doing it better. Besides, these 3 lines of code represent what would have been dozens of code lines 20 years ago. But what is happening here?
A string input is said to be looped for each line of text, additionly giving an index. An array is told to store each line seperately. But that line of text is heavily altered. First, it gets rid of any control signs (like CR, LF, etc.) using chomp. Then that result line is split into single words using split with space as seperator. Those single words are now looped and each of them changed to start with a capital letter. And lastly all of them are joined together again, again using space as seperator. See? I can't even describe it as short as its written in Ruby while still instantly recognizable.
Awesome!
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Why I felt in love with Ruby
PHP:
trim = remove whitespace
ucwords = uppercase words
PHP is quite old but still beats the crap out of the newcomers
- Code: Select all
$foo = ucwords(trim($foo));
trim = remove whitespace
ucwords = uppercase words
PHP is quite old but still beats the crap out of the newcomers
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Why I felt in love with Ruby
MyCo wrote:PHP:
- Code: Select all
$foo = ucwords(trim($foo));
trim = remove whitespace
ucwords = uppercase words
PHP is quite old but still beats the crap out of the newcomers
To keep it fair, you just took a small part of the above
Your example in Ruby:
- Code: Select all
@foo.split.map(&:capitalize).join
doesn't even need an assignment But yes, that PHP code is pretty cool.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Why I felt in love with Ruby
Ever tried ruby's string mangling stuff on German Umlauts? You'd be surprised
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Why I felt in love with Ruby
MyCo wrote:Ever tried ruby's string mangling stuff on German Umlauts? You'd be surprised
I knew before that all the good stuff is limited to ASCII-7, and Flowstone doesn't allow us to use encodings
Have you ever tried to enter a german umlaut in the ruby editor?
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Why I felt in love with Ruby
So i have a question, its says i the manual that ruby can access functions from 3rd party dll's so do you think text to speech and speech synthesis could be brought in to flow stone apps/plugs? it something Ive been interested in for a while! soz to digress!
imran
- cathleenwitmer
- Posts: 1
- Joined: Fri Feb 20, 2015 6:28 am
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 90 guests