In the STL, we conventionally avoid declaring multiple variables on a single line. That is:
int cats, dogs; // we avoid this style
int meow; // we prefer this style
int woof;
Our reasons for this convention are:
- Being aware of the variables in a class or function is important, because humans have difficulty reasoning about program state (especially when it's modifiable). Consistently declaring one variable per line makes it clear when variables are being introduced, and whether they're initialized. (It also makes it "feel costly" to declare many variables, which is subtle encouragement to avoid introducing unnecessary state.)
- C++'s rules for multi-variable declarations are surprising to newer programmers. (In particular, the rules when pointers are involved.) Avoiding such declarations avoids the need to learn/teach/read that bit of complexity.
We're pretty consistent about following this convention, but there are a few files that should be changed. I observe the following occurrences (there may be more):
|
const _Ty *_First, *_Last, *_Other;
|
|
_Iosarray *_Ptr1, *_Ptr2;
|
|
_Iosarray *_Ptr1, *_Ptr2;
|
|
_ULARGE_INTEGER _Available, _Capacity, _Free; |
|
const char *sc, *sd; |
|
const char *s1, *s2; |
|
const char *sc, *sd; |
|
const char *s1, *s2; |
|
char dig, sign; |
- These occurrences are weird-looking, but should be treated similarly:
|
__PURE_APPDOMAIN_GLOBAL extern istream cin, *_Ptr_cin;
|
|
__PURE_APPDOMAIN_GLOBAL extern ostream cout, *_Ptr_cout;
|
|
__PURE_APPDOMAIN_GLOBAL extern ostream cerr, *_Ptr_cerr;
|
|
__PURE_APPDOMAIN_GLOBAL extern ostream clog, *_Ptr_clog;
|
|
|
|
__PURE_APPDOMAIN_GLOBAL extern wistream wcin, *_Ptr_wcin;
|
|
__PURE_APPDOMAIN_GLOBAL extern wostream wcout, *_Ptr_wcout;
|
|
__PURE_APPDOMAIN_GLOBAL extern wostream wcerr, *_Ptr_wcerr;
|
|
__PURE_APPDOMAIN_GLOBAL extern wostream wclog, *_Ptr_wclog;
|
|
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT istream cin, *_Ptr_cin;
|
|
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT ostream cout, *_Ptr_cout;
|
|
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT ostream cerr, *_Ptr_cerr;
|
|
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT ostream clog, *_Ptr_clog;
|
|
|
|
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT wistream wcin, *_Ptr_wcin;
|
|
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT wostream wcout, *_Ptr_wcout;
|
|
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT wostream wcerr, *_Ptr_wcerr;
|
|
__PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT wostream wclog, *_Ptr_wclog;
|
|
extern _CRTIMP2_PURE_IMPORT /* const */ _Dconst _Denorm, _Hugeval, _Inf, _Nan, _Snan; |
|
extern _CRTIMP2_PURE_IMPORT /* const */ _Dconst _FDenorm, _FInf, _FNan, _FSnan; |
|
extern _CRTIMP2_PURE_IMPORT /* const */ _Dconst _LDenorm, _LInf, _LNan, _LSnan; |
- Finally, the occurrences in
xcharconv_ryu.h should not be changed at this time (as this code is kept in sync with the upstream Ryu project):
|
uint32_t __vr, __vp, __vm; |
|
uint64_t __vr, __vp, __vm; |
I found all of these occurrences by using VSCode to regex-search for (\w+)(, \*?\w+)+; excluding files in tests/*.
In the STL, we conventionally avoid declaring multiple variables on a single line. That is:
Our reasons for this convention are:
We're pretty consistent about following this convention, but there are a few files that should be changed. I observe the following occurrences (there may be more):
STL/stl/inc/random
Line 622 in fffbd8f
STL/stl/inc/xiosbase
Line 511 in fffbd8f
STL/stl/inc/xiosbase
Line 532 in fffbd8f
STL/stl/inc/xiosbase
Line 540 in fffbd8f
STL/stl/inc/cvt/wbuffer
Line 264 in fffbd8f
STL/stl/src/filesys.cpp
Line 317 in fffbd8f
STL/stl/src/xstol.cpp
Line 21 in fffbd8f
STL/stl/src/xstoll.cpp
Line 19 in fffbd8f
STL/stl/src/xstoul.cpp
Lines 35 to 36 in fffbd8f
STL/stl/src/xstoul.cpp
Line 40 in fffbd8f
STL/stl/src/xstoull.cpp
Lines 27 to 29 in fffbd8f
STL/stl/src/xstoull.cpp
Line 31 in fffbd8f
STL/stl/src/xxxprec.h
Line 70 in fffbd8f
STL/stl/src/xxxprec.h
Line 105 in fffbd8f
STL/stl/src/xxxprec.h
Line 212 in fffbd8f
STL/stl/inc/iostream
Lines 21 to 29 in fffbd8f
STL/stl/inc/iostream
Lines 33 to 41 in fffbd8f
STL/stl/inc/ymath.h
Line 48 in fffbd8f
STL/stl/inc/ymath.h
Line 56 in fffbd8f
STL/stl/inc/ymath.h
Line 64 in fffbd8f
xcharconv_ryu.hshould not be changed at this time (as this code is kept in sync with the upstream Ryu project):STL/stl/inc/xcharconv_ryu.h
Line 1061 in fffbd8f
STL/stl/inc/xcharconv_ryu.h
Line 1751 in fffbd8f
I found all of these occurrences by using VSCode to regex-search for
(\w+)(, \*?\w+)+;excluding files intests/*.