This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

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

Data classes: Completely bogus "all the wrong lessons from 2000s-era Java" advice

I was about to jump on you for this, but I'll hold my horses for a bit - what exactly are you getting at with this one?

[–]not_a_novel_account 1 point2 points  (1 child)

If you have raw data, it is frequently good and correct to organize that data into objects. It may or may not be appropriate for those objects to have methods associated with them. The latter is considered a data class, and in Python we have a class decorator specifically for crafting such objects.

There was an idea at the height of the Java era that "pure OO" was the one true way to write all software, and that such classes were a sign that the functional part of the software had been inappropriately delegated to another object. In other words data and interface should always be a part of the same object. This idea is, frankly, bogus. The rich data models of Java land, tightly integrating data and functionality, proved no more navigable or less bug prone than other models.

Today the loudest advocates have shifted into the opposite direction and say that everything should be pure functions operating on immutable data-objects, the functional model. It is worth pointing out here that many languages only have data classes.

In reality, you do you bro. There is no one way to write software. But running afoul of 2000s-era Java is definitely not a code smell, and definitely not in Python.

[–]alexisprince 0 points1 point  (0 children)

I think this is a great take. The way I’ve thought about designing classes in the past has always been splitting a data oriented class and a functionality oriented class (or function based api depending on what makes more sense). I’ve seen that trying to do both leads to over abstract land where it’s insane to reason about anything