6 ms·
In Python, OOP boils down to a style choice, which is exactly as it should be, IMO, and is very helpful to beginners. In Java, you're forced to use OOP for eve
by pixelmonkey 13y ago
In Python, OOP boils down to a style choice, which is exactly as it should be, IMO, and is very helpful to beginners.
In Java, you're forced to use OOP for every problem. No beginner understands why to define "hello, world", you also need a class, and a 'static' method on that class, and to invoke a weird-looking special class called "System".
It isn't obvious why there are "String[]" types and "ArrayList" types, and why I should care about the difference. Why does "main()" take "String[]" yet I am encouraged to use "ArrayList" in my code? This is just a sampling of difficult-to-answer questions that a beginner encounters in using Java that don't have a grounding in computer science, but just in Java.
It just so happens that among design choices, the choice to implement your Python code using OOP is a trade-off. It always is, but Python makes the trade-off clear as day.
The win is increased ability to implement interfaces, language protocols, inheritance, polymorphism, the ability to bundle state and behavior, and the ability to bundle related behavior together. The loss is reduced readability and reduced beauty. Since these latter things are counter to The Zen of Python (PEP 20), idiomatic Python programmers will tend to torture themselves over OOP usage, to the point where only data structures that truly demand OOP's features come into existence.
This means that beginners will more often see a useful_function than a UsefulClass in Python's stdlib and associated ecosystem, and this is A Good Thing, since functions are much more composable than classes are (not to mention simpler).
I think Python will therefore also teach beginners vigilance in the use of classes, which the entire software community could use a little more of!
- bad_user 13y agoYou're saying that in Java you're forced to use OOP for every problem and then you exemplify with "hello world". Well ... 1. function definitions being constrained to classes has nothing to do with OOP 2. static functions or members have absolutely nothing to do with OOP I see a lot of criticism of OOP, but when I get to reading the details, it's all about Java's flavor of OOP.
- possibilistic 13y agoI think you missed OP's point. Beginner programmers introduced to Java are forced to grapple with OO from the outset. What is a class or static method? These are OO constructs and require additional mental overhead when learning.
- ericHosick 13y agoThey also struggle with functions, parameters, pointers, scope and so on. You don't need to pass parameters to your car to start it. You don't need to force yourself to only focus on the recipe (scope) when making dinner. None of these things map very well with the real world and could also be considered additional mental overhead when learning. You don't need to know how to code to learn best known practices in building software.
- kazagistar 13y agoFunctions, parameters, and pointers are also optional concepts in python. None of them are needed in a hello world program, nor for a few weeks into an introductory course. Variables, expressions, conditionals, lists, strings, and loops can all exist on their own without any "extra stuff". Learn things one at a time; "best practices" can wait til you can demonstrate why it is a best practice. Why should I make a function? Until you actually face the problems that abstractions are used to solve, learning them is confusing and difficult.
- nightski 13y agoOptimizing for hello world is probably the least important thing when you have a 10+ year journey of learning ahead of you. In the end, what do you learn from python's hello world anyways? This also happens in math quite a bit. There is a knowledge gap when teaching concepts like derivatives for the first time. So we are told to initially ignore details while learning.
- groovy2shoes 13y agoThat's probably why I didn't understand derivatives until Calc 3. I barely passed Calc 1 and 2 because my professors just told us to ignore the details. My Calc 3 professor actually showed us how everything worked, from intuition to theorem to proof. In my experience, it's best not to delay learning the details. You don't have a real understanding of something until you understand the details.
- Goladus 13y agofunction definitions being constrained to classes has nothing to do with OOP It doesn't?
- jfarmer 13y agoYes. Although I disagree that what the GP rebuts what he was intended to rebut, I agree with his particular point, viz., hat the idea of OOP doesn't necessarily entail the idea of classes, although most OOP languages implement many principles of OOP through the class/instance mechanism. JavaScript, for example, is an OOP language without classes per se. Indeed, many JavaScript programmers avoid what little built-in class-like behavior JavaScript has and implement their own class definition/inheritance/instantiation mechanisms via things like Object.extend. And although it's rare, one can define "singleton" methods directly on objects in Ruby, too: animal = "Dog" # This is now defined only on the animal object # and no other String instance def animal.bark! "Woof woof!" end animal # => "Dog" animal.class # => "String" animal.bark! # => "Woof woof!" So, JavaScript is an example of an OOP language without classes at all (or at least one where you often pretend they don't exist) and Ruby is an example of an OOP language which has classes but where function definitions are not constrained to classes. This is the point I understood the GP to be making.
- deleted 13y ago[deleted]
- justinpombrio 13y agoI suspect your parent would agree with (1) and (2). Those criticisms were aimed at Java, not at OOP.
- nilkn 13y ago> I see a lot of criticism of OOP, but when I get to reading the details, it's all about Java's flavor of OOP. The OP actually did a very clear job of distinguishing between Python- and Java-style OOP. I think you're the one cherry-picking his Java example and then extrapolating that to refer to all of OOP.
- jafaku 13y agoIn python you don't even have abstract classes, and instead you have to use horrible hacks.
- RodericDay 13y agohttp://docs.python.org/2/library/abc.html http://docs.python.org/2/library/abc.html ? Even if that had flaws, PyQt carries over all the Qt abstract classes just fine.
- jafaku 13y agoI'm aware of that but that's what people call a hack, don't act like it's not. Python doesn't support abstract classes, period.
- likeclockwork 13y agoUm.. that's in the standard library. What definitions are you using for "support" and "period"?
- possibilistic 13y agoIf you're tying to develop interfaces in Python, I would argue you're using the language from the wrong standpoint. Every language has a design goal. Python doesn't care about interface contracts. The "one correct way" is the contract.
- jafaku 13y agoWith these languages it always seems like first came the language, and then its users tried really hard to make sense of it. So now apparently enforcing contracts is not important anymore. "Let's just code!" - sigh
- possibilistic 13y agoIf you want to enforce contracts, pick a language that encourages it. There are many to choose from. Plenty of people are doing just fine in Python without this. It's almost an entirely distinct problem domain. Besides, what would a contract be in a dynamically typed language? I don't think these features are bad, but they're not appropriate everywhere.