What are some of the best practices to keep in mind while learning to code?

  • I don't know if this list is useful for "learning to code", but I have been at this for the past 20 years and I'm still learning to code!

    These are my own silent confessions. YMMV.

    1. Condition yourself to be sharply aware and mindful whenever you're "copying and pasting". It's a big code smell. Stop, think and ask if you can refactor sensibly into reusable functions, views, models etc.

    2. Be ruthless with naming conventions. If a table, function, API name doesn't sound like what it is supposed to be doing or used for, change it before it's too late. You'll be very sorry if you let this type of procrastination pass as it will confuse you later or worse may have cascading effect on poor naming conventions because one object was named incorrectly at the start.

    3. If you find your own code difficult to enhance and modify the next time you visit it, spend the time immediately to refactor. Next time it's easier to continue. Avoiding this will result in two things:

    3.1 You'll subconsciously develop a strong aversion to visiting the piece of code again (often resulting in all sorts of compensating hacks. Unhealthy holy cows can emerge.)

    3.2 You'll doom your successor for sure.

    4. Don't write programs with no runtime configuration capabilities.

    5. Don't write programs with more than 2 runtime configuration options. If your program needs more than 2, ship - then add as enhancement.

    6. Condition yourself to always think of loading resources as late as possible and release as early as possible. Make this an OCD type of habit. It pays off.

    7. Finally, don't be intimidated by the experts in the field. Don't ever strive to be better than or compare yourself competitively with anyone else. The experience is for yourself. Your programs are your own works, and your curiosity, creativity and insight should drive your passion to improve daily.

    (The last point applies to bodybuilding to, I suppose.)

  • Learn to use a version control system. Preferably git.

    While the direct impact on your code might not be apparent, it can help in subtle ways.

    1. When you check into a VCS, the code with have to take some form. It will ensure that, atleast at the directory level, the mini-project is organized.

    2. The assurance that you can always revert back a change will give you the confidence to not clutter your pages with blocks of commented code.

    3. A few months/years later, it will help you realize how much you have learnt.

    And, maybe, just maybe, you just might end up with a portfolio to showcase :)

  • Look for mentorship.

    Remember that no matter how you code, there are always both better and worse ways of doing it.

    Don't get too polarized about the language you start out with. All programming languages have pros and cons.

    When coding, Don't Repeat Yourself, use source control, and learn to be independent and resourceful by looking up stuff on your own instead of looking for someone to ask about it.

  • Get Feedback, early and continuously. By people you trust and am comfortable telling you to do things.

    Learning to code easily leads you down a rabbit hole where you can't see the outside anymore. Getting feedback allows you to see beyond what you do at the moment and also realise when to do the next step or move to a different topic.

  • This is stuff that takes years to realize

    - Formatting and readability including variable, table and field names (this save a lot of headaches in the long run)

    - File structure

    - Taking time to refactor to achieve the above.

    - Don't be afraid to try a junk idea you've thought about, just trying it would increase your chances of discovering something cool

  • When something is broken, and things will break often, understand as best you can why it's broken.

    Do that several thousand times.

  • The book is Code Complete.

    http://www.amazon.com/Code-Complete-Practical-Handbook-Const...

  • Learning to code? None.