News for hackers. Stuff that matters.
Re:My personal C coding style as of late 2023 by barbs on Monday October 09, 2023 @09:00AM (#37820021)
What alternative would you suggest?
Re:My personal C coding style as of late 2023 by yakubin on Monday October 09, 2023 @09:36AM (#37820333)
In C++ I do it Google style:

  static constexpr int kConstantName = 42;
Re:My personal C coding style as of late 2023 by _moof on Monday October 09, 2023 @10:19AM (#37820708)
This is the old Mac style too. Might just be my upbringing but I prefer it.
Re:My personal C coding style as of late 2023 by avgcorrection on Monday October 09, 2023 @10:44AM (#37820954)
What's the point of the `k` prefix?
Re:My personal C coding style as of late 2023 by smithza on Monday October 09, 2023 @10:51AM (#37821040)
k for konstant
Re:My personal C coding style as of late 2023 by avgcorrection on Monday October 09, 2023 @11:01AM (#37821160)
Yes, that's what it stands for. What's the point of using any prefix at all?
Re:My personal C coding style as of late 2023 by wrs on Monday October 09, 2023 @01:42PM (#37823078)
So you don’t have to wonder if it’s a variable. Old Mac style uses prefixes: kConstant, gGlobalVar, TType, mMemberVar. Remember this was when all coding was done in black and white in a plain text editor.
Re:My personal C coding style as of late 2023 by colejohnson66 on Monday October 09, 2023 @06:03PM (#37826040)
Hungarian notation
Re:My personal C coding style as of late 2023 by Dylan16807 on Wednesday October 11, 2023 @02:39AM (#37841641)
Hungarian notation is for being more specific than the type system allows.

When the type is already "constexpr int", that k isn't helping.

Re:My personal C coding style as of late 2023 by dkersten on Tuesday October 10, 2023 @07:26AM (#37830774)
IMHO that’s much uglier than using caps.

Sometimes when I use C++, I will namespace them however:

    namespace constants {
        static constexpr int name = 42;
    }
    …
    int x = constants::name;
The exact name of the namespace would depend on the use and could be something more descriptive.
Re:My personal C coding style as of late 2023 by avgcorrection on Monday October 09, 2023 @09:08AM (#37820085)
Writing in a normal way in snake case or camel case or whatever the convention is.
Re:My personal C coding style as of late 2023 by xigoi on Tuesday October 10, 2023 @02:18PM (#37835526)
Just use the same style as for variables. What's the point of the distinction? Maybe you'll want to change a constant into a variable later.