Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code indentation #18

Open
standage opened this issue Feb 19, 2016 · 2 comments
Open

Code indentation #18

standage opened this issue Feb 19, 2016 · 2 comments

Comments

@standage
Copy link
Member

The code quality / readability varies quite a bit throughout the xGDBvm codebase: we have everything from neatly organized code to quite-messy-held-together-by-duct-tape code and everything in between. In some cases, the indentation (or lack thereof) of the code makes it extremely difficult for the reader to understand.

Of course, we don't have the time or resources to go through and fix this comprehensively, but it may be a good idea whenever fixing bugs or adding new features to cleanup the relevant code, if needed. It may be a single code block, it may be an entire function, or maybe an entire file, depending on the scope of the bugfix/feature and the amount of time available.

Coding style involves a lot of stylistic/cosmetic decisions about brace placement, presence of whitespace around parentheses and commas, and so on. Most of these decisions are trivial in my opinion and have little effect on readability of code.

The one thing that DOES have a HUGE effect on readability is indentation. Inconsistent indentation doesn't just make the code hard to read, it can even suggest logical structure in the code that isn't really there, which takes extra work to comprehend.

I think a few simple guidelines would go a LONG way to improving the code. Again, this isn't something we need to implement with sweeping changes, but piecemeal as we are able.

  • Indentation should reflect logical flow/organization of the code. All of the following introduce logical structure into the program which should be reflected by indentation.
    • function definitions
    • conditionals (if statements)
    • loops (for, while, do)
  • All commands within a particular code block should have identical indentation.
  • Four white spaces is the preferred unit of indentation.
    • Two white spaces or a tab character are also common conventions.
    • It's less important which unit of indentation is used than it is to simply be consistent!
@vpbrendel
Copy link
Member

This is a common issue in software development. There is no need to invent new conventions.
For example, Linux has the "indent" command to address some of these issues for C.

I have used bcpp instead (for C/C++ programs); http://invisible-island.net/bcpp/bcpp.html

For this project, here are relevant links:
Perltidy for Perl programs: http://perltidy.sourceforge.net/
beautify_bash.py: http://arachnoid.com/python/beautify_bash_program.html

@jduvick
Copy link
Contributor

jduvick commented Feb 19, 2016

Here is one for PHP, although I haven't tried it.http://pear.php.net/package/PHP_Beautifier
I assume we also want to detab all files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants