How to Cut Corners and Stay Cool
Join the DZone community and get the full member experience.Join For Free
you have a task assigned to you, and you don't like it. you are simply not in the mood. you don't know how to fix that damn bug. you have no idea how that bloody module was designed, and you don't know how it works. but you have to fix the issue, which was reported by someone who has no clue how this software works. you get frustrated and blame that stupid project manager and programmers who were fired two years ago. you spend hours just to find out how the code works. then even more hours trying to fix it. in the end, you miss the deadline and everybody blames you . been there, done that?
there is, however, an alternative approach that provides a professional exit from this situation. here are some tips i recommend to my peers who code with me in teamed.io projects. in a nutshell, i'm going to explain how you can cut corners and remain professional, 1) protecting your nerves, 2) optimizing your project's expenses, and 3) increasing the quality of the source code.
here is a list of options you have, in order of preference. i would recommend you start with the first one on the list and proceed down when you have to.
this is the first and most preferable option. if you can't figure out how to fix an issue or how to implement a new feature, it's a fault of the project, not you. even if you can't figure it out because you don't know anything about ruby and they hired you to fix bugs in a ruby on rails code base — it's their fault. why did they hire you when you know nothing about ruby?
so be positive; don't blame yourself. if you don't know how this damn code works, it's a fault of the code, not you. good code is easy to understand and maintain.
don't try to eat spaghetti code; complain to the chef and ask him or her to cook something better (btw, i love spaghetti).
how can you do that? create dependencies — new bugs complaining about unclear design, lack of unit tests, absence of necessary classes, or whatever. be creative and offensive — in a constructive and professional way, of course. don't get personal. no matter who cooked that spaghetti, you have nothing against him or her personally. you just want another dish, that's all.
once you have those dependencies reported, explain in the main ticket that you can't continue until all of them are resolved. you will legally stop working, and someone else will improve the code you need. later, when all dependencies are resolved and the code looks better, try to get back to it again. if you still see issues, create new dependencies. keep doing this until the code in front of you is clean and easy to fix.
don't be a hero — don't rush into fixing the bad code you inherited. think like a developer, not a hacker . remember that your first and most important responsibility as a disciplined engineer is to help the project reveal maintainability issues. who will fix them and how is the responsibility of a project manager. your job is to reveal, not to hide. by being a hero and trying to fix everything in the scope of a single task, you're not doing the project a favor — you're concealing the problem(s).
edit: another good example of a dependency may be a question raised at, for example, stackoverflow.com or a user list of a third-party library. if you can't find a solution yourself and the problem is outside of the scope of your project — submit a question to so and put its link to the source code (in javadoc block, for example).
all dependencies are resolved and the code looks clean, but you still don't understand how to fix the problem or implement a new feature. it's too complex. or maybe you just don't know how this library works. or you've never done anything like that before. anyhow, you can't continue because you don't understand. and in order to understand, you will need a lot of time — much more than you have from your project manager or your scrum board. what do you do?
again, think positively and don't blame yourself. if the software is not clear enough for a total stranger, it's "their" fault, not yours. they created the software in a way that's difficult to digest and modify. but the code is clean; it's not spaghetti anymore. it's a perfectly cooked lobster, but you don't know how to eat lobster! you've never ate it before.
the chef did a good job; he cooked it well, but the restaraunt didn't give you any instructions on how to eat such a sophisticated dish. what do you do?
you ask for a manual. you ask for documentation. properly designed and written source code must be properly documented. once you see that something is not clear for you, create new dependencies that ask for better documentation of certain aspects of the code.
again, don't be a hero and try to understand everything yourself. of course you're a smart guy, but the project doesn't need a single smart guy. the project needs maintainable code that is easy to modify, even by someone who is not as smart as yourself. so do your project a favor: reveal the documentation issue, and ask someone to fix it for you. not just for you, for everybody. the entire team will benefit from such a request. once the documentation is fixed, you will continue with your task, and everybody will get source code that is a bit better than it was before. win-win, isn't it?
now the code is clean, the documentation is good enough, but you're stuck anyway. what to do? well, i'm a big fan of test-driven development, so my next suggestion would be to create a test that reproduces the bug. basically, this is what you should start every ticket with, be it a bug or a feature. catch the bug with a unit test! prove that the bug exists by failing the build with a new test.
this may be rather difficult to achieve, especially when the software you're trying to fix or modify was written by idiotssomeone who had no idea about unit testing. there are plenty of techniques that may help you find a way to make such software more testable. i would highly recommend you read working effectively with legacy code by michael feathers. there are many different patterns, and most of them work.
once you manage to reproduce the bug and the build fails, stop right there. that's more than enough for a single piece of work. skip the test (for example, using
annotation in junit 4) and commit your changes. then add documentation to the unit test you just created, preferably in the form of a
. explain there that you managed to reproduce the problem but didn't have enough time to fix it. or maybe you just don't know how to fix it. be honest and give all possible details.
i believe that catching a bug with a unit test is, in most cases, more than 80% of success. the rest is way more simple: just fix the code and make the test pass. leave this job to someone else.
very often you simply can't reproduce a bug. that's not because the code is not testable and can't be used in a unit test but because you can't reproduce an error situation. you know that the code crashes in production, but you can't crash it in a test. the error stack trace reported by the end user or your production logging system is not reproducable. it's a very common situation. what do you do?
i think the best option here is to create a test that will prove that the code works as intended. the test won't fail, and the build will remain clean. you will commit it to the repository and ... report that the problem is solved. you will say that the reported bug doesn't really exist in real life. you will state that there is no bug — "our software works correctly; here is the proof: see my new unit test."
will they believe you? i don't think so, but they don't have a choice. they can't push you any further. you've already done something — created a new test that proves everything is fine. the ticket will be closed and the project will move on.
if, later on, the same problem occurs in production, a new bug will be reported. it will be linked to your ticket. your experience will help someone investigate the bug further. maybe that guy will also fail to catch the bug with a test and will also create a new, successful and "useless" test. and this may happen again and again. eventually, this cumulative group experience will help the last guy catch the bug and fix it.
thus, a new passing test is a good response to a bug that you can't catch with a unit test.
sometimes the unit test technique won't work, mostly because a bug will be too important to be ignored. they won't agree with you when you show them a unit test that proves the bug doesn't exist. they will tell you that "when our users are trying to download a pdf, they get a blank page." and they will also say they don't really care about your bloody unit tests. all they care about is that pdf document that should be downloadable. so the trick with a unit test won't work. what do you do?
it depends on many factors, and most of these factors are not technical. they are political, organizational, managerial, social, you name it. however, in most cases, i would recommend you disable that toxic feature, release a new version, and close the ticket.
you will take the problem off your shoulders and everybody will be pleased. well, except that poor end user. but this is not your problem. this is the fault of management, which didn't organize pre-production testing properly. again, don't take this blame on yourself. your job is to keep the code clean and finish your tickets in a reasonable amount of time. their job is to make sure that developers, testers, devops, marketers, product managers, and designers work together to deliver the product with an acceptable number of errors.
production errors are not programmers' mistakes, though delayed tickets are. if you keep a ticket in your hands for too long, you become an unmanageable unit of work. they simply can't manage you anymore. you're doing something, trying to fix the bug, saying "i'm trying, i'm trying ..." how can they manage such a guy? instead, you should deliver quickly, even if it comes at the cost of a temporarily disabled feature.
ok, let's say none of the above works. the code is clean, the documentation is acceptable, but you can't catch the bug, and they don't accept a unit test from you as proof of the bug's absence. they also don't allow you to disable a feature, because it is critical to the user experience. what choices do you have? just one.
be professional and say "no, i can't do this; find someone else." being a professional developer doesn't mean being able to fix any problem. instead, it means honesty. if you see that you can't fix the problem, say so as soon as possible. let them decide what to do. if they eventually decide to fire you because of that, you will remain a professional. they will remember you as a guy who was honest and took his reputation seriously. in the end, you will win.
don't hold the task in your hands. the minute you realize you're not the best guy for it or you simply can't fix it — notify your manager. make it his problem. actually, it is his problem in the first place. he hired you. he interviewed you. he decided to give you this task. he estimated your abilities and your skills. so it's payback time.
your "no!" will be very valuable feedback for him. it will help him make his next important management decisions.
on the other hand, if you lie just to give the impression you're a guy who can fix anything and yet fail in the end, you will damage not only your reputation but also the project's performance and objectives.
you may also find these posts interesting:
- making your boss happy is a false objective
- daily stand-up meetings are a good tool for a bad manager
- how to be honest and keep a customer
- you do need independent technical reviews!
- five principles of bug tracking
Published at DZone with permission of Yegor Bugayenko. See the original article here.
Opinions expressed by DZone contributors are their own.