3 ms·
Perhaps the Platonic Ideal of Hungarian notation, but most code bases I've dealt with that use Hungarian notation would simply do (not a real example, but remin
by strlen 13y ago
Perhaps the Platonic Ideal of Hungarian notation, but most code bases I've dealt with that use Hungarian notation would simply do (not a real example, but reminiscent of Win32 sockets APIs):
bool bRateLimitViolation(uint32_t ui32Count, DWORD* dwOutPtrAddr,
std::string& sRefId);
In other words, this does nothing that hitting M-. in emacs+etags (or ctags equivalent for vi(m), etc...) won't do. Instead, consider this code:
bool checkRateLimit(uint32_t attempts_per_sec,
const std::string* resource_hash,
DWORD* raw_violator_ip);
Note a few changes here: there's an implicit convention -- references are only used if they're const references (otherwise
pointers are used), out parameters go left, names of functions are lowerCamelCase, while local variables and parameters are snake_case (presumably cases can be UpperCamelCase), variable
names are meaningful (if a variable is too long I can hit M-/ or -- again -- the vi(m) equivalent, plus the Hungarian notation advocates aren't into the whole brevity thing either).
What does work is using Hungarian notation to document exceptions rather than the rules:
e.g.,
enum {
kMajorVersion = 3
...
};
SomeThingStupid* g_YesIUsedAGlobalHere;
I do also see this argument, but I am not sure even the best
type systems (e.g., Haskell) do a great job here. Yes, this:
data HashString = HashString String
unHashString (HashString s) = s
hs = HashString "foo"
... is fewer lines than:
struct HashString {
std::string s;
std::string as_string() const { return s; }
};
auto hs = HashString {"foo"};
But fundamentally it may be easier for most to simply do:
type HashString = String {- merely an alias, like typedef -}
checkHash :: HashString -> Bool
checkHash hashString = ....
- strlen 13y agos/const std::string* resource_hash/const std::string& resource_hash/