Programming conventions

Hi everyone,

Since I started to do some proper development under Haiku, some conventions let me puzzled. For example, does anyone know why data members a traditionally prefixed with the letter f?

I understand the Microsoft’s now-deprecated Hungarian notation rippling over, but not the choice of letter.

Some other conventions I get:

  • k for konstant (but why not c?)

  • M for Message

  • _ for private members (even if that may be non-compliant with C++ standards)

    This messages may be construed as trying to incite to a flamewar, I beg people who’d answer to restrain, the intent is just to understand some choices :sweat_smile:

AFAIK, “f” is for “field”. I’ve seen some code bases use “m” or “m_” for “member” instead :slight_smile:.

1 Like

This makes so much sense, how couldn’t I think of it :exploding_head:

I had that tradition for a while in C++: m_, mp_, p_, g_, gp_ and c_, that’s it i think. But I’m trying to discard the use nowadays as it doesn’t really add value

My understanding of “k” for constants is three possibilities:

  • at the time the notation was developed, ‘c’ meant ‘character’
  • ‘k’ is commonly used in mathematics for constant values
  • some languages spell ‘constant’ with a ‘k’ (such as German)

pick your favorite!


We don’t go with the “full” hungarian notation (encoding the type of the variable into letters - there’s already C++ mangling for that :sweat_smile: ). But I find the use of f (for fields), k (constants, probably from a German spelling since a lot of Haiku developers are from Germany?), g (globals) and s (static class members) very useful: when looking at a piece of code, you don’t need to look anywhere else to know where a variable comes from and is used.

In codebases that don’t use this convention, I constantly have to search if a variable is local to the function or to the class or something else, and it really degrades my ease of understanding of the code.

It’s very possible that this is only because I have spent way too much time reading and writing Haiku related code :slight_smile: