33
44= Coding Style
55
6- This chapter describes the source code style preferred by the LinuxCNC team.
6+ LinuxCNC is developed in C/C++, Python, BASH and Tcl/TK.
7+ Documentation is written in asciidoc, which includes parts of the
8+ UNIX man pages.
79
8- == Do no harm
10+ These computer languages are not completely independent from each other.
11+ So is C/C++ used to extend the functionality of the other scripting
12+ languages. And executables implemented in any of these languages
13+ may be called from anywhere, mostly from the scripting languages.
14+
15+ Every computer language is its very own syntax and customs to be structured,
16+ and many flavours with every developer being very opinionated about
17+ their very own being the best. And while the exact style does not matter
18+ too much, it is important for the eye to see the source code formatted
19+ consistently.
20+
21+ This chapter hence describes the source code style preferred by the
22+ LinuxCNC team. This shall improve our overall efficiency and avoid
23+ intensive discussions (aka bike-shedding) about how to style it best.
24+
25+ == General comments
26+
27+ === Do no harm
928
1029When making small edits to code in a style different than the one
1130described below, observe the local coding style. Rapid changes from one
@@ -19,17 +38,28 @@ Do not use an editor that makes unneeded changes to whitespace (e.g.,
1938which replaces 8 spaces with a tabstop on a line not otherwise
2039modified, or word-wraps lines not otherwise modified).
2140
22- == Tab Stops
41+ === Tab Stops
2342
2443A tab stop always corresponds to 8 spaces. Do not write code that
2544displays correctly only with a differing tab stop setting.
2645
27- == Indentation
46+ === Indentation
2847
2948Use 4 spaces per level of indentation. Combining 8 spaces into one tab
3049is acceptable but not required.
3150
32- == Placing Braces
51+ === Translations
52+
53+ All program code and documentation is written in US English.
54+ All translations (which soon includes the documentation) are performed
55+ with the help of the (https://hosted.weblate.org/projects/linuxcnc/)[weblate]
56+ services. Our users and developers are kindly asked to help with the
57+ translation. The source tree then maintains the .po files in sync with that online
58+ representation.
59+
60+ == Code implementing functionality for the machine
61+
62+ === Placing Braces
3363
3464Put the opening brace last on the line, and put the closing brace first:
3565
@@ -68,7 +98,7 @@ This brace-placement also minimizes the number of empty (or almost
6898empty) lines, which allows a greater amount of code or comments to be
6999visible at once in a terminal of a fixed size.
70100
71- == Naming
101+ === Naming
72102
73103C is a Spartan language, and so should your naming be. Unlike Modula-2
74104and Pascal programmers, C programmers do not use cute names like
@@ -100,7 +130,7 @@ If you are afraid to mix up your local variable names, you have
100130another problem, which is called the function-growth-hormone-imbalance
101131syndrome. See next chapter.
102132
103- == Functions
133+ === Functions
104134
105135Functions should be short and sweet, and do just one thing. They
106136should fit on one or two screenfuls of text (the ISO/ANSI screen size
@@ -127,7 +157,7 @@ easily keep track of about 7 different things, anything more and it
127157gets confused. You know you're brilliant, but maybe you'd like to
128158understand what you did 2 weeks from now.
129159
130- == Commenting
160+ === Commenting
131161
132162Comments are good, but there is also a danger of over-commenting.
133163NEVER try to explain HOW your code works in a comment: it's much better
@@ -149,7 +179,7 @@ say why something needs fixing. When a change has been made to the
149179affected portion of code, either remove the comment, or amend it to
150180indicate a change has been made and needs testing.
151181
152- == Shell Scripts & Makefiles
182+ === Shell Scripts & Makefiles
153183
154184Not everyone has the same tools and packages installed. Some people
155185use vi, others emacs - A few even avoid having either package
@@ -163,7 +193,7 @@ does not provide, than the script will break for some users. The same
163193would apply to mawk. In short, use the generic awk invocation in
164194preference to gawk or mawk.
165195
166- == C++ Conventions
196+ === C++ Conventions
167197
168198C++ coding styles are always likely to end up in heated debates (a bit
169199like the emacs versus vi arguments). One thing is certain however, a
@@ -254,17 +284,128 @@ of .c and .h are reserved for plain C. Headers are for class, method,
254284and structure declarations, not code (unless the functions are declared
255285inline).
256286
257- == Python coding standards
287+ === Python coding standards
258288
259289Use the http://www.python.org/dev/peps/pep-0008/[PEP 8] style for
260290Python code.
261291
262- == Comp coding standards
292+ === Comp coding standards
263293
264294In the declaration portion of a .comp file, begin each declaration at
265295the first column. Insert extra blank lines when they help group related
266296items.
267297
268298In the code portion of a .comp file, follow normal C coding style.
269299
300+ == Code describing the functionality for the human
301+
302+ This is a very recent (1/2022) part of this document. Please help shaping it if you are familiar with asciidoc.
303+
304+ After the website, and maybe the one or other YouTube Video, the
305+ LinuxCNC documentation is likely the first point of contact for any new
306+ user. The talent to get the documentation right is mostly disjunct from
307+ computationally orchestrating all the moving parts of a mill or lathe,
308+ though. Still, we need this to shine if we want LinuxCNC to shine and
309+ for a transfer of our knowledge for the next generation - this seems
310+ fair to say for a project that was started in the last millenium and few
311+ individuals buying their own mills/lathes before their hair turns gray.
312+
313+ === Overall structure of documentation
314+
315+ There are two basic documents, i.e. the
316+ * Users' Guide and the
317+ * Developers' Guide
318+
319+ All documents created belong to either of these "parental documents"
320+ and are included from the respective document, either directly or that
321+ included file includes it.
322+
323+ === Common challenges
324+
325+ * header tags block like toc etc
326+
327+ Every file should start with a header. This is typically
328+ ----
329+ :lang: en
330+ ----
331+ and longer documents may also chose to set
332+ ----
333+ :toc:
334+ ----
335+ This should be followed by an anchor for that section or chapter that is
336+ represented in that file, like
337+ ----
338+ [[cha:filename]]
339+ ----
340+ If the file has a language-extension like _fr then this extension shall not become part of the anchor.
341+ For a better consistency, and maintainability, the anchors need to be the same for all langages.
342+ If the page needs extras, e.g. for the syntax-highlighting, then such lines may then follow.
343+
344+ * anchors for titles and other blocks
345+
346+ If a chapter/section header shall be granted the option to be
347+ referenced from another part of the documentation then it needs an achor.
348+ The anchor shall be a combination of an indicator of the kind
349+ of block that is referenced (cha,sec,fig,tab,...) together with a
350+ short name identifying the object.
351+
352+ * index entries for titles and other blocks
353+
354+ ?
355+
356+ * lists formatting
357+
358+ ?
359+
360+ * usage of lists vs titles
361+
362+ ?
363+
364+ * use of bold and italic
365+ * structure/page splitting guidance
366+ - avoid 2k+ char long lines
367+ * table formatting
368+
369+ Tables can be presented with a series of options.
370+
371+ - header
372+
373+ With the header-option set, the fist line will be interpreted accordingly.
374+
375+ - column width
376+
377+ in ideal column, the column is constituted only by its data. No
378+ vertical separators should be required. The horizontal alignment will
379+ also not be required since the writing itself is horizontal enough.
380+
381+ If individual fields have too much text then a line-break within that
382+ field should be provoked.
383+
384+ - what lines are visible
385+
386+ As motivated above, there should be no grid lines.
387+ The top and bottom lines should separate the table from the surrounding text.
388+ Another line could be motivated between the header and the main body.
389+
390+ - captions
391+
392+ Asciidoc makes it difficult to nicely prepare captions. At the same time,
393+ captions are the only bit of the whole document that even with the first flick
394+ through the document will not escape the reader's attention.
395+ ----
396+ Instruction needs to be added
397+ ----
398+
399+ - reference
400+
401+ * figure formatting (captions)
402+ - reference
403+ - caption
404+ ----
405+ Instruction needs to be added
406+ ----
407+ * footnotes
408+ * comments
409+ * interaction with other media like videos
410+
270411// vim: set syntax=asciidoc:
0 commit comments