Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Thanked 0 Times in 0 Posts

    How do you write maintainable code?

    I have developed a few tips, but would like to hear your ideas too.

    • Never nest parentheses. I refactor any simple inner expression as its own local variable.
    • Type both opening/closing brackets/parentheses/quotes before entering any content. I type both the opening and closing, then left arrow, and enter the inner content (then right arrow, if needed). If I abandon this construct to refactor out some complicating subexpression, then at least this expression will be syntactically complete on its own.

    I have many others, but would like to hear others tips as well.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Near Chicago, IL, USA
    Thanked 32 Times in 31 Posts
    • comments are your friends
    • there is no substitute for good naming conventions
    • each function does ONE thing (procedural coding basic for good code) and it is encapsulated in "black box" fashion
    • avoid global variables when at all possible. If it isn't a pseudo-constant, you probably don't need it to be global.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts