News for hackers. Stuff that matters.
Re:Never run ‘python’ in your downloads folder by taeric on Sunday August 23, 2020 @11:27AM (#24252534)
Python seems to embrace more magic and other subtle visual cues than any other language. I am convinced it is only "beginner friendly" because of how much folks insist it is so.
Re:Never run ‘python’ in your downloads folder by coldtea on Sunday August 23, 2020 @12:21PM (#24252958)
>I am convinced it is only "beginner friendly" because of how much folks insist it is so.

Well, also because you can open a text editor and have a script with very straighforward code in 10 minutes...

Re:Never run ‘python’ in your downloads folder by cortesoft on Sunday August 23, 2020 @12:43PM (#24253150)
There are quite a few languages that can do that... perl, ruby, bash
Re:Never run ‘python’ in your downloads folder by svachalek on Sunday August 23, 2020 @01:04PM (#24253320)
This is an... interesting idea of "straightforward" in the case of bash and to a lesser degree, perl (although I hear perl 6 is nicer).
Re:Never run ‘python’ in your downloads folder by tyingq on Sunday August 23, 2020 @04:19PM (#24254978)
Raku is even more expressive, so if you're unhappy with Perl 5 for readability reasons, there no improvement there.
Re:Never run ‘python’ in your downloads folder by lizmat on Monday August 24, 2020 @01:45PM (#24263221)
Please note that Perl 6 has been renamed to Raku (https://raku.org using the #rakulang tag on social media). And yes, it is nicer :-)
Re:Never run ‘python’ in your downloads folder by rpastuszak on Sunday August 23, 2020 @06:36PM (#24255882)
How about node/es?
Re:Never run ‘python’ in your downloads folder by Sebb767 on Sunday August 23, 2020 @06:06PM (#24255695)
And php, which is also a really beginner-friendly language. In fact, not needing the big toolchain at the beginning helps experimenting a lot and is probably one big factor of what made both of them take off so much in that niche.
Re:Never run ‘python’ in your downloads folder by dragonwriter on Sunday August 23, 2020 @04:26PM (#24255013)
Perl and Ruby have even more common use of “magic” than python.
Re:Never run ‘python’ in your downloads folder by sitkack on Sunday August 23, 2020 @11:36PM (#24257342)
As a long time (97) user of Python who completed a couple katas in Ruby, Ruby has _regular_ magic, as in it is predictable. Python magic is adhoc.
Re:Never run ‘python’ in your downloads folder by dragonwriter on Monday August 24, 2020 @02:19AM (#24257951)
As a long time user of both Python and Ruby, Ruby has plenty of ad hoc magic, at least as much of Python, though it's likely you won't see that as much in whatever language you are less familiar with.
Re:Never run ‘python’ in your downloads folder by Hamuko on Sunday August 23, 2020 @05:06PM (#24255293)
Can you do straightforward JSON download and processing in bash?
Re:Never run ‘python’ in your downloads folder by heavyset_go on Sunday August 23, 2020 @05:52PM (#24255584)
You can go a long way with jq, pup and similar tools.

As an exercise, I used Bash to build scraping and download scripts for about a dozen websites. I found that I only needed to dip into Python when doing complicated operations on strings, or I needed access to data structures.

I actually liked the approach of using Bash first for scraping, because it gave me direct access to Bash's superior IPC and concurrency constructs. I could plug in a Python script into the pipeline and it wouldn't be any different than interacting with another Bash process.

Re:Never run ‘python’ in your downloads folder by samatman on Sunday August 23, 2020 @07:25PM (#24256165)
I do most of my straightforward JSON download and processing in bash. Well, in fish.

As everyone else replying to you indicated, I use jq for it. But when I type `curl http://example.com | jq .`, I'm programming in fish.

Granted, when I want to do something more complex and durable, I'm likely to reach for, yes, python. But nearly as often, I build up a moderately complex jq command, and set an alias to it.

Re:Never run ‘python’ in your downloads folder by dylan604 on Sunday August 23, 2020 @05:51PM (#24255577)
Is that the sole criteria for a scripting language to be useful?
Re:Never run ‘python’ in your downloads folder by edgyquant on Monday August 24, 2020 @12:22AM (#24257504)
I'd say yes being able to parse JSON is a requirement in today's world
Re:Never run ‘python’ in your downloads folder by Shared404 on Sunday August 23, 2020 @06:40PM (#24255899)
Not generally, but perhaps it is for their use case.
Re:Never run ‘python’ in your downloads folder by buddhiajuke on Sunday August 23, 2020 @06:50PM (#24255960)
With an util like jq, yes.
Re:Never run ‘python’ in your downloads folder by nnt38 on Tuesday August 25, 2020 @07:48AM (#24270370)
curl | jq
Re:Never run ‘python’ in your downloads folder by FartyMcFarter on Sunday August 23, 2020 @12:34PM (#24253061)
The magic is friendlier to beginners than to intermediate/advanced programmers.
Re:Never run ‘python’ in your downloads folder by Alex3917 on Sunday August 23, 2020 @05:35PM (#24255470)
Yup. There are a lot of problems with Python, but you're not going to run into them for several years. If you're running into them right away then you're probably not a beginner.
Re:Never run ‘python’ in your downloads folder by Izkata on Sunday August 23, 2020 @06:32PM (#24255861)
I'm not so sure. A couple times I've shown WTFpython [0] to a co-worker, who after spending a bit of time skimming through it mentions that they finally understand a bug they had when they were learning python. And which entry it is is usually different between them.

[0] https://github.com/satwikkansal/wtfpython

Re:Never run ‘python’ in your downloads folder by Alex3917 on Sunday August 23, 2020 @06:37PM (#24255883)
Yeah there are some weird quirks relating to scope and mutable default arguments, but overall I think there are still way less WAT issues than with javascript.
Re:Never run ‘python’ in your downloads folder by mekkkkkk on Monday August 24, 2020 @01:15AM (#24257694)
Wow. Thanks for sharing that! Fun!
Re:Never run ‘python’ in your downloads folder by endgame on Sunday August 23, 2020 @07:32PM (#24256206)
I run straight into the zoo of packaging systems every time I try to do anything with python.
Re:Never run ‘python’ in your downloads folder by jrott on Sunday August 23, 2020 @04:24PM (#24255005)
Python has a bunch of magic but it's mostly helpful for beginners it’s only when you start to do anything beyond simple scripts that it gets in the way.
Re:Never run ‘python’ in your downloads folder by kevin_thibedeau on Sunday August 23, 2020 @12:08PM (#24252844)
Python has little magic in it. It's 3rd party libraries that do un-Pythonic things.
Re:Never run ‘python’ in your downloads folder by quietbritishjim on Monday August 24, 2020 @01:02PM (#24262672)
The descriptor protocol is definitely magic!

It normally doesn't matter that it's magic because most people don't need to interact with it. And it causes a very intuitive result in the part of the language that most people actually do interact with: that x = obj.foo; x() is the same as obj.foo() (not true in Javascript!). But that doesn't change the fact that method binding happens in a more complex way under the hood than you'd expect.

Re:Never run ‘python’ in your downloads folder by kissgyorgy on Sunday August 23, 2020 @05:03PM (#24255279)
> Python has little magic in it.

LOL

Re:Never run ‘python’ in your downloads folder by pyuser583 on Sunday August 23, 2020 @05:50PM (#24255569)
It’s beginner friendly because of the magic and visuals.

When dealing with beginners, a strict indents policy makes sense.

Also the standard data model - makes tons of sense as a way to introduce to OOP.

Re:Never run ‘python’ in your downloads folder by opportune on Sunday August 23, 2020 @10:03PM (#24256953)
Self is a little beginner-unfriendly if they have exposure to other OO languages. In fact the OO model in Python, aside from inheritance/polymorphism, IMO provides a rather uncompelling story for why you should use it other than just naked data structures, because its implementation is too close to a dict, and it doesn't offer you good compile time/type checks (or if it does, it's not readily apparent how to take advantage of them) which will lead a beginner to lots of AttributeError
Re:Never run ‘python’ in your downloads folder by dralley on Tuesday August 25, 2020 @11:25PM (#24278792)
"self" was what made it finally click for me that methods are just functions that take a copy of the data structure they're operating on.

Java's "this" is just kind of implicit magic in comparison, and it didn't accomplish the same understanding.

Re:Never run ‘python’ in your downloads folder by pyuser583 on Tuesday September 01, 2020 @12:48AM (#24338656)
You should check out Go.
Re:Never run ‘python’ in your downloads folder by pyuser583 on Sunday August 23, 2020 @11:13PM (#24257248)
I saw a meme that was “what if everything was x” for each programming language. For Python it was “what I’d everything was a hash.”
Re:Never run ‘python’ in your downloads folder by Karunamon on Sunday August 23, 2020 @07:20PM (#24256131)
Ruby has it beat on magic, I think. Debugging a misbehaving Rails app is an experience it's hard to get in many other languages or frameworks...
Re:Never run ‘python’ in your downloads folder by chipotle_coyote on Sunday August 23, 2020 @08:15PM (#24256443)
Rails pushes a lot of the "magic adjacent" features of Ruby very, very hard, which I'm not sure has entirely been to Ruby's benefit -- it's very often not just the first exposure someone has to Ruby, but the only exposure. It's not as bad as being introduced to PHP by WordPress, to be sure, but it's still going to color your opinion.

I think Ruby's actually a very nice general-purpose scripting language; as much as I like Python in principle, I find myself reaching for Ruby more often.

Re:Never run ‘python’ in your downloads folder by uryga on Monday August 24, 2020 @05:43PM (#24265895)
> It's not as bad as being introduced to PHP by WordPress

i had to learn PHP to do WordPress stuff (after programming in other langs for many years). what's so bad about their usage of PHP?

(off the top of my head: in WP's "everything happens in some hooked callback" model, debugging can be a pain, lots of messing with globals and gluing strings together)

Re:Never run ‘python’ in your downloads folder by chipotle_coyote on Wednesday August 26, 2020 @01:56AM (#24279564)
Your "off the top of my head" would be the main ones I would have come up with, maybe not quite as fast as you did. :) WP is very much of its time in terms of PHP good (and bad) practice.

(Also, WP's style guidance is super weird compared to, well, just about any other PHP style that I've ever seen anywhere, or that of any other C-style language, for that matter. I know that's subjective, but it's Just. So. Weird.)

Re:Never run ‘python’ in your downloads folder by jefftk on Sunday August 23, 2020 @05:12PM (#24255334)
I've used Python for so long that it's hard for me to see its flaws; what (aside from the behavior of import which we're discussing here) seems most worryingly "magical" to you?
Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @05:29PM (#24255435)
Okay, here you go. Find (& explain) the bug in this class definition:

  class A(object):
    def __init__(self):
      self.x = 1
Re:Never run ‘python’ in your downloads folder by jefftk on Sunday August 23, 2020 @08:28PM (#24256522)
Even accepting your argument downthread that the absence of "super().__init__()" here is a bug, this would be a problem that comes from two little magic, not too much! Python requires you to be explicit about this aspect of multiple inheritance, and it sounds to me like you're saying you would rather it be implicit.
Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @08:42PM (#24256606)
No I'm not saying I would rather it be implicit. That can have other adverse repercussions. My goal here was just to identify the problem precisely, because (as you can clearly tell from the thread) it is anything but obvious, even for people who've been using Python for years. I can imagine other ways to mitigate it that don't have dangerous side-effects (like warnings), but there are lots of approaches, and how to solve it is a bit more subjective and warrants a longer discussion.

The pitfall is only part of the problem. The problem is much deeper than that. In Python, the solution lies in the base class, which another author may have written in a totally different time/place. Yet the problem only manifests itself when you, another poor soul, try to derive from it later. This kind of spooky action at a distance pierces abstractions, which is just about the last thing you should want from a programming language... and in a sense it literally violates causality (for the lack of a better word). The poor soul that notices this in multiple-inheritance will have to go very much out of their way to work around it: after spending a while trying to track it down (and understanding what's even going on, which is not easy), they'll have to either monkey-patch the original class at runtime, or introduce superfluous wrappers. That is a very high price to pay, and that's on top of the silent failure that led your code to crash and burn.

But anyway, I was just illustrating Python can be quite complicated (even moreso than C++ in some ways) and has flaws despite its simple and straightforward appearance, and it can catch even experienced developers completely off-guard. Just answering the question you asked, basically.

Re:Never run ‘python’ in your downloads folder by saeranv on Sunday August 23, 2020 @05:36PM (#24255471)
I admit I can't see anything wrong here. What's the bug?
Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @05:43PM (#24255515)
This should help: what should the following code output?

  class B(object):
    def __init__(self):
      self.y = 2

  class C(A, B):
    pass

  print(C().y)
Re:Never run ‘python’ in your downloads folder by doteka on Sunday August 23, 2020 @05:50PM (#24255566)
The original code snippet had no bugs until you added more code, stop arguing in bad faith.

Also, the new snippet has a syntax error, the last version where this was valid reached end of life January 1st, and has been deprecated for 10 years prior to that. Not sure how much stock to put in your python opinions given that context.

Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @05:54PM (#24255604)
> The original code snippet had no bugs until you added more code, stop arguing in bad faith.

Wow, that's a really low blow. I'm arguing in perfectly good faith. Failing to call the base class initializer introduces misbehavior in multiple inheritance and the way this happens in Python is completely unexpected. Not every language is like this.

> Also, the new snippet has a syntax error, the last version where this was valid reached end of life January 1st, and has been deprecated for 10 years prior to that. Not sure how much stock to put in your python opinions given that context.

Er, what syntax error are you talking about? https://ideone.com/3hI4Wj

Re:Never run ‘python’ in your downloads folder by ZephyrBlu on Sunday August 23, 2020 @07:06PM (#24256045)
> Wow, that's a really low blow. I'm arguing in perfectly good faith. Failing to call the base class initializer introduces misbehavior in multiple inheritance and the way this happens in Python is completely unexpected. Not every language is like this

Isn't this a bug in class C, not your original snippet?

I'm also not sure what you mean by "failing to call the base class initializer introduces misbehavior in multiple inheritance", this seems like an issue related to the MRO of the inherited classes.

If you write class C with class B inherited first, the code runs.

Example: https://repl.it/repls/BumpyPreemptiveQuerylanguage

Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @07:31PM (#24256197)
> Isn't this a bug in class C, not your original snippet?

It's not. The bug is in A.__init__. It needs to call super().__init__(). C would work fine in that case.

Re:Never run ‘python’ in your downloads folder by jbay808 on Sunday August 23, 2020 @08:01PM (#24256361)
I take it that your claim is that every class should always call super().__init__(), or else it's a bug? What makes you think so?
Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @08:20PM (#24256484)
The answer is a qualified "yes". Because not only can it no longer participate in multiple inheritance, but it is very prone to misbehaving silently when used in such a manner, even for experienced Python users.

I say qualified because whether or not the bug warrants fixing is another matter. It's more warranted for public-facing APIs than internal code, since it's less practical for downstream users to modify your code. In your internal code, if your team knows about the issue or just avoids multiple inheritance altogether, or if you have some kind of static analysis to check class hierarchies for you, it might be safe to avoid. (Just listing some considerations that I can think of. There might be more.)

My overall point though was just to illustrate one particular example of a flaw that catches even experienced Python developers off-guard, let alone beginners.

Re:Never run ‘python’ in your downloads folder by pansa2 on Sunday August 23, 2020 @08:48PM (#24256633)
> every class should always call super().__init__()

For this to work, should every class also have an __init__ method that accepts zero arguments?

Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @08:52PM (#24256652)
That's an excellent question and this opens the door to another another interesting discussion. I don't have the energy for that unfortunately, but to reply to your comment: it's not really important that it succeeds per se. Drastically increasing the likelihood of an error is good enough. What's important is that it mitigates the chances of introducing a bug silently.
Re:Never run ‘python’ in your downloads folder by glyph on Monday August 24, 2020 @10:49PM (#24267727)
There’s no error in the original example; in Python, the ability to participate in inheritance diamonds with arbitrary other classes is a feature which must be explicitly documented and maintained. James Knight wrote a really good piece on this many years ago: https://fuhm.net/super-harmful/

The solution is just to avoid inheritance. It’s full of terrible pitfalls in most languages, but Python more than most.

Re:Never run ‘python’ in your downloads folder by ZephyrBlu on Sunday August 23, 2020 @08:23PM (#24256498)
> C would work fine in that case

C also works fine in the case where you understand how multiple inheritance works in Python and structure your classes accordingly though...

I.e. inherit B first instead of A like I showed.

Re:Never run ‘python’ in your downloads folder by WesolyKubeczek on Sunday August 23, 2020 @06:13PM (#24255745)
You're still arguing in bad faith. Your original code snippet didn't mention any kind of inheritance at all.
Re:Never run ‘python’ in your downloads folder by vore on Sunday August 23, 2020 @05:45PM (#24255536)
What's the issue with the original code snippet? This seems to be demonstrating the pitfalls of multiple inheritance which is super clunky in any language.
Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @05:48PM (#24255550)
It's missing a super().__init__() call. This code would've worked fine had that line been there.

You would not encounter this issue in e.g. C++. It's strictly due to Python's idiosyncratic linearization of the inheritance hierarchy, which can make your sibling class (which you have no knowledge of) your superclass. (!!)

Re:Never run ‘python’ in your downloads folder by vore on Sunday August 23, 2020 @06:44PM (#24255918)
The solution in C++ isn't so great either, considering:

  struct Base { Base() { cout << "Base" << endl; } };
  struct Derived1 : Base  { Derived1() { cout << "Derived1" << endl; } };
  struct Derived2 : Base { Derived2() { cout << "Derived2" << endl; } };
  struct Join : Derived1, Derived2 { Join() { cout << "Join" << endl; } };
And then you get two calls to Base:

  Base
  Derived1
  Base
  Derived2
  Join
There's virtual base class inheritance but then that's a different problem that's hardly any more straightforward than Python.
Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @07:59PM (#24256357)
> And then you get two calls to Base:

"2 calls to Base" is a misleading way to put it. You in fact get exactly 1 call per every instance of Base in the hierarchy (and they act independently). Contrast that with Python where you can accidentally call the same constructor multiple times for the same instance of that class, and Python doesn't care to prevent you. (And notice how others' proposed solutions in another comment did exactly that, and they didn't realize it either.)

> There's virtual base class inheritance but then that's a different problem that's hardly any more straightforward than Python.

This is debatable (the Python behavior is quite unintuitive) but "straightforwardness" is actually besides my point. At least with virtual base classes, the solution (whether complicated or not) is in the same place as the problem: both are in the derived class. With Python, the solution is in the base class, which another author wrote a long time ago. Whereas the problem only occurs when you, another poor soul, tries to derive from it a long time later. This kind of spooky action at a distance makes it impractical to abstract things away... in a sense it literally violates causality (for the lack of a better word)! That's not something to take lightly, to say the least.

Re:Never run ‘python’ in your downloads folder by theg5prank on Sunday August 23, 2020 @06:55PM (#24255985)
That's not at all what Python does. It linearizes the inheritance hierarchy for the purposes of superclass attribute lookup, in an attempt to solve some aspects of the diamond problem, or at least make them solvable. But it doesn't touch the types themselves, only the MRO used by the super builtin. That's why the super builtin type takes both the "current" class and the object instance itself, which was more visible before the whining of people who didn't understand it grew too loud to be borne by the maintainers and the project introduced the `super()` syntactic sugar. Not that I'm bitter about that or anything.

Anyway, your argument seems to be that you should be able to use naively written classes in a multiple inheritance hierarchy. I suppose that's a defensible opinion, but it's also not the case in any language I know of; C++ solves the problem of not calling the "correct" superclass by default by foisting the responsibility of choosing the correct subset onto the derived class author, but doesn't solve the "I called my superclass' method too many times" problem, only the "I have too many (n>1) copies of my superclass' data" problem (the solution to which is also opt-in). Python resolves all three of these, but in so doing requires careful construction of multiple inheritance hierarchies and use of the super builtin that is religious to the point of fanatical. That's a tradeoff made in respect to a feature that, IMO, is inherently sharp.

Aside: "idiosyncratic" is an interesting word to use given that the C3 MRO was originally intended for Dylan.

Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @07:48PM (#24256286)
> That's not at all what Python does.

I know what's going on and my comment was sufficiently accurate to get the point across in 1 sentence. I wasn't exactly intending to get into a lecture on MRO here.

> C++ solves the problem of not calling the "correct" superclass by default by foisting the responsibility of choosing the correct subset onto the derived class author

Which is much better than leaving a ticking time bomb.

> doesn't solve the "I called my superclass' method too many times"

Er, yes it does. Every class instance in a hierarchy is initialized exactly once. Trying to call it twice will produce an error (e.g. "class has already been initialized").

> Python resolves all three of these

It does not. It's perfectly fine letting you call a class's __init__ multiple times. Unlike with C++.

> Aside: "idiosyncratic" is an interesting word to use given that the C3 MRO was originally intended for Dylan.

It is a fine word. "Idiosyncrasy" does not imply there exists only 1 person in the whole world engaging in the given practice:

"Her habit of using “like” in every sentence was just one of her idiosyncrasies."

https://www.merriam-webster.com/dictionary/idiosyncrasy

I'm tired of the pointless arguing so this will be my last comment.

Re:Never run ‘python’ in your downloads folder by renewiltord on Sunday August 23, 2020 @06:01PM (#24255656)
What is the usual pattern here? I imagine you have A.__init__(self) and B.__init__(self) in C.__init__(), right?

i.e. child logic is handled in the child, not in the parent.

Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @06:03PM (#24255672)
No I don't (the code is as-is), but in fact if I did, those those would still suffer from basically the same problem even if I did (exercise for the reader). In modern Python you're supposed to use super().__init__() to let it handle this issue with multiple inheritance.
Re:Never run ‘python’ in your downloads folder by renewiltord on Sunday August 23, 2020 @06:06PM (#24255694)
No no, I understand the problem you're talking about. It is a problem. I'm asking about the solution. Why wouldn't you handle it in the child instead of having siblings be superable?

Essentially, why not do it like this:

    class A():
        def __init__(self):
          self.x = 1

    class B():
        def __init__(self):
          self.y = 2

    class C(A, B):
        def __init__(self):
            A.__init__(self)
            B.__init__(self)

    print(C().y)
Re:Never run ‘python’ in your downloads folder by theg5prank on Sunday August 23, 2020 @06:13PM (#24255741)
Now your class C can't necessarily be used in a multiple inheritance hierarchy with some other class D, and a class E that inherits from C and D, as C hardcodes what its parents are. Python uses the C3 MRO algorithm to traverse all relevant classes in your hierarchy when you religiously use the super builtin.

https://www.python.org/download/releases/2.3/mro/

But; multiple inheritance is a beast in any language due to its complexity and bringing it up in a discussion of "magic" that python exposes beginners to is specious. It's true that C++ doesn't have this problem, because it has no super keyword and you must explicitly delegate everything, but also introduces the problem that you can have multiple instances of a base class and so has added complexity, virtual inheritance, to solve THAT problem. And tons of languages have a problem where omitting a call to "super" is logically required is not statically diagnosable.

Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @07:09PM (#24256064)
> It's true that C++ doesn't have this problem, because it has no super keyword and you must explicitly delegate everything

It's emphatically not "having a super keyword" or not having it. That's a red herring. Visual C++ has __super and yet it doesn't suffer from this: it errors with "ambiguous call to overloaded function" when there are multiple candidates.

There's a lot more I could say about this (frankly the issue I outlined just scratch the surface of a deeper problem in Python), but this is diverting the discussion. Nobody even said C++ is simple or somehow easier to learn than Python in the first place; I was just pointing out an insidious issue in Python, and frankly, it could've been done better without any need to emulate C++'s approach at all. (Exercise for the reader: suggest improvements.)

Re:Never run ‘python’ in your downloads folder by theg5prank on Sunday August 23, 2020 @07:16PM (#24256108)
> It's emphatically not "having a super keyword" or not having it. That's a red herring. Visual C++ has __super and yet it doesn't suffer from this: it errors with "ambiguous call to overloaded function" when there are multiple candidates

What's your point about this nonstandard extension? My point is that C++ doesn't have the problem of classes not written to be part of a multiple inheritance hierarchy delegating somewhere unexpected because, by design, it doesn't attempt to solve the same problems that Python is. If anything that this nonstandard extension doesn't work in multiple inheritance is agreeing with the points I'm making.

> There's a lot more I could say about this (frankly the issue I outlined just scratch the surface of a deeper problem in Python), but this is diverting the discussion. Nobody even said C++ is simple or somehow easier to learn than Python in the first place; I was just pointing out an insidious issue in Python,

You were the one who brought up C++! (EDIT: this was in a cousin comment.) My point is that different languages navigate this thorny landscape in different ways, but the way in which Python does isn't as haphazard as you are suggesting.

> Exercise for the reader: suggest improvements

Perhaps being part of a multiple inheritance hierarchy is sharp and uncommon enough that it should be opt-in. What are yours?

Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @07:26PM (#24256173)
> What's your point about this nonstandard extension?

My point was what I said: you can have your cake and eat it too. You claimed the issue was due to a lack of a super keyword and I showed you it would not occur even if C++ had super.

> You were the one who brought up C++!

I "brought it up" to illustrate it does one particular thing better than Python. Not to claim it does everything better than Python. If you want a simple, beginner-friendly language, avoid C++ like the plague.

> What are yours?

Idk, for starters maybe produce a warning when multiple inheritance occurs and one of the __init__s in the hierarchy doesn't have an obvious call super().__init__.

Re:Never run ‘python’ in your downloads folder by theg5prank on Sunday August 23, 2020 @07:42PM (#24256256)
> My point was what I said: you can have your cake and eat it too. You claimed the issue was due to a lack of a super keyword and I showed you it would not occur even if C++ had super.

I made no such claim. I said (in my opinion) C++ doesn't have the issue you're raising with Python because it has a completely different design that doesn't attempt to solve diamond problems in superclass attribute lookup. Are we not in agreement?

> I "brought it up" to illustrate it does one particular thing better than Python. Not to claim it does everything better than Python. If you want a simple, beginner-friendly language, avoid C++ like the plague.

You can validly think that C++'s choice here is better. I don't think there's a counterargument to personal preference here. My point was that it does not solve all of the problems Python's super builtin is designed to. And that's fine! It avoids the issue in question! I actually don't understand what you are arguing with here. Personally I think the design goals here are just so wildly different that I don't have a preference, but I admit that's kind of a cop-out.

> Idk, for starters maybe produce a warning when multiple inheritance occurs and one of the __init__s in the hierarchy doesn't call super().__init__.

In general I think having more "warning labels" on multiple inheritance is the right idea, if a language is going to persist in offering it at all. I think this would be a good start, especially for a linter.

Re:Never run ‘python’ in your downloads folder by renewiltord on Sunday August 23, 2020 @06:21PM (#24255796)
Ohhh, that makes sense, because any later child will need to know that A and B are C's parents! Okay, thanks!
Re:Never run ‘python’ in your downloads folder by theg5prank on Sunday August 23, 2020 @06:41PM (#24255906)
That, and: I forgot to mention that not using the super builtin can also lead to unintentionally calling a method twice or more for the same base class in a diamond situation (note that with new-style classes, all multiple inheritance has at least one "diamond" class, often object, but people normally do not delegate to object for obvious reasons; you can imagine a base class Z in this example that A and B inherit from instead, if you wish). So, not using the super builtin can result in both delegating to a superclass' implementation too much, and not at all! This is a problem with multiple inheritance that Python actually solves; virtual inheritance doesn't touch it.

Note that `object` being the root of the class hierarchy implies that you must have careful coordination between all classes in a multiple inheritance hierarchy to determine, for a particular method, when subclasses may/must delegate to super, what the arguments to the method are, and even what the argument names are in some cases! You can't just go glomming classes together and expect it to go well unless you know the classes either don't use the same method names or agree very carefully on what the delgatable interfaces are.

Re:Never run ‘python’ in your downloads folder by renewiltord on Sunday August 23, 2020 @06:43PM (#24255914)
Oh, ah yes, that's good. With the A.__init(self) approach you'd overcall in a diamond-pattern. Okay, I'm convinced.
Re:Never run ‘python’ in your downloads folder by stOneskull on Sunday August 23, 2020 @10:56PM (#24257187)
i think in modern python, you leave out the (object) and just write class A:
Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @10:58PM (#24257201)
You can, but Python 2 is still the default on some systems so I thought I'd just put it and make people's lives easier.
Re:Never run ‘python’ in your downloads folder by wisty on Sunday August 23, 2020 @07:19PM (#24256127)
Multiple inheritance was a mistake.
Re:Never run ‘python’ in your downloads folder by 8note on Sunday August 23, 2020 @08:23PM (#24256494)
when does a beginner run into this though?
Re:Never run ‘python’ in your downloads folder by mehrdadn on Sunday August 23, 2020 @08:49PM (#24256638)
I'm not suggesting it's common; it really depends what the beginner is doing. If you're just learning Python because you're trying to use e.g. a web framework like Django (that uses mixin classes all over the place), then chances are you'll put __init__ somewhere and run into this. If you're doing something else, you might never see this in your life. My comment was just responding directly to the parent comment though (pointing out a Python flaw), not trying to suggest every Python developer will run into this.
Re:Never run ‘python’ in your downloads folder by travisoneill1 on Sunday August 23, 2020 @05:40PM (#24255496)
Woks in the REPL
Re:Never run ‘python’ in your downloads folder by brian_cloutier on Sunday August 23, 2020 @06:12PM (#24255730)
What makes this so pernicious is that it does work, until you later try to make subclasses
Re:Never run ‘python’ in your downloads folder by piva00 on Sunday August 23, 2020 @04:19PM (#24254969)
Have you ever worked or seen Ruby? Python is quite straightforward, not like Go but I wouldn't say it's too much magic happening...
Re:Never run ‘python’ in your downloads folder by alexbanks on Sunday August 23, 2020 @07:21PM (#24256141)
God, when I was in the Ruby world it felt like other engineers would always say things like "Just type < insert magic line of text > and it'll just do this for you". I hated it. I hated it so much.
Re:Never run ‘python’ in your downloads folder by zitterbewegung on Sunday August 23, 2020 @11:41AM (#24252644)
I have heard the opposite from my friends who interacted with people saying that the language is intimidating because its "a real programming language".

But, to be fair deployment and package management of python is a mess when you try to scale up.

Re:Never run ‘python’ in your downloads folder by dnautics on Sunday August 23, 2020 @11:51AM (#24252712)
That's also true of its "explicit is better than implicit" rule.
Re:Never run ‘python’ in your downloads folder by pansa2 on Sunday August 23, 2020 @08:32PM (#24256550)
> subtle visual cues

Such as? The only thing that comes to mind is significant whitespace - but some other languages are much more sensitive to whitespace than Python.

Re:Never run ‘python’ in your downloads folder by booleandilemma on Sunday August 23, 2020 @06:26PM (#24255820)
I’m pretty sure the only reason Python is popular at all is because Google pushed it so hard.
Re:Never run ‘python’ in your downloads folder by DangitBobby on Sunday August 23, 2020 @09:57PM (#24256922)
...what? I had no idea they were involved at all.