Object Orientated UnderScores

I’ve got a burning question for y’all.

I’ve noticed that a lot of the really well written OOP modules, such as Roact & Nevermore will use underscores in the beginnings of variable names. I understand that the _ is suppose to signify that the variable is private, but I don’t understand how it is anymore private/secure than any other variable name.

3 Likes

It’s not anymore private/secure than any other name (Lua doesn’t have built-in encapsulation), the underscore just signifies “this is internal only meaning you shouldn’t use it and it’s subject to change anytime”.

12 Likes

From what I recall, Python developers are the ones who popularized this. In Python, there’s no such thing as a “private” class member, so it is commonly understood that methods or fields starting with an underscore are considered private and shouldn’t be touched.

Edit: From the Python docs:

[Source]

8 Likes