7 ms·
First, I disagree with your premise that PHP's flaws can be attributed primarily to lack of OO design. But regardless: For all its (many) flaws, PHP was (and
by Goladus 13y ago
First, I disagree with your premise that PHP's flaws can be attributed primarily to lack of OO design. But regardless:
For all its (many) flaws, PHP was (and is) an extraordinarily successful project relative to the vast majority of programming projects attempted. This is in fact a confirmation of the original post's thesis. The theory is that teaching OOP to beginners bogs them down worrying about the architecture of their code before they've had any experience solving problems at the scale where the architecture matters. It's easy for a beginning programmer to waste hours on pointless refactoring that doesn't actually improve their program in any meaningful way, simply in order to appeal to some professor, teacher, or other religious figure's concept of "good code". PHP, on the other hand, said "screw you religous types, we're just going to design a product people will use."
The reason that OOP should not be taught to beginners is not because it's a difficult concept. The reason OOP should not be taught to beginners is that it is an advanced concept. There are many other important fundamentals that can come first.
- TazeTSchnitzel 13y ago>First, I disagree with your premise that PHP's flaws can be attributed primarily to lack of OO design. That's not my premise. I just point to PHP (and its community) as it has some examples of it. >The reason OOP should not be taught to beginners is that it is an advanced concept. I've never quite got this. Spend any time writing code that's not using classes and you end up reinventing OOP anyway.
- jiggy2011 13y agoIt's true that if you make programming more difficult to learn then you will self-select only programmers who are especially dedicated or intelligent. I've never quite got this. Spend any time writing code that's not using classes and you end up reinventing OOP anyway. I think that letting beginners rediscover this for themselves and then exposing language constructs that make this easier probably allows a smoother path to enlightenment. It's often not obvious to beginners why copy-pasting code a bunch of times is bad compared to using loops and functions for example. It certainly wasn't for me, until I tried to build a program that was not highly trivial.
- TazeTSchnitzel 13y agoBut OOP doesn't make programming more difficult. It just makes structuring your code easier.
- betterunix 13y agoHM... class Hello { public static void main(String args[]) { System.out.println("Hello, world!"); } } Versus: (print "Hello, world!") Yes, this is a deliberately extreme example, but the point is that object-oriented code does not make it easier to structure CS101-level programs. All it does is introduce a bunch of keywords that students have trouble understanding until they are sitting in a much higher-level course.
- TazeTSchnitzel 13y agoI think it can help once you've dealt with dictionaries and functions. Classes are handy for storing a bunch of variables and functions together, and that's how I'd teach it.
- Goladus 13y agoThe problem there is you have to know which variables and functions belong together. You have to commit to coupling them early on, meaning you have to make a design decision that a beginning programmer might not be prepared to make. This means they may struggle figuring out the best way to organize their code when solving problems when such organizational concerns are really not that important. Here's a sample programming problem a beginner might encounter: CIDR data is available as a "127.0.0.1/8" style string and you need to access the IP and Netmask separately. In python, the simplest, most straightforward path to a solution that still results in encapsulated, re-usable code is to write a standalone function that accepts a string and returns a tuple. You could also create a CIDR class with a "to_tuple" method, or that stores the values in 'ip' and 'netmask' attributes, but this is simply extra scaffolding and without knowing more about the larger context of the program it's impossible to know whether such a design will be beneficial. The problem with beginners is that they'll see the straightforward solution, but because they're not just trying to solve a problem but also demonstrate "Object Oriented Programming" skills to their teacher, they're going to worry about doing a whole bunch of extra work that may not be appropriate. I believe this is wasted energy that could be spent gaining real experience solving problems and learning about how computers and software work.
- Goladus 13y agoI've never quite got this. Spend any time writing code that's not using classes and you end up reinventing OOP anyway. "Spend any time" implies substantially more experience than what most beginners possess, hence the term "advanced." "Intermediate" might be a better term in an absolute sense. OO design is something to learn after you understand the basic tools and techniques. Also, a lot can be accomplished without OOP (for most values of OOP) and even if you're writing de facto OO code, it's not always clear whether using explicit OO language features is a net win or not.
- TazeTSchnitzel 13y agoWell, I think it's better to teach OOP early on to avoid people ending up reinventing it.
- Goladus 13y agoObviously. I strongly disagree. There are many more important things to learn first. OOP can be introduces little by little as it gradually becomes relevant.
- TazeTSchnitzel 13y agoWell, I'd introduce classes after dictionaries and functions, because that's all they are, really.
- kazagistar 13y ago> I've never quite got this. Spend any time writing code that's not using classes and you end up reinventing OOP anyway. Only if you start with C. I find that if provided with reasonable alternatives (like function composition) or consistently restricted problem domains (vector manipulations) you very well might never create anything resembling objects.