Are you a boy scout coder?
Join the DZone community and get the full member experience.
Join For Freethe boy scouts have a rule: “always leave the campground cleaner than you found it.” if you find a mess on the ground, you clean it up regardless of who might have made the mess. /../ the original form by robert stephenson smyth baden-powell, was “try and leave this world a little better than you found it.”
what if we followed a similar rule in our code: “always check a module in cleaner than when you checked it out.” no matter who the original author was, what if we always made some effort, no matter how small, to improve the module. what would be the result?
by uncle bob at o’reilly commons
when i first saw this rule in clean code i loved it! it’s just such an awesome rule. you come into a file, you clean it up a little bit. remove a stupid comment, indent something better … anything.
it makes the world a better place and everyone a happy camper right?
well, this might be great in theory and work well when you are employed by a company where you will spend the next few years of your life. the software you’re working on will live and grow with you, with your team. you are the guy shouting “fuck this! who the fuck made this code! this is bloody impossible to maintain!” a year from now.
for a freelancer the situation is a bit different.
here you are, plomped into the middle of an ongoing project. decisions have been made, rabbit holes have been followed. the deadline is in a month and as a crack team of one specialist on a tight deadline, you’re making nice gold per hour.
right there in front of you. a mess. code so ugly, so horrible, it would make a grown man cry. you’re just supposed to add a feature. figure out the mess, add two or three lines of code, cross your fingers and hope for the best.
or should you rewrite the whole function?
rewriting would be the right thing ™ to do. the code will be more maintainable, easier to test, it will save your client a bunch of money down the line. you won’t be maintaining this so you have a responsible towards everyone coming after you to fix something.
but, right now, right this very instance, you are strong-arming the poor client to pay more. sure, you’re making the code better, but they care about that one feature. should you really spend three hours rewriting the code instead of one hour adding something and hoping for the best?
on the other hand: when the messy code breaks, and it will break, it will be your fault. you’re the last guy who touched it. not rewriting will come back to haunt you. the guy who maintains your code will curse you in their sleep and dream of delicious murder. and it’s not even your code!
so what do you do?
personally i always try to rewrite crappy code. add testing suites. anything i can do to make the codebase better. but i always carefully explain the situation to my client. why am i doing this, how is it benefiting the client . it’s important to make them understand i’m not just inventing work to rake in more gold.
clients are surprisingly permissive most of the time and i can sleep better at night. win-win!
source:
http://swizec.com/blog/are-you-a-boy-scout-coder/swizec/3471
Opinions expressed by DZone contributors are their own.
Comments