1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-28 02:50:27 +00:00
TiddlyWiki5/editions/dev/tiddlers/from tw5.com/TiddlyWiki Coding Style Guidelines.tid

44 lines
1.6 KiB
Plaintext
Raw Normal View History

2015-04-30 15:22:39 +00:00
modified: 20150430153333808
2014-01-12 16:56:05 +00:00
title: TiddlyWiki Coding Style Guidelines
2014-02-16 19:10:55 +00:00
tags: dev
2014-01-12 16:56:05 +00:00
! Motivation
2014-06-18 12:54:24 +00:00
TiddlyWiki is a large project with many interested parties. It benefits everyone if the code is as easy to read as possible. A key part of that it must be written and laid out consistently -- the code should read as though it were written by a single author.
2014-01-12 16:56:05 +00:00
! Guidelines
2014-10-16 09:01:02 +00:00
This list of guidelines isn't exhaustive but captures some of the common problems. The ultimate guide is the existing TiddlyWiki code-base. There are still some places where the coding guidelines aren't used consistently within the core; pull requests are welcome to help resolve those issues.
2014-01-12 16:56:05 +00:00
!! Tabs and whitespace
TiddlyWiki uses 4-character tabs for indenting.
One blank line is used to separate blocks of code. Occasional blank lines are permitted within blocks for clarity, but should be avoided unless they solve a specific readability problem.
!! Layout of basic constructs
See the following example for layout of basic JavaScript constructs:
2014-11-28 10:06:17 +00:00
```js
2014-01-12 16:56:05 +00:00
/*
Multiline comments are used to introduce a block of code such as a function definition
*/
function demoFunction(param,more) {
2015-04-30 15:22:39 +00:00
// Proper sentence capitalisation for comments; prefer strict equality checks
if(condition === "something") {
// Always use braces, even when optional; no space between "if" and the brackets; always spaces around binary operators
2014-01-12 21:28:58 +00:00
something = somethingElse;
2014-01-12 16:56:05 +00:00
myOtherFunction(one,two); // No whitespace within function parameters
do {
myCondition.explore(); // Always use semicolons
} while(myCondition < worsens);
}
}
```
!! Strings
Double quotes are preferred over single quotes for string literals.