Hacker News new | past | comments | ask | show | jobs | submit login

The problem isn't DRY, the problem is "helpers". Helpers are an anti-pattern, they don't fit in your architecture, they have no mental model, they're difficult (impossible) to name and organize, and they're extremely resistant to refactoring. Effectively they're spaghetti code.

The example I always come back to is auth. If you're doing the same thing like "parse a cookie header, get the session, make a DB connection, look up the session info, etc. etc.", consider how you could architect the layers of your application using a mental model that people would find easy to reason about. That might be some OO, middleware, or even a macro, but the point is that it's thought about, designed, engineered, and documented.

The reason helpers are more prevalent than thoughtful architecture is that humans are a lot better at prioritizing the short term "I improved it" fix from factoring into helpers over doing the long term work of architecture. If you want to change this, it starts with cultural values that prioritize long term sustainability.




What about the "helpers" found in the standard library? How do you feel about those things?


Do you have an example you’re thinking of? I don’t think standard libraries automatically have good architecture (see: PHP), but they do have a big influence on culture, which is interesting.


No, I meant if you think helpers are anti-pattern that results into a spaghetti code, then you must also think that standard libraries are an anti-pattern mess. I don't think there's a standard library that doesn't have helpers, unless we don't agree on what a helper is?


Hmm that could be it. Like, Python has json and it works like pickle before it. I don’t think that’s a helper and I like that it reinforces that serialization pattern.

What I think of as helpers are like base64_auth_to_username_password. That’s factoring out like 2-3 lines of code that may be duplicated in a half dozen places, but in truth represents an incomplete abstraction, layer, or subsystem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: