3 ms·
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
by Waterluvian 4y 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.
- ziml77 4y agoI 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.
- Waterluvian 4y agoI 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.
- ziml77 4y agoYou'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.
- ahartmetz 4y agoIME, 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.
- bitexploder 4y agoA 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.
- Rexxar 4y agoThe 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.
- idontwantthis 4y agoW.E.T. then D.R.Y. (Write Everything Twice)
- glitchc 4y agoFeels like a dad joke!
- kayodelycaon 4y agoAh yes. Just like Ruby and meta-programming games with send, define_method, and method_missing.
- Waterluvian 4y agoThey call it “reflection” because the more you use it, the more you ought to stop and reflect on your choices. ;)
- matheusmoreira 4y agoYes. 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.
- Stratoscope 4y ago> 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/ https://temperanceblues.web.illinois.edu/how-dry-i-am/
- Tade0 4y ago#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.
- 9dev 4y agoOh, you mean like the oh-so-great Laravel framework, which is structured like this exclusively?
- eximius 4y agoso, a normal ruby codebase?
- valand 4y agoBe 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