idiomatic?

C

cnb

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
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
 
J

Joost Diepenmaat

cnb said:
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
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?
 
R

Rico

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top