Maximum Method Name Length

前端 未结 9 1632
忘了有多久
忘了有多久 2020-11-30 05:19

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 i

相关标签:
9条回答
  • 2020-11-30 05:53

    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.

    0 讨论(0)
  • 2020-11-30 05:58

    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;
    }
    
    ?>
    
    0 讨论(0)
  • 2020-11-30 06:00

    in Progress (OpenEdge) the limit is 32 char.

    0 讨论(0)
  • 2020-11-30 06:03

    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.

    0 讨论(0)
  • 2020-11-30 06:05

    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;
    
    0 讨论(0)
  • 2020-11-30 06:05

    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.

    0 讨论(0)
提交回复
热议问题