naming convention for keys in toml file - naming-conventions

looking at toml repo, I don't see any restriction/suggestion on naming convention for keys
looks like most of the variables are lowercase but wanted to know what's the best practice -naming convention- for keys?
let's say I want to have a key called firstname which one is better?
firstname
first_name
first-name
firstName
FirstName

Standard is underscore_naming. It isn't documented, but most .toml files use that.

Related

How should I write words with dash in camelCase?

For example: Meta-information
metaInfornation, metainformation or metainfo?
getMetainfo, getMetaInfo or getMetaInformation?
what about objective-c style?
I am personally a fan of camelCase and no abbreviations. So I would use metaInformation. metaInfo is also good because it's a very common abbreviation.
What I dislike is something like printAttr or similar.
Apple has docs on that topic describing the conventions.
Note that you should not use get in your getter!
When you apply these conventions you have many opportunities (e.g. Key-Value-Coding).
If it's a property, then you'd want to use metaInformation or metaInfo, and it will generate the getter as -metaInformation or -metaInfo. Never use get in a method name.

Naming convention for multiword view files in Yii?

If I have a view with two or more words, e.g.:
public function actionApprovalQueue()
what is the naming convention of the view file itself?
approval-queue.php
approvalQueue.php
approvalqueue.php
??
The documentation on Conventions only says:
View files should be named after the view name. For example, the index
view is in the index.php file.
which gives no clue about views with two or more words.
When it comes to naming conventions, it comes down to what suits your organisation, or what is followed in your organisation, or what the rest of your team decides. The key is consistency throughout your code base.
I would say go with the dash(hyphen), because variables are generally named $xyzAbc or $xyz_abc. So it would make sense to use approval-queue.php.
Definitely do not go for approvalqueue.php.
Edit: Read more about Yii's conventions here.
Yii recommends naming variables, functions and class types in camel case which capitalizes the first letter of each word in the name and joins them without spaces. Variable and function names should have their first word all in lower-case, in order to differentiate from class names (e.g. $basePath, runController(), LinkPager). For private class member variables, it is recommended to prefix their names with an underscore character (e.g. $_actionList).
Because namespace is not supported prior to PHP 5.3.0, it is recommended that classes be named in some unique way to avoid name conflict with third-party classes. For this reason, all Yii framework classes are prefixed with letter "C".
A special rule for controller class names is that they must be appended with the word Controller. The controller ID is then defined as the class name with first letter in lower case and the word Controller truncated. For example, the PageController class will have the ID page. This rule makes the application more secure. It also makes the URLs related with controllers a bit cleaner (e.g. /index.php?r=page/index instead of /index.php?r=PageController/index).

Naming Convention for Property Name that has a Dot

Is there a naming convention for a property/variable that has a dot/decimal in the name of the thing that the property/variable represents?
For example:
A class has a property that represents a 2.5 volt battery. Since we can't name the property/variable as "2.5VoltBattery" (the idea being that we can't have the decimal point in the name), I have always used the convention "2Point5VoltBattery" (replace the dot with the word Point).
I'm curious if there is a naming convention for this.
No; it is preferential and will vary by team preference more than anything.
You can use Battery_2_5_Volts. Not sure whether is exact naming convention. To me it feels as a relevant one.

What's the benefit of postfixing arrays with "List" for variables?

I have seen numerous developers postfixing variable names with a "List" when it's an array. What's the point of this and would you encourage this style? For example:
// Java
String[] fileList;
String file;
// PHP
$fileList = array();
$file = '';
The idea applies to any language with support for arrays.
The idea? Readability - you can tell the variable is a collection in one glance. This can be achieved with pluralizing the variable name (ie. files).
If the fact that the data type is a list is significant (assuming several different collection types), then using that postfix is the right thing to do (as opposed to simply being a collection).
I personally tend to pluralize variable names, using a list postfix only if it adds information or can't be inferred from the name otherwise (say a list of lists).
I think this is mostly a matter of taste. I tend to name things to reflect what they are or what they do. So if I have a collection or array of File instances, the variable would most probably named files, or have a more specific name if the context allows it. Naming an array of Files fileList is in my humble opinion plain wrong, because, at least in Java, an array is not a List. But then, the compiler won't complain...
More complex collections like a Map get names like keyToValue. So if I had a map which assigns teachers to classrooms this would be called teacherToRoom in my code. I hate grepping through the code to find out what the variables are meant to do, so I try to be as specific as needed with the names.
In conclusion it's all about correct code, and variable names can not influence this outcome from the compiler perspective. But they can very well affect the outcome when it comes to humans working with the code, so it's best to do whatever works for the majority of people working on a codebase.

Really long class/variable/property/method names

Some friends and colleagues of mine have a little running contest to find or write the longest class/variable/property/method names possible. Keep in mind, we try to be good boys and girls and keep the naming intelligible and concise, while still explaining what the thing does via its name.
Sometimes it just doesn't happen though. Have you run in to this? I'd just like to see what's out there. (Maybe my friends and I aren't as crazy as we think)
Note: I'm not looking for bad naming. That's already here. I'm looking for good naming that just got a little long.
This isn't a class name but an enum, but it's a lot longer:
VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeStateVmDirectPathGen2InactiveReasonOther
from the VMware vSphere API. Google for it and you'll find the online documentation.
It isn't really long but my favorite variable name ever was to indicate that a user had opted in to receive email.
User.IsSpammable
I find it's nice to have long test names which describe the test. For instance:
testMapWithOneEntryAllowsDifferentEntryPreservingFirst
testMapWithOneEntryAllowsDuplicateEntryOverwritingFirst
(These are just examples off the top of my head... you get the idea though.)
org.aspectj.weaver.patterns;
public class HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor {
boolean ohYesItHas = false;
public boolean wellHasItThen/*?*/() {
return ohYesItHas;
}
... more methods...
}
Some times ago, I had a problem with Hibernate.
I got a NullPointerException in the method called findIntendedAliasedFromElementBasedOnCrazyJPARequirements !
protected virtual OcrBarcodeSymbologies GetSupportedBarcodeSymbologies() { }
The excellent GTK+ library "suffers" from this. It has very neatly named functions, but since the main API is C, and GTK+ is very object-oriented, it must encode class names in the functions name. The constructor for class X is X_new(), and so on. This leads to beaties such as gtk_recent_chooser_widget_new_for_manager().
I'm sure there are even longer function names in there, this was just one that I found quickly. :)
Long variable names don't bother me as long as there's not an obvious more concise name and the naming is sane. For instance, in Kamaelia, there's a class type named this:
threadedadaptivecommscomponent
A naming convention I've seen, years before fluent became en vogue
public DataSet SelectAllUsersWhereDobIsGreaterThan1980AndIsMaleOrderByNameAndAge()
Check out Apple's documentation. They're kings at that. Very descriptive, but sometimes miles long. A couple of examples from the NSString class:
NSString.completePathInfoString:caseSensitive:matchesToArray:filterType
NSString.stringByAddingPercentEscapesUsingEncoding
My favourite in the Microsoft world: SetProcessWorkingSetSize
bool instrumentAreaDockWidgetVisibilityFollowsChildPresence;
In the apple mail app:
_synchronouslyTellServicesToRegisterAndSync()
In a app I wrote:
User.CanViewRestrictedItems()
I an app a colleague wrote:
Profile.DisplayMyDraftOrPendingProfile()
Profile.DisplayMyApprovedProfile()
Just to get started.
new:
A foreign key constraint name:
constraint ReportCompanyReportTemplateIDVersionID_ReportTemplateVersionReportTemplateIDVersionIDFk foreign key (ReportTemplateID, VersionID) references customer_ReportTemplateVersion (ReportTemplateID, VersionID)
get the js items that will be retrieved and if page should display recommendations.