复用- build for last

博客强调软件编程中“复用”思想的重要性,常见形式有 copy+paste 及基于二进制的复用。个人写代码若追求复用,代码应清晰简洁、接口完善。还提到编程的四个层次,从会用 OO 语言到设计 Frame Work,鼓励程序员追求更高的“复用”层次。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

by Zhang Hui

去年有一本书,英文名叫build for last,中文名应该是"基业长青"
这句话反映到软件上就是"复用"
虽然最初人们的理想"软件IC"看来是很难实现了,但是,"复用"的思想还是在我们的生活中时时处处体现着.

普遍的形式是copy+paste,然后修修改改.高档一点的形式是Net等基于二进制的复用.具体到我们个人,如果我们写代码的目标不是"能转就行",那么我们应该瞄准"复用",基于这个目标,我们思考软件的写法会有差异.

如果我们希望,自己的code能被别人以copy+paste的形式复用,那么至少因该清晰,简洁,有适当的注解.

如果我们希望自己的code能别人以类库的形式复用,那么应该保持接口的清晰,功能完整,并且各个接口测试充分.最好有相应的sample code.

至于各种各样的基于二进制上的复用,如unix下的small & sharp的工具理念和Net的想法,都需要具体的平台支持,已经超出个人所能干预的范围,这里就不说了

练武的人常说境界,编程也一样.
层次一:会用C++等OO语言编出面相对象的软件
层次二:能写出封装严谨,接口完善的类库,这是一个人说"我掌握了面相对象思想"的基本条件
层次三:理解Frame Work,能解析流行的Frame Work, 最好能写出MFC Lite和VCL Lite.候捷,3721的CEO据说都能做到这个层次.普通的人,能努力做到层次三就很不错了.
层次四:当然是设计Frame Work了. MFC, VCL, 以及Emacs的作者无疑都是具有这方面功力的人
更高的层次我目前还看不到,就不造次了.

只为了写出"能转"的程序,那么你只是以写程序谋生

能主动去写可以复用的软件,那么你有更高的精神追求.

如果说一个物的生命价值在于它所能惠及的范围和时间,那么,程序员,如果你珍惜自己的职业生涯的话,就请不断追求更高的"复用"层次吧.

=======================================
版权所有 /copyright 张辉 2003
本文可原封不动的拷贝和自由地再发行,但在拷贝和再发行的拷贝中必须
原封不动地含有这段版权声明。
http://forestsong.blogone.net

(dev) E:\Project\python-can-4.5.0\python-can-4.5.0>pip install -e . Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple Obtaining file:///E:/Project/python-can-4.5.0/python-can-4.5.0 Installing build dependencies ... done Checking if build backend supports build_editable ... done Getting requirements to build editable ... error error: subprocess-exited-with-error × Getting requirements to build editable did not run successfully. │ exit code: 1 ╰─> [54 lines of output] Traceback (most recent call last): File "D:\ProgramData\miniconda3\envs\dev\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module> main() ~~~~^^ File "D:\ProgramData\miniconda3\envs\dev\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) ~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\ProgramData\miniconda3\envs\dev\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 157, in get_requires_for_build_editable return hook(config_settings) File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\build_meta.py", line 473, in get_requires_for_build_editable return self.get_requires_for_build_wheel(config_settings) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\build_meta.py", line 331, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=[]) ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\build_meta.py", line 301, in _get_build_requires self.run_setup() ~~~~~~~~~~~~~~^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup exec(code, locals()) ~~~~^^^^^^^^^^^^^^^^ File "<string>", line 1, in <module> File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\__init__.py", line 117, in setup return distutils.core.setup(**attrs) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 148, in setup _setup_distribution = dist = klass(attrs) ~~~~~^^^^^^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\dist.py", line 323, in __init__ _Distribution.__init__(self, dist_attrs) ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 309, in __init__ self.finalize_options() ~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools\dist.py", line 788, in finalize_options ep(self) ~~^^^^^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools_scm\_integration\setuptools.py", line 123, in infer_version _assign_version(dist, config) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools_scm\_integration\setuptools.py", line 58, in _assign_version _version_missing(config) ~~~~~~~~~~~~~~~~^^^^^^^^ File "C:\Users\016433\AppData\Local\Temp\pip-build-env-xylngrjp\overlay\Lib\site-packages\setuptools_scm\_get_version_impl.py", line 117, in _version_missing raise LookupError( ...<11 lines>... ) LookupError: setuptools-scm was unable to detect version for E:\Project\python-can-4.5.0\python-can-4.5.0. Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work. For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj Alternatively, set the version with the environment variable SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${NORMALIZED_DIST_NAME} as described in https://setuptools-scm.readthedocs.io/en/latest/config. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build editable did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. (dev) E:\Project\python-can-4.5.0\python-can-4.5.0> 什么问题,如何处理
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值