[osg-users] [ANN] Cross-platform examples for Linux, macOS, Windows, Android, iOS, and Web

Robert Osfield robert.osfield at gmail.com
Wed Sep 26 07:17:23 PDT 2018


Hi Michael,

On Wed, 26 Sep 2018 at 09:16, michael kapelko <kornerr at gmail.com> wrote:
> I started to use explicit `this` to simplify reading and increase
> "shareability" of code:

Doing something that very few other developers do is likely to reduce
"shareability", I'm experienced engineer and read lots of third party
code and found myself wondering why the code was different.

> * I don't need to rely on IDE to highlight member or local
> variables/functions for me, so I can get away with simpler and faster
> tools (VIM, in my case)
> * I can paste such code blocks anywhere, and a reader won't need to
> run IDE to know this is member or local variable/function/etc.

If the code is well written then it should be relatively clear what a
global functions and what a local method calls.  Most modern C++
programs have few global variables and functions so if you see a
function call it's generally safe to assume it's a local method, for
variables then it's most likely the variable is a local or member
variable.  For the OSG we just prefect with _ to make it clear it's a
member variable rather than global, other codebases use m_ or keep the
class/structs simple enough that it's clear.  Personally I don't use
m_ as I find it distracting and reduces the flow of readability, and
find this-> is even more verbose and distracting.

> So far this approach looks better to me. When I see code referencing
> member variables/functions without `this`, I need to know what
> particular color IDE uses to tell member/local variables apart. And to
> make things more complicated, different IDEs use different colors :)

this-> is a lot of typing you keep having to do just to make your code
intentions clear.  Developers are used to code without it and should
be able to work out what is local or member variable/functions pretty
easily if the class/structs are kept straight forward and the member
function kepts small enough that you can see where local variables are
being written.

As for different IDE's doing different things.  Personally the first
stop should be making the code clear enough that these bells and
whistles aren't required, and if they are added then the developer
will likely be just using one IDE for majority of their work and
shouldn't end up confused.

Personally I don't use IDE's, I just use the KDE kate editor and read
the class interfaces and implementations, it does highlighting of many
things by not discriminating between member vs local variables etc.  I
don't have particular issues trying to read code.

When writing code for others to digest I think it is probably best to
avoid doing things that are unusual, and as a good practice the
CppCoreGuindelines are probably a good place to start as any.

Cheers,
Robert.


More information about the osg-users mailing list