u/emfloured

PFRAII (Pre-emptive Fatigue Reduction Arrangement Is Initialization) :D

PFRAII (Pre-emptive Fatigue Reduction Arrangement Is Initialization) :D

{update}: I got it now. This is a wrong design. Thank you guys!

{original post}:
This is about using custom short aliases of C++ types via a namespace. I am not saying it's perfect but here me out.

The goal is achieving minimum number of keystrokes when repeatedly writing some of these boring big-ass type-names. (the auto keyword is too ambiguous to be used most of the time)

I have created these weird looking type aliases that I am thinking to use everywhere.
https://godbolt.org/z/4x1fzdbY5

Design:
0: Every type is const by default.
1: A type name ending with 'm' means the object is mutable.
2: A type name ending with 'r' means the object is reference to this type.
3: A type name ending with 'mr' means the object is mutable and reference to this type.

I mean even though we are used to it yet literally who the even loves to write something like this:
const std::unordered_map<std::uint32_t, std::vector<std::vector<uint64_t>>>

when,
mp<i32um, vc<vc<i64um>>>
is easier to look at, more code fits into the screen and once you get comfortable with new terminology; it should take no more than a day, your eyes get to easily focus more on the expressions and logic rather than spending more time on scanning the code.

Yes, I acknowledge the risk of global namespace pollution.
but this should work fine if all of the following is true, right!?

0: Never use "using namespace <namespace-name>" at the global scope.
1: Never use variable/constants at the global scope.
2: No declaration/definition of free function, class, struct, enum, enum class whatever at the global scope.
3: Only things that can exist at global scope is definition of namespaces.
4: All free constants/variables, free functions, classes, structures, enum, enum class etc exist only inside its respective namespace.

Fox example, the NSTypeAlias namespace will be used as:

namespace NSMyCustomUtility::FileIO {
  using namespace NSTypeAlias;
          
}

or

int main(){
  using namespace NSTypeAlias;
  
  return 0;
}

or

namespace NSMyFileSystem {
 using namespace NSTypeAlias;
    
 class FileSystemX1{
        
 }
}

And in case the name collision does happen some day because we found a library to collide with we can always use it as

using Tpi32m = NSTypeAlias::i32m; or something like that inside that specific inner context whereever the name collision occurs.

or we simply revert to the stock C++ type names within that particular context and use a comment that says, /* can't use the custom type names because of collision */

because nothing is perfect and is ever going to be perfect anyway.

or, am I coping hard and bringing the other foot of mine into the possible blast radius as well? lol

u/emfloured — 3 days ago