Comment on Python classes aren’t always the best solutionparentComments−kubb1yChill, people are learning and not everyone has the luxury of reading the manual or going to school or using Python at work or whatever.−pydry1yThere is harmful advice in this article. "Just chill and use a dict or a namedtuple" leads inexorably to buggy code.The advice to use dataclasses is good but... dataclasses are, um, classes.−hidelooktropicOP1yI thought readers would understand that an alternative to a class just meant you don't have to create one from scratch. Maybe not.−ackfoobar1ydataclasses are, um, classesSo is the case when you use `namedtuple`, which creates a new class. This is not an interesting gotcha.Classes (the Python language construct) are how you implement records (the language-neutral concept) in Python.It's ironic that the "There Is Only One Way to Do It" language has multiple bad ways to implement records though.−quietbritishjim1yAre people really making classes with a single static method and nothing else? It just feels like filler material.−Sohcahtoa821yYes. They probably learned Java first.−callc1y+1. I learned Java first, in school and on my own. I needed to unlearn the OOP-first mindset.−AstroBen1yThis has nothing to do with OOP. A class with a single static method isn't OOPYou can use the 'class' keyword and write your program functionally, or procedurally−Jtsummers1ySo you actually thought you needed, in Python, classes with static methods instead of just plain old modules? What was your first Python "hello world" like?
Comments
Chill, people are learning and not everyone has the luxury of reading the manual or going to school or using Python at work or whatever.
There is harmful advice in this article. "Just chill and use a dict or a namedtuple" leads inexorably to buggy code.
The advice to use dataclasses is good but... dataclasses are, um, classes.
I thought readers would understand that an alternative to a class just meant you don't have to create one from scratch. Maybe not.
So is the case when you use `namedtuple`, which creates a new class. This is not an interesting gotcha.
Classes (the Python language construct) are how you implement records (the language-neutral concept) in Python.
It's ironic that the "There Is Only One Way to Do It" language has multiple bad ways to implement records though.
Are people really making classes with a single static method and nothing else? It just feels like filler material.
Yes. They probably learned Java first.
+1. I learned Java first, in school and on my own. I needed to unlearn the OOP-first mindset.
This has nothing to do with OOP. A class with a single static method isn't OOP
You can use the 'class' keyword and write your program functionally, or procedurally
So you actually thought you needed, in Python, classes with static methods instead of just plain old modules? What was your first Python "hello world" like?