C# 编程普通型计算器经验与感悟

先贴图:

计算器截图

这是用 C# 语言编写的普通型计算器,功能基本模仿 Windows 8.1 自带计算器程序(版本 6.3,内部版本 9600)。支持加、减、乘、除、退格、清除、平方根、倒数、相反数、连续四则、连续等号、自动补齐、记忆、键盘输入等功能。可以应对已知的多种形式输入而不发生崩溃,计算结果基本正确。

但是该计算器与 Windows 自带版本相比还有很多不足,例如:精度无法达到后者水平;“显示屏”部分只有一行,无法显示当前运算式子;未对运算时十进制与二进制相互转化造成数据丢失的现象做优化(例如:formula,即“安卓计算器 Bug”);功能相比后者也更为简单。

该计算器程序特点:色彩较为鲜艳,至于美不美,就仁者见仁智者见智了;由于“显示屏”只有一行,设计当 M 中存有数据时,使 MR 按钮颜色变化来提示;另外在某处藏有彩蛋,数目不详。

编写的感悟

The Zen of Python

The Zen of Python, by Tim Peters
Python 之道

Beautiful is better than ugly.
美观胜于丑陋。

Explicit is better than implicit.
显式胜于隐式。

Simple is better than complex.
简单胜于复杂。

Complex is better than complicated.
复杂胜于过度复杂。

Flat is better than nested.
平面胜于嵌套。

Sparse is better than dense.
稀少胜于稠密。

Readability counts.
可读性需要考虑。

Special cases aren't special enough to break the rules.
即使情况特殊,也不应打破原则,

Although practicality beats purity.
尽管实用胜于纯净。

Errors should never pass silently.
错误不应悄无声息的通过,

Unless explicitly silenced.
除非特意这么做。

In the face of ambiguity, refuse the temptation to guess.
当有混淆时,拒绝猜测(深入的搞明白问题)。

There should be one-- and preferably only one --obvious way to do it.
总有一个,且(理想情况下)只有一个,明显的方法来处理问题。

Although that way may not be obvious at first unless you're Dutch.
尽管那个方法可能并不明显,除非你是荷兰人。(Python 的作者 Guido 是荷兰人,这是在致敬)

Now is better than never.
现在开始胜过永远不开始,

Although never is often better than right now.
尽管永远不开始经常比仓促立即开始好。

If the implementation is hard to explain, it's a bad idea.
如果程序实现很难解释,那么它是个坏主意。

If the implementation is easy to explain, it may be a good idea.
如果程序实现很容易解释,那么它可能是个好主意。

Namespaces are one honking great idea -- let's do more of those!
命名空间是个绝好的主意,让我们多利用它。


Comments

您可以匿名发表评论,无需登录 Disqus 账号,勾选“我更想匿名评论”后,姓名和电子邮件分别填写“匿名”和“someone@example.com”然后发表评论即可。您也可以登录 Disqus 账号后发表评论。您的评论可能需要经过我审核后才能显示。点赞投票按钮(Reactions)无需登录即可点击。Disqus 评论系统在中国大陆可能无法正常加载和使用。

Statements

Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License

本作品采用知识共享署名—非商业性使用—禁止演绎 4.0 许可协议国际版(CC BY-NC-ND 4.0)进行许可。

This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License (CC BY-NC-ND 4.0).

Written by a Human, Not by AI

本作品由人类创作,整体内容符合 Not By AI 90% 规则。人工智能工具仅在有限程度上提供灵感启发、错别字与语法检查,以及在不改变原意的前提下进行润色。所有修改在采纳前均经过作者仔细审阅。

This work was created by a human author, and the overall content complies with the Not By AI 90% Rule. Artificial intelligence tools were used only to a limited extent for idea inspiration, typo and grammar checking, and stylistic refinement without altering the original meaning. All modifications were carefully reviewed by the author before adoption.

Top