{"id":812,"date":"2010-11-21T23:55:38","date_gmt":"2010-11-21T15:55:38","guid":{"rendered":"http:\/\/leegorous.net\/blog\/?p=812"},"modified":"2012-03-03T19:18:45","modified_gmt":"2012-03-03T11:18:45","slug":"length-of-variable-naming","status":"publish","type":"post","link":"http:\/\/leegorous.net\/blog\/2010\/11\/21\/length-of-variable-naming\/","title":{"rendered":"\u53d8\u91cf\u547d\u540d\u7684\u957f\u5ea6"},"content":{"rendered":"<p>\u901a\u5e38\uff0c\u53d8\u91cf(\u5e7f\u6cdb\u5730\u5305\u542b\u51fd\u6570\u540d)\u547d\u540d\u7684\u957f\u5ea6\u4f3c\u4e4e\u663e\u800c\u6613\u89c1\u662f\u4e0d\u4f1a\u5b58\u5728\u4ec0\u4e48\u6807\u51c6\u53c2\u8003\u503c\u7684\u3002\u6211\u4e5f\u4e0d\u5047\u601d\u7d22\u5730\u63a5\u53d7\u8fd9\u4e2a\u8bf4\u6cd5\u3002\u4f46\u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d\uff0c\u6211\u53c8\u9690\u7ea6\u611f\u89c9\u5230\u5e94\u8be5\u662f\u9700\u8981\u6709\u4e2a\u6807\u51c6\u7684\uff0c\u4e0d\u7136\u98ce\u683c\u5c31\u5bb9\u6613\u4e71\u4e86\u3002\u8fd9\u7edd\u5bf9\u4e0d\u4ec5\u4ec5\u662f\u51fa\u4e8e\u7f8e\u5b66\u89c2\u70b9\u7684\u8003\u8651\u3002<\/p>\n<p>\u6709\u4e9b\u8001\u7f16\u8bd1\u5668\uff0c\u5bf9\u53d8\u91cf\u540d\u7684\u957f\u5ea6\u662f\u6709\u9650\u5236\u7684\uff0c\u6bd4\u5982\u6709\u4e25\u683c\u7684 8\u4f4d\uff0c<a href=\"http:\/\/202.195.237.152\/ec\/C141\/no3\/right3-1-2.html\" target=\"_blank\">\u5f53\u53d8\u91cf\u540d\u8d85\u8fc7 8\u4f4d \u65f6\u7f16\u8bd1\u5668\u4f1a\u8fdb\u884c\u622a\u53d6\u800c\u4e0d\u662f\u62a5\u9519<\/a>\uff0c\u4e8e\u662f student_name == student_number\uff0c\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u679c\u9519\u5f97\u79bb\u8c31\u3002\u5f53\u7136\u73b0\u5728\u7528\u4e0a\u8fd9\u79cd\u5f88\u4e0a\u5e74\u7eaa\u7684\u7f16\u8bd1\u5668\u7684\u51e0\u7387\u5fae\u4e4e\u5176\u5fae\uff0c\u4f46\u662f\u5c31\u53ef\u4ee5\u4e71\u6765\u4e86\u5417\uff1f<\/p>\n<p>\u867d\u7136\u957f\u5ea6\u4e0d\u9650\uff0c\u4f46\u7f16\u7a0b\u6559\u7a0b\u4e0a\u4f1a\u6709\u8fd9\u79cd\u6307\u793a\uff1a<a href=\"http:\/\/book.51cto.com\/art\/200809\/88627.htm\" target=\"_blank\">\u53d8\u91cf\u540d\u4e0d\u5e94\u592a\u957f<\/a>\u3002\u800c\u6211\u89c9\u5f97\u8fd9\u51e0\u4e4e\u662f\u8ddf\u6ca1\u8bf4\u4e00\u6837\u3002<\/p>\n<p>\u591a\u957f\u624d\u7b97\u592a\u957f\u5462\uff1f\u6211\u5c31\u53d1\u73b0\u6709\u4e9b\u4eba\u559c\u6b22\u7528\u5f88\u957f\u7684\u540d\u5b57\uff0c\u6bd4\u5982 lengthOfPrerogativeName \uff0c\u5982\u679c\u53ea\u662f\u50cf lengthOfPrerogativeName++ \u8fd9\u6837\u7528\u7528\u8fd8\u597d\uff0c\u4f46\u5982\u679c\u662f <\/p>\n<pre name=\"code\" class=\"brush: java\">\r\nlengthOfPrerogativeName = lengthOfPrerogativeName + \r\n    (lengthOfPrerogativeName &gt; 0 ? &quot;.&quot; + lengthOfSubPrerogativeName);\r\n<\/pre>\n<p><!--more--><br \/>\n\u6211\u53cd\u6b63\u662f\u770b\u7740\u5c31\u5934\u6655\u3002\u800c\u4e14\u8fd9\u8fd8\u4e0d\u662f\u6781\u7aef\u60c5\u51b5\uff0c\u5f53\u6574\u4e2a\u4ee3\u7801\u90fd\u5145\u65a5\u8fd9\u4e9b long long things \u4e4b\u540e\uff0c\u5f88\u591a\u884c\u5c31\u4f1a\u56e0\u4e3a\u8d85\u8fc7 80 \u4e2a\u5b57\u7b26\u800c\u9700\u8981\u6362\u884c\uff0c\u6574\u4f53\u770b\u8d77\u6765\u662f\u7f8e\u89c2\u4e86\uff0c\u4f46\u662f\u6bcf\u884c\u4ee3\u7801\u6240\u80fd\u8868\u8fbe\u7684\u610f\u601d\u5c31\u5c11\u4e86\uff0c\u4e0d\u591f\u5b8c\u6574\u4e86\uff0c\u6bd4\u5982\u4e0a\u9762\u90a3\u4e2a\u7b80\u5355\u7684\u62fc\u63a5\u64cd\u4f5c\u7adf\u7136\u4e5f\u9700\u8981\u4e24\u884c\u3002<\/p>\n<p>\u4e0d\u8fc7\u4f3c\u4e4e\u6709\u4eba\u66f4\u52a0\u62c5\u5fc3\uff0c\u5982\u679c\u540d\u5b57\u592a\u77ed\u5c31\u770b\u4e0d\u51fa\u6765\u8fd9\u4e2a\u53d8\u91cf\u662f\u5e72\u4ec0\u4e48\u7528\u7684\u3002\u4f46\u6211\u66f4\u52a0\u62c5\u5fc3\u957f\u4e45\u9762\u5bf9\u8fd9\u79cd\u4ee3\u7801\uff0c\u5728\u641e\u6e05\u695a\u4ee3\u7801\u5728\u8868\u8ff0\u4ec0\u4e48\u529f\u80fd\u4e4b\u524d\uff0c\u9996\u5148\u8981\u82b1\u8d39\u4e0d\u5c11\u65f6\u95f4\u53bb\u201c\u9605\u8bfb\u201d\u53d8\u91cf\u540d\uff0c\u800c\u4e14\u7a0d\u6709\u4e0d\u614e\uff0c\u9519\u8bef\u4e00\u89e6\u5373\u53d1\u3002<\/p>\n<p>\u53d8\u91cf\u540d\u77ed\u4e9b\uff0c\u4ee3\u7801\u770b\u8d77\u6765\u4f1a\u6bd4\u8f83\u6e05\u6670\u3002\u8fd9\u5b9e\u9645\u4e0a\u662f\u5229\u7528\u4e86\u4eba\u8111\u7684\u4e34\u65f6\u8bb0\u5fc6\u529f\u80fd\uff0c\u4f46\u5982\u679c\u6240\u6709\u540d\u5b57\u90fd\u77ed\uff0c\u6709\u66f4\u591a\u542b\u4e49\u9690\u85cf\u5728\u5b57\u4e0b\u9762\uff0c\u5c31\u53d8\u76f8\u8981\u6c42\u4ee3\u7801\u9605\u8bfb\u8005\u53bb\u8bb0\u5fc6\u90a3\u4e9b\u53d8\u91cf\u7684\u542b\u4e49\uff0c\u8fd9\u4e5f\u4f1a\u8ba9\u6211\u5934\u6655\u7684\u3002\u6bd4\u5982\uff1a<\/p>\n<pre name=\"code\" class=\"brush: java\">\r\nint a, b, c, d, e, f;\r\na = name.length;\r\nb = subName.length;\r\nc = a &gt; 0 ? 1 : 0;\r\nc = a + c + b;\r\nd = 2 * a + c\r\ne = d + b;\r\nf = e - c;\r\n<\/pre>\n<p>\u867d\u7136\u8fd9\u4ee3\u7801\u6ca1\u4ec0\u4e48\u5b9e\u9645\u610f\u4e49\uff0c\u4f46\u662f\u4e5f\u8981\u82b1\u70b9\u65f6\u95f4\u7784\u6e05\u695a\u4e86\u624d\u4f1a\u53d1\u73b0\uff0c\u662f\u4e0d\u662f\u5f88\u4e0a\u5f53\u7684\u611f\u89c9\uff0c\u7279\u522b\u662f\u5728\u627e bug \u7684\u65f6\u5019\uff0c\u53ef\u60f3\u800c\u77e5\u6709\u591a\u75db\u82e6\u3002<\/p>\n<p>\u4ee3\u7801\u8fc7\u7a0b\u4e2d\u514d\u4e0d\u4e86\u91cd\u6784\u3002\u5982\u679c\u4e00\u4e2a\u77ed\u540d\uff0c\u5982\u201ci\u201d\uff0c\u5230\u5904\u4f7f\u7528\uff0c\u800c\u53c8\u9700\u8981\u6539\u4e0b\u540d\u5b57\u7684\u65f6\u5019\uff0c\u5982\u679c\u7c97\u7565\u5730\u5168\u66ff\u6362\u662f\u4fdd\u8bc1\u51fa\u9519\u7684\u3002\u5982\u679c\u7f16\u8f91\u5668\u7f3a\u4e4f\u5bf9\u91cd\u6784\u7684\u4e00\u4e9b\u6709\u5229\u5e2e\u52a9\uff0c\u90a3\u5c31\u6ce8\u5b9a\u4e86\u662f\u4e00\u573a\u8d39\u529b\u800c\u4e14\u5bb9\u6613\u51fa\u9519\u7684\u98ce\u9669\u4f5c\u4e1a\u3002<\/p>\n<p>\u6b63\u5982<a href=\"http:\/\/news.ycombinator.com\/item?id=840331\" target=\"_blank\">\u8fd9\u7bc7\u8ba8\u8bba<\/a>\u6240\u603b\u7ed3\u7684\uff0c\u201cour conventions for naming things should take into consideration the limitations of the human brain\u201d\u3002\u5982\u679c\u662f\u4f5c\u4e3a\u5168\u5c40\u53d8\u91cf\uff0c\u957f\u5ea6\u7ea6\u4e3a 10-20 \u6bd4\u8f83\u5408\u9002\uff0c\u5168\u90e8\u5927\u5199\u4f1a\u66f4\u9192\u76ee\uff1b\u53ea\u5728\u4e00\u4e2a\u5faa\u73af\u91cc\u9762\u7528\u5230\u7684\uff0c&#8221;i&#8221; \u5c31\u8db3\u591f\u4e86\u3002<\/p>\n<p>\u901a\u5e38\u4ee3\u7801\u91cc\u90fd\u4e0d\u6b62\u8fd9\u4e24\u79cd\u60c5\u51b5\uff0c\u4e0d\u8fc7\u53ef\u4ee5\u6309\u7167\u540c\u6837\u7684\u601d\u8def\u5728\u63a8\u65ad\uff0c\u5230\u5e95\u591a\u957f\u6bd4\u8f83\u5408\u9002\u3002\u4e0d\u540c\u7684\u4f5c\u7528\u57df\u4ece\u5c0f\u5230\u5927\uff0c\u5176\u5408\u9002\u957f\u5ea6\u5728\u589e\u5927\u3002\u957f\u5ea6\u5927\uff0c\u4e0d\u5bb9\u6613\u91cd\u590d\uff0c\u800c\u4e14\u6709\u5229\u4e8e\u5206\u8fa8\uff0c\u6bd4\u5982\u5168\u5c40\u53d8\u91cf\u3002\u7c7b\u4e00\u7ea7\u7684\uff0c\u5355\u8bcd\u6216\u8bcd\u7ec4\uff0c\u5173\u952e\u662f\u8981\u6e05\u6670\u8868\u8fbe\u53d8\u91cf\u6240\u6307\u3002\u65b9\u6cd5\u91cc\u9762\uff0c\u5355\u8bcd\u6216\u8005\u7f29\u5199\uff0c\u4ee3\u7801\u5757\u5185\uff0c\u7b80\u5199\u751a\u81f3\u5355\u4e2a\u5b57\u6bcd\uff0c\u8981\u8003\u8651\u66f4\u7b80\u6d01\u6e05\u6670\u5730\u8868\u8fbe\u6d41\u7a0b\u548c\u529f\u80fd\u3002<\/p>\n<p>\u5355\u5c31\u957f\u5ea6\u800c\u8bba\uff0c\u89c4\u5219\u53ef\u4ee5\u662f\u76f8\u5f53\u6e05\u6670\u660e\u786e\u7684\u3002\u6700\u7ec8\u90fd\u662f\u4e3a\u4e86\u8ba9\u4ee3\u7801\u6709\u66f4\u597d\u7684\u8868\u73b0\u529b\uff0c\u9605\u8bfb\u8d77\u6765\u66f4\u52a0\u6d41\u7545\uff0c\u9664\u4e86\u5728\u957f\u5ea6\u4e0a\u4f7f\u7528\u4e00\u81f4\u7684\u89c4\u8303\uff0c\u5728\u6570\u91cf\u4e0a\uff0c\u529f\u80fd\u5206\u5e03\u4e0a\u90fd\u5e94\u8be5\u6709\u6240\u8bbe\u8ba1\u3002<\/p>\n<p>\u4ee3\u7801\u662f\u7ed9\u4eba\u770b\u7684\uff0c\u662f\u4eba\u4e0e\u673a\u5668\u4e4b\u95f4\u4ea4\u6d41\u7528\u7684\uff0c\u4e5f\u662f\u4eba\u548c\u4eba\u4e4b\u95f4\u4ea4\u6d41\u7528\u7684\uff0c\u5b83\u4e5f\u6709\u53d8\u7f8e\u4e3d\u7684\u8981\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u5e38\uff0c\u53d8\u91cf(\u5e7f\u6cdb\u5730\u5305\u542b\u51fd\u6570\u540d)\u547d\u540d\u7684\u957f\u5ea6\u4f3c\u4e4e\u663e\u800c\u6613\u89c1\u662f\u4e0d\u4f1a\u5b58\u5728\u4ec0\u4e48\u6807\u51c6\u53c2\u8003\u503c\u7684\u3002\u6211\u4e5f\u4e0d\u5047\u601d\u7d22\u5730\u63a5\u53d7\u8fd9\u4e2a\u8bf4\u6cd5\u3002\u4f46 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/leegorous.net\/blog\/2010\/11\/21\/length-of-variable-naming\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u53d8\u91cf\u547d\u540d\u7684\u957f\u5ea6\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[53,14],"tags":[105],"_links":{"self":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/812"}],"collection":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/comments?post=812"}],"version-history":[{"count":7,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/812\/revisions"}],"predecessor-version":[{"id":1060,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/812\/revisions\/1060"}],"wp:attachment":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/media?parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/categories?post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/tags?post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}