Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum Method Name Length

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:

  • Does the language specification limit this?
  • What does the compiler limit it to?
    • Is it different on 32bit vs 64bit machines?
like image 863
Josh Avatar asked Jan 08 '09 21:01

Josh


People also ask

How long should method names be?

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.

What is the maximum length of a variable name in Java?

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.

What can be the length of a variable name?

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 (.).

Why are Java method names so long?

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.


2 Answers

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.

like image 152
Jon Skeet Avatar answered Oct 07 '22 16:10

Jon Skeet


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; }  ?> 
like image 41
Greg Avatar answered Oct 07 '22 18:10

Greg