When is a function name too long?

后端 未结 27 1556
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 18:45

I try to be rather descriptive with my function names, where possible. This occasionally results in function names in the twenty to thirty character range such as \"GetActionFr

27条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-03 18:57

    Function and method names start getting too long when the developer forgets about the descriptive nature of arguments (assuming meaningful argument and variable names). For example:

     my $template = HTML::Template->new( filename => 'home.html'); 
     $template->param( title => 'Home Page' );
     $html = $template->output;
    

    is transparent in what it does even if you know no Perl and have never heard of HTML::Template.

    I have seen too often the temptation to name that output method something like RenderHTMLViewFromTemplateObject. If all the libraries used have such naming conventions, it becomes simply impossible for me to follow what is going on.

提交回复
热议问题