我们正在生成一个可移植的代码(win+macOs),我们正在研究如何使代码变得更加粗糙,因为它经常崩溃……(通常是溢出或错误的初始化) :-(
我读到Google Chrome对每个标签页都使用一个进程,所以如果出现问题,程序不会完全崩溃,只有那个标签页会崩溃。我认为这是相当整洁的,所以我可能会尝试一下!
所以我想知道是否有人有一些技巧,帮助,阅读列表,评论,或者其他可以帮助我构建更多rubust c++代码的东西(可移植总是更好)。
在同一主题中,我还想知道是否有可移植的进程库(如boost)?
好的非常感谢。
发布于 2008-09-17 17:09:17
我在许多多平台C++应用程序上进行了开发(最大的是150万行代码,运行在7个平台上-- AIX、HP-UX PA-RISC、HP-UX Itanium、Solaris、Linux、Windows、OS )。你的帖子里实际上有两个完全不同的问题。
- Use unit tests to find logic problems before they kill you.
- Use debuggers to find out what's causing the crashes if it's not obvious.
- Use boost and similar libraries. In particular, the pointer types will help you avoid memory leaks.
- Again, use libraries that are designed for this when possible. Particularly for any GUI bits.
- Use standards (e.g. ANSI vs gcc/MSVC, POSIX threads vs Unix-specific thread models, etc) as much as possible, even if it requires a bit more work. Minimizing your platform specific code means less overall work, and fewer APIs to learn.
- Isolate, isolate, isolate. Avoid in-line #ifdefs for different platforms as much as possible. Instead, stick platform specific code into its own header/source/class and use your build system and #includes to get the right code. This helps keep the code clean and readable.
- Use the C99 integer types if at all possible instead of "long", "int", "short", etc -- otherwise it will bite you when you move from a 32-bit platform to a 64-bit one and longs suddenly change from 4 bytes to 8 bytes. And if that's ever written to the network/disk/etc then you'll run into incompatibility between platforms.
就我个人而言,我会先稳定代码(不添加更多功能),然后再处理跨平台问题,但这取决于您。请注意,Visual Studio有一个出色的调试器(上面提到的代码库正是因为这个原因才被移植到Windows上的)。
发布于 2008-09-17 16:17:49
Chrome的答案更多的是关于故障缓解,而不是代码质量。做Chrome正在做的事情就是承认失败。
更好的QA,不仅仅是程序员测试自己的工作。
坦率地说,如果你的软件经常因为溢出和错误的初始化而崩溃,那么你就会有一个非常基本的编程质量问题,这是不容易修复的。这听起来像哈希和刻薄,这不是我的意图。我的观点是,坏代码的问题必须是您的主要关注点(我确信是这样)。像Chrome或自由使用异常处理来捕捉程序缺陷的东西只会分散你对真正问题的注意力。
发布于 2008-09-17 16:09:47
您没有提到目标项目是什么;每个选项卡都有一个进程并不一定意味着更“健壮”的代码。您的目标应该是编写可靠的代码,而不考虑可移植性-只需阅读有关编写良好的C++代码的内容:)
至于可移植性部分,请确保从第一天起就在两个平台上进行测试,并确保在特定于平台的问题得到解决之前不会编写任何新代码。
https://stackoverflow.com/questions/84817
复制相似问题