What Does @ Mean?
XavierAP
n3minis-git at yahoo.es
Mon Apr 8 14:19:04 UTC 2019
On Monday, 8 April 2019 at 11:58:49 UTC, Ron Tarrant wrote:
>
> And while I'm asking, does an underscore have special meaning
> when used either at the beginning or end of a variable name?
In D, @ is used as Adam has explained as a prefix indicating
attributes (either user-defined ones or, confusingly enough, some
of the standard ones).
The only other example of language using @, in an almost but not
quite completely different way, is C#. It's also a prefix that
allows you to define names that would collide with reserved
words, for example string @class = "menu"; Of course you should
never do this unless you absolutely need for interop.
Underscore prefixes are used in some languages by pure user
convention mainly for private members (fields), to avoid name
clashing. For example in D you could have a public property
length and a private member _length.
Python takes this a step further. Since it supports classes but
no public/private visibility at all, users and IDEs have convened
to use (one or two) underscore prefixes to signal members that
aren't meant to be accessed publicly from outside the class, even
if there's nothing stopping you (besides auto code completion not
showing them).
For C and C++ the convention (recognized by the standards) is
different: names prefixed by any number of underscores are all
reserved; basically because the global namespace is so badly
polluted already. In this case I've seen some other annoying
conventions, for example private member variables being prefixed
with m_
More information about the Digitalmars-d-learn
mailing list