Does anyone happen to know what the maximum length of a method name is in your programming language of choice? I was going to make this a C# specific question, but I think it would be nice to know across the spectrum.
What are the factors involved as well:
Use short enough and long enough variable names in each scope of code. Generally length may be 1 char for loop counters, 1 word for condition/loop variables, 1-2 words for methods, 2-3 words for classes, 3-4 words for globals.
The length of field and method names, field and method descriptors, and other constant string values is limited to 65535 characters by the 16-bit unsigned length item of the CONSTANT_Utf8_info structure (§4.4.
Variable names can be up to 64 bytes long, and the first character must be a letter or one of the characters @, #, or $. Subsequent characters can be any combination of letters, numbers, nonpunctuation characters, and a period (.).
The classes and variables have long names because the things they represent have long names. Understanding them doesn't make them shorter. But they aren't Conventions, they are InternationalizationConventions.
For C# I don't believe there's a specified hard limit. (Section 2.4.2 of the C# 5 spec doesn't give a limit, for example.) Roslyn v2.2.0.61624 seems to have a limit of 1024 characters; this is way beyond the bounds of readability and even a sensible machine-generated name.
For Java, section 3.8 of the spec states:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
PHP seems to be limited only by the script's memory limit.
With 128Mb I was able to create a class (and method) with 4 million characters.
<?php ini_set('memory_limit', '128M'); $i = 1024 * 1024; while ($i < 10000000) { $className = str_repeat('i', $i); eval("class $className { public function $className() { echo '$i<br>'; } }"); new $className(); $i *= 2; } ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With