Coding style and naming conventions for C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everybody,

I'd like to discuss a few things about the coding style for C++ in
Spice (looking at the streaming agent atm).

Trying to keep this short and concise.


1. Method names
Currently the method names are in CamelCase throughout the streaming
agent. Methods are basically functions attached to a class, I suggest
we use snake_case to be consistent with the function names.

It's rather confusing when you see a call like SomeObject(), which
looks like a constructor, but you actually find out it's a method call
from another method of the same class.


2. Namespace names
Although not standard (you may have different experience), usually
namespaces are lowercase in C++. Also, they are hierarchical, I suggest
we use that and in streaming agent we change the namespace like so:

SpiceStreamingAgent -> spice::streamingagent

or (imho better):
SpiceStreamingAgent -> spice::streaming_agent

And stick to this scheme, i.e. lowercase and toplevel namespace
'spice', inside it a namespace of the component.


3. Namespace coding style

a) Let's not use `using namespace ...` ever even in .cpp files (see
i.e. [1]). In streaming agent we have at the beginning of every .cpp:

using namespace std;
using namespace SpiceStreamingAgent;

For namespace std, "std::" is not a long prefix, clearly expresses the
identifier is from the standard library and AFAIK most C++ projects use
it this way.

For namespace SpiceStreamingAgent, I didn't even know it worked for
definition of symbols in the namespace. First time I see it, it is very
unusual. see b).

b) Let's keep the following coding style for namespaces, i.e. for
streaming agent:

namespace spice {
namespace streaming_agent {

THE_CODE

}} // namespace spice::streaming_agent


We should add the guidelines to the website next to the C coding style,
but I have no intention to be exhaustive (see [1] for how long it can
be), let's add important cases as they come up and just use common
sense, keep the style of the local code and codereview to keep things
in check?

Lukas


[1] https://google.github.io/styleguide/cppguide.html#Namespaces
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]