by Buttons840 · 3y ago · 0 comments
I would argue that Python dominates Ruby in this metric.
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".
New users wonder what a function is exactly. They form an intuition, but their initial intuition doesn't encompass all 7 different types of callables in Ruby, so many surprises and frustrations await.
Python is much more boring in this respect, users are more likely to form accurate intuitions.
What follows is my subjective experience as I came to like Python but hate Ruby: I learned Python in the mid 2000's while trying to script Asterisk. Asterisk had an existing community around PHP and Ruby, so I looked at Python, PHP, and Ruby with fresh eyes, Python appealed to me most. I remember being very confused about what Ruby "gems" were, I thought they were something like "JavaEE" that I'd heard about in passing at school, some kind of compiler plugins or something complicated. Python had "libraries" though, I knew what they were. I didn't seek out learning materials for the languages, I only saw how people were talking about them in the Asterisk community. I'm sure the right material would have explained what a "gem" was very well, but those obscure mailing lists I was reading did not. I never did give Ruby a fair shake, so don't take this as advice, these were merely my experiences as a new programmer looking at both languages with fresh eyes.
I can say that personally using Ruby, Python felt like a massive step backward. I can see how others might disagree, but I feel like it's all in what you know first. On a certain level, most of us know JavaScript is just terrible, but there have been millions of new devs who knew nothing else and thought it's fine--better than fine, its great, it's the other stuff that's weird! But then you go on for a while, maybe eventually find lisp and/or functional programming, and you realize how brain-damaged our most commonly used tools really are.
And you'd be wrong.
I can confidently say that since I fully expecteded python to win over ruby and it did. Every time I used to hear hipsters dev being all the rage about ruby, I knew they implicitly discounted the cognitive load that goes with learning ruby.
The path from pseudo code to working python code was ( is? ) straight forward and ruby doesn't bring anything in term of paradigm over python that justifies foregoing that advantage.
So everytime a bright mind wanted to implement a library in her field of expertise, python was her tool of choice. And that's how python conquered field after field.
I'd agree with that. I've done a lot of work in Python and Ruby. I mostly do Python these days. I think Ruby's ergonomics were better, especially for novices. (E.g., if you want to know what methods you can call on an object, in Ruby you can just look at the object, but in Python there are a whole zoo of global functions you're supposed to know about. [1]) But I think ergonomics just don't matter much when compared with more practical considerations like availability of libraries or number of developers available to hire.
By 2005 or so Python was already the #1 scripting language (other than PHP, I guess).
So, I would say that the most common scripting language in the late 90s was VBScript.
I also can't recall any of the Unix gurus at our company using Python. They used bash, zsh or other shells.
I feel the Ruby community is very syntax oriented. As evidence of this:
I see Ruby developers interested in Elixir and Crystal, languages that are syntactically similar, but technically very different.
I do not see Ruby developers interested in Python, even though, if we ignore syntax, Python and Ruby mine as well be the same language. Technically speaking, and in the grand scope of all languages, Ruby and Python are very very similar.
Unfortunately this turned out not to be the case. Here's my gripes with Python as a Ruby developer that really wanted to love Python:
There's a bunch of global functions that should have been methods on objects, like `len()`. OO in general seems slapped on later, as evidenced by the weird double underscores, and the explicit this object as first arguments for methods. (OO is core to Ruby and very elegantly implemented imo).
Higher order functional programming is a lot more awkward than you would expect from a scripting language that's generally praised for its data processing qualities. It's nice that function definitions are closures but you can't make them anonymously as function arguments, the reason apparently being that Guido didn't want to complicate the parser. This is a contrast with Ruby's most interesting and unique feature, the do syntax which is a syntactic trick making it really easy to use higher order functions that take a single function as their last argument.
Sort of an aside, but from an interview I read with Guido I understand that he actually regrets making Python have semantic whitespace, he actually doesn't like it. To me the semantic whitespace is one of Python's few redeeming qualities and I just wish Ruby would have adopted it as well. Maybe if it had we'd all be unanimously using Ruby.
From some angles these are strange, but from where I sit they seem elegant and pragmatic.
The global functions and double underscore methods are part of the same thing: the language defining and enforcing a protocol that many types of objects should support. Other languages do this by having common names (.length() or whatever), but this has problems that the python way avoids:
- it's hard to add new ones because they share the same namespace as user code - they may have different meanings in different contexts (e.g. a line has a length, but isn't iterable) - the language can't enforce the protocol (e.g. len accepts only one argument, checks the result is an integer, and raises the correct exceptions)
For operator overloading, using regular methods with special names is nice because it avoids having special syntax for it, and makes it easier to interactively inspect and experiment with (as you can just call the methods).
The explicit self thing is similar, in that it avoids a load of special syntax: no this keyword, no syntax for static methods, no syntax for superclass calls (until super was added). It even means that there's only really one 'kind' of call.
I can see some confusion about where self actually comes from, but then most languages i've experienced where this is implicit also have corner-cases and awkwardness around it.
IMO these kind of simplifications seem a bit frivolous when looked at in isolation, but end up simplifying your mental model of the language, which helps beginners get more out of it quicker.
> It's nice that function definitions are closures but you can't make them anonymously as function arguments.
I thought this for a while, and it would still be nice in a few situations, but really it's not a burden to name your callbacks, and discouraging overly-clever code isn't a bad thing if you're trying to build an ecosystem that's accessible to as many people as possible. I used to use map/reduce/filter a lot, but most of the time list comprehensions and regular loops end up easier to read.
Python's OO does feel slapped on. As a Python user I've come to see object-oriented code as just some syntax to organize data and functions. To me, it's all functions, always has been.
I'm curious to know if you have similar thoughts biased towards objects? Do you view functional code as just a way of creating and organizing object-like concepts? I have heard that Ruby is quite pure in its philosophy and approach to object orientation, like SmallTalk, but I don't know either language well enough to fully appreciate this way of thinking.
Same things are happening with Python. And if I have to be honest, if I come from a different profession and want to change my career, I would pick either Python or Javascript for my first step.
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?
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.
IIRC, they're syntactic sugar over "string".format(locals())
https://docs.python.org/3/library/string.html#format-string-... https://docs.python.org/3/reference/lexical_analysis.html#f-...
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.
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.
To begin with I could never understand why there need to be those global functions in Python to do meaningful things with lists.
In Ruby the "everything is an object" really works down to every nut and bolt and is clean and very conceptually pleasing.
Whether you call a package a gem, module, jar or whatever isn't very central.
if len(mylist) > 10:
pass
Only general things dealing with common needs are global, list-centric methods are on the list where they belong. I learned Java before Python and don't really miss value.toString() or value.length() much. if mylist.length > 10The optional parentheses example is a good one. That mistake was carried over to Crystal, it's such a silly little inconsistency that I'm sure the designers considered "cute" or "clever". It's naught but a constant pain in the butt.
Another good example is YAML vs JSON. I understood the entirety of JSON syntax pretty much immediately upon seeing it, it's trivial. YAML is supposed to be "easier for humans", but by forgoing a uniform and consistent syntax it ended up an order of magnitude harder.