Not so important developer/coding style question
Function/method names should be lower case based on the current coding styles of Vanilla. Generally I would say that every word followed by brackets would be written lowercase then. But I'm not sure about something like that:
$userModel = Gdn::UserModel();
$userModel = Gdn::userModel();
$commentModel = new CommentModel();
$commentModel = new commentModel();
Without a doubt, the name of the class is UserModel/CommentModel and as a class name it should be uppercase. I've already learned that Gdn::...
are only calls to static methods, so I'm sure that 2. would be correct and 1. would be false, since 2. is a call to a function of class Gdn.
But where I'm hesitating is 3 and 4. "Semantically" the part behind the new-keyword is a the class name which should be instantiated, correct? So as a class name it would have to written with an uppercase letter like in 3., but since it is followed by brackets it seems to be a method or a function (at least for the interpreter) and as such it should be written lowercase like in 4.
I know that this is not important, but I'm just curious. Can anybody enlighten me?
Best Answer
-
Linc Admin
3 is correct. You're calling the class's name, and classes are CapitalCase.
(You're also right that 2 is correct, not 1 - it's a method call in that scenario.)
3
Answers
As one who has not followed standards but is just learning about them with the hope of one day conforming to the standards, I'd like to say that as an "outsider" it appears to me that while looking at large chunks of code my eyes find it the easiest to read camel case form. So I wish that the recommendation would have been:
So that every reference to $UserModel would be as it is in this sentence.
Personal taste / wishful thinking / "I do
don't know what I'm talking about"?
Yes, but
$UserModel = Gdn::UserModel();
is the old coding standard and$userModel = Gdn::userModel();
is the new one, that's for sure.But I totally agree: I was also enjoying that form much more.
What I've learned only recently is that there is a group of programmers which form something like a "standardization committee": http://www.php-fig.org
That group has released some coding standards: http://www.php-fig.org/psr/psr-2/
Vanilla is taking over those standards slowly and I think having a unique style guide which is not framework agnostic is a very, very, very good idea. And as always when it comes to personal taste, there are people who like a style guide and there are people who do not like it.
Since I like having a standard much more than I "dislike" (which is a much too strong word in this case) PSR-2, I'm totally fine with sticking to the Vanilla coding style.
By the way: you are always free to use whatever you like in your plugins. Sticking to Vanillas coding style is only a must if you like to contribute to Vanillas sources on GitHub.
But as well as I try to make all comments in my source code in proper English because that's what most of the people understand best, I try to write my code in "proper Vanillish"
I once met a colleague from Austria who said that the longest word in German has 43 characters (something to do with a Danube ship captain, don't remember the actual word). I think I would only be able to read the word if it were in camelcase...
And come to think of it, neither is Antidisestablishmentarianism readable ☺
I think I'll stick to camelcase for Bandwurmwörter (tapeworm words) (a term I just learned of here)
Donaudampfschifffahrtskapitän?
DonauDampfSchiffFahrtsKapitän
Danube steamshipping captain
But those are not even 30 letters. All longer words are simply constructs ranging from easy ones
DonauDampfSchiffFahrtsKapitänsMütze
Danube steamshipping captains cap
up to arbitrary long rubbish
DonauDampfSchiffFahrtsKapitänsAusbilderAktenTaschenVerschlussSchnalle
Danube steamshipping captains trainer briefcase lock handle
And you could do this endlessly:
DonauDampfSchiffFahrtsKapitänsAusbilderAktenTaschenVerschlussSchnallePolierMittelVerschlussKappenÖffner
But if you choose variable names like that you are lost anyway...
I'd be drowning in the Danube
DonauDampf reads to me like someone with a lisp trying to say Donald Drumpf….
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
@R_J And not only with the Danube X) All sentences in german can be converted in words if they don't have comma or points. Sense isn't necessary. So yes, in German words are endless.
K17 is remembering his german hours at school. You get it, He's crying.
3 is correct. You're calling the class's name, and classes are CapitalCase.
(You're also right that 2 is correct, not 1 - it's a method call in that scenario.)
@Linc: thanks for not loosing track in that language mess here
I can image how you feel about that. Having to learn French 4 years in school was no fun either ;-)
The hardest thing was to accept that in French nothing is spoken as it is written. That makes learning vocabularies a pain! Written French is even longer than German would be...
Deux baguettes, s’il vous plaît
Döh Bagett sivupläh
@vrijvlinder: I will consider only referring to him as Donald Dampf in future times. But only as long as he has not been elected. Afterwards I would have to think about nicknames for the US people...
he=> dumbzilla² that makes his supporters => dumbzetta
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
@R_J Prefer French X) I find it more.... Less vomitive language
Someone tracked Donald's ancestry and the last name was originally Drumpf (from Germany). So @vrijvlinder was very close...
'if he gets elected" - who would have thought Canada would have so many immigrants
Or Mexico….
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
No, there would be a "beautiful wall", remember?
A beautiful wall around Donald is costless than between the USA and Mexico
Mexico will not pay for that shite… because they know it would not help… i.e. El Chapo…
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
But of course, I was sarcastic about the Drumpf, the wall, Mexico, Canada, etc.
Of course… otherwise you risk being a dumbzetta… and I think you are too clever for that to be the case…
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
May I always quote you? I am going to print and frame that.
I'll let you define the appropriate exploding CSS style.