views:

2258

answers:

7

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?
+8  A: 

For C# I don't believe there's a hard limit - I think I looked into this before, and came to the conclusion that by the time you reached the limit you'd be way beyond the bounds of readability and even a sensible machine-generated name. Section 2.4.2 of the spec which describes identifiers doesn't give any limit.

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.

Jon Skeet
+5  A: 

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;
}

?>
Greg
That is Craziness!!!
Josh
+1  A: 

Common Lisp symbols's names are strings; strings have a length limit of array-dimension-limit

The value of array-dimension-limit is a positive integer that is the upper exclusive bound on each individual dimension of an array. This bound depends on the implementation but will not be smaller than 1024. (Implementors are encouraged to make this limit as large as practicable without sacrificing performance.)

In practice this can be quite large

Welcome to Clozure Common Lisp Version 1.3-dev-r11583M-trunk  (DarwinX8664)!
? array-dimension-limit
72057594037927936
? 

Welcome to Clozure Common Lisp Version 1.3-dev-r11583M-trunk  (DarwinX8632)!
? array-dimension-limit
16777216
?

This answer ignores the method name's package name; this could double the lengh.

Doug Currie
A: 

In D I don't know this to be the case but I suspect that it is something insane like >100MB. It might be an out-of-memory thing. This is based on knowing that I and other people have run into object file format limitation of about 11kB for symbol names and that this has been fixed.

BCS
A: 

In Java, I believe a length limit is not given. See this from the online Sun Java Tutorial:

Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter...

Like others above, I would guess the length is dependent upon the available memory.

Bill
+3  A: 

Hi, in C# is 511 characters length.

Vanilla
The IDE may impose some limits on lines, but the C# spec doesn't impose any limit.
Josh
The compiler, not the IDE. The IDE will colorize only the first 511 characters of the name though, and keep the rest black.
Kirill Osenkov
+1  A: 

Microsoft's C# implementation is 511, VB.NET implementation is 1023.

Visual Studio will only colorize the first 511 (1023 for VB) characters of the identifier and keep the rest black.

Kirill Osenkov