summaryrefslogtreecommitdiffstats
path: root/crawl-ref/docs/coding_conventions.txt
diff options
context:
space:
mode:
authorpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-17 23:32:51 +0000
committerpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-17 23:32:51 +0000
commitcd1d40cfd788e60fc2b1e8b743d80985225f8d21 (patch)
tree41da99de44ba56f6a648f25078b693c4de80a128 /crawl-ref/docs/coding_conventions.txt
parent96dc1ace19b1b73246b0972754aab54ae3b9b55d (diff)
downloadcrawl-ref-cd1d40cfd788e60fc2b1e8b743d80985225f8d21.tar.gz
crawl-ref-cd1d40cfd788e60fc2b1e8b743d80985225f8d21.zip
First draft of coding conventions. If you're reading this, and you're interested,
can you comment? git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3695 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/docs/coding_conventions.txt')
-rw-r--r--crawl-ref/docs/coding_conventions.txt70
1 files changed, 70 insertions, 0 deletions
diff --git a/crawl-ref/docs/coding_conventions.txt b/crawl-ref/docs/coding_conventions.txt
new file mode 100644
index 0000000000..06f2b4ca7f
--- /dev/null
+++ b/crawl-ref/docs/coding_conventions.txt
@@ -0,0 +1,70 @@
+Crawl coding conventions
+========================
+
+This file documents the conventions currently in use in the crawl codebase,
+as well as the conventions new and/or modified code should conform to.
+
+Use 4 spaces to indent, and indent with spaces only (no tabs).
+Use underscores_as_spaces instead of mixedCase. Other conventions are
+pointed out by example, below:
+
+
+// - Global variables are capitalized and underscored.
+// Warning: there are currently many globals which don't do this.
+int Some_Global_Variable;
+
+
+// - Internal functions are prefixed with underscores.
+// Warning: This is a new convention, so much code doesn't follow it.
+static void _remove_from_inventory(item_def* item);
+
+
+// - Functions use underscores_as_spaces, but there are currently
+// a lot of mixedCase functions.
+void destroy_item(item_def* item)
+{
+ // - Variables use underscores too.
+ int item_weight = /* ... */;
+
+ if (item_weight > SOME_LIMIT)
+ {
+ // - Braces are put on their own line.
+ do_something();
+ }
+
+ // - It's allowable to omit braces, but be careful.
+ if (item != NULL)
+ _remove_from_inventory(item);
+ else
+ _something_else();
+}
+
+
+// - There's no convention for class/struct names (yet?)
+class TextDB
+{
+ public:
+ // - No rules for static member functions; they're not used often anyway.
+ static void whatever();
+
+ // - Public member functions: named like functions.
+ void* get_value();
+
+ private:
+ // - Internal member functions: also named like functions.
+ void _parse_text_file(const char*);
+
+ // - Member variables get a prefix.
+ DB* m_db;
+
+ // - Static member variables get a prefix, too.
+ std::vector<DB*> sm_all_dbs;
+};
+
+
+// - But structures tend to use underscores
+struct coord_def
+{
+ // - Simple structures don't need the "m_" prefixes
+ int x, y;
+};