18 ms·
In CPython, types implemented in C are part of the type tree
- CurtHagenlocher 6y agoIf I remember correctly, this was not originally true but type unification happened early in the life of 2.x.
- loeg 6y agoI don't know if it's related to C classes at all, but an interesting semi-related tidbit: 2.x has a weird distinction between "classic" classes and "new-style" classes that inherit from object. In 3.x, everything descends from object.
- dapids 6y agoC has classes?
- chc 6y agoPython has classes defined in C.
- Spivak 6y agoAnd “classes in C” is really just a matter of agreeing on a convention. GObject and COM are object systems that have C implementations. I suppose it’s a mental thing when you’re “below” the abstract object system instead of getting to treat them as tangible things unto themselves. Like how C doesn’t really have strings — they’re pointers or structs and so you don’t get any sort of encapsulation that’s not enforced by convention. You have to maintain the invariants or only use methods that maintain them.
- dapids 6y agoWow, it was a legitimate query, I wasn't sure what OP was referring to. Thanks for the downvotes.
- monkeybutton 6y agoObject, the root of all evil.
- westurner 6y agoThe docs should have coverage on this: Python/C API Reference Manual: https://docs.python.org/3/c-api/index.html https://docs.python.org/3/c-api/index.html Python/C API Reference Manual » Object Implementation Support > Type Objects: https://docs.python.org/3/c-api/typeobj.html https://docs.python.org/3/c-api/typeobj.html CPython Devguide > Exploring Python Internals > Additional References: https://devguide.python.org/exploring/ https://devguide.python.org/exploring/
- wizzwizz4 6y agoSome of the info is out of date; it's Python 2 only.
- quietbritishjim 6y agoCould you be specific? The article's targeted at Python 3 and I don't see anything that's really obviously Python 2 only. Did you mean the link in the sidebar maybe? That was written back in 2011 and I don't know whether it's still true or not, but it only talks about "new style" (at the time) classes so it still could be.
- wizzwizz4 6y agoThe paragraph containing it; the described repr behaviour is Python 2 behaviour.
- legerdemain 6y agoUgh... The type hierarchy of Python is painfully intertwined with the implementation of its type system. That implementation varies by Python implementation, and since the Python language is as old as Visual Basic, Borland Pascal, Werther's caramels, and trilobites, it varies dramatically over time. Add to that the fact that Python has a philosophy of wearing leaky abstractions proudly on its sleeve and barfing implementation-level details at its users. Python really is one of the most complex, arbitrary, and poorly abstracted languages in popular use. I have no idea how anyone lives with it for anything except writing extremely repetitive, formulaic, and superficial code, because having to dig into its guts feels like a nightmare. Even Java's type system, as antiquated and simplistic as it is, is easier to understand and work with by comparison.
- orf 6y agoProviding some specific details would make your argument a lot more convincing.
- legerdemain 6y agoSure! In Python 2.x, "class" was an instance of "type." In Python 3.x, "type" is an instance of "class." (This is, of course, an over-simplification of a much more complicated reality.)
- chrismorgan 6y agoCould you expand on that? I’m not sure what exactly you’re saying, because you’re not using standard or unambiguous terminology. (`type` is a thing, but “class” isn’t a thing, but rather a category of things, a syntactic construct.) Python 2: >>> class OldStyleClass: pass >>> isinstance(OldStyleClass, type) False >>> class NewStyleClass(object): pass >>> isinstance(NewStyleClass, type) True Python 3: >>> class Class: pass >>> isinstance(Class, type) True Old-style classes were kind of their own thing in their own space, but with new-style classes, classes are to `type` as instances are to `object`, and I don’t recall there being any major 2/3 difference beyond the simple removal of old-style classes.
- mistrial9 6y agoI like python, python3 might be ok but I dont care
- nijave 6y agoIt seems like a lot of criticism of Python is directed at the data science community but I'm curious what the alternative is here? Is it surprising people trained in math are writing hard to maintain programs? Is biology+Perl any better (I'd argue worse). What languages exist that are hard to write bad code in? I've worked at places that rewrite abominations of Java every 5 years because they are such coupled, unmaintainable messes. JPMC has Athena and Pinterest seem firmly committed to Python. I know some people that worked at Braintree (now part of PayPal) that heavily used Python Home Assistant and Ansible are two massive OSS projects
- neolog 6y ago> What languages exist that are hard to write bad code in? Plenty of languages exist that are hard to write any code in, good or bad.
- carlmr 6y agoI often think that stopping people from writing code might be the best way to avoid bad code. Stricter languages like Rust, ADA, or even F# (quite strongly typed), will not let you compile until you reach a certain level of explicitness/correctness. Thereby teaching you some basic things until you can compile. Languages like Perl and Python allow you to do a lot of things, which ends up unmaintainable because it's too easy. The easy version just breaks during runtime then.
- cercatrova 6y agoJulia is apparently gaining steam in scientific computing.
- neilparikh 6y ago> What languages exist that are hard to write bad code in? A language with a good type system (ex. Haskell, OCaml, Rust etc.) makes it hard to write bad code, because it eliminates a large class of potentially "bad" programs, and thus provides guarantees about the code that does type check. If I have an arbitrary Haskell program, it might still be messy and hard to read, but I know I'll have certain guarantees about the code. For example, if a function isn't in IO, it won't have any effects, and a replacing it with a function that returns the same values for the same arguments will be safe. Additionally, the language makes it easy for libraries to have well designed APIs, that ensure that the user doesn't forget to make the required checks. For example, removing null, and forcing Option/Maybe for functions that might fail forces the the caller to handle the failure case, instead of just forgetting to check for null, which is common.