Maximum Method Name Length

亡梦爱人 提交于 2019-11-27 04:10:48

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

?>

I just did a test in C# Visual Studio 2010 (x64): made an identifier:

int a123456789a123...;

And repeated. At 512 characters, VS gives me the error "Identifier too long." 511 is fine though. (Checked character count in Word.)

Another example:

int whyintheworldwouldyoueverhaveanidenfifierthislongitsreallyjustquiteridiculousimeancmonyoucouldatleasthavethecommoncourtesyofmakingitcamelcasesoitsnotsohardtoreadcmonjuststopnowyourereallyreachingtomakethisaslongaspossiblearentyou123412341234alrightwellthatsenoughnowisntitwelliguessnotbecauseimstillgoingthisisofficallytheworstidentifiereverಠ_ಠokaynowthatithasunicodeitsofficialbutseriouslythisthingissolongthatihadtogetupinthemiddleofittotakeabreakbeforesittingdowntofinishtoppingitofftothemaxcharlimitof___511;

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.

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.

in C# is 511 characters length.

in Progress (OpenEdge) the limit is 32 char.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!