On Monday, March 26, 2018 at 6:05:17 AM UTC-4, Jorgen Grahn wrote:
> On Sun, 2018-03-25, Daniel wrote:
> > I've been skimming the boost include directory for inspiration for
> > naming subdirectories, namespaces, and class names, when the most
> > natural name would be the same. As in boost, assume all lower case
> > naming convention, so no help from mixed case differentiation.
> >
> > Some examples from boost:
> >
> > subdirectory name: bimap
> > namespace name: bimaps
> > class name: bimap
> >
> > subdirectory name: iterator
> > namespace name: iterators
> > class name: iterator
> >
> > subdirectory name: function_types
> > namespace name: function_types
> > class name: function_type
> >
> > subdirectory name: optional
> > namespace name: optional_ns
> > class name: optional
>
> Note that Boost is a general library; different needs compared to a
> class in a program.
The context is a general purpose open source library for json, cbor,
msgpack and related json-inspired data models, as well as standard and defacto standard algorithms that apply to these data models, such as
jsonpath, json content rules, jsonpointer, and jsonpatch. So the needs are
the same.
>
> > Any thoughts? My immediate context is where the most natural name
> > for a subdirectory, namespace and class name is "cbor" (a class
> > encapsulating the Concise Binary Object Representation and related
> > algorithms.)
>
> Having a 1:1 mapping between subdirectories and major namespaces
> sounds like a good idea.
Agreed. That's what boost does most of the time, except in the few cases
where the "natural" name for the subdirectory, path and class are the same,
e.g. bimap. In that case boost made the namespace plural, but in the case
of option, they made the namespace option_ns.
>
> My only thought is that having both a namespace and a class named cbor
> seems a bit suspect. Maybe the namespace isn't needed?
It is. cbor, msgpack, jsonpointer, jsonpath etc. are distinct libraries.
> Or maybe
> there's a better class name? I'm not familiar with CBOR, but I could
> imagine cbor::Encoder and cbor::Decoder being better names.
>
Encoders, decoders, validators, there are all of those things, but
in addition there's a need for a value representation of the bytes,
with a corresponding set of member functions, some common to json,
cbor, and msgpack. That's what allows query algorithms like jsonpointer
and jsonpath to be applied to any of the json-like data models,
whether unpacked or binary encoded.
But this is the main issue, whether to choose a different namespace
name, which seems to be boost's practice, or to give the value like class a
different name, e.g. cbor_val or cbor_value.
> The class name should IMHO be read as in the context of the namespace,
> and then cbor::cbor would just be superfluous, and say nothing about
> the class itself.
>
I suppose cbor::value (msgpack::value) would be an option, but value by
itself seems uninspired. Or perhaps cbor::packed (msgpack::packed), as
these encapsulate packed arrays of bytes.
Thanks for the comments, questions about naming conventions tend to be sparsely responded to here :-) But at the same, there are clearly best practices for naming, and with libraries it's helpful to follow conventions,
so feedback appreciated.
Daniel