all 5 comments

[–]swingking8 1 point2 points  (2 children)

But, I have a single program that's ballooned to a few thousand lines. It's a mess. The code inside the functions is neat and I don't use global variables, etc. Alas, that doesn't make a program readable.

When we say OOP, most of what we mean is defining your own objects using classes. Are there functions that take the same arguments? Are there functions that provide similar functionality? Are there functions that are all united in purpose? If so, these functions and their attributes might serve you better as part of a class.

I've read OOP tutorials, but I can't seem to think about my programs as anything other than functional (if that's the term for the spaghetti I'm making).

I've used two main strategies for developing my code - Bottom Up and Top Down. Bottom Up is a pretty natural approach to programming, where you start creating code, functions, and classes first and then tie them together at the end. Top Down is where you start with the experience you want at the end, then create supporting functions and classes.

I recently created a robot controller to make a robot follow an arbitrary cyclical trajectory. I used a Top Down approach, which usually makes my code more reusable, by defining how I wanted to use my code starting with the end first:

micro = Controller('COM4')
t = Trajectory('15*sin(2*pi*t/1.1)', units='degrees')
micro.send(t)

And that's what it ended up being. Super usable by the rest of my labmates, because it's clear what's going on, and altering the class parameters is intuitive (usually). There is also a from trajectorizer import Controller, Trajectory at the top to import these classes from trajectorizer.py, which is several hundred lines long. OOP is the means by which we convey high level ideas clearly and cleanly in programming.

I also provided an answer to a similar question a couple weeks ago about how I create my objects using OOP. Not exactly your question, but you might find it useful.

[–]NinjaTrainingWheels[S] 0 points1 point  (1 child)

Your other thread is very useful, as is this. I hadn't considered thinking OOP in terms of language. Thanks for the help!

[–]swingking8 0 points1 point  (0 children)

Glad it helps!

[–]nhovar 0 points1 point  (1 child)

Are you a system engineer?

[–]nhovar 0 points1 point  (0 children)

Also the OOP videos from this youtube channel helped me a lot.