Discuss OOP(Don't get why?) in the Python Programming forum on Dev Shed. OOP(Don't get why?) Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Time spent in forums: 4 Days 12 h 36 m 28 sec
Reputation Power: 24
OOP is a very popular and will be popular for a very long time from now, forum of programing. Almost every modern programing language is oo, if any new commers want to be even thought about they most be capible of oo.
The reasons oo is great is because it simplifies things and treats everything in a diff manner than normal programing does. With oo you can reuse code very easly. When i say reuse i mean within the same program and with other projects/programs. I know you probably know all about functions and such well Imagin that you can group a bunch of functions together that relie on eachother and work with eachother. Well for that to work you have to call the other sending all the premiters, and such. Then the other function has to know witch premiters are being sent and it can turn into a mess.
with OO it isn't like that. You set up a logical grouping of functions and veribles. Then you make the hole class in its hole. Then its done. no going back and switching things around. Then you go on to the next class make the hole thing then its done. Set up one single way for one class to talk to the other and its all work. No going back and testing this if statment to see if it will not cancel out the others. For premitors within the class you can just need self. witch will have all the curren't state of the veribles that are shared between everything. So you could have 3 things of the same class running all diff.
You could i suppose to everything with conventional ways of programing that you can do with oo, but that would be absolutly stupid. You can also make the same program in convetional maners that you could in OO but the OO would be supior because lets say you want to add more to the conventional app, you will spend at least 4 times as much time trying to make it work, possible rewriting half the application again. While with OO you just had to edit a few lines and add a few new methods, and your done.
Trust me, i use to be like you. I didn't understand why OO was so important, i actually thought it was dumb. It only took me to learn Java, a lang that forces you to use OO, for me to actually learn the importance of it. Once you use OO you will never want to code in any other manner.
Time spent in forums: 21 h 40 m 18 sec
Reputation Power: 9
Mostly agree, but:
Once you use OO you will never want to code in any other manner.
OO isn't the be all and end all of programming styles - there's also logic programming (Prolog), functional programming (Haskell, ML, etc), aspect oriented programming (AspectJ)... and sometimes plain procedural programming is all that's required, particularly for short scripts.
Just as procedural programming allows code to be simplified through factoring out commonalities of code, OO allows code to be simplified through factoring out commonalities of interface and organised through the collection of behaviours for notional "things" eg:
def calculate_rectangle_area(length, width):
rectangles = [(5,15),
for rect in rectangles:
Fairly simple... and certainly a lot shorter than the OO version:
def __init__(self, side):
self.side = side
def __init__(self, length, width):
self.length = length
self.width = width
def __init__(self, radius):
self.radius = radius
rectangles = [Rectangle(5,15),
for rect in rectangles:
Ok ... so it looks like all OO gives you is a lot of extra typing, right?
But what if you want to have a list of different shapes - you then have to associate a type with data - the procedural version would be:
shapes = [Circle(7),
for shape in shapes:
... and what if you wanted to add in colours and patterns to your shape ... and a function to calculate the perimeter... and more shapes. And what if you wanted to then add a coordinate system... and overlap shapes to create new shapes. Suddenly using functions no longer seems so simple.
OO allows you to simplify bookkeeping as your code grows by making you do a little more up-front work.
Last edited by hydroxide : April 17th, 2005 at 03:44 AM.
Reason: Fix bug in Circle.calculate_area() [*blush*]
Time spent in forums: 2 Weeks 4 Days 2 h 58 m 23 sec
Reputation Power: 1372
Originally Posted by monkeyman23555
Okay I get the point now
But whats with deleting a line in a txt file...
the simplest way to delete a line in a file is to copy the file line by line to another file except the line you want to delete. When you are done, delete the old file and rename the new file to it. Depending on how you identify the line you want to delete, you could do it with unix tools such as grep or sed. If you are on a Windows machine then download cygwin and use a unix tool such as grep or sed.
This may take a while if the file is a billion lines long.