Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on programming.dev

5 replies

piefed.ca

Coming from C++, I initially thought it aggravating that you have to go self. everywhere when working with classes in Python. But I've conceded that it improves code-legibility, and now I'm going this-> everywhere when I'm back in C++.

2
bterwijnreply
programming.dev

Another common naming convention in C++ is using an underscore as prefix for member variables: int _memberVariable{123};

0
piefed.ca

My personal convention in C++ was to use an m prefix on member variables and a g for class variables.

I guess in Python, I think of _ as equivalent to protected scope in C++ and __ (double underscore) as equivalent to private. Not a perfect analogy, but it works for me.

1
aionreply
lemmy.world

Just don't use double underscores in C++, identifiers containing double underscores are reserved for the compiler/linker/standard library.

2

Same thing in Python, double underscore prefix triggers "name mangling". There are issues that can pop up when using it if not aware.

1

You reached the end

Difference between 'instance', 'class', and 'static' method visually explained | Spyke