3 ms·
The "worthless example to explain features" in my pet peeve... This is something like "we're going to have a class named Vehicle" and "class Car inherits Vehic
by zdw 15y ago
The "worthless example to explain features" in my pet peeve...
This is something like "we're going to have a class named Vehicle" and "class Car inherits Vehicle" in an OO language.
You would almost never use something like this in a real program, and it takes what's a minor and problem fraught feature (inheritance) and quickly has new programmers creating bizzaro hierarchies that never should be.
- turkeygizzard 15y agoForgive me, but I'm really new to programming, and I don't really understand why your example is something that shouldn't be used in real programming. Should a Car be a Vehicle object instead of a sub-class?
- driax 15y agoThe problem lies in that you never have a "Car" which should inherit "Vehicle". It's a question that never comes up in programming. The bad part of it, is that it sometimes makes new programmers look for these kind of concepts in their code, and write class-based code around them. Exactly the problem http://pyvideo.org/video/880/stop-writing-classes http://pyvideo.org/video/880/stop-writing-classes discusses. Basicly it teaches people to think in taxonomies, which is not good for object-oriented programming since it usually results in highly complicated code, with way to many classes and inheritance. Inheritance is mostly good for factoring out common code between different sub-classes. Or extending library classes in a way that wasn't thought of when they were written.
- zdw 15y agoDitto on this. It's an abuse of the concept of inheritance, which teaches the wrong reasons to use the concept.
- deleted 15y ago[deleted]
- nikcub 15y agoI don't think I have ever read a programming book that teaches OO in the same way that most developers use it - that is implement top level first and then when you have commonalities between objects abstract them out into parent objects. Thinking about and mapping out class hierarchies is something that Java enterprise analysts do. A good example to teach OO would be a config parser. Write a config parsing object, then sub-class for parsing Yaml, INI, XML, etc.
- johnkchow 15y agoOne of the very first things I learned almost immediately after college is that inheritance typically is a bad idea and that composition is a better strategy. With inheritance you have so much thinking overhead with parent to children relationships when most abstractions could easily be viewed as building it through small pieces. Its sad but during my 5 years in UCLA I have not heard the word "composition" once.
- zdw 15y agoThe point is that OO isn't everything, and making the first thing people learn being class hierarchies colors their perceptions of programming in ways that sometimes are very damaging. For example, about 15 years ago I was an idiot and managed to get a job writing some text parsing code. I, of course, used what I just learned in my Comp Sci 101 "Intro to Programming" class and did a fully OO implementation in C++ with iostreams that took nearly a month to write, and never quite worked. Looking back, the solution was probably implementable in under 10 lines of a scripting language with judicious use of regex. The point is that people often fall for the first thing they're given, and OO (which incredibly useful when used properly) is an extremely enticing concept that can be very distracting from actually getting a job done.
- goostavos 15y agoAs a semi-new programmer myself, I can't agree enough. OOP concepts like classes in Python were initially very foreign to me. The book I learned from gave no real world examples -- "Image the super class is a bird. Now we can subclass a canary! Clearly you can see how powerful classes are in Python!". I skipped the rest of the chapter because it seemed like something I would never need. I would also like to gripe a bit about boring examples. One of the books I chose while starting out was Beginning Python.. My lord, what a travesty! "Think of a dictionary as a fridge." and "Now for this exercise, we're going to make an omelet!" my eyes would glaze over from boredom. It made it really fucking tough to be excited about the learning process when the assignment is making a digital egg. I disagree on his book length point, as well. If done correctly (which I have found to be all to rare unfortunately) having a giant book filled with thorough explanations is a great value, in my opinion. By far, the best programming book I have ever read is Programming in C. It's pretty damn massive. Somewhere in the area of 600 pages at least. But I loved every bit of it! All of the end of chapter exercises were like little puzzles that needed to be solved using the newly acquired techniques. They were actually fun to do! and gave a great feeling of accomplishment once I finally figured out how to do them. Way better than making some crappy pretend omelet! One final gripe for you future book writers. I would love to see mid chapter exercises rather than one big end-of-chapter dump. Each new concept should be given time to be internalized -- or at least familiarized -- before moving onto the next thing.