Re:Data Classification: Does Python still have a need for cl...
by eru on Tuesday February 14, 2023 @07:42AM
(#34788499)
Dicts are much more annoying to give types for. They are also slower.
Re:Data Classification: Does Python still have a need for cl...
by bl0rg on Tuesday February 14, 2023 @06:58AM
(#34788152)
1. Dots are nicer to type for sure
2. It's a bit easier to define types for class attributes than dictionaries IMO
3. You can absolutely have methods on dataclasses
Re:Data Classification: Does Python still have a need for cl...
by Liquid_Fire on Tuesday February 14, 2023 @07:18AM
(#34788300)
There is clear value in being able to pass around several pieces of information about the same thing without having to individually name them every time (less typing, you can decide to include more members at a later time, less overhead in passing by reference, users can treat it as an opaque type without needing to know the contents, etc).
Re:Data Classification: Does Python still have a need for cl...
by thanatropism on Tuesday February 14, 2023 @09:04AM
(#34789381)
This. I look at old code I wrote and cringe at things like
def foo(...):
...
return yhat, sse, aic, bic
yhat, _, _, _ = foo(ytrue)
plot(ytrue, yhat)
Re:Data Classification: Does Python still have a need for cl...
by st4lz on Tuesday February 14, 2023 @08:26AM
(#34788905)
There is a slight distinction between a dictionary and a class. Dict is a mutable key-value storage, so can be used as a collection of objects (or values) and benefit from its dynamism. Dataclasses are meant to define an object, so the emphasis is on clearly declaring the purpose of it upfront, enhancing readability.
Re:Data Classification: Does Python still have a need for cl...
by sakex on Tuesday February 14, 2023 @08:33AM
(#34788985)
Documenting your type.
Re:Data Classification: Does Python still have a need for cl...
by evomassiny on Tuesday February 14, 2023 @08:52AM
(#34789228)
dataclasses document the full set of attribute they can hold, along with their type.
Re:Data Classification: Does Python still have a need for cl...
by thanatropism on Tuesday February 14, 2023 @09:02AM
(#34789357)
Future-proofed, self-documenting code?
Re:Data Classification: Does Python still have a need for cl...
by zzzeek on Tuesday February 14, 2023 @09:59AM
(#34790225)
classes themselves are types, which is semantically valuable and also provides for a straightforward inheritance pattern. attributes on classes are easier to type. There's pep-589 TypedDict but it's not very easy to use right now.
Re:Data Classification: Does Python still have a need for cl...
by beiller on Tuesday February 14, 2023 @10:24AM
(#34790598)
I'm in the same boat. I've been using TypedDict all over the place and it's quite nice! The only plus side to dots I had was the IDE auto-filling it, and my IDE seems to work just fine with TypedDict.
Re:Data Classification: Does Python still have a need for cl...
by teddyh on Tuesday February 14, 2023 @11:07AM
(#34791375)
Classes can change an attribute to a property while keeping the interface intact. Like turning an SQL table into an updateable view.
Re:Data Classification: Does Python still have a need for cl...
by BeFlatXIII on Tuesday February 14, 2023 @05:02PM
(#34796798)
IDE autocompletion is better with classes than with dicts.
About 10 years ago someone who I thought was pretty smart said it was because dots are nicer to type, fair enough I guess. It just always seemed silly to me to go through setting up a class but not getting the benefits of using methods.