WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WordPress coding standards (4 posts)

  1. Neil
    Member
    Posted 2 years ago #

    Hi,

    I started learning WordPress plugin development and I would like to learn as many things as possible the right way at the beginning.

    I have been going over the coding standards page:
    http://codex.wordpress.org/WordPress_Coding_Standards

    In the "Space Usage" section, it suggests to add spaces before and after parenthesis of blocks and functions. I accept that this improves the readability but when I checked the WordPress installation files (e.g., wp-login.php) I noticed that they are not standardized either. In some places there are spaces as suggested, but in some places there aren't.

    I am used to coding with no spaces (if not necessary) and I want to ask your opinion about this coding standards. Is it better that I stick to them? If they are standards, why the WordPress files are not following them strictly?

    Thanks,

    Nail

  2. If they are standards, why the WordPress files are not following them strictly?

    The standards are really a guideline to make PHP code more readable and by extension understandable. Adherence is subjective and that makes it dubious to decide what's good or not.

    Although while bad code is easy to spot, it's not so easy to clearly state where the line is. ;)

    I am used to coding with no spaces (if not necessary) and I want to ask your opinion about this coding standards. Is it better that I stick to them?

    It's your code but it really comes up when you submit your plugin, theme, or patch for others to review. No spaces doesn't necessarily mean not readable but it could.

    If you want your code to be accepted into the plugin repo, ask yourself "if a complete stranger who understands PHP read my code, would he get it or walk away with a headache?"

    That's part of what that standard is attempting to address and help you create clean concise readable code. It's also why I think it's better to stick with them.

  3. Actually the only reason un-readable code MIGHT get yanked from the repo is if it looks like the author's intentionally obfuscating naughty things.

    But there isn't much to prevent someone from getting hosted, just the cardinal 'don't be a d**k' ;)

  4. Neil
    Member
    Posted 2 years ago #

    Thanks for your ideas.

Topic Closed

This topic has been closed to new replies.

About this Topic