Besides some of the very, very obvious (don’t copy/paste 100 lines of code, make it a function! Write comments for your future self who has forgotten this codebase 3 years from now!), I’m not sure how to write clean, efficient code that follows good practices.

In other words, I’m always privating my repos because I’m not sure if I’m doing some horrible beginner inefficiency/bad practice where I should be embarrassed for having written it, let alone for letting other people see it. Aside from https://refactoring.guru, where should I be learning and what should I be learning?

  • @[email protected]
    link
    fedilink
    7
    edit-2
    1 month ago

    The already given advice is good: use linters, read.

    However, just to say something different: Write a lot of code and do complex stuff. The reason you write code that “just works” is most probably because that’s all you’ve needed.

    Good code is good for a reason: it’s maintainable. If you never write code that needs to be maintained, you’re going to go uphill. If you write complex code you’ll NEED to write maintainable code. After refactoring the same kind of code multiple times, you’ll see why it is a bad pattern, and you’ll learn good code because you need it.

    Avoid “simple” languages like python or JavaScript. They let you patch old code too easily to work with new code, creating a mess of legacy code that you’ll be afraid to touch. Rust, C++, Ada, java and many others are much less forgiving on bad code, specially due to their type system and compilers.