马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
鱼油们,
对于上了一定年纪的人,
英语没学好,小学拼音也没学的人来说,
对命名变量实在是件头痛的事
英语可以死记硬背,当时记住了,过段时间就会忘记,不利日后阅读代码
拼音嘛,勉强能拼出来,但是看到就拼一次,再说同音实在多,也不利以日后阅读代码
另外可以用纯中文命名变量,试过能跑不报错。
就想问问鱼油们有没有一些好的英文字母命名方法,易懂,又易读的
比如以下代码:几行能读,若代码多起来恐怕是件头痛的事<div style="background-color:#282c34;color:#bbbbbb;font-family:'JetBrains Mono',monospace;font-size:13.5pt;white-space:pre;">count = <span style="color:#d19a66;">1
</span>s = <span style="color:#d19a66;">0
</span>sign = <span style="color:#d19a66;">1 </span><span style="color:#5c6370;font-style:italic;"># </span><span style="color:#5c6370;font-style:italic;font-family:'宋体',monospace;">用来标记正负号
</span><span style="color:#d55fde;font-style:italic;">while </span>count < <span style="color:#d19a66;">100</span>:
s += sign * count
sign = -sign <span style="color:#5c6370;font-style:italic;">#</span><span style="color:#5c6370;font-style:italic;font-family:'宋体',monospace;">每次执行累加后,把标记赋值为相反数
</span><span style="color:#5c6370;font-style:italic;font-family:'宋体',monospace;"> </span>count += <span style="color:#d19a66;">1
</span><span style="color:#2bbac5;">print</span>(s)</div>
换成中文后读起来容易多了<div style="background-color:#282c34;color:#bbbbbb;font-family:'JetBrains Mono',monospace;font-size:13.5pt;white-space:pre;">i = <span style="color:#d19a66;">1
</span><span style="font-family:'宋体',monospace;">累计 </span>= <span style="color:#d19a66;">0
</span><span style="font-family:'宋体',monospace;">正负 </span>= <span style="color:#d19a66;">1 </span><span style="color:#5c6370;font-style:italic;"># </span><span style="color:#5c6370;font-style:italic;font-family:'宋体',monospace;">用来标记正负号
</span><span style="color:#d55fde;font-style:italic;">while </span>i <= <span style="color:#d19a66;">100</span>:
<span style="font-family:'宋体',monospace;">累计 </span>+= <span style="font-family:'宋体',monospace;">正负 </span>* i
<span style="font-family:'宋体',monospace;">正负 </span>= -<span style="font-family:'宋体',monospace;">正负 </span><span style="color:#5c6370;font-style:italic;">#</span><span style="color:#5c6370;font-style:italic;font-family:'宋体',monospace;">每次执行累加后,把标记赋值为相反数
</span><span style="color:#5c6370;font-style:italic;font-family:'宋体',monospace;"> </span>i += <span style="color:#d19a66;">1
</span><span style="color:#2bbac5;">print</span>(<span style="font-family:'宋体',monospace;">累计</span>)</div>
鱼油大大门请发表下你们的意见,谢谢。
|