Hacker News new | ask | show | jobs
by Waterluvian 1275 days ago
They forgot the masterpiece I saw years ago:

1. Give all your Python class members a tedious naming convention.

2. Be DRY by writing helper functions that do name lookup based on a string of the last half of the member name.

3. Be even more DRY by having the function guess a little if the match isn’t exact

You now have an application where you cannot search for where members are referenced.

8 comments

I did something like step #2 in C# some years ago. Pulled data from the database based on the calling function’s name.

Clean Code was mental poison for me and certainly led to a bunch of overly abstracted or overly-DRY code.

I feel like every coder has to overdo it at least once to truly grok why it is a balancing act. And I think that oftentimes leads to the discovery that every best practice is a balancing act.
A good rule is two maybe even three duplications is ok. After that, probably tome to refactor at least a little. Often this rule of thumb saves some efforts.
W.E.T. then D.R.Y.

(Write Everything Twice)

The rule should not be primarily based on a number of duplications but if we know that all the duplicated parts need to be changed when one is changed.
You're probably right on that. I now weigh my options to try to find a middle ground between impossible to change because it wasn't designed for change and impossible to change because it was designed for too many future use cases that will never happen.
IME, extensible code comes from thinking of possible extensions and then not getting in their way, which usually just means keeping it simple. Easy to say but hard to do.
Ah yes. Just like Ruby and meta-programming games with send, define_method, and method_missing.
They call it “reflection” because the more you use it, the more you ought to stop and reflect on your choices. ;)
Yes. It's very easy to get addicted to that powerful Ruby stuff. Unlike C and Lisp though, there is no way to get a compiler to expand the macros and show you the resulting metaprogrammed source code. You can inspect the objects at runtime but it's cumbersome compared to reading source code.

Sometimes repetition is good.

Oh, you mean like the oh-so-great Laravel framework, which is structured like this exclusively?
#2 Sounds like your typical Angular 1.x app.

For some reason everyone tried to be clever with code reuse in them which almost always resulted in an unsearchable mess.

> Be even more DRY by having the function guess a little if the match isn’t exact

At that point you'll be singing How DRY I Am!

https://temperanceblues.web.illinois.edu/how-dry-i-am/

Be even more DRY by having function that does quite a bit of everything, accepts different arguments, and returns different type. You only need to supply different strings to the first parameter
so, a normal ruby codebase?
Feels like a dad joke!