Hacker News new | ask | show | jobs
by mellavora 1028 days ago
>New users wonder how to call functions. They form an intuition ("use parenthesis"), but it's unreliable. "Oh, parenthesis are optional--oh, parenthesis are only optional sometimes".

print f"are you {sure} you need parenthesis to call a function in python"

>Python is much more boring in this respect, users are more likely to form accurate intuitions.

is defining a class the same as defining a function? What about functions implicitly defined when you define a class?

__what__ is __with__ __some_words__?

why do you need an empty file called init.py in the same directory as your actual code?

2 comments

> print f"are you {sure} you need parenthesis to call a function in python"

This example doesn't call any functions. The print statement was removed in Python 3 and turned into a function, so you do need parentheses to call it and the example above is a syntax error. Python 2 (which had a print statement instead of a print function) didn't support f-strings. And f-strings, unlike JavaScript's template strings, are not function calls.

In other words, yes, you consistently use parentheses to call functions in Python.

> And f-strings, unlike JavaScript's template strings, are not function calls.

IIRC, they're syntactic sugar over "string".format(locals())

With the exception of properties, of course.
Double underscores are ugly, but not surprising or frustrating. I say they are not frustrating because the language doesn't force beginners to be aware of how they work right away. Double-underscore methods are there for people to seek out when they're ready, but the language and the surrounding community doesn't push people into comprehending them. Intuition is good enough for a long time. Ruby has more focus on metaprogramming which is likely to force users into some pretty complicated stuff before they're ready.

print as a statement is inconsistent and surprising, but the explanation is shallow--they made an exception for print, that's all there is to it. It's not beautiful but it is unlikely to cause a 2 hour debugging session.

A lot of Rubyists are turned off by Python because there are just too many ugly things and exceptions in Python.
100% fair. They're probably right; certainly right from their own subjective view, which is what matters.

I'll also note that the OP focused on how "fun" Ruby was. Ruby is beautiful and fun.

Going back to the original question: why did Python grow more than Ruby? My first answer was going to be a rhetorical question: which beautiful and fun language has been the most successful?

C isn't especially beautiful or fun, not in the same way. (It has a nice minimalism and connection to the hardware maybe.) C++ is beautiful--is a thing that nobody has ever said. Java ain't beautiful. JavaScript, Python, etc, none are especially beautiful or fun.

I think another answer to the OPs question is that beautiful and fun languages are, apparently, not what most people are looking for. Evidently we should not expect a language to succeed because it is beautiful and / or fun.

Python had a huge head start. It was already one of the most used scripting languages by the late 90s and Ruby barely even existed outside of Japan.

Ruby’s beginner-friendliness and consistent OO design managed to help it expand in the early aughts and Rails brought the language to prominence in 2005, but by that time Python was already replacing Perl in its niche and had support from giants like Google.

Ruby got more adoption than would have been predicted based on its late entrance and lack of truly differentiating features, and that’s a credit to its ergonomics, community and how easy it is to learn.

I prefer to say that underscores mean that designers failed
Failed to design a beautiful language, yes. But they didn't fail to design a usable workhorse language.
It isnt hard to make stuff usable

Designing it correctly is an art