6
Parzi
114d

How the fuck do classes work in Python? Why, exactly, do people make them for themselves? I get doing it for like making modules other people will use, but just for your own shit...?

Comments
  • 15
    For the same reasons you would do it in other languages...
  • 6
    To have some semblance of good code architecture
  • 3
    @12bitfloat @C0D4 if you can't structure code in a good way without multiple files and classes you need to take a step back and wonder where the fuck you went wrong
  • 8
    If you would do it for someone else, why the hell wouldn't you do it for yourself?

    Others get the good treatment.
    I get the best treatment. 😉
  • 8
    @Parzi sorry, I do like to compartmentalise my code so every class is on its own instead of massive files that go for miles.
  • 0
    @C0D4 what, pray tell, the fuck would be that long?
  • 7
    @Parzi e-commerce.

    Not everyone writes "small" software for the cli.
  • 5
    You are a beginner arent you?

    Try making a game and youll understand oop.
  • 5
    @Parzi you're obviously trolling. At least I hope so
  • 3
    I came to Python from Java, so it took a while to learn when classes are actually necessary and when they aren't. Most of the time they aren't. I can count on one hand the number of classes I've created in Python in the past couple years.
  • 7
    Some applications get large pretty fast man, in that case it is best to compartmentalize decent code structures across multiple files. Say for example you are writing an api with Flask or Django, let us think of flask first, you could very well add your entire application in one file, but that can get messy quite fast, normally people would define each endpoint in its own set of files and call them out as needed, modify them as needed, or add more to them as needed, in this case simple methods with decorators would become quite cumbersome and classes would represent an easier way to maintain and pass stuff around.

    You don't have to per-se, but for larger applications it is best if you do.
  • 4
    @Parzi So you like writing spaghetti code without any real structure? Well, good luck I guess
  • 3
    @AleCx04 It's not even about the size of the code base. Just like writing a novel, programming is art and you want to have some form of quality even if it's just a 4 page short story
  • 3
    @12bitfloat you are saying that as if I don't do it on my own codebase. While I don't share the "art" perspective of it, I can appreciate good structure and the need for proper engineered solutions. But if our boy here ain't seeing the benefits on it then I will provide the more logical reasoning behind it, if not for the sake of art(in the event of him not sharing said views) then for the sake of completeness and properly engineered platforms.
  • 2
    @Parzi well, the moment you leave basic web pages and dive into web applications you can easily get thousands of lines of server side code for a single page.
  • 2
    @AleCx04 I wasn't implying your code was bad, I do agree with you
  • 0
    @C0D4 That's fair, as Tkinter's not the greatest.

    @yellow-dog why would you make a game in Python? Just... don't. It's not a good lang for that.

    @don-rager i'm serious, actually.

    @EmberQuill I've never made one for actual use, even for my own use. Never had to.

    @AleCx04 if you properly format and document your code, it's not hard to just use one file. In a team with dickheads, this may not hold true, but...

    @12bitfloat Proper documentation and formatting makes it not terrible, and i've never needed them as functions do everything I'd need to be disjointed from the main code. Hopefully real-world pros don't make every line their own function, like my CIS class implies. You don't need to make a separate function to print an arbitrary string to the screen, just use print() inline ffs

    @Voxera I don't do web design or webapps, i'd honestly rather die.
  • 4
    Yeah, hes a beginner
  • 2
  • 0
    @yellow-dog I mean, if anyone who doesn't do it for a living is a beginner, then yes. Otherwise, not really, no.
  • 4
    Nothing wrong with that, just your lack of real world experience shows.

    And to answer your claim, every language is good for anything, some are just more geared towards certain tasks
  • 4
    @Parzi Making every single line of code a seperate function is obviously wrong. Making every logical unit of code a seperate function or class on the other hand is not
  • 1
    @sweetnothings i'm used to linear code structure, or at least semi-linear, as it's actually intuitive, but if you say so...
  • 1
    Reminds me of the way I used to rationalize not to use git back when I was starting out which prevented me from learning it properly for quite a while.
  • 0
    @don-rager Just because i don't use them doesn't mean i don't know how they work or can't use them, I just have yet to find a use for them that's not overkill. I've toyed with them some, which is why I know I don't have a use for them at present. I know very well that i will need to use them at some point, I just haven't found a situation where functions don't do the same job better yet.
Add Comment