C++ Weekly - Ep 192 - Stop Using Double Underscores

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

Upcoming Workshops:

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

Рекомендации по теме
Комментарии
Автор

The audio at the end cut off because you invoked too much undefined behavior in your video.

Tinfoilpain
Автор

Use the notation 'this->' before the variables members (and function members). It make the code more clear and elegant. For example, the the variable member 'PrivateData' [4:10] will keep its name in the struct declaration and in the function members it is referenced as 'this->PrivateData'.

tecoberg
Автор

A colleague of mine uses an anonymous struct called something like m or member in the private section of classes and structs.

I can see why this makes sense, as it's actually using the language for keeping track of members. Doing this consequently also ensures no shadowing of parameters, as you cannot write something like:
void myMethod(int m.x, int m.y)
in a class declaration.



The only downside to this, is that your constructors might look a little strange, but outside of that, I'd say the idea is solid

ROCKROLLnPIES
Автор

You are a hero for bringing this to our attention!

GregoryTheGrster
Автор

I only use single underscores and/or trailing underscores for exactly this reason. My nasal passages will never be used by demons!

Omnifarious
Автор

I do like the m_ prefix, been using it for quite some time. Nice!

antoniocs
Автор

I've adopted #define FILENAME_HPP etc. from Qt and never considered using anything else.

ldmnyblzs
Автор

I've been doing it wrong all these years! But, I am writing C#

davidporterrealestate
Автор

Because of this I put a single underscore at the end of a member variable. All my code is lowercase. The reason for this is that the first thing you want to read is the variable name, and the fact that its a member var and not a local var is some extra info at the end. It's a similar reason why I use trailing return types. You first want to read the name of the method or function, and (if not automaticly deduced) you can read what it returns; which shouldn't matter that much with proper generic code since you should be able to make that out from the method name anyway

ruadeil_zabelin
Автор

In C it is allowed to use double underscores in the middle of identifiers. I have seen double underscores for namespacing in C like mylib__init or mylib__destroy_object. This would make these libraries invalid to use in C++, or would it?

cmdlp
Автор

Okay, I'll just use *triple* underscores. :-)

esra_erimez
Автор

I've only noticed the tendency to python++ style naming in C++ in the last 5 years or so (but I am in a rather conservative industry). I also go along with the 'no leading underscores' rule. For my own code I tend to use camelCase.

paulfloyd
Автор

The authors of popular gsoap framework should watch this episode. Their scheme for converting xml identifiers to C++ assumes using __ a lot (e.g. soap_get_xsd__duration). Every application which uses gsoap invokes UB and the users can do nothing about that

pazdziochowaty
Автор

I've been using _name (lowercase) for a while for member variables before switching to trailing _

dawidwdowiak
Автор

but I want my C++ to be more Pythonic. Also no more switches only maps of case values to callable objects.

hicklc
Автор

I wonder if there's any chance for a video about asynch/promise/future difference
I understand what threads do, but can't quite grasp how those other multithread things are working

NoNameAtAll
Автор

Why would anyone want to start something with an underscore? Just makes ugly code, even if it was legal.

Norman_Fleming
Автор

#ifdef is part of the c preprocessor not part of the compiler or libraries. By the time the compiler gets to the source the double underscore multiple inclusion prevention symbol is gone.

Not sure whether the c preprocessor is covered by the section of the standard you were quoting.

homomorphic
Автор

An additional advice: start using #pragma once instead of the ifdef's ;)

rnr
Автор

Why do use `m_` prefix? What's the benefit of it? C++ has its own keyword that can be used instead of `m_`... it's named `this` ;)

antekone
visit shbcf.ru