News for hackers. Stuff that matters.
Re:Display 100 Hello World Without Using Loops by antirez on Friday May 25, 2012 @06:27AM (#4022867)
that reminds me why I don't like Python. Ad-hoc tools (many) instead of a few general concepts working well together.

Btw at interview time this solution would not be acceptable, because you are using still a built-in language construct for looping.

Re:Display 100 Hello World Without Using Loops by 430gj9j on Friday May 25, 2012 @06:44AM (#4022913)
You're right, Python isn't beautifully minimal. But the Scheme version is boring ;)

Rather than asking the interview candidate to use recursion for a problem that shouldn't be solved using recursion (unless in a language where recursion is the idiomatic iteration method), it would be better to ask about a problem that is best solved using recursion rather than printing "Hello world" -- perhaps something from Project Euler (http://projecteuler.net/).

Re:Display 100 Hello World Without Using Loops by ajitk on Friday May 25, 2012 @06:47AM (#4022919)
On the contrary, wouldn't OP's solution be an example of more generalized implementation of multiplication? I can see that it is similar to (X * 2) where X defines behavior of __mul__.

Yes, there is chance that arbitrary objects can provide different semantics for __mul__. It would be true for any language.

Re:Display 100 Hello World Without Using Loops by hythloday on Friday May 25, 2012 @06:38AM (#4022899)
Huh? This is a specific case of the * operator, which is overloaded for type string to return a repetition of the string. The only ad-hoc in the example is the print statement, which is gone in 3.2.

How do you know the __mul__ operator overload for string is implemented with iteration?

Re:Display 100 Hello World Without Using Loops by lloeki on Friday May 25, 2012 @06:47AM (#4022921)
> This is a specific case of the * operator, which is overloaded

It is not operator overloading in the strictest sense, but more of duck typing. In Python (and Ruby), operators are syntactic sugar for method calls on the first operand.

Operator overloading on the contrary suggests a function add(a, b) that reacts differently through polymorphism (i.e according to the types of its arguments).

The distinction is important as overloading and polymorphism simply do not exist in Ruby and Python, only overriding.

Re:Display 100 Hello World Without Using Loops by hythloday on Friday May 25, 2012 @09:44AM (#4023402)
My hope in using the phrase "operator overloading" was to bring to mind the familiar concept of operator ad-hoc polymorphism (which I would maintain duck typing is an example of) rather than to misleadingly describe the internals of the Python language. Nonetheless you are quite right on the details.
Re:Display 100 Hello World Without Using Loops by lloeki on Friday May 25, 2012 @06:35AM (#4022888)
Well then you don't seem to know python and focus on some red herrings, because it's much more of the latter than the former. The example leverages general concepts such as duck typing and defining __mul__ for a string as doing something thoughtful.
Re:Display 100 Hello World Without Using Loops by masklinn on Friday May 25, 2012 @06:35AM (#4022881)
> because you are using still a built-in language construct for looping.

That... makes no sense, the code is not looping anywhere.

And if you could somehow disqualify this bit, then recursion most definitely wouldn't qualify.