Does anyone do things like this

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Does anyone do things like this

Post by MrGodin » February 20th, 2017, 8:00 pm

Just to clarify things

Code: Select all

#if !defined(internal)// static function calls, i know std has std::internal
#define internal static
#endif
#define global_variable static// self explanatory
#define local_persist static// local in a scope
Curiosity killed the cat, satisfaction brought him back

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Does anyone do things like this

Post by Ziltwix » February 21st, 2017, 5:02 pm

Whatcha doing here, MrGodin?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Does anyone do things like this

Post by albinopapa » February 21st, 2017, 6:38 pm

Nope, I just use static as is. Why would you want to alias it?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Does anyone do things like this

Post by MrGodin » February 21st, 2017, 11:07 pm

albinopapa wrote:Nope, I just use static as is. Why would you want to alias it?
I was watching a professional coding in C and he does all kinds of typedef, and defines, I thought it was weird, but at the same time kinda interesting. His reasoning was so he has better clarity. Each to their own i guess
Last edited by MrGodin on February 21st, 2017, 11:18 pm, edited 1 time in total.
Curiosity killed the cat, satisfaction brought him back

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Does anyone do things like this

Post by MrGodin » February 21st, 2017, 11:16 pm

Ziltwix wrote:Whatcha doing here, MrGodin?
There are things you can do to type less (in other words, being lazy). Sometimes there are variables that have long names and if you use then often, it's a pain to type out all the time. These little tricks can make life easier.
example
typedef std::string sString;
so instead of typing std::string all the time, you can now go.. sString name = "whatever the name is" ... instead of std::string name = "wahtever the name is".
It's still a std::string but you just give it a different name, so to speak.
I wouldn't recommend doing this yourself yet, best to learn the original way at first :)
Doing this can really upset someone trying to read your code too, so it's not always a good idea
Curiosity killed the cat, satisfaction brought him back

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Does anyone do things like this

Post by albinopapa » February 22nd, 2017, 4:17 am

instead of using typedef, you can also use using.

old way

typedef std::string sString;

new way

using sString = std::string;
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Does anyone do things like this

Post by MrGodin » February 22nd, 2017, 5:36 am

albinopapa wrote:instead of using typedef, you can also use using.

old way

typedef std::string sString;

new way

using sString = std::string;
Yeah, i haven't used that yet. Don't really see a difference, just new terminology ?.
Curiosity killed the cat, satisfaction brought him back

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Does anyone do things like this

Post by albinopapa » February 22nd, 2017, 5:48 am

The ordering is different.

Also, using has more benefits as well. You can template the alias also

template< class T >
using myvector<T> = std::vector<T>;

I've used this method to avoid 'using namespace' or using Microsoft::WRL::ComPtr;

template<class T>
using comptr<T> = Microsoft::WRL::ComPtr<T>;

that's something you can't do with typedef.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Does anyone do things like this

Post by Ziltwix » February 25th, 2017, 3:51 pm

That's really interesting! I'll just stick with what I know before I do a flip into a whole new dimension, haha!

Post Reply