Old OOP habits die hard

229 points Aggressive_Sherbet64 87 comments

Man, old habits die hard.

It's so easy without thinking to follow old patterns from OOP inside of rust that really don't make sense - I recently was implementing a system that interacts with a database, so of course I made a struct whose implementation is meant to talk to a certain part of the database. Then I made another one that did the same thing but just interacted with a different part of the database. Didn't put too much thought into it, nothing too crazy just grouping together similar functionality.

A couple days later I took a look at these structs and I saw that all they had in them was a PgPool. Nothing else - these structs were functionally identical. And they didn't need anything else - there was no data that needed to be shared between the grouping of these functions! Obviously these should have all been separate functions that took in a reference to the PgPool itself.

I gotta break these old OOP habits. Does anyone else have these bad habits too?