7 ms·
What concepts does a language force a new user to be aware of, and how reliable are user's first intuitions about those concepts? I would argue that Python dom
by Buttons840 3y ago
What concepts does a language force a new user to be aware of, and how reliable are user's first intuitions about those concepts?
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.
- mellavora 3y 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?
- ptx 3y ago> 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.
- Izkata 3y ago> And f-strings, unlike JavaScript's template strings, are not function calls. IIRC, they're syntactic sugar over "string".format(locals())
- raziel2p 3y agoThey're really not, the internals are different, many features were added. https://docs.python.org/3/library/string.html#format-string-syntax https://docs.python.org/3/library/string.html#format-string-... https://docs.python.org/3/reference/lexical_analysis.html#f-strings https://docs.python.org/3/reference/lexical_analysis.html#f-...
- DangitBobby 3y agoWith the exception of properties, of course.
- Buttons840 3y agoDouble 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.
- preordained 3y agoI'd argue that better relative ergonomics had diddly squat effect on Python's current position. It's first mover advantage, plain and simple. It got its hooks in data science like JavaScript got its in the browser. 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.
- Buttons840 3y agoCan you explain more about how (you feel) Python is a step backwards? I'm curious if the "steps backward" are syntax level? 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.
- tinco 3y agoI really wanted to love Python. As a Ruby programmer I thought Python would be like Ruby, but with a prettier syntax because of the syntactic white space. 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.
- oezi 3y agoIt is sad to me that you hate Ruby. It is a better language than Python for my taste in all dimensions except number of libraries available. 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.
- mixmastamyk 3y agoWas simply for readability, as in similar to English prose. What if the length of my list is greater than 10? 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.
- oezi 3y agoBut it is absolutely unintuitive why it shouldn't be if mylist.length > 10
- mixmastamyk 3y agoIf the length of mylist ... see how length comes first? Only unintuitive if you never spoke English or other european languages.
- AlchemistCamp 3y agoThis construction is something my French friend often does in English instead of using a possessive—the <property> of <thing>. As a native speaker of English, I’d just say, “if mylist’s length is more than 10”.
- jbergens 3y agoA really, really bad argument in my opinion. That thinking would lead us to Cobol.
- Mawr 3y agoYes, it's essentially UI/UX principles as applied to language design, with developers being the users. You want your users to be able to build reliable mental models of your interface [1]. The 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. [1]: https://news.ycombinator.com/item?id=36396256 https://news.ycombinator.com/item?id=36396256