How A Pull Request Rocked My World
clayallsopp.com
How A Pull Request Rocked My World
1–10 of 158 posts
Re: How A Pull Request Rocked My World
#2EDIT: I just checked, yes he does (well, unless we're talking about another Fabio of course, which is possible...)
Re: How A Pull Request Rocked My World
#3Re: How A Pull Request Rocked My World
#4Here's why: When I am maintaining somebody else's code, even if I guess that this is going on, I rarely trust these kinds of name-generation tricks. When I need to change some code, I'm going to grep the codebase for 'SwitchRow' and add a new line in whatever conditional to instantiate my new class. When grep can't find any instances of SwitchRow's constructor being called, I become suspicious and it costs me more time, because I am making sure I properly understand what is actually going on.
Re: How A Pull Request Rocked My World
#5The classic "Replace Conditional with Polymorphism" design pattern, which took me way to long to realize that it also applies to Python.
Re: How A Pull Request Rocked My World
#6Re: How A Pull Request Rocked My World
#7tl;dr: polymorphism is usually better than if/else.
Re: How A Pull Request Rocked My World
#8Metaprogramming is something you do when you can't do it easily in the usual way. If a dispatch table or inheritance takes care of something, use the existing language features instead of building your own.
(EDIT: On examination, there already is a RowType, and the pull request is a lot closer to my suggestion than I first thought, so mostly ignore this.)
Re: How A Pull Request Rocked My World
#9I know we have git and we can always do a diff to see what changed. What I am talking about is a more holistic view. Being able to search a code base for SwitchRow and then somehow the code comes up where it was refactored into this dynamic programming style.
Git can do this but only if you are actively looking for it. I wish you could do a metacomment on the refactor without cluttering up the code.
Re: How A Pull Request Rocked My World
#10"You can reuse code with inheritance. Absolutely crazy. Brilliant.
All of this blew me away."
Honestly?