crap code indicators

本文讨论了多位开发者眼中构成糟糕代码的主要特征,包括错误处理缺失、语言特性使用不当、文档不足、函数过长等问题。

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

Roger:

These are some of my "crap" indicators:
- No error detection/handling.
- Incorrect or non use of language features/standard libraries.
- Non understanding/incorrect use of programming paradigms (e.g. "is a", "uses a" ...).
- Useless, lack of, or bad documentation.
- Massive functions or methods
- Obfuscated code.

I hate it when:
Someone recreates functions because they were too distracted/overworked/lazy/dumb to see if a working function already existed.
Someone codes 5 lines to do something that could have been done with 1.
There are no naming conventions.
Someone uses one name for an object in one section of code but a different name in another but the two sections relate or interact. Duh!
There is no way to know who wrote the code or who made changes to it.
There is no formatting or inconsistent formatting.

Reiterate:
"more than 2 instructions in a line" is crap.
"no documentation or poor docs/comments" is crap.

> What code characteristics would make you say: “Pardon my French, but this code is crap!”

This is actually one of my favorite interview questions. I think lots of you guys already nailed the big ones: Functions with side effects. Big classes. Low cohesion. High coupling. Cut-paste-tweak duplication. Meaningless comments. Premature optimization. Premature generalization. Nonexistent error handling. Error handling everywhere. Empty catch blocks. Lots of "if" statements (special cases). Shared state concurrency.

I'll buck the trend and say the following aren't code smells, however:

* m_ notation. There are many abuses of Hungarian, but this isn't one of them.
* Multiple instructions on a line.
* Superficial layout inconsistencies. I don't think code has to cater to OCD sufferers to be considered "readable".
* Few comments. Well-written code doesn't need a lot of comments. (No comments at all is definitely a problem, but it's also one I've never run into. I have seen lots of problematic heavily commented code, though).
* Long functions. I look more at the number of locals and the level of indentation. Sometimes you really do need to do A, then B, then C, all the way to Z -- and in many cases, arbitrarily chopping it up into funclets is actually the wrong thing to do.

内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
<think>好的,我需要回答用户关于CRAP算法在机器人路径规划中的应用以及软件实现的问题。首先,我需要确认CRAP算法的具体信息。不过,用户提到的CRAP算法可能是一个笔误或混淆,因为常见的路径规划算法如A*、Dijkstra、RRT等更为常见。CRAP可能是指某个特定领域或文献中的算法,但经过初步检索,发现它并不是广泛认可的术语。 接下来,我需要考虑可能的解释。用户可能混淆了算法名称,比如可能是RAP(Resource Allocation Problem)或CAP(Collision Avoidance Planning)的变体,或者是某种特定实现的缩写。此外,还需检查是否有拼写错误,比如CRAP可能应为RRT*(Rapidly-exploring Random Tree Star)或其他类似算法。 假设CRAP确实存在,但可能不常见,我需要查找相关文献或资料。根据提供的引用,引用[3]提到ROS(机器人操作系统)在路径规划中的应用,但指出其存在一些局限性。这可能意味着CRAP算法是ROS中的某个模块或特定实现,但需要进一步验证。 另外,考虑到路径规划中的常用方法,如势场法、A*算法、Dijkstra算法、RRT等,用户可能想了解这些算法中的某一种。因此,在回答时需要指出可能的混淆,并提供常见算法的信息,同时尝试推测CRAP的可能含义。 在软件实现方面,引用[1]提到C/C++的算法库,引用[2]涉及编译器和开发环境,这可能与算法实现相关。因此,可以建议使用这些资源进行路径规划算法的开发。 总结回答结构:首先指出CRAP算法可能不常见或存在混淆,然后介绍常见的路径规划算法,并推测可能的CRAP解释,最后提供软件实现的建议和相关资源引用。</think>关于CRAP算法在路径规划中的应用,目前该名称并未被广泛认知为机器人领域的标准算法。可能的情况包括: 1. **术语混淆**:可能是对RRT(快速扩展随机树)[^1]、A*算法或势场法等经典方法的误称 2. **特定实现缩写**:某些研究团队可能使用自定义缩写,如"Collision-Resistant Autonomous Planning"(防碰撞自主规划)的简称 ### 常见路径规划算法对比 | 算法 | 类型 | 适用场景 | 时间复杂度 | |------|------|---------|-----------| | A* | 启发式搜索 | 已知环境全局规划 | $O(b^d)$ | | RRT | 随机采样 | 高维空间运动规划 | $O(n \log n)$ | | 势场法 | 虚拟力场 | 实时避障 | $O(n)$ | ### 软件实现建议 1. **基础框架**:建议使用ROS(机器人操作系统)中的nav2导航栈[^3] 2. **算法库**:可参考C++实现的OMPL(开放运动规划库)[^1] 3. **硬件集成**:使用Gazebo进行仿真测试后部署到真实机器人 ```cpp // 示例:RRT算法核心伪代码 Node* RRT::growTree(Node* root) { Node* q_rand = sampleRandomNode(); Node* q_near = findNearestNode(q_rand); Node* q_new = extend(q_near, q_rand); if (checkCollision(q_near, q_new)) { addEdge(q_near, q_new); return q_new; } return nullptr; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值