this post was submitted on 25 Jun 2025
24 points (90.0% liked)

Python

7250 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
 

This is a question for people more experienced with Python, but everybody feel free to answer if you feel like you can provide something decent to the discussion.

Also feel free to explain why you feel that way and your experiences with Python and the paradigms.

top 31 comments
sorted by: hot top controversial new old
[–] Diplomjodler3@lemmy.world 15 points 4 days ago (2 children)

I used to struggle with OOP because all the explanations I saw were in terms of metaphors of real world objects. Once i started seeing OOP as a way to better structure your code, it all fell into place. If you do anything marginally complex, OO is the way to go.

[–] Custodian6718@programming.dev 7 points 4 days ago (1 children)

I do agree except for the last sentence because I do not think that OOP is the silver bullet for everything.

[–] Diplomjodler3@lemmy.world 4 points 4 days ago (1 children)

I was talking about Python specifically. And no, of course it's not a silver bullet. It's a solution for structuring your code base in a way that lets you not lose track of what does what.

[–] phutatorius@lemmy.zip 1 points 2 days ago

It's also a good way to structure your code to effectively model your problem domain.

And there are also many cases where that's not true, so use it where it makes sense and don't use it where it doesn't.

[–] FizzyOrange@programming.dev 1 points 3 days ago (2 children)

I disagree. You can write a lot of high quality Python code (yeah it exists) before you need to use inheritance. If you're reaching for inheritance as the solution to all complexity, GoF-style, then you're doing it wrong.

It's an occasionally useful tool that has its place, not something you should instinctively reach for.

[–] Sleepkever@lemm.ee 4 points 3 days ago

OOP not just inheritance. Object oriented programming starts with structuring things in objects, like the name suggests. It quickly has a place in anything more then a few hundred lines of code.

[–] Diplomjodler3@lemmy.world 3 points 3 days ago (1 children)

I rarely use inheritance. Like i said, I see OOP mainly as a way to achieve cleaner code structure and better readability. That last point is really my main concern.

[–] FizzyOrange@programming.dev 2 points 3 days ago

Ah yeah I agree. Misread your comment.

[–] bluGill@fedia.io 9 points 4 days ago (1 children)

The question is invalid!

Write the code that makes sense for your problem. This is not religion where choosing the wrong thing can land you in hell for eternity or whatever it is your gods will do if they don't like you. You should be mixing OO, functional, and procedural code all the time as each does some things well and some things poorly. Of course don't create a mess by the mix, but good code has a need for all 3 styles. (IIRC there are more styles the good code needs, but I can't think of what it might be at the moment)

[–] jwmgregory@lemmy.dbzer0.com 4 points 4 days ago (2 children)

I love the almost spiritual nature of software development. It sounds crazy but the best devs I have ever worked with all immediately understood this perspective or had their own version of it.

The way we have these three categories of programming styles… off in one rhetorical direction, we see millions of little threads, innumerable individual languages, syntaxes, little styles… in the other direction? A monadic unity. All three categories are programming languages, which are just… forms of communication… which is just, well, shifting values of information. And that? Information? Formally it’s the potential for data but philosophically it is the noumena itself. The information world and the real world are one in the same.

I think people who are under the false impression that “everything has already been discovered” are so unfortunately blind to the beautiful world we have been endowed to discover, especially in contemporary times.

[–] Hammerheart@programming.dev 3 points 3 days ago (1 children)

Could you elaborate on how information is the noumena?

[–] jwmgregory@lemmy.dbzer0.com 2 points 2 days ago

yeah that’s definitely the boldest claim made in the OP comment. was surprised to see it hang out unchallenged for so long.

there’s been a growing trend to assign ontological primacy to information over mass/energy/space/etc. it’s a hot point for debate in computer science and physics research because, as my Kantian diction was kind of intended to imply: we can’t really empirically verify any ontological theories we have so we end up arguing over things that seem semantic from the outside in.

that means that, at least for now, “information is the noumena” is a matter of opinion. i just have strong, albeit potentially misplaced feelings - that mass, energy, and information are all different expressions of the same substrate that builds reality itself and that there is an undiscovered mechanic governing all three in a self-consistent manner.

[–] chaos@beehaw.org 0 points 3 days ago

Computers only have one language and one data type. Everything else is a construct, which we can build up into a beautiful thing: a mathematics that exists in the real world instead of the pure realm of axioms and symbols, and because it's purely our own creation and not the universe's, we know it from the fundamentals and don't have to struggle with all the unknowns of physics, which presents us with very different, more mysterious mathematical objects to interact with instead.

[–] danzabia 10 points 4 days ago (1 children)

For me it depends on the use case. If I'm designing something with an interface for someone downstream to use, I'll usually define (data)classes even if I have a functional interface.

For data science/modeling/notebooks I usually wouldn't define classes.

I think it also depends on your team; if everyone else is a functional programmer and you're writing classes or vice versa, this will undoubtedly create frictions.

[–] driving_crooner@lemmy.eco.br 1 points 4 days ago (1 children)

I use python for data sciences (kinda) and never write any classes or something object oriented, but given that dataframes are the bread and butter of everything I do, I guess I work in a object oriented workflow?

[–] danzabia 1 points 3 days ago

Yeah that's a great point -- the dataframe is in a sense a class or object standardized for data analysis. Its flexibility (like being able to store arrays or dicts even) obviates the need in most cases for a user-written class.

[–] koala@programming.dev 6 points 3 days ago

Well, it's more procedural than object-oriented because it's easier to avoid object-oriented programming than procedural code :D

(Note: I wouldn't call defining classes OOP until you start using inheritance. Overriding __str__ and stuff might count, but not a lot to me.)

Personally, as time goes on, I use inheritance less.

[–] Tja@programming.dev 7 points 4 days ago (1 children)

Any language can be procedural if you insist (maybe Haskell will fight you?), creating objects is a design choice to organize the code better. Any project beyond a few hundred lines of code should probably use objects.

The language itself can be considered object oriented since it allows the typical OOP patterns.

[–] Custodian6718@programming.dev 5 points 4 days ago* (last edited 4 days ago) (1 children)

Obviously (almost) in any language code can be forcefully programmed the way you want, yes. But that is not how we normally code now is it? Usually languages & their community lean more towards certain paradigms than others.

[–] Tja@programming.dev 1 points 4 days ago

Depends also on what you use python for. If you build a whole piece of software, you will be using objects. But many teams use Java for the business logic and python as a scripting language to call some api, or automate a task. In those cases python will be used procedurally, as a nicer bash basically.

[–] tunetardis@piefed.ca 4 points 4 days ago

As with most script languages, you can hit the ground running in a very procedural sort of way, as you don't even have to define a main entry point. You just start coding.

But Python certainly has an object model. If I'm not mistaken, everything in Python is an object. Like even functions.

I suppose there are some aspects of the class implementation that feel a little tacked on? Like the way you need to manage the self reference manually where it may be implicitly handled for you in other languages. At least the way you call super() now is a lot less kludgy.

One thing I miss a bit in Python is method overloading. In a general sense, function overloading is not an OOP feature per se, but I find it useful in OOP, particularly with object initializers. You can sort of achieve it with @functools.singledispatch but it's pretty janky. For initialization, I prefer keeping the __init__ method pretty rudimentary and writing factory functions to do more complex initializations. And with @dataclass, you can forego writing an __init__ altogether if you do it that way.

[–] thingsiplay@beehaw.org 3 points 4 days ago

It supports both and depending on the situation its more procedural or more object oriented. Do you consider the standard library as part of the language and are you forced to use it? Then certainly the object oriented parts of the language would be forced to use and therefore it is object oriented. Or do you only evaluate the language and its features itself? In that case, Python supports object oriented programming with classes and objects, but you are not forced to use it.

Are we talking about the language features itself or the produced programs with it in the real world?

So regardless if you look at the language itself or the common standard library that most Python programs use, objects and classes are an part of the language. Even if you write simple procedural scripts, does not take away that Python itself is a more object oriented programming language.

[–] Narann@jlai.lu 1 points 3 days ago

Most of my objects are actually dataclasses.

[–] grue@lemmy.world 1 points 3 days ago

I like writing Python in a relatively Functional way most of the time, with lots of list and dict comprehensions.

The language supports both, so it really depends on the user. The standard library doesn't have a clear preference, and uses both approaches, along with functional style.

So I'll say both, and my preference is a hybrid of functional and procedural.

[–] LodeMike@lemmy.today 1 points 3 days ago (1 children)

Neither: it's a piece of shit.

If I had a gun to my head and had to answer, it'd be procedural because scopes are a lie in this language.

[–] FooBarrington@lemmy.world 2 points 3 days ago (1 children)

I like the cut of your jib

[–] LodeMike@lemmy.today 0 points 3 days ago* (last edited 3 days ago) (2 children)

Python is good if you need to write a hundred or two or maybe three lines of code.

Its not good for large programs.

Conversely its good for large systems. Facebook makes all its microservices in python because the data model and how that scales along with data safety matters much more than a microservice taking 10-100 times as long to execute.

I consider it a scripting language. Just one without integer++ for some goddamn reason.

[–] FooBarrington@lemmy.world 1 points 3 days ago

My issue with Python is that so many "pythonic" practices lead to horrible-to-read code. List comprehensions are nice, except for when they go more than one level deep. kwargs leads to horrible code. Lots of valid Python code cannot be typed correctly, which makes editor inference far worse. Don't get me started on metaclasses and the like.

Python right now is basically what JavaScript was before TS.

[–] el_bhm@lemm.ee 0 points 3 days ago

Python is good if you need to write a hundred or two or maybe three lines of code

Sooooo, any language?

[–] rumschlumpel@feddit.org 1 points 4 days ago

It's whatever you want it to be, baby.