File: StyleCpp.rst

package info (click to toggle)
seqan2 2.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 228,748 kB
  • sloc: cpp: 257,602; ansic: 91,967; python: 8,326; sh: 1,056; xml: 570; makefile: 229; awk: 51; javascript: 21
file content (1200 lines) | stat: -rw-r--r-- 35,588 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
.. sidebar:: ToC

    .. contents::

.. _infra-contribute-style-cpp:

C++ Code Style
==============

The aim of this style guide is to enforce a certain level of canonicity on all SeqAn code.
Besides good comments, having a common style guide is the key to being able to understand and change code written by others easily.

(The style guide partially follows the `Google C++ Code Style Guide <https://github.com/google/styleguide/blob/gh-pages/cppguide.xml>`_.)

C++ Features
------------

Reference Arguments
^^^^^^^^^^^^^^^^^^^

We prefer reference arguments to pointer arguments.
Use ``const`` where possible.

Use C-Style Logical Operators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Use ``&&``, ``||``, and ``!`` instead of ``and``, ``or``, and ``not``.

.. container:: foldable

    While available from C++98, MSVC does not support them out of the box, a special header ``<iso646.h>`` has to be included.
    Also, they are unfamiliar to most C++ programmers and nothing in SeqAn is using them.

Default Arguments
^^^^^^^^^^^^^^^^^

Default arguments to global functions are problematic with generated forwards.
They can be replaced with function overloading. So do not use them!

.. container:: foldable

    You can replace default arguments with function overloading as follows.
    Do not do this.

    .. code-block:: cpp

        inline double f(int x, double y = 1.0)
        {
            // ...
        }

Do this instead.

.. container:: foldable

    .. code-block:: cpp

        inline double f(int x, double y)
        {
            // ...
        }

        inline double f(int x)
        {
            return f(x, 1.0);
        }

Exceptions
^^^^^^^^^^

SeqAn functions throw exceptions only to report unrecoverable errors, usually during I/O.
Instead, functions expected to either success or fail use boolean return values to report their status.

Virtual Member Functions
^^^^^^^^^^^^^^^^^^^^^^^^

SeqAn heavily uses template subclassing instead of C++ built-in subclassing.
This technique requires using global member functions instead of in-class member functions.

If the design requires using in-class member functions, the keyword ``virtual`` should be avoided.
Virtual member functions cannot be inlined and are thus slow when used in tight loops.


``static_cast<>``
^^^^^^^^^^^^^^^^^

Prefer ``static_cast<>`` to C-style casts.

``const_cast<>``
^^^^^^^^^^^^^^^^

Use const-casts only to make an object const. Do not remove consts.
Rather, use the ``mutable`` keyword on selected members.
``const_cast<>`` is allowed for interfacing with external (C) APIs where the ``const`` keyword is missing but which do not modify the variable.

.. container:: foldable

    The following is an example where ``const_cast<>`` is OK:

    .. code-block:: cpp

        template <typename T>
        bool isXyz(T const & x)
        {
            return x._member == 0;
        }

        template <typename T>
        bool isXyz(T & x)
        {
            return const_cast<T const &>(x)._member == 0;
        }

``reinterpret_cast<>``
^^^^^^^^^^^^^^^^^^^^^^

Only use ``reinterpret_cast<>`` when you absolutely have to and you know what you are doing!
Sometimes, it is useful for very low-level code but mostly it indicates a design flaw.

pre/post increment/decrement
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Prefer the "pre" variants for decrement and increment, especially in loops.
Their advantage is that no copy of an object has to be made.

.. container:: foldable

    Good:

    .. code-block:: cpp

        typedef Iterator<TContainer>::Type TIterator;
        for (TIterator it = begin(container); atEnd(it); ++it)
        {
            // do work
        }

    Bad:

    .. code-block:: cpp

        typedef Iterator<TContainer>::Type TIterator;
        for (TIterator it = begin(container); atEnd(it); it++)
        {
            // do work
        }

Code Quality
------------

Const-Correctness
^^^^^^^^^^^^^^^^^

Write const correct code.
Read the `C++ FAQ const correctness article <https://www.parashift.com/c ++-faq-lite/const-correctness.html>`_ for more information.
Besides other things, this allows to use temporary objects without copying in functions that do not need to change their arguments.

Compiler Warnings
^^^^^^^^^^^^^^^^^

All code in the repository must compile without any warnings using the flags generated by the CMake system.

.. container:: foldable

    Currently, the GCC flags are:

    ::
        -W -Wall -Wstrict-aliasing -pedantic -Wno-long-long -Wno-variadic-macros

Style Conformance
^^^^^^^^^^^^^^^^^

Follow this code style whenever possible.
However, prefer consistency to conformance.

If you are editing code that is non-conforming consider whether you could/should adapt the whole file to the new style.
If this is not feasible, prefer consistency to conformance.

Semantics
---------

Parameter Ordering
^^^^^^^^^^^^^^^^^^

The general parameter order should be (1) output, (2) non-const input (e.g. file handles), (3) input, (4) tags.
Within these groups, the order should be from mandatory to optional.

.. container:: foldable

    In SeqAn, we read functions ``f(out1, out2, out3, ..., in1, in2, in3, ...)`` as ``(out1, out2, out3, ...) <- f(in1, in2, in3, ...)``.

    E.g. ``assign()``:

    .. code-block:: cpp

        template <typename T>
        void f(T & out, T const & in)
        {
            out = in;
        }

Scoping, Helper Code
--------------------

Global Variables
^^^^^^^^^^^^^^^^

Do not use global variables.
They introduce hard-to find bugs and require the introduction of a link-time library.

Tags In Function Arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^

Tags in function arguments should always be const.

.. container:: foldable

    .. code-block:: cpp

        // somewhere in your code:

        struct Move_;
        typedef Tag<Move_> Move;

        // then, later:

        void appendValue(TContainer, Move const &)
        {
            // ...
        }

Structs and Classes
-------------------

Visibility Specifiers
^^^^^^^^^^^^^^^^^^^^^

Visibility specifiers should go on the same indentation level as the ``class`` keyword.

.. container:: foldable

    Example:

    .. code-block:: cpp

        class MyStruct
        {
        public:
        protected:
        private:
        };

Tag Definitions
^^^^^^^^^^^^^^^

Tags that are possibly also used in other modules must not have additional parameters and be defined using the ``Tag<>`` template.
Tags that have parameters must only be used within the module they are defined in and have non-generic names.

.. container:: foldable

    Tags defined with the ``Tag<>`` template and a typedef can be defined multiply.
    These definitions must have the following pattern:

    .. code-block:: cpp

        struct TagName_;
        typedef Tag<TagName_> TagName;

    This way, there can be multiple definitions of the same tag since the struct ``TagName_`` is only declared but not defined and there can be duplicate typedefs.

    For tags (also those used for specialization) that have template parameters, the case is different.
    Here, we cannot wrap them inside the ``Tag<>`` template with a typedef since it still depends on parameters.
    Also we want to be able to instantiate tags so we can pass them as function arguments.
    Thus, we have to add a struct body and thus define the struct.
    There cannot be multiple identical definitions in C++.
    Thus, each tag with parameters must have a unique name throughout SeqAn.
    Possibly too generic names should be avoided.
    E.g. ``Chained`` should be reserved as the name for a global tag but ``ChainedFile<>`` can be used as a specialization tag in a file-related module.

    Note that this restriction does not apply for internally used tags (e.g.  those that have an underscore postfix) since these can be renamed without breaking the public API.

In-Place Member Functions
^^^^^^^^^^^^^^^^^^^^^^^^^

Whenever possible, functions should be declared and defined outside the class.
The constructor, destructor and few operators have to be defined inside the class, however.

.. container:: foldable

    The following has to be defined and declared within the class (also see `Wikipedia <https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B>`_):

    * constructors
    * destructors
    * function call operator ``operator()``
    * type cast operator ``operator T()``
    * array subscript operator ``operator[]()``
    * dereference-and-access-member operator ``operator->()``
    * assignment operator ``operator=()``

Formatting
----------

Constructor Initialization Lists
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If the whole function prototype fits in one line, keep it in one line.
Otherwise, wrap line after column and put each argument on its own line indented by one level.
Align the initialization list.

.. container:: foldable

    Example:

    .. code-block:: cpp

        class Class
        {
            MyClass() :
                member1(0),
                member2(1),
                member3(3)
            {}
        };

Line Length
^^^^^^^^^^^

The maximum line length is 120. Use a line length of 80 for header comments and the code section separators.

Non-ASCII Characters
^^^^^^^^^^^^^^^^^^^^

All files should be UTF-8, non-ASCII characters should not occur in them nevertheless.

.. container:: foldable

    In comments, use ``ss`` instead of ``ß`` and ``ae`` instead of ``ä`` etc.

    In strings, use UTF-8 coding.
    For example, ``"\xEF\xBB\xBF"`` is the Unicode zero-width no-break space character, which would be invisible if included in the source as straight UTF-8.

Spaces VS Tabs
^^^^^^^^^^^^^^

Do not use tabs! Use spaces.
Use ``"\t"`` in strings instead of plain tabs.

.. container:: foldablej

    After some discussion, we settled on this.
    All programmer's editors can be configured to use spaces instead of tabs.
    We use four spaces instead of a tab.

    There can be problems when indenting in for loops with tabs, for example.
    Consider the following (``-->|`` is a tab, ``_`` is a space):

    .. code-block:: cpp

        for (int i = 0, j = 0, k = 0, ...;
        _____cond1 && cond2 &&; ++i)
        {
          // ...
        }

    Here, indentation can happen up to match the previous line.
    Mixing tabs and spaces works, too.
    However, since tabs are not shown in the editor, people might indent a file with mixed tabs and spaces with spaces if they are free to mix tabs and spaces.

    .. code-block:: cpp

        for (int i = 0, j = 0, k = 0, ...;
        -->|_cond1 && cond2 &&; ++i)
        {
          // ...
        }

Indentation
^^^^^^^^^^^

We use an indentation of four spaces per level.

Note that '''namespaces do not cause an increase in indentation level.'''

.. container:: foldable

    .. code-block:: cpp

        namespace seqan2 {

        class SomeClass
        {
        };

        }  // namespace seqan2

Trailing Whitespace
^^^^^^^^^^^^^^^^^^^

Trailing whitespace is forbidden.

.. container:: foldable

    Trailing whitespace is not visible, leading whitespace for indentation is perceptible through the text following it.
    Anything that cannot be seen can lead to "trash changes" in the GitHub repository when somebody accidentally removes it.

Inline Comments
^^^^^^^^^^^^^^^

Use inline comments to document variables.

Possibly align inline comments.

.. container:: foldable

    .. code-block:: cpp

        short x;    // a short is enough!
        int myVar;  // this is my variable, do not touch it

Brace Positions
^^^^^^^^^^^^^^^

Always put brace positions on the next line.

.. code-block:: cpp

    class MyClass
    {
    public:
        int x;

        MyClass() : x(10)
        {}
    };

    void foo(char c)
    {
        switch (c)
        {
        case 'X':
            break;
        }
        // ...
    }

Conditionals
^^^^^^^^^^^^

Use no spaces inside the parantheses, the ``else`` keyword belongs on a new line, use block braces consistently.

.. container:: foldable

    Conditional statements should look like this:

    .. code-block:: cpp

        if (a == b)
        {
            return 0;
        }
        else if (c == d)
        {
            int x = a + b + d;
            return x;
        }

        if (a == b)
            return 0;
        else if (c == d)
            return a + b + d;

    Do not leave out the spaces before and after the parantheses, do not put leading or trailing space in the paranthesis.
    The following is wrong:

    .. code-block:: cpp

        if (foo){
            return 0;
        }
        if(foo)
            return 0;
        if (foo )
            return 0;

    Make sure to add braces to all blocks if any block has one.
    The following is wrong:

    .. code-block:: cpp

        if (a == b)
            return 0;
        else if (c == d)
        {
            int x = a + b + d;
            return x;
        }

Loops and Switch Statements
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Switch statements may use braces for blocks.
Empty loop bodies should use ``{}`` or ``continue``.

.. container:: foldable

    Format your switch statements as follows.
    The usage of blocks is optional.
    Blocks can be useful for declaring variables inside the switch statement.

    .. code-block:: cpp

        switch (var)
        {
        case 0:
            return 1;
        case 1:
            return 0;
        default:
            SEQAN_FAIL("Invalid value!");
        }

        switch (var2)
        {
        case 0:
            return 1;
        case 1:
        {
            int x = 0;
            for (int i = 0; i < var3; ++i)
                x ++ i;
            return x;
        }
        default:
            SEQAN_FAIL("Invalid value!");
        }

    Empty loop bodies should use ``{}`` or ``continue``, but not a single semicolon.

    .. code-block:: cpp

        while (condition)
        {
          // Repeat test until it returns false.
        }

        for (int i = 0; i < kSomeNumber; ++i)
            {}  // Good - empty body.
        while (condition)
            continue;  // Good - continue indicates no logic.

Expressions
^^^^^^^^^^^

Binary expressions are surrounded by one space. Unary expressions are preceded by one space.

.. container:: foldable

    Example:

    .. code-block:: cpp

        if (a == b || c == d || e == f || !x)
        {
            // ...
        }
        bool y = !x;
        unsigned i = ~j;

Type Expressions
^^^^^^^^^^^^^^^^

No spaces around period or arrow.
Add spaces before and after pointer and references.
``const`` comes after the type.

.. container:: foldable

    The following are good examples:

    .. code-block:: cpp

        int x = 0;
        int * ptr = x;                     // OK, spaces are good.
        int const & ref = x;               // OK, const after int
        int main(int argc, char ** argv);  // OK, group pointers.

    Bad Examples:

    .. code-block:: cpp

        int x = 0;
        int* ptr = x;         // bad spaces
        int *ptr = x;         // bad spaces
        const int & ref = x;  // wrong placement of const
        int x = ptr -> z;     // bad spaces
        int x = obj. z;       // bad spaces

Function Return Types
^^^^^^^^^^^^^^^^^^^^^

If a function definition is short, everything is on the same line.
Otherwise, split.

.. container:: foldable

    Good example:

    .. code-block:: cpp

        int foo();

        template <typename TString>
        typename Value<TString>::Type
        anotherFunction(TString const & foo, TString const & bar, /*...*/)
        {
            // ...
        }

Inline Functions
^^^^^^^^^^^^^^^^

If a function definition is short, everything is on the same line. Otherwise put inline and return type in the same line.

.. container:: foldable

    Good example:

    .. code-block:: cpp

        inline int foo();

        template <typename TString>
        inline typename Value<TString>::Type
        anotherFunction(TString const & foo, TString const & bar, /*...*/)
        {
            // ...
        }

Function Argument Lists
^^^^^^^^^^^^^^^^^^^^^^^

If it fits in one line, keep in one line.
Otherwise, wrap at the paranthesis, put each argument on its own line.
For very long function names and parameter lines, break after opening bracket.

.. container:: foldable

    Good example:

    .. code-block:: cpp

        template <typename TA, typename TB>
        inline void foo(TA & a, TB & b);

        template </*...*/>
        inline void foo2(TA & a,
                         TB & b,
                         ...
                         TY & y,
                         TZ & z);

        template </*...*/>
        inline void _functionThisIsAVeryVeryLongFunctionNameSinceItsAHelper(
            TThisTypeWasMadeToForceYouToWrapInTheLongNameMode & a,
            TB & b,
            TC & c,
            TB & d,
            ...);

Template Argument Lists
^^^^^^^^^^^^^^^^^^^^^^^

Follow conventions of function parameter lists, no blank after opening ``<``.

.. container:: foldable

    As for function parameters, try to fit everything on one line if possible, otherwise, break the template parameters over multiple lines and put the commas directly after the type names.

    .. code-block:: cpp

        template <typename T1, typename T1>
        void foo() {}

        template <typename T1, typename T2, ...
                  typename T10, typename T11>
        void bar() {}

Multiple closing ``>`` go to the same line and are only separated by spaces if two closing angular brackets come after each other.

.. container:: foldable

    .. code-block:: cpp

        typedef Iterator<Value<TValue>::Type,
                         Standard> ::Type

        typedef String<char, Alloc<> > TMyString
        // -------------------------^

Function Calls
^^^^^^^^^^^^^^

Similar rules as in `Function Argument Lists`_ apply.
When wrapped, not each parameter has to occur on its own line.

.. container:: foldable

    Example:

    .. code-block:: cpp

        foo(a, b);

        foo2(a, b, c, ...
             x, y, z);

        if (x)
        {
            if (y)
            {
                _functionThisIsAVeryVeryLongFunctionNameSinceItsAHelper(
                    firstParameterWithALongName, b, c, d);
            }
        }

Naming Rules
------------

In the following, camel case means that the first letter of each word is written upper case, the remainder is written in lower case.
Abbreviations of length 2 are kept in upper case, longer abbreviations are camel-cased.

Macros
^^^^^^

Macros are all upper case, separated by underscores, prefixed with ``SEQAN_``.

.. container:: foldable

    Example:

    .. code-block:: cpp

        SEQAN_ASSERT_EQ(val1, val2);

        #define SEQAN_MY_TMP_MACRO(x) f(x)
        // ...
        SEQAN_MY_TMP_MACRO(1);
        // ...
        #undef SEQAN_MY_TMP_MACRO

Variable Naming
^^^^^^^^^^^^^^^

Variables are named in camel case, starting with a lower-case parameter.
Internal member variables have an underscore prefix.

.. container:: foldable

    Example:

    .. code-block:: cpp

        int x;
        int myVar;
        int saValue(/*...*/);
        int getSAValue(/*...*/);

        struct FooBar
        {
            int _x;
        };

Constant / Enum Value Naming
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Constant and enum values are named like macros: all-upper case, separated by dashes.

.. container:: foldable

    Example:

    .. code-block:: cpp

        enum MyEnum
        {
            MY_ENUM_VALUE1 = 1,
            MY_ENUM_VALUE2 = 20
        };

        int const MY_VAR = 10;

Struct / Enum / Class Naming
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Types are written in camel case, starting with an upper case character.

.. container:: foldable

    Internal library types have an underscore suffix.

    Example:

    .. code-block:: cpp

        struct InternalType_
        {};

        struct SAValue
        {};

        struct LcpTable
        {};

Metafunction Naming
^^^^^^^^^^^^^^^^^^^

Metafunctions are named like structs, defined values are named ``VALUE``, types ``Type``.

.. container:: foldable

    Metafunctions should not export any other types or values publically, e.g. they should have an underscore suffix.

    Example:

    .. code-block:: cpp

        template <typename T>
        struct MyMetaFunction
        {
            typedef typename RemoveConst<T>::Type TNoConst_;
            typedef TNonConst_ Type;
        };

        template <typename T>
        struct MyMetaFunction2
        {
            typedef True Type;
            static bool const VALUE = false;
        };

Function Naming
^^^^^^^^^^^^^^^

The same naming rule as for variables applies.

.. container:: foldable

    Example:

    .. code-block:: cpp

        void fooBar();

        template <typename T>
        int saValue(T & x);

        template <typename T>
        void lcpTable(T & x);

Names In Documentation
^^^^^^^^^^^^^^^^^^^^^^

In the documentation, classes have the same name as in the source code, e.g. the class StringSet is documented as "class StringSet."
Specializations are named "``$SPEC $CLASS``\ ", e.g. "Concat StringSet", "Horspool Finder."

Comments
--------

File Comments
^^^^^^^^^^^^^

Each file should begin with a file header.

.. container:: foldable

    The file header has the format.
    The ``skel.py`` tool automatically generates files with appropriate headers.

    .. code-block:: cpp

        // ==========================================================================
        //                              $PROJECT NAME
        // ==========================================================================
        // Copyright (C) 2010 $AUTHOR, $ORGANIZATION
        //
        // $LICENSE
        //
        // ==========================================================================
        // Author: $NAME <$EMAIL>
        // ==========================================================================
        // $FILE_DESCRIPTION
        // ==========================================================================

Class, Function, Metafunction, Enum, Macro DDDoc Comments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Each public class, function, metafunction, enum, and macro should be documented using :ref:`dox API docs<infra-contribute-dox>`.
Internal code should be documented, too.

.. container:: foldable

    Example:

    .. code-block:: cpp

        /*!
         * @class IntervalAndCargo
         * @headerfile <seqan/refinement.h>
         * @brief A simple record type that stores an interval and a cargo value.
         *
         * @signature template <typename TValue, typename TCargo>
         *            struct IntervalAndCargo;
         *
         * @tparam TValue The value type of the record, defaults to int.
         * @tparam TCargo The cargo type of the record, defaults to int.
         */

        template <typename TValue = int, typename TCargo = int>
        class IntervalAndCargo
        {
            // ...
        };

        // This functions helps the XYZ class to fulfill the ABC functionality.
        //
        // It corresponds to function FUNC() in the paper describing the original
        // algorithm.  The variables in this function correspond to the names in the
        // paper and thus the code style is broken locally.

        void _helperFunction(/*...*/)
        {}

Implementation Comments
^^^^^^^^^^^^^^^^^^^^^^^

All functions etc. should be well-documented.
In most cases, it is more important how something is done instead of of what is done.

TODO Comments
^^^^^^^^^^^^^

TODO comments have the format ``// TODO($USERNAME): $TODO_COMMENT``.
The username is the username of the one writing the item, not the one to fix it.
Use GitHub issues for this.

Source Tree Structure
---------------------

File Name Rules
^^^^^^^^^^^^^^^

File and directories are named all-lower case, words are separated by underscores.

.. container:: foldable

    Exceptions are ``INFO``, ``COPYING``, ``README``, ... files.

    Examples:

    * ``string_base.h``
    * ``string_packed.h``
    * ``suffix_array.h``
    * ``lcp_table.h``

File Structure
--------------

Header ``#define`` guard
^^^^^^^^^^^^^^^^^^^^^^^^

The header ``#define`` include guards are constructed from full paths to the repository root.

.. container:: foldable

    Example:

    +-------------------------------------------+-----------------------------------------------------+
    | filename                                  | preprocessor symbol                                 |
    +===========================================+=====================================================+
    | seqan/include/seqan/basic/iterator_base.h | ``SEQAN_INCLUDE_SEQAN_BASIC_ITERATOR_BASE_H_``      |
    +-------------------------------------------+-----------------------------------------------------+

    .. code-block:: cpp

        #ifndef SEQAN_INCLUDE_SEQAN_BASIC_ITERATOR_BASE_H_
        #define SEQAN_INCLUDE_SEQAN_BASIC_ITERATOR_BASE_H_
        #endif  // #ifndef SEQAN_INCLUDE_SEQAN_BASIC_ITERATOR_BASE_H_

Include Order
^^^^^^^^^^^^^

The include order should be (1) standard library requirements, (2) external requirements, (3) required SeqAn modules.

In SeqAn module headers (e.g. *basic.h*), then all files in the module are included.

CPP File Structure
^^^^^^^^^^^^^^^^^^

.. code-block:: cpp

    // ==========================================================================
    //                                $APP_NAME
    // ==========================================================================
    // Copyright (c) 2006-2026, Knut Reinert, FU Berlin
    // All rights reserved.
    //
    // Redistribution and use in source and binary forms, with or without
    // modification, are permitted provided that the following conditions are met:
    //
    //     * Redistributions of source code must retain the above copyright
    //       notice, this list of conditions and the following disclaimer.
    //     * Redistributions in binary form must reproduce the above copyright
    //       notice, this list of conditions and the following disclaimer in the
    //       documentation and/or other materials provided with the distribution.
    //     * Neither the name of Knut Reinert or the FU Berlin nor the names of
    //       its contributors may be used to endorse or promote products derived
    //       from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
    // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    // DAMAGE.
    //
    // ==========================================================================
    // Author: $AUTHOR_NAME <$AUTHOR_EMAIL>
    // ==========================================================================
    // $FILE_COMMENT
    // ==========================================================================

    #include <seqan/basic.h>
    #include <seqan/sequence.h>

    #include "app_name.h"

    using namespace seqan2;

    // Program entry point
    int main(int argc, char const ** argv)
    {
        // ...
    }

Application Header Structure
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: cpp

    // ==========================================================================
    //                                $APP_NAME
    // ==========================================================================
    // Copyright (c) 2006-2026, Knut Reinert, FU Berlin
    // All rights reserved.
    //
    // Redistribution and use in source and binary forms, with or without
    // modification, are permitted provided that the following conditions are met:
    //
    //     * Redistributions of source code must retain the above copyright
    //       notice, this list of conditions and the following disclaimer.
    //     * Redistributions in binary form must reproduce the above copyright
    //       notice, this list of conditions and the following disclaimer in the
    //       documentation and/or other materials provided with the distribution.
    //     * Neither the name of Knut Reinert or the FU Berlin nor the names of
    //       its contributors may be used to endorse or promote products derived
    //       from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
    // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    // DAMAGE.
    //
    // ==========================================================================
    // Author: $AUTHOR_NAME <$AUTHOR_EMAIL>
    // ==========================================================================
    // $FILE_COMMENT
    // ==========================================================================

    #ifndef APPS_APP_NAME_HEADER_FILE_H_
    #define APPS_APP_NAME_HEADER_FILE_H_

    // ==========================================================================
    // Forwards
    // ==========================================================================

    // ==========================================================================
    // Tags, Classes, Enums
    // ==========================================================================

    // --------------------------------------------------------------------------
    // Class ClassName
    // --------------------------------------------------------------------------

    // ==========================================================================
    // Metafunctions
    // ==========================================================================

    // --------------------------------------------------------------------------
    // Metafunction MetafunctionName
    // --------------------------------------------------------------------------

    // ==========================================================================
    // Functions
    // ==========================================================================

    // --------------------------------------------------------------------------
    // Function functionName()
    // --------------------------------------------------------------------------

    #endif  // APPS_APP_NAME_HEADER_FILE_H_

Library Header Structure
^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: cpp

    // ==========================================================================
    //                 SeqAn - The Library for Sequence Analysis
    // ==========================================================================
    // Copyright (c) 2006-2026, Knut Reinert, FU Berlin
    // All rights reserved.
    //
    // Redistribution and use in source and binary forms, with or without
    // modification, are permitted provided that the following conditions are met:
    //
    //     * Redistributions of source code must retain the above copyright
    //       notice, this list of conditions and the following disclaimer.
    //     * Redistributions in binary form must reproduce the above copyright
    //       notice, this list of conditions and the following disclaimer in the
    //       documentation and/or other materials provided with the distribution.
    //     * Neither the name of Knut Reinert or the FU Berlin nor the names of
    //       its contributors may be used to endorse or promote products derived
    //       from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
    // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
    // DAMAGE.
    //
    // ==========================================================================
    // Author: AUTHOR NAME <AUTHOR EMAIL>
    // ==========================================================================
    // SHORT COMMENT ON WHAT THIS FILE CONTAINS
    // ==========================================================================

    #ifndef INCLUDE_SEQAN_BASIC_ITERATOR_BASE_H_
    #define INCLUDE_SEQAN_BASIC_ITERATOR_BASE_H_

    namespace seqan2 {

    // ==========================================================================
    // Forwards
    // ==========================================================================

    // ==========================================================================
    // Tags, Classes, Enums
    // ==========================================================================

    // --------------------------------------------------------------------------
    // Class ClassName
    // --------------------------------------------------------------------------

    // ==========================================================================
    // Metafunctions
    // ==========================================================================

    // --------------------------------------------------------------------------
    // Metafunction MetafunctionName
    // --------------------------------------------------------------------------

    // ==========================================================================
    // Functions
    // ==========================================================================

    // --------------------------------------------------------------------------
    // Function functionName()
    // --------------------------------------------------------------------------

    }  // namespace seqan2

    #endif  // INCLUDE_SEQAN_BASIC_ITERATOR_BASE_H_