Think, think, think… before you code!

This article was first published on gautamdhameja.com .

Image source:
https://whycantpeoplejustthink.wordpress.com/

I have a weird habit — I am rarely at my work desk when I have a programming task at hand. When I’m not at my desk, I’m mostly walking around or looking at a whiteboard in the most secluded focus room available. The reason being — It helps me focus; it helps me understand the bigger picture; it helps me design the solution in a much better way. And after all these years, I’ve realized, planning your code is even more important than actually coding.

Most of the time, we as programmers, out of passion and excitement, rush to solve the programming problems. As soon as the requirement document is available, as soon as there is an acceptance criteria in the user story, as soon as the meeting is over, we just fire up the IDE and start coding, don’t we? I have been like this before, during the first couple of years of my career. Then I realized that this habit is actually slowing me down rather than making me faster at solving problems. Here’s how.

Let’s take an example — let’s say that we have a simple problem at hand to read data from a database, transform it and then show it back to the user in a web page. To make this happen, what I would’ve done a few years ago is — 1. Create data model classes, 2. Create a database service/wrapper class, 3. Get data from database in the service class using data models and then pass it to the web page using the view-model object. And voila, work is done and I can go home and play with my dog. :)

Now, let’s see what could have been better in the above solution and what I missed — I didn’t try to find if there is already a service/wrapper class available in the solution which can be reused, I didn’t check if the models can be reused or derived from any existing classes, I didn’t think about extensibility, scalability and performance of the app, I didn’t think about using the right data structures, design patterns and code structuring. Well, it seems I missed a lot of things.

If I would’ve thought of all these things, the overall application would have been much more organized, stable and performant, to say the least. Most of the time, when we rush to code, without thinking and proper planning, we miss all these things and when the time comes to release the bits in production, then we are hit with all the bugs related to performance and regression. This ultimately makes us slow and delays the deliverable.

Now, after realizing this, I tried to change my approach towards solving programming problems. What I do now is I take time before starting to code. First of all, I try to find if there is an existing solution to the problem I am trying to solve. Sometimes there is a solution in the same code base and we just have to look for it, otherwise internet/google/stack overflow are always there to help. Then, if there are multiple solutions available then I try to find out which one best fits the existing code base and timelines.

And then starts the fun part — I generally write the problem statement and then draw possible solutions on a white board and then look at them to get the bigger picture. Once I have that big picture in my head then I take a walk and think about the pros and cons of these solution options. By the time I reach my desk, I generally have a decision and a final solution to code. This approach has helped me solve some of the most challenging problems with the most satisfying solutions. At the end of the day, I guess, we all are looking for satisfaction from our work, aren’t we?

codeburst责编内容来自:codeburst (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » Think, think, think… before you code!

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录