1. tutorial// Ruby to Euphoria
- Posted by _tom (admin) May 24, 2016
- 1911 views
- Last edited May 30, 2016
Warning:
I edited this entry to respect the comments that follow:
- no intent to insult Ruby
- comments are incomplete because I do not program in Ruby
- notes are made as a starting point for my understanding of Ruby, nothing else
_tom
Going from Ruby to Euphoria involves learning to think simpler.
Ruby reference: The Book of Ruby H. Collingbourne ( www.sapphiresteel.com )
"Ruby’s syntax may look simple at first sight but, the more you get to know the language the more you will realize that it is, on the contrary, extremely complex."
Some observations on the differences between Ruby and OpenEuphoria.
Ruby | Euphoria |
very entity oriented (OOP) | not based on entities |
They say "object" I say "entity" because we use object as a data-type.
OOP is trendy and popular with many programmers. All OOP languages have the alias problem where a copy does not produce a new unique object. This requires you learn how to clone objects.
Euphoria does not have dot notation.
OOP languages emphasize polymorphism as a way to make code gerenic and versatile. Euphoria is naturally generic so you will find functions that work on strings can work on raw numbers just as nicely.
Extra code to create and then use entities may complicate small programs.
Ruby | Euphoria |
self-modifiying code possible | no self-modifiying code |
First, Euphoria is interpreted and apps can be distributed as a "bound" executable. Second, Euphoria can be translated and compiled using C compiler. This close compatibility with "C" means that code is not self-modifying.
Ruby | Euphoria |
no declarations, inferred types | explicit declarations; only three primary data-types |
Euphoria has a "no surprise" police; that means no variables become declared or have values assigned in some spontaneous fashion without your explicit intentions. The Ruby NIL value does not magically appear when you forget to assign a value to a variable.
In a array if you output an non existing item you get NIL. In Euphoria you get an error message that the non-existing item does not exist.
That means all variables must be declared. We use atom ( individual value) and sequence (list of values) to show the intended use of a variable. But, you could use object which is the universal data-type.
Note that real, integer, character data-types are all atom.
I feel this "no surprise" policy makes reading Euphoria code easier.
Ruby | Euphoria |
creative syntax | simple pedictable syntax |
In Ruby you can, sometimes, leave out parentheses as part of a routine name: print and print() can be the same. In Ruby you can leave out the "then" keyword in a if statement (except when you can't leave it out.) You have one syntax in Euphoria with no shortcuts.
A multiline comment must have start and end markers flush with the left margin. Ruby syntax may follow different rules depending on context. Euphoria is always consistent.
Ruby uses just the "end" keyword to terminate a code block. Euphoria always include the starting keyword name: an "if" statement terminates with "end if". In the case of nested code this makes Euphoria easier to read.
Euphoria syntax is fixed but freeform. You can not leave out keywords, but you can choose the layout , spacing, and line breaks when you write code to suite you personal style.
Ruby | Euphoria |
use global variables a lot | global variables are rare; better to select from export or plublic |
fine grained control of scope |
See documentation on scope to understand the Euphoria way.
Ruby | Euphoria |
three styles "Hello" << " world" "Hello" + " world" "Hello" " world" |
one style "Hello" & " world" |
Ruby concatentation is tricky. Euphoria concatenation is the same regardless of the items.|
Ruby | Euphoria |
constant has first letter capitalized | use constant keyword, use any valid identifier |
Ruby has some specific rules for identifiers.
Ruby | Euphoria |
special trailing ! added to routines to work around alias problem | no alias problem, all routines work the same |
A Ruby routine named capitalize! (with !) will modify a string. Routines without the (!) result in a new entity.
Ruby | Euphoria |
for output need .to_s (to string) methods | for string output use puts, for number output use ? or print |
Ruby | Euphoria |
zero based indexing | one based indexing |
s[1,3] | s[2..4] |
s[-1] | s[$] |
Indexing logic in Ruby is different.
given = "Hello" then s[1] is e and s[1,3] is ell (second value is for number of items)
Euphoria
given s = "Hello" then s[2] is e and s[2..4] is ell
All Euphoria index values are postive. Ruby uses negative indexing to count backwards from the end. In Euphoria the $ marks the last itme in a sequence list so that $-1 is the second last item.
Ruby | Euphoria |
def keyword for function defintions | keyword procedure for if no value returned keyword function if value must be returned |
Intent of a routine is explicit and clear form the procedure and function keywords. A function must return a value, however these return values may be ignored.
Ruby | Euphoria |
creative | could use while ... end while loop for almost everything |
From my reference, p75, you can write code that looks like
def tired # some code ... end def snore # some code ... end def sleep # some code ... end while tired do sleep end while tired sleep end sleep while tired begin sleep snore end while tired
If you think in Ruby this all makes sense.
Euphoria is a lot simpler than Ruby, much less to learn.
_tom
2. Re: tutorial// Ruby to Euphoria
- Posted by ryanj May 24, 2016
- 1876 views
Interesting comparison.
I feel this "no surprise" policy makes reading Euphoria code easier. ... Euphoria syntax is fixed but freeform. You can not leave out keywords, but you can choose the layout , spacing, and line breaks when you write code to suite you personal style.
This is a big reason why i like Euphoria so much more than any other language i have seen so far.
3. Re: tutorial// Ruby to Euphoria
- Posted by andi49 May 25, 2016
- 1843 views
You have never ever used ruby or even tried it!?
I'am correct?
Andreas
4. Re: tutorial// Ruby to Euphoria
- Posted by _tom (admin) May 26, 2016
- 1830 views
I have tried it. I can not program in Ruby. But, I do not claim to be able to program in Euphoria either.
Are any of my observations incorrect?
From wikipedia
Matsumoto defined it this way in an interview:[60]
Everyone has an individual background. Someone may come from Python, someone else may come from Perl, and they may be surprised by different aspects of the language. Then they come up to me and say, 'I was surprised by this feature of the language, so Ruby violates the principle of least surprise.' Wait. Wait. The principle of least surprise is not for you only. The principle of least surprise means principle of least my surprise. And it means the principle of least surprise after you learn Ruby very well. For example, I was a C++ programmer before I started designing Ruby. I programmed in C++ exclusively for two or three years. And after two years of C++ programming, it still surprises me.
Now to quote myself from another thread
In "Ruby thinking" there is a tendency to invent a new convenient rule for every situation. If your mind works like that of Matsumoto, then these "rules" effectively do not exist and you become a fan of Ruby. If you study how Ruby is put together you will find lots of inconsistencies, but if you think in Ruby then these inconsistencies are why you use Ruby.
In "Euphoria thinking" there are just a few rules that work the same all the time. The "charm" of Euphoria is that you don't have to put lots of ideas into your head, and when everything works the same, all the time, you reduce "congnitive load" and your brain feels better.
Going from Ruby to Euphoria involves learning to think simpler.
Tossing out understanding how OOP works is a big simplification.
I am constantly trying to invent some marketing jargon such as "learning to think simpler." I welcome comments.
_tom
5. uby is really slowRe: tutorial// Ruby to Euphoria
- Posted by andi49 May 27, 2016
- 1872 views
I have tried it. I can not program in Ruby. But, I do not claim to be able to program in Euphoria either.
Are any of my observations incorrect?
There are some points where you are not correct/accurate.
(function(ignoring results) vs. def)
(puts vs. puts)
This also works in Ruby, go to https://www.ruby-lang.org/en/ and try a few reloads. Same as the OpenEuphoria Homepage.
"test"+"test"
is not same as
"test"<<"test"
I can go there for every line you wrote.
You can't compare things that are not comparable, this sheds a bad light on OpenEuphoria (if an Ruby Programer reads this)
OpenEuphoria has a lot of good points. But trying to make an other Language look worse is not the way to go.
My point of view.
Andreas
# Das berühmte Hallo-Welt- # Programm ist trivial in # Ruby. Überflüssig sind: # # * eine "main"-Methode # * Newline-Zeichen # * Semikolons # # Hier ist der Code: puts "Hallo Welt!"
From wikipedia
Matsumoto defined it this way in an interview:[60]
Everyone has an individual background. Someone may come from Python, someone else may come from Perl, and they may be surprised by different aspects of the language. Then they come up to me and say, 'I was surprised by this feature of the language, so Ruby violates the principle of least surprise.' Wait. Wait. The principle of least surprise is not for you only. The principle of least surprise means principle of least my surprise. And it means the principle of least surprise after you learn Ruby very well. For example, I was a C++ programmer before I started designing Ruby. I programmed in C++ exclusively for two or three years. And after two years of C++ programming, it still surprises me.
Now to quote myself from another thread
In "Ruby thinking" there is a tendency to invent a new convenient rule for every situation. If your mind works like that of Matsumoto, then these "rules" effectively do not exist and you become a fan of Ruby. If you study how Ruby is put together you will find lots of inconsistencies, but if you think in Ruby then these inconsistencies are why you use Ruby.
In "Euphoria thinking" there are just a few rules that work the same all the time. The "charm" of Euphoria is that you don't have to put lots of ideas into your head, and when everything works the same, all the time, you reduce "congnitive load" and your brain feels better.
Going from Ruby to Euphoria involves learning to think simpler.
Tossing out understanding how OOP works is a big simplification.
I am constantly trying to invent some marketing jargon such as "learning to think simpler." I welcome comments.
_tom
6. uby is really slowRe: tutorial// Ruby to Euphoria
- Posted by petelomax May 28, 2016
- 2010 views
trying to make another language look worse is not the way to go.
I have to agree.
Anyway, I found a few interesting reads (at least for me, and not meant as "ammunition"):
http://www.leonardteo.com/2012/07/ruby-on-rails-vs-php-the-good-the-bad/
http://blog.parse.com/learn/how-we-moved-our-api-from-ruby-to-go-and-saved-our-sanity/
Pete