Taro Logo
1

How to write bug-free code as a junior engineer?

Profile picture
Associate Member of Technical Staff at Taro Community3 months ago

I'm an entry-level engineer who recently joined a team working in a new domain for me. Despite my best efforts, I find myself making mistakes in my code, such as forgetting edge cases, missing function calls, or mishandling character escaping (to quote a few recent ones). While these errors should ideally be caught during unit or integration testing, our team lacks a formal review process, leaving me solely responsible for testing my code before it gets merged. Consequently, bugs occasionally slip through, requiring post-deployment fixes. Although we're not a customer-facing team, I am afraid this puts a question on my reliability and erodes trust the team can place on me to write good code, that doesn't require iterations of fixes.

Could anyone offer advice on how I can better anticipate scenarios and prevent bugs from being introduced? I'm also unsure whether my challenges stem from a lack of technical skills or effective communication. How can I ensure I'm asking the right questions and considering all relevant factors before writing code?

Any insights or suggestions would be greatly appreciated.

93
2

Discussion

(2 comments)
  • 1
    Profile picture
    Tech Lead @ Robinhood, Meta, Course Hero
    3 months ago

    What's your current process? From this post, it seems like you're operating more in a single-player model instead of a multi-player model where you are proactively soliciting feedback before a single line of code is written. If you build a reputation as a stellar planner (i.e. someone who lays out the plan in the task and is great at getting feedback for it), you will be on your way to a mid-level promotion in no time! Follow the advice from my code quality course starting from this lesson: Sweat The Details, Call Out Edge Cases

    When it comes to edge cases, the course also has an incredibly detailed example which hopefully helps configure your brain at least a little bit better to catch edge cases going forward.

    All that being said, I want to make clear that it's 100% okay to make mistakes, especially for a junior engineer working on a new domain like yourself. What's important is that you never make the same mistake twice. Follow the advice here to do that:

  • 1
    Profile picture
    Tech Lead/Manager at Meta, Pinterest, Kosei
    2 months ago

    IMO the goal should NOT be to write bug-free code. (This is an impossible task.) The goal should be to have enough tests/metrics/alerts in place so that you can quickly identify and fix anything that goes wrong.

    This discussion can/should be included in the test plan of your diff :)

    Very relevant discussion: Getting over a fear of breaking code - How to do it?