主要内容是解释为什么重写了原来的 Python 的程序。
- Architecturally, the existing architecture was incapable of scaling to other technologies or changing direction without massive amounts of effort. The business had just been forced to change to MQTT from another IaaS provider because of licensing cost concerns, and the cutover took nearly a year. With new devices released every year (e.g. BLE, Wifi, Z-Wave, Zigbee, arbitrary REST APIs) the business wants to be able to change IoT stacks quickly to adapt to new technology.
- There were technical debt items nobody understood or was prepared to resolve. (Did I mention that none of the original programmers were still around to fix bugs or answer questions?) Fixing obvious issues in one place often broke the program in completely unrelated parts of the code.
- The program had unit tests in places, but there were no coding standards — someone’s “very clever” generator expression state machine drove the serial framing protocol, but it took weeks to figure out why it was broken.
- There was dead code everywhere, but we couldn’t prove it was really dead code.
- Holy cow, the bugs. Did I mention the bugs?
- There were opportunities to replace the error-prone first-party Python Z-Wave handler code with a vendor-supplied reference implementation written in C. It would have been more effort to hack the existing Python implementation around the C library than to just rewrite the thing.
- We wanted to run more customers on cheaper hardware. Improving that ratio directly drives higher profit margins for the business.
- 有些技术债没有人懂也没人解决。(我想说目前没有任何之前的程序员还在修bug或回答问题？)在一个地方修复一个简单的 bug 通常会破坏其他完全不相关的部分。
- 天啊，到处是 bugs，我有提到 bugs 吗？
- 有机会用供应商提供的用C语言编写的参考实现来替换自己容易出错的Python Z-Wave处理代码。但要想绕过C语言库修改现有的Python实现，比重写要麻烦得多。
So from those business needs we can start to pick apart some of the actual requirements in the chosen language for our particular project:
- It needs to talk C and run against C libraries.
- There are timing requirements (because of the serial communications).
- We need to be able to run it on a potato (because of cost).
- It has to be able to run both the serial communications and a bunch of command/telemetry at the same time, without bugs.
- String manipulation should be easy, because the commands and responses are all JSON.
- The software must work correctly and deterministically, even though we are not all genius programmers.
- It needs to be secure.
- 我们需要能够在 potato 上运行它(因为成本)。
As it happened, Rust fit the bill for all of these needs.