This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cplusplus-coding-guidelines.html
914 lines (872 loc) · 44.2 KB
/
cplusplus-coding-guidelines.html
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
<!DOCTYPE html>
<!--
Generated by Apache Maven Doxia at 2015-12-08
Rendered using Reflow Maven Skin 1.1.1 (http://andriusvelykis.github.io/reflow-maven-skin)
-->
<html xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<title>Apache Trafodion C++ Coding Guidelines</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta http-equiv="content-language" content="en" />
<link href="http://netdna.bootstrapcdn.com/bootswatch/2.3.2/cerulean/bootstrap.min.css" rel="stylesheet" />
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" rel="stylesheet" />
<link href="./css/bootswatch.css" rel="stylesheet" />
<link href="./css/reflow-skin.css" rel="stylesheet" />
<link href="http://yandex.st/highlightjs/7.5/styles/default.min.css" rel="stylesheet" />
<link href="./css/lightbox.css" rel="stylesheet" />
<link href="./css/site.css" rel="stylesheet" />
<link href="./css/print.css" rel="stylesheet" media="print" />
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="page-cplusplus-coding-guidelines project-trafodion" data-spy="scroll" data-offset="60" data-target="#toc-scroll-target">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target="#top-nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.html">Apache <span class="color-highlight">Trafodion</span></a>
<div class="nav-collapse collapse" id="top-nav-collapse">
<ul class="nav pull-right">
<li ><a href="download.html" title="Download">Download</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">About <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="index.html" title="Project Overview">Project Overview</a></li>
<li ><a href="new-features.html" title="New Features">New Features</a></li>
<li ><a href="roadmap.html" title="Roadmap">Roadmap</a></li>
<li ><a href="performance.html" title="Performance">Performance</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="team-list.html" title="Team">Team</a></li>
<li ><a href="presentations.html" title="Presentations">Presentations</a></li>
<li ><a href="mail-lists.html" title="Mailing List">Mailing List</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="source-repository.html" title="Source Repository">Source Repository</a></li>
<li ><a href="issue-tracking.html" title="Issue Tracking">Issue Tracking</a></li>
<li ><a href="license.html" title="License">License</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Using <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="quickstart.html" title="Quick Start">Quick Start</a></li>
<li ><a href="download.html" title="Download">Download</a></li>
<li ><a href="install.html" title="Install">Install</a></li>
<li ><a href="management.html" title="Managing Trafodion">Managing Trafodion</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="documentation.html" title="Documentation">Documentation</a></li>
<li ><a href="faq.html" title="FAQ">FAQ</a></li>
<li ><a href="release-notes.html" title="Release Notes">Release Notes</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Features <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="architecture-overview.html" title="Architecture Overview">Architecture Overview</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/security-ansi-schemas" title="ANSI Schema Support" class="externalLink">ANSI Schema Support</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/ustat-automation" title="Automated Update Statistics" class="externalLink">Automated Update Statistics</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/bulkunload" title="Bulk Unload" class="externalLink">Bulk Unload</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Trafodion_Manageability#Logging_Events" title="Event Handling" class="externalLink">Event Handling</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/hybrid-query-cache" title="Hybrid Query Cache" class="externalLink">Hybrid Query Cache</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/identity-column" title="Identity Column" class="externalLink">Identity Column</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Creating_Statistics_During_Bulk_Load" title="Immediate Update Statistics" class="externalLink">Immediate Update Statistics</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/lob-support" title="Large Object (LOB)" class="externalLink">Large Object (LOB)</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/ddl-query-invalidation" title="Metadata Query Invalidation" class="externalLink">Metadata Query Invalidation</a></li>
<li ><a href="https://cwiki.apache.org/confluence/display/TRAFODION/Cmp-divisioning" title="Multi-Temperature Data" class="externalLink">Multi-Temperature Data</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/access-external-hbase-tables" title="Native HBase Tables" class="externalLink">Native HBase Tables</a></li>
<li ><a href="docs/Trafodion_odb_User_Guide.pdf" title="ODB">ODB</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/sql-query-cancel" title="Query Cancel" class="externalLink">Query Cancel</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/security-privilege-updates" title="Privilege Checking" class="externalLink">Privilege Checking</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Trafodion_Manageability" title="Repository" class="externalLink">Repository</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/enable-get-statistics-thru-rms" title="Runtime Management System" class="externalLink">Runtime Management System</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/sequence-numbers" title="Sequence Numbers" class="externalLink">Sequence Numbers</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/skew-buster" title="Skew Buster" class="externalLink">Skew Buster</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Tutorial:_The_object-oriented_UDF_interface" title="Table-Oriented UDF" class="externalLink">Table-Oriented UDF</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Data_Loading#Trickle_Loading_Data_Into_Trafodion_Tables" title="Trickle Load" class="externalLink">Trickle Load</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Backup_and_Restore" title="Backup/Restore Utility" class="externalLink">Backup/Restore Utility</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Metadata_Cleanup" title="Metadata Cleanup Utility" class="externalLink">Metadata Cleanup Utility</a></li>
</ul>
</li>
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contributing <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="contribute.html" title="Contribute">Contribute</a></li>
<li ><a href="advocate.html" title="Advocate">Advocate</a></li>
<li ><a href="develop.html" title="Develop">Develop</a></li>
<li ><a href="testing.html" title="Test">Test</a></li>
<li ><a href="merge.html" title="Merge">Merge</a></li>
<li ><a href="release.html" title="Release">Release</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="create-dev-environment.html" title="Create Dev Environment">Create Dev Environment</a></li>
<li ><a href="manage-dev-environment.html" title="Manage Dev Environment">Manage Dev Environment</a></li>
<li ><a href="setup-build-environment.html" title="Setup Build Environment">Setup Build Environment</a></li>
<li ><a href="build.html" title="Build Trafodion">Build Trafodion</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="code.html" title="Modify Code">Modify Code</a></li>
<li ><a href="tests.html" title="Modify Tests">Modify Tests</a></li>
<li ><a href="document.html" title="Modify Documentation">Modify Documentation</a></li>
<li ><a href="website.html" title="Modify Web Site">Modify Web Site</a></li>
<li ><a href="wiki.html" title="Modify Wiki Pages">Modify Wiki Pages</a></li>
<li ><a href="http:divider" title=""></a></li>
<li class="active"><a href="" title="C++ Coding Guidelines">C++ Coding Guidelines</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Apache <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="http://incubator.apache.org/projects/trafodion.html" title="Status Page" target="_blank" class="externalLink">Status Page</a></li>
<li ><a href="http://www.apache.org/foundation/how-it-works.html" title="Apache Foundation" target="_blank" class="externalLink">Apache Foundation</a></li>
<li ><a href="http://www.apache.org/licenses/" title="Apache License" target="_blank" class="externalLink">Apache License</a></li>
<li ><a href="http://www.apache.org/security/" title="Apache Security" target="_blank" class="externalLink">Apache Security</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="http://www.apache.org/foundation/sponsorship.html" title="Sponsorship" target="_blank" class="externalLink">Sponsorship</a></li>
<li ><a href="http://www.apache.org/foundation/thanks.html" title="Thanks" target="_blank" class="externalLink">Thanks</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<!-- Masthead
================================================== -->
<header>
<div class="jumbotron subhead">
<div class="row" id="banner">
<div class="span12">
<div class="pull-left">
<a href="index.html" id="bannerLeft"><h1>Apache <span class="color-highlight">Trafodion</span></h1></a>
<p class="lead">Transactional SQL-on-Hadoop Database</p>
</div>
<div class="pull-right">
</div>
</div>
</div>
</div>
<div>
<ul class="breadcrumb">
<li><a href="index.html" title="Trafodion">Trafodion</a></li>
<li class="divider">/</li>
<li>C++ Coding Guidelines</li>
</ul>
</div>
<hr class="toc-separator" />
<div id="toc-bar" class="navbar" data-spy="affix" data-offset-top="250">
<div class="navbar-inner">
<div id="toc-scroll-target" class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target="#toc-nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse collapse" id="toc-nav-collapse">
<ul id="toc" class="nav">
<li class="dropdown">
<a href="#header_files" title="Header Files" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Header Files <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#header_files" title="Header Files">Header Files</a></li>
<li class="divider"></li>
<li><a href="#Including_Standard_Header_Files" title="Including Standard Header Files">Including Standard Header Files</a></li>
<li><a href="#Include_Guards" title="Include Guards">Include Guards</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#variable_declaration_and_naming_standards" title="Variable Declaration and Naming Standards" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Variable Declaration and Naming Standards <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#variable_declaration_and_naming_standards" title="Variable Declaration and Naming Standards">Variable Declaration and Naming Standards</a></li>
<li class="divider"></li>
<li><a href="#Class_Member_Variable_Names" title="Class Member Variable Names">Class Member Variable Names</a></li>
<li><a href="#Function_Names" title="Function Names">Function Names</a></li>
<li><a href="#Enums" title="Enums">Enums</a></li>
<li><a href="#Boolean_Variables" title="Boolean Variables">Boolean Variables</a></li>
<li><a href="#Constants" title="Constants">Constants</a></li>
<li><a href="#Namespace_Names" title="Namespace Names">Namespace Names</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#indentation_and_formatting" title="Indentation and Formatting" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Indentation and Formatting <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#indentation_and_formatting" title="Indentation and Formatting">Indentation and Formatting</a></li>
<li class="divider"></li>
<li><a href="#Indentation" title="Indentation">Indentation</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#comments" title="Comments" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Comments <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#comments" title="Comments">Comments</a></li>
<li class="divider"></li>
<li><a href="#Comment_Style" title="Comment Style">Comment Style</a></li>
<li><a href="#WhenWhere_Comments_Should_Be_Used" title="When/Where Comments Should Be Used">When/Where Comments Should Be Used</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#error_handling" title="Error Handling" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Error Handling <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#error_handling" title="Error Handling">Error Handling</a></li>
<li class="divider"></li>
<li><a href="#Asserts" title="Asserts">Asserts</a></li>
<li><a href="#Error_ReturnRetrieval" title="Error Return/Retrieval">Error Return/Retrieval</a></li>
<li><a href="#Exception_Handling" title="Exception Handling">Exception Handling</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#" title="More…" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">… <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-submenu">
<a href="#general_guidelines" title="General Guidelines">General Guidelines</a>
<ul class="dropdown-menu" role="menu">
<li><a href="#Casting" title="Casting">Casting</a></li>
<li><a href="#Types" title="Types">Types</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
<div class="main-body">
<div class="row">
<div class="span12">
<div class="body-content">
<!-- Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the
License. -->
<p>These are the C++ coding guidelines that are part of the acceptance criteria for code submitted to the Trafodion. Trafodion reviewers use these guidelines when reviewing changes.</p>
<p>The guidelines describe practices that are either required or preferred. In addition, areas where there is no preference between two or more practices are described.</p>
<p>Trafodion is composed of several distinct sub-projects, some of which have coding guidelines that differ from the Trafodion standard; for example, a requirement in most areas of the code may be only preferred in others.</p>
<p>There may also be existing code that violates one or more of the published requirements. The intent is to correct these over time, and corrections are encouraged when changing code to make a fix or implement new functionality. However, changes that are solely coding guideline changes are not recommended since this places undue burden on the reviewers.</p>
<div class="page-header">
<h1 id="header_files">Header Files</h1>
</div>
<p>Keep <b><tt>#include</tt></b> directives to a minimum in header files. </p>
<p>You may forward declare classes and structs when the only use within the header file is a pointer or reference. While includes should be kept to a minimum, if something is used in a header file and cannot be forward declared, it must be explicitly included. </p>
<p>All files, headers and implementation, should include everything they need to be self-sufficient. They should never assume something will be pre-included. In other words, the contents of a header file should compile cleanly by itself. To help ensure this, all implementation files should include their respective header file first.</p>
<p>Header files should not contain declarations for public items that are only used by the implementation file. Public items that are require in the implementation file but not the header file should be declared in the implementation file. The preference is NOT to create header files that consist only of includes of other header files.</p>
<p>Declare as little as possible in the header file and keep as much of the actual implementation private as is reasonable. For instance, don’t include in a header file declarations of types, enums, and functions that are only referenced by the implementation file.</p>
<div class="section">
<h2 id="Including_Standard_Header_Files">Including Standard Header Files</h2>
<p>The preference is for C++ style includes over C style includes for standard header files.</p>
<div class="source">
<div class="source">
<pre>//Preferred
#include <cstdio>
//Accepted
#include <stdio.h>
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Include_Guards">Include Guards</h2>
<p>All header files must use include guards. The name of the include guard <b><tt>#define</tt></b> should be the filename in all uppercase, with underscore used in place of periods.</p>
<p>For instance, if the header file is named <b><tt>ServerInterface_ODBC.h</tt></b>, the header file should begin and end as follows:</p>
<div class="source">
<div class="source">
<pre>#ifndef SERVERINTERFACE_ODBC_H
#define SERVERINTERFACE_ODBC_H
...
#endif /* SERVERINTERFACE_ODBC_H */
</pre>
</div>
</div>
<p>Comments following the <b><tt>#endif</tt></b> indicating the include guard are preferred.</p>
<h1 id="variable_declaration_and_naming_standards">Variable Declaration and Naming Standards</h1>
<p>Trafodion uses a combination of Pascal and Camel case. </p>
<ul>
<li>Pascal case means that the first letter in each word in an identifier is capitalized.</li>
<li>Camel case is similar except the first letter is in lower case.</li>
</ul>
<p>For both, underscores are <b>not</b> used to separate words. The general rule is that identifiers with local scope start with a lower case letter and identifiers with global scope start with an upper case letter.</p>
<div class="source">
<div class="source">
<pre>//Pascal case
class AuthenticationMessage;
//Camel case (aka lower Camel case or camelCase)
int logonCount;
Class Names
</pre>
</div>
</div>
<p>Class names should be Pascal case and should describe the object contents (not what it does), with as little abbreviation as possible. When names include acronyms, the acronyms should be in all upper case.</p>
<p><b>Acceptable Examples</b></p>
<div class="source">
<div class="source">
<pre>//Preferred
class SQLSessionContext; // an object that contains the context for a SQL session
class PrivilegeList; // a list of privileges
</pre>
</div>
</div>
<p><b>Poor Examples</b></p>
<div class="source">
<div class="source">
<pre>class OutputInfo; // Doesn’t describe class contents, no context
class ReadTableDef; // Describes what class does, not contents
class Cmdline_Args; // Prefer Pascal case, no underscore, for class names
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Class_Member_Variable_Names">Class Member Variable Names</h2>
<p>Private member data variables should be suffixed with an underscore and should use Camel case. When names include acronyms, the acronyms should be in all upper or all lower case, dependent on which case the first letter should be.</p>
<p><b>Example</b></p>
<div class="source">
<div class="source">
<pre>class Employee
{
public:
Employee ();
private:
std::string firstName_;
std::string lastName_;
uint16_t departmentNumber_;
std::string departmentName_;
uint32_t irsSSN_;
}
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Function_Names">Function Names</h2>
<p>Class member functions and static file functions should use Camel case. External non-class functions should use Pascal case. Except for constructors, destructors, and operators, the function name should include a verb that describes the action the function is performing.</p>
<p><b>Good Examples</b></p>
<div class="source">
<div class="source">
<pre>//Class member functions
int32_t getSalary() const;
int32_t setAuthID();
int32_t closeAllCursors();
</pre>
</div>
</div>
<p><b>Bad Examples</b></p>
<div class="source">
<div class="source">
<pre>// Is it setting break enabled, returning it or ???
int32_t SQLCLI_BreakEnabled();
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Enums">Enums</h2>
<p>Enum types should use Pascal case and describe the class of enums. If the enum is declared outside of a class, the type name should include an indication of the scope of the enums.</p>
<p>Enums themselves should be declared as all upper case. The names may begin with a common prefix or be independent, depending on the usage.</p>
<p>When enums represent an arbitrary set of return values (that is, error codes, state codes, etc.), then avoid the values -1, 0, and 1 if using weakly typed enums, to reduce the chance of matches with Booleans or uninitialized variables.</p>
<p>The preference is to declare enums as strongly typed.</p>
<div class="source">
<div class="source">
<pre>enum class EnumName {...};
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Boolean_Variables">Boolean Variables</h2>
<p>Boolean variables names should include a verb, state, and optionally a noun (object whose state is in question) indicating the nature of the Boolean. Any combination is acceptable, however verbState is the most common.</p>
<p><b>Good Examples</b></p>
<div class="source">
<div class="source">
<pre>bool isValid; // verbState
bool isValidTable; // verbStateNoun
bool tableIsDroppable; // nounVerbState
bool hasData; // verbState
</pre>
</div>
</div>
<p><b>Bad Examples</b></p>
<div class="source">
<div class="source">
<pre>bool valid;
bool tableState;
bool empty;
</pre>
</div>
</div>
<p>Functions that return a Boolean should also have names of the form verbState or verbStateNoun if the functions return state information. (This naming standard does not apply to functions returning Boolean as indication of success or failure.)</p>
<p><b>Good Examples</b></p>
<div class="source">
<div class="source">
<pre>bool isValidHbaseName();
bool isHostNameExcluded();
bool canUseCbServer();
</pre>
</div>
</div>
<p><b>Bad Examples</b></p>
<div class="source">
<div class="source">
<pre>// Don’t use get for Boolean accessors
bool getUDRAccessModeViolation();
// Don’t use integer return for Boolean functions
short existsInHBase();
// Function name implies it is sending settings to the compiler, but it is
// actually only returning an indication that settings should be sent.
// A better name would be shouldSendSettingsToCompiler().
bool sendSettingsToCompiler();
</pre>
</div>
</div>
<p>Parts of Trafodion code use one of two Boolean typedefs, <b><tt>NABoolean</tt></b> and <b><tt>ComBoolean</tt></b>, declared as follows:</p>
<div class="source">
<div class="source">
<pre>typedef int Int32;
typedef Int32 NABoolean;
typedef NABoolean ComBoolean;
const NABoolean TRUE = (1 == 1);
const NABoolean FALSE = (0 == 1);
</pre>
</div>
</div>
<p>Exercise care when mixing usage of bool and <b><tt>NABoolean</tt></b>/<b><tt>ComBoolean</tt></b> types, as the latter are not guaranteed to only contain values of TRUE and FALSE. The use of non-standard Boolean types is gradually being phased out.</p>
</div>
<div class="section">
<h2 id="Constants">Constants</h2>
<p>All constant names should be all upper case, regardless of how the constant is declared. That is, enums, defines, and variables with the <b><tt>const</tt></b> modifier should be named in all upper case.</p>
<p>Defines, enums, and const are all permitted and used throughout Trafodion, although most code in Trafodion uses enum for numerical constants and defines for character constants. </p>
<p>For new code, the use of const char or string is preferred for character constants instead of defines.</p>
</div>
<div class="section">
<h2 id="Namespace_Names">Namespace Names</h2>
<p>The preference is for namespaces to be all lower case, with preference to single words (note the exception to the rule that a name with global scope should start with an upper case). </p>
<p>If a namespace must be dual-worded, use underscores. If mixed case names are used, Pascal case is preferred.</p>
<p><b>Examples</b></p>
<div class="source">
<div class="source">
<pre>//Preferred
namespace compiler
//Accepted
namespace Compiler
</pre>
</div>
</div>
<h1 id="indentation_and_formatting">Indentation and Formatting</h1>
</div>
<div class="section">
<h2 id="Indentation">Indentation</h2>
<p>TAB characters are not permitted in source files except for text files (for example, makefiles) that require them.</p>
<p>Trafodion code uses several indenting depths, including 2, 3, 4, and 8 spaces. Most common is 2 and 3. </p>
<p>Use the style found in existing code, and when writing new code, use either 2, 3, or 4, and remain consistent.</p>
<p>A variety of control block indentation styles are used throughout Trafodion, most commonly Allman, Whitesmith, Stroustrup, and GNU. Follow the predominant style when making small to medium changes to existing code. For new code, the Allman style is preferred.</p>
<div class="source">
<div class="source">
<pre>//Allman
if (x > 5)
{
error = doThis(x);
if (error != 0)
{
return false;
}
}
else
{
doThat(x);
}
//Whitesmith
if (x > 5)
{
error = doThis(x);
if (error != 0)
{
return false;
}
}
else
{
doThat(x);
}
//Stroustrup
if (x > 5) {
error = doThis(x);
if (error != 0) {
return false;
}
}
else {
doThat(x);
}
</pre>
</div>
</div>
<p>Note that the Stroustrup and the similar K&R formats were popularized by usage in books where conservation of line count was a goal.</p>
<div class="source">
<div class="source">
<pre>//GNU
if (x > 5)
{
error = doThis(x);
if (error != 0)
{
return false;
}
}
else
{
doThat(x);
}
</pre>
</div>
</div>
<h1 id="comments">Comments</h1>
</div>
<div class="section">
<h2 id="Comment_Style">Comment Style</h2>
<p>C++ style comments are preferred, but C comments are acceptable as well.</p>
<p>Some code uses Doxygen style comments, but this is not required.</p>
</div>
<div class="section">
<h2 id="WhenWhere_Comments_Should_Be_Used">When/Where Comments Should Be Used</h2>
<p>Every file should have a comment at the beginning describing the purpose of the file.</p>
<p>In header files where classes are declared, there should be a comment describing the class, including purpose and usage. Also describe anything out of the ordinary, such as the use of multiple inheritance.</p>
<p>Within implementation files, in addition to the comment at the beginning of the file, add comments for any global or static variables defined in the file, and how the variable is handled in a multi-threaded environment (if applicable).</p>
<p>Also, for each function defined, describe the purpose and intent of the function. For each parameter, list whether it is input or output (or both), how it is used, and any range restrictions imposed. For functions not returning void, describe the possible return values.</p>
<p>Within the body of the function, there is no need to write comments that document the obvious. But if there is any complexity to the logic, at a minimum document the intent, and consider documenting the details (assumptions, limits, unexpected side effects from function calls, etc.)</p>
<p>If a feature is only partially implemented, add a comment indicating at a high level what work remains. Prefix the comment with //TODO.</p>
<div class="source">
<div class="source">
<pre>//TODO Code is currently not thread safe. Need to protect allocation of ...
</pre>
</div>
</div>
<h1 id="error_handling">Error Handling</h1>
</div>
<div class="section">
<h2 id="Asserts">Asserts</h2>
<p>Trafodion uses asserts in the “debug” build. Use asserts freely, but ensure they do not contain any side effects as the code is not present in the “release” build.</p>
</div>
<div class="section">
<h2 id="Error_ReturnRetrieval">Error Return/Retrieval</h2>
<p>Avoid the use of integer return codes for success and error codes. Instead, use bool for simple succeeded/failed and enum types for returns with multiple conditions.</p>
</div>
<div class="section">
<h2 id="Exception_Handling">Exception Handling</h2>
<p>Trafodion code mixes usage of exceptions and error returns. When using try/catch blocks, keep the scope as small as possible. Ensure all exceptions thrown are handled, potentially in main() if nowhere else.</p>
<h1 id="general_guidelines">General Guidelines</h1>
</div>
<div class="section">
<h2 id="Casting">Casting</h2>
<p>Avoid using C-style casts. Use C++-style casts instead, as they are often safer and easier to search for.</p>
<div class="source">
<div class="source">
<pre>//Preferred
int x = static_cast<int>(shortVariable);
MyType *myVar = reinterpret_cast<MyType *>(voidPtr);
</pre>
</div>
</div>
<p>Don’t blindly cast to remove a compiler error or warning. Ensure the cast is safe.</p>
<p>Use const casting sparingly. Often the use of mutable or changing a function to be const correct is a better solution.</p>
</div>
<div class="section">
<h2 id="Types">Types</h2>
<p>Use standard types defined in <b><tt><cstdint></tt></b> or <b><tt><stdint.h></tt></b>. Note that Trafodion defines and uses many non-standard types (for example, <b><tt>Int32</tt></b>, <b><tt>Lng32</tt></b>), but this usage is being phased out.</p>
<p>Use types with explicit sizes (for example, <b><tt>int32_t</tt></b>, <b><tt>int64_t</tt></b>) when size is a factor in the code, such as an external API, or column in a table. </p>
<p>Where size is not a factor (counters, indexes) a non-sized type such as <b><tt>int</tt></b> or <b><tt>long</tt></b> may be used. However, in general, <b><tt>size_t</tt></b> and <b><tt>ssize_t</tt></b> are preferred for variables where fixed size is not required.</p>
</div>
</div>
</div>
</div>
</div>
</div><!-- /container -->
<!-- Footer
================================================== -->
<footer class="well">
<div class="container">
<div class="row">
<div class="span2 bottom-nav">
<ul class="nav nav-list">
<li class="nav-header">About</li>
<li >
<a href="index.html" title="Project Overview">Project Overview</a>
</li>
<li >
<a href="new-features.html" title="New Features">New Features</a>
</li>
<li >
<a href="roadmap.html" title="Roadmap">Roadmap</a>
</li>
<li >
<a href="performance.html" title="Performance">Performance</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="team-list.html" title="Team">Team</a>
</li>
<li >
<a href="presentations.html" title="Presentations">Presentations</a>
</li>
<li >
<a href="mail-lists.html" title="Mailing List">Mailing List</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="source-repository.html" title="Source Repository">Source Repository</a>
</li>
<li >
<a href="issue-tracking.html" title="Issue Tracking">Issue Tracking</a>
</li>
<li >
<a href="license.html" title="License">License</a>
</li>
</ul>
</div>
<div class="span2 bottom-nav">
<ul class="nav nav-list">
<li class="nav-header">Using</li>
<li >
<a href="quickstart.html" title="Quick Start">Quick Start</a>
</li>
<li >
<a href="download.html" title="Download">Download</a>
</li>
<li >
<a href="install.html" title="Install">Install</a>
</li>
<li >
<a href="management.html" title="Managing Trafodion">Managing Trafodion</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="documentation.html" title="Documentation">Documentation</a>
</li>
<li >
<a href="faq.html" title="FAQ">FAQ</a>
</li>
<li >
<a href="release-notes.html" title="Release Notes">Release Notes</a>
</li>
</ul>
</div>
<div class="span2 bottom-nav">
<ul class="nav nav-list">
<li class="nav-header">Features</li>
<li >
<a href="architecture-overview.html" title="Architecture Overview">Architecture Overview</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/security-ansi-schemas" title="ANSI Schema Support" class="externalLink">ANSI Schema Support</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/ustat-automation" title="Automated Update Statistics" class="externalLink">Automated Update Statistics</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/bulkunload" title="Bulk Unload" class="externalLink">Bulk Unload</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Trafodion_Manageability#Logging_Events" title="Event Handling" class="externalLink">Event Handling</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/hybrid-query-cache" title="Hybrid Query Cache" class="externalLink">Hybrid Query Cache</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/identity-column" title="Identity Column" class="externalLink">Identity Column</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Creating_Statistics_During_Bulk_Load" title="Immediate Update Statistics" class="externalLink">Immediate Update Statistics</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/lob-support" title="Large Object (LOB)" class="externalLink">Large Object (LOB)</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/ddl-query-invalidation" title="Metadata Query Invalidation" class="externalLink">Metadata Query Invalidation</a>
</li>
<li >
<a href="https://cwiki.apache.org/confluence/display/TRAFODION/Cmp-divisioning" title="Multi-Temperature Data" class="externalLink">Multi-Temperature Data</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/access-external-hbase-tables" title="Native HBase Tables" class="externalLink">Native HBase Tables</a>
</li>
<li >
<a href="docs/Trafodion_odb_User_Guide.pdf" title="ODB">ODB</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/sql-query-cancel" title="Query Cancel" class="externalLink">Query Cancel</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/security-privilege-updates" title="Privilege Checking" class="externalLink">Privilege Checking</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Trafodion_Manageability" title="Repository" class="externalLink">Repository</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/enable-get-statistics-thru-rms" title="Runtime Management System" class="externalLink">Runtime Management System</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/sequence-numbers" title="Sequence Numbers" class="externalLink">Sequence Numbers</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/skew-buster" title="Skew Buster" class="externalLink">Skew Buster</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Tutorial:_The_object-oriented_UDF_interface" title="Table-Oriented UDF" class="externalLink">Table-Oriented UDF</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Data_Loading#Trickle_Loading_Data_Into_Trafodion_Tables" title="Trickle Load" class="externalLink">Trickle Load</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Backup_and_Restore" title="Backup/Restore Utility" class="externalLink">Backup/Restore Utility</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Metadata_Cleanup" title="Metadata Cleanup Utility" class="externalLink">Metadata Cleanup Utility</a>
</li>
</ul>
</div>
<div class="span2 bottom-nav">
<ul class="nav nav-list">
<li class="nav-header">Contributing</li>
<li >
<a href="contribute.html" title="Contribute">Contribute</a>
</li>
<li >
<a href="advocate.html" title="Advocate">Advocate</a>
</li>
<li >
<a href="develop.html" title="Develop">Develop</a>
</li>
<li >
<a href="testing.html" title="Test">Test</a>
</li>
<li >
<a href="merge.html" title="Merge">Merge</a>
</li>
<li >
<a href="release.html" title="Release">Release</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="create-dev-environment.html" title="Create Dev Environment">Create Dev Environment</a>
</li>
<li >
<a href="manage-dev-environment.html" title="Manage Dev Environment">Manage Dev Environment</a>
</li>
<li >
<a href="setup-build-environment.html" title="Setup Build Environment">Setup Build Environment</a>
</li>
<li >
<a href="build.html" title="Build Trafodion">Build Trafodion</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="code.html" title="Modify Code">Modify Code</a>
</li>
<li >
<a href="tests.html" title="Modify Tests">Modify Tests</a>
</li>
<li >
<a href="document.html" title="Modify Documentation">Modify Documentation</a>
</li>
<li >
<a href="website.html" title="Modify Web Site">Modify Web Site</a>
</li>
<li >
<a href="wiki.html" title="Modify Wiki Pages">Modify Wiki Pages</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li class="active">
<a href="#" title="C++ Coding Guidelines">C++ Coding Guidelines</a>
</li>
</ul>
</div>
<div class="span4 bottom-description">
<blockquote><a href="http://trafodion.apache.org/">Apache Trafodion</a> is a webscale SQL-on-Hadoop solution enabling transactional or operational
workloads on Hadoop. <br /><br />The name "Trafodion" (the Welsh word for transactions, pronounced
"Tra-vod-eee-on") was chosen specifically to emphasize the differentiation that
Trafodion provides in closing a critical gap in the Hadoop ecosystem.<br /><br />
Trafodion builds on the scalability, elasticity, and flexibility of Hadoop. Trafodion extends
Hadoop to provide guaranteed transactional integrity, enabling new kinds of big data
applications to run on Hadoop.</blockquote>
</div>
</div>
</div>
</footer>
<div class="container subfooter">
<div class="row">
<div class="span12">
<p class="pull-right"><a href="#">Back to top</a></p>
<p class="copyright">Copyright ©2015 <a href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.</p>
<hr/>
<div class="row span16">
<span>Disclaimer: Apache Trafodion is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC.
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making
process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the
completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.</span>
<br/>
<br/>
<span>Apache, Apache Maven, Apache Maven Fluido Skin, the Apache feather logo, the Apache Maven project logo and the Apache Incubator project logo
are trademarks of The Apache Software Foundation.</span>
<br/>
<br/>
<span>
<a target="_blank" href="http://www.apache.org">
<img id="asf-logo" alt="Apache Software Foundation" src="images/logos/feather-small.gif"/>
</a>
<a target="_blank" href="http://incubator.apache.org/">
<img id="incubator-logo" alt="Apache Incubator" src="images/logos/egg-logo.gif"/>
</a>
</span>
</div> </div>
</div>
</div>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script src="./js/lightbox.min.js"></script>
<script src="./js/reflow-scroll.js"></script>
<script src="http://yandex.st/highlightjs/7.5/highlight.min.js"></script>
<script src="./js/reflow-skin.js"></script>
</body>
</html>