Student Login

3 fascinating points about data classes

Python 3.7 has a fun new thingy called data classes...

And it's really a fascinating tool. A few things I noticed:

It's Well Designed

Data classes solve a set of problems that have, over and over, shown up in people's Python programs.

Even better: They let you solve these problems easily, and quickly.

The common, simple things you'll want to use data classes for are easy to learn and use. Because it's designed that way.

And the necessarily more complex problems have solutions from data classes that are, necessarily, more complicated... but once you understand that more complex problem being solved, the solution makes sense.

It's hard to think of ways to improve the design of this tool, without losing something important.

Data Classes Reward Deep Knowledge Of Python

The simple uses of data classes are really great. You'll use them a lot.

But data classes give you even more, for free. And to be honest, the typical Python programmer won't be able to grok what that "even more" is yet.

But as you learn Python more deeply... as you get into the "wizard" levels of the language...

You'll realize more and more these extra, "hidden" benefits of data classes.

In other words: this feature grows in value to you, as you grow in your mastery of Python.

Under The Hood, It's Harder Than It Looks

As I mentioned, the interface of data classes is quite simple.

Even the more complex parts are straightforward. So you might think the Python code implementing data classes is straightforward.

You'd be so wrong.

Take a look at the source of the "dataclasses" module. The calm, tranquil surface of @dataclass hides furious activity in the underlying code.

There's a great lesson in here about hiding complexity. And the value your software provides when you do.

For Teams Bootcamp