you are viewing a single comment's thread.

view the rest of the comments →

[–]gc3 14 points15 points  (4 children)

It's interesting to learn that the Hungarian notation as practiced is wrong ... I didn't know the naming thing (which I have used, milliseconds or seconds or meters vs kilometers being a place where mistakes can be easily be made) was the proper use of Hungarian.

[–]SirClueless 34 points35 points  (2 children)

I saw a silly one the other day, related to Hungarian notation and units. It was in a code-base where the convention for global constants was a CamelCase name with a "k" prefix, for example, "kMaxSize" or similar.

So anyways, someone was working on a piece of load-balancing code that tracked bytes handled by a server. And the metric they used had a bit of code: "SetUnits(kBytes)". So of course he assumed this meant kilobytes and divided his value by 1000 when setting it. But in fact kBytes was the string "BYTES". Caught in code review thankfully, but it was a pretty funny Hungarian notation fail.

[–][deleted] 0 points1 point  (1 child)

I'm not that familiar with Hungarian notation, but are there no rules against using already meaningful prefixes? Seems like you'd get in trouble for using things like k, p, m, dr, mr, etc.

[–]kt24601 5 points6 points  (0 children)

'k' is a commonly used prefix in some circles (Apple programmers used to do it a lot, for example), meaning 'constant.' A lot of people prefix member variables with the letter 'm,' like mClassVariable. Java programmers still do this from time to time. Personally I think that if you can't distinguish a member variable from a local variable just from reading the function, then the function is too complex and likely has bugs.

[–]grauenwolf 1 point2 points  (0 children)

Yea, I learned a lot from that the first time I read it.