关于好的代码(Aspects to good code)

本文探讨了构成好代码的关键因素,包括代码的可维护性、简洁性和可测试性等,并强调了良好的代码对于团队协作的重要性。

我常常思考是什么造就了好的代码 (good code).使用最新的语言特性、最佳的模式(best pattern)、最好的层次化设计(best layered design)、使用最少内存、亦或最佳的执行性能(performs the best)?很明显,这些项目都会在设计时考虑,但它们是首先要最主要的原因吗(the first things you think of)?或许并不是!


那什么呢?经过一段冥思苦想之后,我有了结论.显然代码或系统应当可裁剪(scalable),正确(correct ,no bugs),完整 (complete, 成功交付), 可扩展(extendable, 可以用系统地增长),并且有好的文档化(well documented),但最终它需要存在很长一段时间,并且会有不同人为它工作,就像击鼓传化(drum roll). 所以它需要便于维护(be easy to maintain),当然需要高质量的代码(good quality,比如有单元测试).



                         (大图)

什么是好的代码?(What is good code then)

我觉得好的代码就是让"所有人(everyone)"都理解.它要易于修改,增加和重构.需要尽可能的简单(而不只是相对简单) (be as simple as possible (but no simpler)),还要尽量减少与其它系统间的耦合(as loosely coupled to other systems).


为什么要写好代码(Why should we write good code?)

基本上项目中的写代码的人也会有周期性的变化.人员离职,出车祸,迁走他乡,坐牢了等等(反正没好事),一旦发生了,其他人就要顶上来维护代码.绝大多的维护人员要么想完全重写代码,要么就惧怕动到任何东西(最好什么都别动),因为系统确实太复杂了.这两种情况都不是什么好事.理想情况下(ideally),如果所有项目都像"Ubuntu"那样充满激情(spirit) (比如为了支持者无私的进行编码),即便在很长的时期内,事情会运转得很好


并且,如果我们一开始就正确地保证质量(比如运用TDDunit test), 它就会让人们易于修改代码,因为他们可以有通过一系统的测试树立信心 (前提是测试能抓到一些没考虑到的副作用(side effect)).

   

                                       (大图)

后来我们为一些公司做了代码审计(code audits).纳入了关于软件开发的许多不同 的角度.如下表:

  Architecture and design (架构与设计)

    • Scalability (可裁剪性)

    • Integration points and methods (整合点和方法)

    • Flexibility (系统弹性)

    • Performance and monitoring (性能和监控)

    • Database layout and schema (数据库规划)

   Code quality (代码质量)

    • Follows coding style (遵循一定的代码风格)

    • Commented and “JavaDoc”ed (注释及代码归档工具)

    • Simple as possible design

    • Patterns implemented (实现模式)

   Documentation (文档)

    • Architecture documentation (UML, Context diagram,etc.)

    • Specification of some sort

    • Technical specification

    • Non-functional requirements (load, performance,etc..) (非功能性需求)

   Testing (测试)

    • Unit tests

    • Load tests (负载测试)

    • Performance testing and monitoring

   Change control processes (变更管理)

    • Source control implemented (源代码管控)

    • Processes around change management (变更管理流程)

    • Continuous build environment (持续编译环境)

    • Issue management process 


原文地址: http://www.stevevandermerwe.net/blog/?p=83

转载请注明出处:http://blog.csdn.net/horkychen

<think> Hmm, the user is asking about how to use code downloaded from GitCode, specifically referencing several citations about GitCode setup and contribution workflows. Let me piece this together. First, looking at the citations: [1] mentions installing Git and basic verification, [2] talks about cloning repositories and contributing via Pull Requests, while [3] explains SSH vs HTTPS cloning differences. The core question is about post-download usage though. The user seems to be a developer transitioning from basic Git setup to actual code utilization. They probably completed the initial setup (git --version works) but now face the "what next?" after cloning. Their tone suggests mild urgency - likely stuck at starting a downloaded project. Key aspects to cover: - The fundamental "git clone" step as prerequisite (cite [2],[3]) - Critical post-clone actions: dependency installation, configuration, build process - Different project types may have different execution methods (Python vs Java etc) - The importance of reading project-specific docs (README etc) I notice citations [2] and [3] contradict slightly on HTTPS push authentication - should clarify that while cloning is easy, contributing requires auth. But since user only asked about usage (not contribution), that's secondary. Biggest risk is oversimplifying - "usage" varies wildly by project. Need to emphasize documentation while giving concrete examples like package managers and build tools. Should distinguish between running pre-built projects versus developing on them. </think> 基于你的需求,以下是GitCode下载代码后的完整使用流程(结合引用内容): ### 一、基础环境准备 1. **安装Git工具**(引用[1]) - 下载地址:https://git-scm.com/downloads - 验证安装:命令行执行 `git --version`,显示版本号即成功 ```bash $ git --version git version 2.37.1 # 示例输出 ``` 2. **选择克隆方式**(引用[3]) | 方式 | 特点 | 适用场景 | |------|-------------------------------|------------------| | SSH | 需配置密钥,push免密验证 | 高频代码提交 | | HTTPS| 每次push需账号密码验证 | 临时操作 | --- ### 二、代码获取与使用 1. **克隆仓库**(引用[2]) ```bash # 进入目标目录 $ cd your_project_folder # 克隆代码(替换为实际URL) $ git clone https://gitee.com/username/project.git ``` > 提示:URL在GitCode项目页点击「克隆/下载」获取 2. **代码结构解析** 典型项目包含: ```plaintext project-root/ ├── src/ # 源代码 ├── docs/ # 文档 ├── README.md # 必读文件(含依赖说明) ├── requirements.txt # Python依赖 └── Makefile # 编译脚本 ``` 3. **安装依赖** - **Python项目**: ```bash $ pip install -r requirements.txt ``` - **Node.js项目**: ```bash $ npm install ``` - **Java项目**: ```bash $ mvn clean install ``` 4. **运行项目** - 参考 `README.md` 的执行指令,例如: ```bash # Python示例 $ python main.py # JavaScript示例 $ node app.js ``` --- ### 三、常见问题解决 1. **依赖安装失败** - 检查文档要求的运行环境版本(Python/Node.js/JDK等) - 使用虚拟环境隔离(Python的venv/Node的nvm) 2. **配置文件缺失** - 查找项目中的 `.env.example` 或 `config.sample.ini` 文件 - 复制为正式配置文件并按需修改 3. **编译错误** - 确认是否遗漏构建步骤(如前端项目需要打包): ```bash $ npm run build # React/Vue项目 ``` > **重要提示**:90%的问题可在 `README.md` 或 `docs/` 目录找到解决方案[^3],开源项目通常包含详细配置指南和问题排查章节。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值