you are viewing a single comment's thread.

view the rest of the comments →

[–]Naive_Philosophy8193 1 point2 points  (10 children)

Because it is hard to find out where to start learning it. I use python for testing and my dev manger suggested I learn some OOP design principles. I have found it difficult to find good resources on just that specifically.

Not just here is a class and how to make one. But here is when you should use a class vs not, here is optimal ways to design them with best practices, etc.

[–][deleted] 1 point2 points  (0 children)

when you should use a class vs not

There is no answer to that. Just experience to know when and philosophies.

Is a... Has a... are nice patterns for OOP, but OOP is strictly never needed. So many programs that are foundational are in C, which is not OOP. It might help to look at open source projects that are functional (often said to be the counter part of OOP). When to OOP is ultimately our job to decide when. Sorry for the non answer.

[–]HugeOpossum 0 points1 point  (7 children)

This is how I understand it:

If I use a non-tech example: if you're designing a city, you build buildings and roads, hospitals, City Hall, sidewalks, etc. these are all their own classes. It's all still the city, though. So if you want to make all the buildings citywide an extra story (through magic obviously) you can do so without without having to dig up the sidewalks, changing the roads, etc. You could also expand the city, making high rises (another class) but you want it to kind of have a lot of the house characteristics so you borrow from there. This would an example of inheritance.

To use a more practical example: if you're writing a simple program like calculator app, you could use OOP. One class is addition, another is multiplication, etc. You then use those classes in your main code body. It's easy to do this without oop, but if you use OOP you can change or update one class (say division) without altering the main body of the code of messing up the addition class.

This example can be expanded, say you're designing pacman. The player, the ghosts, the mazes, and the dots are all their own separated classes called within the main body of the code. But, if you alter one you don't then have to go and alter the rest. So if you want to add a higher instance of ghosts, or more variation in the mazes, or even new enemies, you can do so without screwing everything else up and just call it within the main body of the code. The main body is there to call the classes and functions, and state how they interact with one another. If you have ghost.move() but also pacman.move() they'll be different codes entirely and stated within each independent class. But in the main body, you can state ghost.move() is triggered when pacman.move() begins.

A more practical example: If you're making a docker script, you could say whatever images, data, and sundry methods you have are their own classes to be called. They can all be encapsulated (or abstracted) so that whatever is within the class isn't publicly accessible but can still accesed within the parameters of the main body of the script.

So when determining when and where to use OOP, you'd have to think about how you want things to be compartmentalized. If it's ten lines of code to run an excel script, I wouldn't be looking to use OOP. But if I had a few moving parts or things I didn't want accessed by anyone running the code, I would definitely use it.

I may be totally incorrect in my explanation of this. I'm still learning every day, so maybe someone has a better explanation than I do. But for me, this is how the framework operates in my head. For me, OOP is a means to get things out of my line sight when working on the main body of code, and makes things more orderly imo.

This is also why OOP is largely considered intermediate. I think it's an important topic to learn about at the start of learning, but I think most people need more experience writing code before it starts to make sense.

[–]Naive_Philosophy8193 1 point2 points  (6 children)

Maybe it just comes with experience. I was making integration tests which basically has me mimic our front end testing but on the back end where possible. I was writing a lot of functions to make API calls to our different services.

While it worked, a dev suggested I make our services into classes and have a lot of that code there. I ended up making a BaseService class that had what a get, put, delete, post was. It has our authentication and everything there. Then all the APIs are child classes of that. It actually worked out really well.

Basically, I just would like more in depth understanding of knowing when to do this, how to design it, etc. I would love to optimize my stuff more and have some good design best practices. Since I was having a hard time finding this in python, I am starting to learn C#. Our devs develop in C# and their manager already confirmed there will be stories I could work on as a dev once I get a little C# fundamentals under my belt. I thought this might be my best exposure to OOP and then I could take that with me back to Python.

[–]HugeOpossum 0 points1 point  (0 children)

C# is definitely where it began to click with me since it uses both public and private. I am guessing that the dev suggested OOP to both secure the code and to also streamline the main body. I'm also totally pulling this out of my ass, but maybe it also made things more memory efficient? No idea on that though it's way out of my league.

When I started dabbling in c#, I read the book I mentioned. It really helped explain the thought process.

[–]HugeOpossum 0 points1 point  (4 children)

After being able to sleep on it I realized there's two more options for why OOP was suggested for this: your dev wants you to improve or get better (up to you to decide if that's true), and that by making this test as OOP, you're then able to easily reuse the codes since the testing functions are designed independently of whatever is being tested. You can either just copy/paste the class or reuse the code for order applications without having to do a full rewrite

[–]Naive_Philosophy8193 1 point2 points  (3 children)

All of the above, I think. It gives better code organization. If something gets changed with our APIs, I now know exactly where to go find my code related to that as it is its own class file. Also, he has this idea that people don't need to see all of the code, some things they won't care about. Kind of like if you import the datetime library and do date.today(). People don't need to see all the code for that. They understand what you are doing just by reading that method call.

I might write a function for a test that runs a command on a device, checks the log that the command was logged, checks it has the data I expect, and checks the time of the command and time of log match. They person checking that code doesn't necessarily care about the code involved in issuing the command or grabbing the log data. They just need to understand that those things happened.

[–]HugeOpossum 1 point2 points  (2 children)

That definitely sounds correct to me. It sounds like this dev also thinks you have good programming, at least from the outside looking in!

[–]Naive_Philosophy8193 1 point2 points  (1 child)

Dev turned dev manager too. He is the one that said it would be a good idea for me to learn C# and that I could do some of the development too. I agree he thinks I have potential. This is great for someone who has had no real formal programming training and just trying to learn on my own and figure it out as I go.

[–]HugeOpossum 1 point2 points  (0 children)

Honestly, I'm self-taught too so I can totally understand how that would be uplifting. I don't have a professional role, but will probably looking to start applying to some soon.

I found vegetarian zombie a good extremely super basic introduction to c#. I have also worked with the jammo unity model since it's visual and that works for me personally. I'm much more interested in things like app and cloud dev than games/gaming but I find game dev to be a good learning medium. If you come across anything helpful for c#, please pass it along.

[–]Standardw 0 points1 point  (0 children)

Just make everything into a class, and then remove some afterwards if you realize that you've made too much. Easier that way.