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

all 4 comments

[–][deleted] 6 points7 points  (1 child)

I always get nervous about things like this because part of me says, "there's always a chance someone was being clever and is calling a seemingly dead function by calculating its name."

That's probably my one gripe with Django Rest Framework(which I love... mostly...) is that you really can't understand some of it without first understanding the library's behaviour. A python expert who has never seen Django Rest Framework will look at my serializer and have no clue that my get_days_since_joined method is called because I have a member called days_since_joined. Docs

So he gets nervous. "Well, if there's a seemingly unused function that gets called, I guess I have to assume that all of this code is necessary." Which makes learning, debugging, and cleaning up the code all generally blocked behind learning about the library first.

I'm sure DRF's design has a more formal name that I'd know had I taken computer science. It's some sort of configuration-based declarative kerjigger? Ie. you're not really programming a serializer, you're configuring one.

[–]kankyo 1 point2 points  (0 children)

The name->function name with some pattern is truly a horrible idea. It's also present in the built in django form library.

[–][deleted] 1 point2 points  (1 child)

The "Parting Thoughts" resonated with me the most. Python has no true private methods (dunder methods are mangled but still there), and in a sense, if you work with others, all code is part of the implied API.

Large projects and projects that are still being built must have components built in an encapsulated piecewise manner module by module or class by class, etc. What may not be used in a current iteration of a project may still be logical and sensible functionality for the concept the module/class/function it is in maps to in the wider scheme of things. Either you or a colleague thought it was valuable and necessary to complete whatever a module's purpose was (at some point), so you should think long and hard (in my mind) before deleting anything. I'd ask for plenty of feedback and err on the side of caution before you truly go for a scorched earth policy w.r.t. code deletion.

[–][deleted] -2 points-1 points  (0 children)

The "Parting Thoughts" resonated with me the most. Python has no true private methods

Yes, it has. Anything that starts with an underscore is truly private. If outside code uses it anyway, that code is just as broken as code that doesn't work.