# Idiomatic?

**URL:** <https://www.ruby-forum.com/t/idiomatic/147994>\
**Category:** Ruby\
**Created:** [September 8, 2008, 5:16am UTC](https://www.ruby-forum.com/t/idiomatic/147994 "2008-09-08T05:16:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cnb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@cnb](https://www.ruby-forum.com/u/cnb)\
**Post date:** [September 8, 2008, 5:16am UTC](https://www.ruby-forum.com/t/idiomatic/147994/1 "2008-09-08T05:16:48Z")

</div>

which is more idiomatic? amazing how similar ruby and python are.

and what does the guy mean with “pure” here:  
[http://www.linuxjournal.com/article/4834](http://www.linuxjournal.com/article/4834)  
that it is purely OO and consequent? Would Python be impure in his  
meaning of pure?

def fib(n, a=0, b=1)  
if n \> 0  
then fib(n-1, a+b, a)  
else a  
end  
end

def fibo(n)  
a, b = 0, 1  
while n \> 0  
a, b, n = a+b, a, n-1  
end  
a  
end

def fac(n, acc=1)  
if n \> 0  
then fac(n-1, n\*acc)  
else acc  
end  
end

def fac2(n)  
acc = 1  
for x in 1…n+1  
acc \*= x  
end  
return acc  
end

---

<div class="post-metadata">

**Author:** ![cnb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@cnb](https://www.ruby-forum.com/u/cnb)\
**Post date:** [September 8, 2008, 12:12pm UTC](https://www.ruby-forum.com/t/idiomatic/147994/2 "2008-09-08T12:12:16Z")

</div>

Not sure what you mean, but one small example is that in Python, you  
have to do:

len(array)  
string.upper(“foo”)

whereas in Ruby you do

array.length  
“foo”.upcase

The latter is pure OO, the former is not. This is possible because  
everything in Ruby is an object.

---

<div class="post-metadata">

**Author:** ![cnb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9dc877/32.png) [@cnb](https://www.ruby-forum.com/u/cnb)\
**Post date:** [September 8, 2008, 11:00am UTC](https://www.ruby-forum.com/t/idiomatic/147994/3 "2008-09-08T11:00:41Z")

</div>

cnb [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> which is more idiomatic? amazing how similar ruby and python are.
> 
> and what does the guy mean with “pure” here:  
> [Ruby | Linux Journal](http://www.linuxjournal.com/article/4834)  
> that it is purely OO and consequent?

I’m not him, but luckily I don’t have to guess. It’s in the article:

“Everything, including primitive data types like strings and integers,  
is represented as an object. Even constants and classes are represented  
as objects. This makes Ruby a pure object-oriented language.”

> Would Python be impure in his  
> meaning of pure?

I have only minimal knowledge of Python, but IIRC, python is not as  
object-oriented as Ruby is.

> def fib(n, a=0, b=1)  
> if n \> 0  
> then fib(n-1, a+b, a)  
> else a  
> end  
> end

[snip]

What do these have to do with anything?
