Taro Logo

What are some good resources for learning how to write better code?

Profile picture
Mid-Level Software Engineer at A Large Financial Services Company3 months ago

What are some good books or online resources for learning how to write better code? I am looking for actual code examples demonstrating best practices for someone who already has programming experience but who wants to improve. Examples of topics I am looking to see covered would be whether a function should always include a return, when it makes sense to use try-catch instead of handling bad input with control flow, or when to use different approaches for handling invalid input.



  • 2
    Profile picture
    Tech Lead @ Robinhood, Meta, Course Hero
    3 months ago

    If you haven't already, I recommend going through my code quality course: [Course] Level Up Your Code Quality As A Software Engineer

    As the course digs into, there's no such thing as objectively good code and anything claiming to be "best practice" needs to be taken with a grain of salt. My overall approach to code is "When in Rome, do as the Romans do". So for all the scenarios you mentioned, you should just figure out what your teammates are doing and then do that. Consistency is a huge component behind readability, and readability lets engineers iterate on code faster to improve it for the end-user (the ultimate goal of any and all code).

    At the end of the day, coding is all about trade-offs. There are very, very few scenarios where it's 100% correct to always do a certain thing. If you want to understand the trade-offs, feel free to start discussions in the Taro forum with code samples (we use Markdown so this is supported). I'm personally happy to chime in on any of those.

    Here's an example of a code snippet:

    try {
      // Some crazy code here
    } catch (exception: ScaryException) {
      // Should I be doing this instead of using if statements?
  • 3
    Profile picture
    Tech Lead/Manager at Meta, Pinterest, Kosei
    3 months ago

    In addition to the course that Alex mentioned, one very specific tactic I can recommend:

    • Identify engineers in your company you respect (if you don't know, just find the senior-most folks).
    • Find some code changes they've submitted recently
    • Apply their code change locally and run it. Try to break their code. Add print statements. Consider alternative approaches. If you do this regularly, you'll quickly understand (and then write) better code.