Testing Challenge – Clean Up My Code
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
― Martin Fowler
Martin Fowler said it all. It is easy to write code that machines understand. They don’t even read the code but the compiler is there to translate your code into machine language which computer understands. Now, people do not have compilers to help them with understanding bad code. We need to read it, use our brain to draw conclusions out of it and that is how we make sense from what we read. For me it is OK to write a working draft and then clean up my code as the last step of the process.
Don’t understand the code you’re reading?
What happens when we don’t understand what we read? Usually, it’s a feeling of confusion, frustration, despair, denial and anger, not necessarily in that order. In short, it’s a WTF moment. Someone wrote that the measure of good code is a number of WTF per minute. The lower number is better. So, the conclusion is: don’t do to others what you don’t want others to do to you. Write clean code and have it easily maintainable. I wrote down some of the advice for writing clean code although this is not all there is to know about it.
The challenge
Below is a code snippet written with all the possible anti best practice for coding. Review it, try to understand what it does and make a clean solution of it. It was written in Selenium with Java which should be widely used solution. The example shows small snippet of logging in to Demo Blaze website. If you want to, you can rewrite the clean version with a different programming language, Cypress, Playwright or any other tool you predominantly use.
A textual explanation of what should be changed and avoided will be sent in the next newsletter. Make sure you subscribe to my newsletter to get the advice.