Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > sci.physics > #610246
| From | Jeff-Relf.Me <@.> |
|---|---|
| Newsgroups | comp.os.linux.advocacy, sci.physics, comp.lang.c++ |
| Subject | My C++ Coding Standards ( apologies to Bjarne Stroustrup ). |
| Date | 2016-12-23 17:06 -0800 |
| Organization | Glorb Internet Services, http://www.glorb.com |
| Message-ID | <Jeff-Relf.Me@Dec.23--5.06P.Seattle.2016> (permalink) |
| References | (1 earlier) <o3jsu7$he6$1@pcls7.std.com> <mbuq5cpls71t5eoq0mqo32lspj1l3vjhsr@4ax.com> <o3jveq$ll6$2@dont-email.me> <D482D7F6.85EDE%usenet@gallopinginsanity.com> <o3k5gr$c3c$1@dont-email.me> |
Cross-posted to 3 groups.
My C++ Coding Standards ( apologies to Bjarne Stroustrup ):
1. If everything ( but the top node ) were local,
then you'd be spending all your time traversing trees,
like an ant, instead of doing real work.
So use Global Variables/Functions early and often.
This, the common way, is ambiguous:
if ( HandleEvents(1) ) ...
Instead, use globals (below), like this:
WaitForClick = 1, HandleEvents(); if ( Click ) ...
Globals:
int WaitForClick, Click ;
void HandleEvents() { MSG Msg ;
GetMsg: PeekMessage( &Msg, 0, 0, 0, PM_REMOVE );
Click = Msg.message == WM_LBUTTONDOWN ;
// Handle system events, like WM_NCACTIVATE... Blah Blah.
// When WaitForClick == 1, Exit if-and-only-if there's a Click:
if ( Click || !WaitForClick ) { WaitForClick = 0 ; return ; }
// Draw Stuff... Blah Blah.
goto GetMsg ; }
2. InLine Conditionals ( Bool ? True() : False() ) are nice and concise.
For example:
inline int TheSmaller( int X, int Y ) { return X < Y ? X : Y ; }
#define FlagTheNym /* 'V' is for Visitor. */ \
Nym.Trusted ? 'T' : Nym.Dropped ? 'D' : Nym.Kid ? 'K' : Nym.Adult ? 'A' : 'V'
3. Simplify Odd system calls, like this:
wchar aString[999];
Str( aString, L"A 32 bit, unsigned Random Integer: %I64d", Rand32 );
Globals:
typedef wchar_t wchar ;
unsigned int uiRand ;
#define Rand32 ( rand_s( &uiRand ), uiRand ) // Seeding is implicit.
#define Str swprintf // Print to a Unicode string, "printf" style.
4. A variable's declared type isn't always appropriate; so Type Cast.
#define szStr (int)wcslen // Return the length of a Unicode string.
#define Zero( X ) memset( & X, 0, sizeof X ) // Implicit cast to (void*).
Zero( aStruct );
5. Create fewer/larger functions.
Put everything in a single, large .CPP file -- don't create .H files.
6. Local, ShortTerm variables are nice. Like:
wchar _T[999], *P = _T ;
Loop(3) { _Loop(4) P += Str( P, L"( %d, %d )%s", J, JJ, J == eJ ? L"\n" : L" " ); }
printf( _T );
Globals:
#define Loop( N ) int eJ = ( N ) - 1, J = -1 ; while ( ++J <= eJ )
#define _Loop( N ) int JJ = J, eJ = ( N ) - 1, J = -1 ; while ( ++J <= eJ )
#define Str swprintf
typedef wchar_t wchar ;
Output:
( 0, 0 ) ( 1, 0 ) ( 2, 0 ) ( 3, 0 )
( 0, 1 ) ( 1, 1 ) ( 2, 1 ) ( 3, 1 )
( 0, 2 ) ( 1, 2 ) ( 2, 2 ) ( 3, 2 )
See X.CPP in "Jeff-Relf.Me/X.ZIP".
Back to sci.physics | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Loop(100) Jeff-Relf.Me <@.> - 2016-12-17 12:34 -0800
Command Line jockies use plenty of aliases, no ? ! Jeff-Relf.Me <@.> - 2016-12-17 21:59 -0800
Re: Loop(100) moroney@world.std.spaamtrap.com (Michael Moroney) - 2016-12-19 17:20 +0000
I don't worry about "optimizations", don't need to. Jeff-Relf.Me <@.> - 2016-12-19 10:56 -0800
Re: I don't worry about "optimizations", don't need to. moroney@world.std.spaamtrap.com (Michael Moroney) - 2016-12-20 12:30 +0000
Other people's code is hard to learn/modify. Jeff-Relf.Me <@.> - 2016-12-20 06:06 -0800
Re: Other people's code is hard to learn/modify. Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-12-20 15:31 +0100
Re: Other people's code is hard to learn/modify. chrisv <chrisv@nospam.invalid> - 2016-12-20 09:04 -0600
Re: Other people's code is hard to learn/modify. Double-A <double-a3@hush.com> - 2016-12-20 13:33 -0800
Re: Other people's code is hard to learn/modify. moroney@world.std.spaamtrap.com (Michael Moroney) - 2016-12-20 15:06 +0000
What The Fuck is wrong with your peers ? ! Jeff-Relf.Me <@.> - 2016-12-20 09:59 -0800
Re: What The Fuck is wrong with your peers ? ! moroney@world.std.spaamtrap.com (Michael Moroney) - 2016-12-20 23:22 +0000
I won, bigly. Jeff-Relf.Me <@.> - 2016-12-20 16:15 -0800
AutoFormatting hides the fingerprints. Jeff-Relf.Me <@.> - 2016-12-21 02:55 -0800
Re: AutoFormatting hides the fingerprints. Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-12-21 14:33 +0100
Re: AutoFormatting hides the fingerprints. moroney@world.std.spaamtrap.com (Michael Moroney) - 2016-12-22 03:21 +0000
My code is dense, and hard to read, like the Washington Post. Jeff-Relf.Me <@.> - 2016-12-22 02:36 -0800
Re: My code is dense, and hard to read, like the Washington Post. moroney@world.std.spaamtrap.com (Michael Moroney) - 2016-12-22 21:22 +0000
Re: My code is dense, and hard to read, like the Washington Post. chrisv <chrisv@nospam.invalid> - 2016-12-23 07:54 -0600
Re: My code is dense, and hard to read, like the Washington Post. flatfish+++ <flatfish@linuxmail.org> - 2016-12-23 09:35 -0500
Re: My code is dense, and hard to read, like the Washington Post. moroney@world.std.spaamtrap.com (Michael Moroney) - 2016-12-23 16:21 +0000
My code is dense, and hard to read, like the Washington Post. Jeff-Relf.Me <@.> - 2016-12-23 08:52 -0800
Re: My code is dense, and hard to read, like the Washington Post. moroney@world.std.spaamtrap.com (Michael Moroney) - 2016-12-23 19:12 +0000
Re: My code is dense, and hard to read, like the Washington Post. chrisv <chrisv@nospam.invalid> - 2016-12-23 13:27 -0600
Re: My code is dense, and hard to read, like the Washington Post. Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-12-23 20:56 +0100
Re: My code is dense, and hard to read, like the Washington Post. Snit <usenet@gallopinginsanity.com> - 2016-12-23 13:32 -0700
Re: My code is dense, and hard to read, like the Washington Post. Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-12-23 22:40 +0100
Re: My code is dense, and hard to read, like the Washington Post. Snit <usenet@gallopinginsanity.com> - 2016-12-23 15:19 -0700
My C++ Coding Standards ( apologies to Bjarne Stroustrup ). Jeff-Relf.Me <@.> - 2016-12-23 17:06 -0800
Re: My C++ Coding Standards ( apologies to Bjarne Stroustrup ). Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-12-24 10:40 +0100
Re: My code is dense, and hard to read, like the Washington Post. jmfbahciv <See.above@aol.com> - 2016-12-24 14:04 +0000
I explain each of the warnings I disable, and why. Jeff-Relf.Me <@.> - 2017-01-19 03:00 -0800
Re: I explain each of the warnings I disable, and why. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-01-19 12:09 +0100
Re: I explain each of the warnings I disable, and why. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-01-20 04:29 +0000
Re: I explain each of the warnings I disable, and why. chrisv <chrisv@nospam.invalid> - 2017-01-20 06:48 -0600
Re: I explain each of the warnings I disable, and why. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-01-20 16:52 +0100
It's fucking email ! ! Jeff-Relf.Me <@.> - 2017-01-19 02:53 -0800
Someday, if you're lucky, you'll know the freedoms I enjoy. Jeff-Relf.Me <@.> - 2016-12-23 08:05 -0800
Re: My code is dense, and hard to read, like the Washington Post. GreyCloud <mist@cumulus.com> - 2016-12-23 13:49 -0700
Whitespace and (borked) comments. Jeff-Relf.Me <@.> - 2017-01-19 02:24 -0800
Re: Whitespace and (borked) comments. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-01-19 11:30 +0100
Re: Whitespace and (borked) comments. chrisv <chrisv@nospam.invalid> - 2017-01-19 07:29 -0600
Re: Whitespace and (borked) comments. Jerry Stuckle <jstucklex@attglobal.net> - 2017-01-19 10:36 -0500
Re: Whitespace and (borked) comments. Peter Köhlmann <peter-koehlmann@t-online.de> - 2017-01-19 16:48 +0100
Re: Whitespace and (borked) comments. GreyCloud <mist@cumulus.com> - 2017-01-19 11:20 -0700
Re: Whitespace and (borked) comments. Jerry Stuckle <jstucklex@attglobal.net> - 2017-01-19 14:49 -0500
Re: Whitespace and (borked) comments. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-01-20 04:26 +0000
About a hundred thousand people have used my code, last 24 years. Jeff-Relf.Me <@.> - 2017-01-19 20:57 -0800
Re: Whitespace and (borked) comments. jmfbahciv <See.above@aol.com> - 2017-01-20 13:39 +0000
Re: Whitespace and (borked) comments. chrisv <chrisv@nospam.invalid> - 2017-01-20 07:46 -0600
Re: Whitespace and (borked) comments. jmfbahciv <See.above@aol.com> - 2017-01-21 14:08 +0000
Re: Whitespace and (borked) comments. Vir Campestris <vir.campestris@invalid.invalid> - 2017-01-20 22:02 +0000
Re: Whitespace and (borked) comments. noTthaTguY <abu.kuanysh05@gmail.com> - 2017-01-20 18:31 -0800
Re: Whitespace and (borked) comments. jmfbahciv <See.above@aol.com> - 2017-01-21 14:08 +0000
Re: Whitespace and (borked) comments. Vir Campestris <vir.campestris@invalid.invalid> - 2017-01-22 17:58 +0000
Whenever/Wherever you spot a lot of whitespace and comments. Jeff-Relf.Me <@.> - 2017-01-19 02:18 -0800
Re: I won, bigly. Silver Slimer <.m@nsn.s> - 2016-12-21 09:09 -0500
Re: I won, bigly. benj <benj@nobody.net> - 2016-12-21 17:37 -0500
Re: What The Fuck is wrong with your peers ? ! chrisv <chrisv@nospam.invalid> - 2016-12-21 07:14 -0600
csiph-web