Click here to Skip to main content
15,886,110 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
Marcelo Huerta9-Jan-23 6:16
Marcelo Huerta9-Jan-23 6:16 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
jmaida8-Jan-23 15:54
jmaida8-Jan-23 15:54 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
BillWoodruff8-Jan-23 20:33
professionalBillWoodruff8-Jan-23 20:33 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
Mircea Neacsu10-Jan-23 6:34
Mircea Neacsu10-Jan-23 6:34 
AnswerRe: What are some stupid-useful coding tricks you rely on? Pin
Mike Hankey8-Jan-23 7:42
mveMike Hankey8-Jan-23 7:42 
AnswerRe: What are some stupid-useful coding tricks you rely on? Pin
Marc Clifton8-Jan-23 11:28
mvaMarc Clifton8-Jan-23 11:28 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
honey the codewitch8-Jan-23 12:01
mvahoney the codewitch8-Jan-23 12:01 
AnswerRe: What are some stupid-useful coding tricks you rely on? Pin
Gary R. Wheeler8-Jan-23 13:53
Gary R. Wheeler8-Jan-23 13:53 
honey the codewitch wrote:
Template-instance statics
I've done that for cases where I didn't want to pass around a singleton instance:
class API
{
public:

    static void DoThing();

private:

    API();

    static API *_This;
};

API *API::_This = NULL;

void API::DoThing()
{
    if (_This == NULL) _This = new API();
}
It's useful for create-only-if-needed scenarios. For us, those arise fairly often adapting to different hardware. They're also useful when the creation process is expensive or time-consuming.

In C++ I like the idea that API::DoThing() is a blatant syntax for a singleton concept.

I've also had cases where the public static functions define the 'API' for a collection, while the instance members and values are the elements in the collection.

Now, I know that singletons are a 'code smell', but trust me... I know what I'm doing. Big Grin | :-D
Software Zen: delete this;

GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
honey the codewitch8-Jan-23 14:52
mvahoney the codewitch8-Jan-23 14:52 
PraiseRe: What are some stupid-useful coding tricks you rely on? Pin
Gary Wheeler9-Jan-23 2:38
Gary Wheeler9-Jan-23 2:38 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
honey the codewitch9-Jan-23 5:18
mvahoney the codewitch9-Jan-23 5:18 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
Gary Wheeler9-Jan-23 5:23
Gary Wheeler9-Jan-23 5:23 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
honey the codewitch9-Jan-23 5:54
mvahoney the codewitch9-Jan-23 5:54 
AnswerRe: What are some stupid-useful coding tricks you rely on? Pin
Mircea Neacsu8-Jan-23 14:08
Mircea Neacsu8-Jan-23 14:08 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
honey the codewitch8-Jan-23 14:53
mvahoney the codewitch8-Jan-23 14:53 
GeneralRe: What are some stupid-useful coding tricks you rely on? Pin
CPallini8-Jan-23 20:28
mveCPallini8-Jan-23 20:28 
AnswerRe: What are some stupid-useful coding tricks you rely on? Pin
Dan Sutton9-Jan-23 6:30
Dan Sutton9-Jan-23 6:30 
AnswerRe: What are some stupid-useful coding tricks you rely on? Pin
HappyDotNet10-Jan-23 5:01
professionalHappyDotNet10-Jan-23 5:01 
AnswerRe: What are some stupid-useful coding tricks you rely on? Pin
englebart21-Jan-23 9:29
professionalenglebart21-Jan-23 9:29 
AnswerRe: What are some stupid-useful coding tricks you rely on? Pin
FormerBIOSGuy26-Jan-23 6:13
FormerBIOSGuy26-Jan-23 6:13 
GeneralStrange RDP problem Pin
dandy728-Jan-23 4:33
dandy728-Jan-23 4:33 
GeneralRecursively Searching for "text" in files in windows 11 Pin
jmaida7-Jan-23 18:10
jmaida7-Jan-23 18:10 
GeneralRe: Recursively Searching for "text" in files in windows 11 Pin
David O'Neil7-Jan-23 20:27
professionalDavid O'Neil7-Jan-23 20:27 
GeneralRe: Recursively Searching for "text" in files in windows 11 Pin
jmaida8-Jan-23 13:16
jmaida8-Jan-23 13:16 
GeneralRe: Recursively Searching for "text" in files in windows 11 Pin
David O'Neil8-Jan-23 13:26
professionalDavid O'Neil8-Jan-23 13:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.