dpdx51205 2011-01-11 04:19
浏览 32
已采纳

根据流行度命名功能

You need two functions:
1. Retrieves plain text from a DB.
2. Based on 1, retrieves rich text - with new lines, font styles etc.

You expect function 2 to be much more used than function 1.

Would you name 1 text() and 2 - rich_text() or would you use the simpler text() for the name of 2, since it's expected to be more popular and use something like plain_text() for 1?

The more general question would be - do you consider function's expected "popularity" when naming it?

  • 写回答

3条回答 默认 最新

  • dougu8742 2011-01-11 04:23
    关注

    No, I don't consider a function's popularity. It's best to have descriptive names for both functions (e.g. one is plain_text() and one is rich_text()).

    I think that it's best to use relatively specific names for all functions, since using more general names 1.) doesn't give the user too much of an idea of what the function does by reading the name and 2.) can lead to confusion.

    Of course, how you name your functions is your choice: I just recommend that you give them somewhat descriptive names and that you name them (and order the arguments) consistently.

    I hate nothing more than programming with an API where every function name is short and cryptic (PHP's string functions are that way, even though I'm used to it now -- strstr and strtok are hardly intuitive names for what they do).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接