"Rowan Collins" wrote in message
news:3351770b-c53e-4062-a91a-d3aa7439f...@gmail.com...
On 5 June 2017 09:14:47 BST, Tony Marston <tonymars...@hotmail.com> wrote:
Seriously, can you explain in words of one syllable the precise
benefits of
such a consistency?
I will try:
- When we write code, we need to know how to spell the names of things. If
the things all have names that look the same, it is less hard for us to
guess what the name is. This means we take less time to learn the names,
and get less things wrong.
Words and abbreviations are spelled the same whether you use snake_case or
CamelCase, the only difference is how you show the boundary between one word
and the next. Studies have shown that snake_case is more readable than
CamelCase.
- Our brains are made to spot when things are the same, and when things are
not the same. When one thing is not like the things near it, we think "why
is that?" This slows us down.
Seeing a name written in snake_case does not slow you down. In normal
writing there is a space between each word, but as names in software cannot
have embedded spaces. This is why underscores are used, and this is
infinitely more readable than replacing spaces with a capital letter.
- When we get things wrong, we need to find out what we did wrong. If one
way to write a name is wrong, we can spot when we wrote it that way, and
know that it is wrong.
Writing a name wrong has nothing to do with the difference between
snake_case and CamelCase. My IDE will show me existing names that match what
I am typing as soon as I start typing, so I can easily pick the name that I
want.
- If we make two things that mean the same thing, but do not look the same,
we might not spot that we wrote a third thing that does not mean the same
thing.
If you try to instantiate a class that does not exist, or call a
method/function which does not exist, then you will soon know about it.
Using snake_case instead of CamelCase does not invite more errors.
I think there are more things that make it good to have names that look the
same, but I hope this helps for now.
The only universally accepted "rule" for names is that they be unique and
convey proper meaning. In proper languages all names are case-insensitive as
the ability to write the same name with the exact same spelling but
different case is simply inviting disaster.
--
Tony Marston
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php