Blame HACKING

Packit a7d494
Guidelines for GtkSourceView
Packit a7d494
============================
Packit a7d494
Packit a7d494
GtkSourceView source code is maintained using the git version control system
Packit a7d494
and is available at the following location:
Packit a7d494
Packit a7d494
    git://git.gnome.org/gtksourceview
Packit a7d494
Packit a7d494
Or if you have an account on GNOME servers:
Packit a7d494
Packit a7d494
    ssh://USERNAME@git.gnome.org/git/gtksourceview
Packit a7d494
Packit a7d494
A web interface is available at:
Packit a7d494
Packit a7d494
    https://git.gnome.org/browse/gtksourceview/
Packit a7d494
Packit a7d494
Please don't commit directly to the git repository unless
Packit a7d494
you have been given the green light to commit freely to GtkSourceView.
Packit a7d494
When in doubt assume you haven't ;-).
Packit a7d494
Packit a7d494
Please attach patches in bugzilla (http://bugzilla.gnome.org).
Packit a7d494
If the patch fixes a bug that is not reported yet in bugzilla or is
Packit a7d494
an enhancement, create a new bugreport.
Packit a7d494
Packit a7d494
Please create patches with the git format-patch command.
Packit a7d494
Packit a7d494
If you are a translator feel free to mark strings for translation,
Packit a7d494
fix typos in the code, etc.
Packit a7d494
Packit a7d494
Please send patches for build & configure fixes too.  I really appreciate
Packit a7d494
your help, I just want to review these fixes before applying.
Packit a7d494
Packit a7d494
If you are a "build sheriff", feel free to commit fixes for build and
Packit a7d494
configure.
Packit a7d494
Packit a7d494
When committing to the GtkSourceView git repository make sure to include a
Packit a7d494
meaningful commit message. Changes without a sufficient commit message
Packit a7d494
will be reverted. Commit messages should have the following format:
Packit a7d494
Packit a7d494
=== begin example commit ===
Packit a7d494
Short explanation of the commit
Packit a7d494
Packit a7d494
Longer explanation explaining exactly what's changed, whether any
Packit a7d494
external or private interfaces changed, what bugs were fixed (with bug
Packit a7d494
tracker reference if applicable) and so forth. Be concise but not too brief.
Packit a7d494
=== end example commit ===
Packit a7d494
Packit a7d494
  - Always add a brief description of the commit to the _first_ line of
Packit a7d494
    the commit and terminate by two newlines (it will work without the
Packit a7d494
    second newline, but that is not nice for the interfaces).
Packit a7d494
Packit a7d494
  - First line (the brief description) must only be one sentence and
Packit a7d494
    should start with a capital letter unless it starts with a lowercase
Packit a7d494
    symbol or identifier. Don't use a trailing period either. Don't exceed
Packit a7d494
    72 characters.
Packit a7d494
Packit a7d494
  - The main description (the body) is normal prose and should use normal
Packit a7d494
    punctuation and capital letters where appropriate. Normally, for patches
Packit a7d494
    sent to a mailing list it's copied from there.
Packit a7d494
Packit a7d494
  - When committing code on behalf of others use the --author option, e.g.
Packit a7d494
    git commit -a --author "Joe Coder <joe@coder.org>" and --signoff.
Packit a7d494
Packit a7d494
Packit a7d494
Code conventions
Packit a7d494
================
Packit a7d494
Packit a7d494
You may encounter old code that doesn't follow all the following code
Packit a7d494
conventions, but for new code it is better to follow them, for consistency.
Packit a7d494
Packit a7d494
  - Avoid trailing whitespace.
Packit a7d494
Packit a7d494
  - Indent the C code with tabulations with a width of eight characters.
Packit a7d494
Packit a7d494
  - The files should have a modeline for the indentation style.
Packit a7d494
Packit a7d494
  - All blocks should be surrounded by curly braces, even one-line blocks. It
Packit a7d494
    spaces out the code, and it is more convenient when some code must be added
Packit a7d494
    or removed without the need to add or remove the curly braces.
Packit a7d494
Packit a7d494
  - Follow the C89 standard. In particular, no "//"-style comments.
Packit a7d494
Packit a7d494
  - As a general rule of thumb, follow the same coding style as the surrounding
Packit a7d494
    code.
Packit a7d494
Packit a7d494
  - Do not be cheap about blank lines, spacing the code vertically help
Packit a7d494
    readability. However never use two consecutive blank lines, there is really
Packit a7d494
    no need.
Packit a7d494
Packit a7d494
Packit a7d494
Programming best practices
Packit a7d494
==========================
Packit a7d494
Packit a7d494
GtkSourceView is a pretty big piece of software, developed over the years by
Packit a7d494
different people and GNOME technologies. Some parts of the code may be a little
Packit a7d494
old. So when editing the code, we should try to make it better, not worse.
Packit a7d494
Packit a7d494
Here are some general advices.
Packit a7d494
Packit a7d494
  - Simplicity: the simpler code the better. Any trick that seem smart when you
Packit a7d494
    write it is going to bite your ass later when reading the code. Given that
Packit a7d494
    you spend 90% of the time staring at the code and 10% writing it, making
Packit a7d494
    reading the code harder is a net loss.
Packit a7d494
Packit a7d494
  - Brevity: make an effort to refactor common code into utility functions and
Packit a7d494
    use library function whenever is possible: every time you cut and paste a
Packit a7d494
    line of code you are throwing away all the precious seconds of your life
Packit a7d494
    that you will later spend trying to figure out the differences among the two
Packit a7d494
    copies that will have surely diverged.
Packit a7d494
Packit a7d494
  - Code for change: code is bound to contain bugs no matter how well it is
Packit a7d494
    written. A good coding style allows to fix these bugs with minimal changes
Packit a7d494
    instead of reformatting a whole section of unrelated code, this is
Packit a7d494
    especially important to make patch review easier and to easily understand
Packit a7d494
    the commit history. Some practical examples are:
Packit a7d494
Packit a7d494
      - Factor code into self contained functions so that changing a function
Packit a7d494
	does not require to change all the callers.
Packit a7d494
Packit a7d494
      - Do not align variable declaration, "case" statements etc, since this
Packit a7d494
	will inevitably mean that when a line will change you'll have to
Packit a7d494
	reformat all the surrounding ones.
Packit a7d494
Packit a7d494
      - Declare variables in the strictest scope as possible.
Packit a7d494
Packit a7d494
      - Reorder functions so that you do not need prototypes for static
Packit a7d494
	functions so that when you change them you need to change them only in
Packit a7d494
	one place.
Packit a7d494
Packit a7d494
  - Self documentation and code comments: use code comments parsimoniously. Code
Packit a7d494
    should be written so that it is clear and evident without the need of
Packit a7d494
    comments. Besides, comments usually get outdated when the code is changed
Packit a7d494
    and they become misleading. In particular avoid stating the obvious e.g. "a
Packit a7d494
    = 1; /* assign 1 to a */". Use good function names and variables to make the
Packit a7d494
    code self-documented.
Packit a7d494
Packit a7d494
    A good function name is one that explain clearly all what its code really
Packit a7d494
    does. There shouldn't be hidden features. If you can not find easily a good
Packit a7d494
    function name, you should probably split the function in smaller pieces. A
Packit a7d494
    function should do only one thing, but do it well.
Packit a7d494
Packit a7d494
    Please avoid lots of one-letter variables. And a variable should be used for
Packit a7d494
    only one purpose.
Packit a7d494
Packit a7d494
    Self-documentation is obviously not always possible, so when a comment is
Packit a7d494
    needed, it is needed. In those cases make sure to explain why and not only
Packit a7d494
    how a specific thing is done: you can deduce the "how" from the code, but
Packit a7d494
    not the "why".  Public library functions should always be documented and in
Packit a7d494
    particular should include the calling conventions, e.g. if the result should
Packit a7d494
    be freed by the caller.
Packit a7d494
Packit a7d494
    Do not use fancy frames around comments like a line full of
Packit a7d494
    /*---------------*/ etc.
Packit a7d494
Packit a7d494
  - Contribute below on the stack. Fix a problem at the right place, instead of
Packit a7d494
    writing hacks to work around a bug or a lack of feature in an underlying
Packit a7d494
    library.
Packit a7d494
Packit a7d494
Packit a7d494
See also
Packit a7d494
========
Packit a7d494
Packit a7d494
https://wiki.gnome.org/Apps/Gedit/DevGettingStarted
Packit a7d494
https://developer.gnome.org/programming-guidelines/stable/
Packit a7d494
https://wiki.gnome.org/Projects/GTK%2B/BestPractices
Packit a7d494
http://ometer.com/hacking.html
Packit a7d494
http://blogs.gnome.org/swilmet/2012/08/01/about-code-quality-and-maintainability/
Packit a7d494
Packit a7d494
For a shared library:
Packit a7d494
Packit a7d494
http://davidz25.blogspot.be/2011/07/writing-c-library-intro-conclusion-and.html
Packit a7d494
http://akkadia.org/drepper/
Packit a7d494
	- How to Write Shared Libraries
Packit a7d494
	- Good Practices in Library Design, Implementation, and Maintenance
Packit a7d494
Packit a7d494
Packit a7d494
Thanks,
Packit a7d494
Packit a7d494
  The GtkSourceView team.