3 ms·
I feel like this is a real newbie question but since I've never seen it answered I'm gonna dare ask it: Isn't Python widely considered a good programming langu
by wodenokoto 11y ago
I feel like this is a real newbie question but since I've never seen it answered I'm gonna dare ask it:
Isn't Python widely considered a good programming language, and isn't everything in Python an object?
How does this fit with OOP being bad?
- andybak 11y agoPython allows functions not tied to objects and therefore isn't 'strict' OO in the sense that Java is.
- nradov 11y agoJava allows static functions that aren't tied to objects. They are defined in classes, but the classes just serve as namespaces to prevent naming collisions. Those static methods aren't OO in any meaningful sense.
- lmm 11y agoEverything is an object in Python, but not in an intrusive way. * You can write a script that's "just" a script, it doesn't have to be an object with a main method or anything like that * You can have free-floating functions and values at top level * Modules are first-class and not really objects in the classical OO sense * Python culture favours using tuples or maps as records, and free-floating functions, over using objects for everything
- noelwelsh 11y agoLet me take a crack at this. There have been three main movements or philosophies in programming. The first was the "structured programming" movement starting in the late 50s, discussed in the article. This was at the time when high-level languages (for a weak definition of high-level) were first becoming usable, and most people were used to using assembler. Structured programming gave some structure (hence the name) to the control flow methods used at the time. This is where for and while loops come from. "GOTO Considered Harmful" is one of the main texts from this period, and I think we can say by the 70s structured programming had won over the mindshare of most developers. The second is object-oriented programming, which started in the late 60s, and achieved mindshare in the mid-80s to early 90s. The most influential OO language is Smalltalk (1983). The third is functional programming, which either started in the 50s or the 70s (depending on where you draw the line) and is in the process of winning mindshare from OO right now. It's important to note that the modern incarnation of functional programming (by which I mean static types + abstractions like monads and applicatives) is very new, in programming language terms. The main standard for Haskell is 1998, Scala was created in 2005, and key techniques such as free monads are the subject of ongoing research. It has only been viable to do production quality statically typed FP for about a decade. Python was created in the early 90s, and looks back to Smalltalk for inspiration. Culturally Python is (obviously) in the OO camp. Culturally, most developers are in the OO camp as well. Thus their definition of "good" is OO, and Python fits this. The linked post is a sign of the change that is happening right now---more developers are discovering FP and their definition of good is switching from OO to FP. From the perspective of an FP proponent, Python is not a good language. The key point I'm trying to make is that programming is a cultural movement. We like to pretend we're objective and scientific, but we aren't. That's ok. Neither is science (see, e.g., "The Structure of Scientific Revolutions"). I do believe, however, that we're improving over time (said as a true FP adherent, of course :-)
- wodenokoto 11y agoThank you for the very thorough explanation. I was under the impression that lisp was the mother of all functional languages, so I was surprised not to see it in your comment.
- nv-vn 11y agoInterestingly, Lisp tends to be more closely related to modern imperative or OOP languages than modern FP languages most of the time (although this is very much a matter of dialect, as Clojure and Scheme code tend to resemble FP much more than CL and Elisp code do). Lisp had some ideas influential to FP that also made their way into other types of programming (garbage collection, closures, etc.), but things which are considered a modern necessity for functional programming are not present in most dialects of Lisp (like immutability of data, at least by default, currying, etc.). In fact, most Lisp dialects don't even have first-class functions (in the sense that variables and functions are stored in totally different namespaces), which even languages like C# support. So to call Lisp 'functional' is a bit of a stretch, despite the large divides between different dialects and the multi-paradigm abilities of those languages, but that's not to say that it wasn't hugely instrumental in the onset of functional programming.
- js8 11y agoI think another way to look at it is that Lisp took untyped lambda calculus and turned it into practical programming language, although in an opinionated way that was necessary at the time for performance reasons. However, modern FP languages always start from some form of typed lambda calculus, because it has more desirable properties.
- noelwelsh 11y agonv-vn has given a good explanation. When I said "[FP] started in the 50s or the 70s (depending on where you draw the line)" I was implicitly referring to Lisp (1958) and to Scheme and ML (1970s). Although Scheme does not have a static type system it is culturally a functional programming language and has had a large influence on the field.
- lucian1900 11y agoPython still suffers from unrestricted mutation, which isn't helped by the lack of a type system. And I say this as someone who primarily uses Python. If anything, Smalltalk is the closest to "everything is an object". It doesn't even have an "if" statement, it's just a method call. Even there, the problem of mutation is present.
- exDM69 11y agoI've written a fair bit of Python code, but I can't recall the time I last wrote a "class" in Python, and when I did, it was just a simple struct-type object with no inheritance or anything like that. Most of the time my "objects" are just tuples, lists and dictionaries, with free functions to manipulate them. In general, I dislike attaching complex semantics to types because that makes code more difficult to read. When you look at a function call and can't tell where it's leading by just looking at the code, there's an instant loss in productivity. At worst, you have to open the debugger and step through the code. This is particularly annoying when the problem domain requires no such abstractions, but they're in place just to shave a few lines of code.