c********r 发帖数: 107 | 1 How can I improve my C/C++ coding quality (efficient, reliable)? Reading
code complete, effective C++, etc? are there any other sources I can refer
to or other means I can take?
thx | l********a 发帖数: 1154 | 2 profile to find bottleneck first | D*****r 发帖数: 6791 | 3 这也可以profile?
有个具体问题:怎么处理异常?
左一个try, 右一个try,稍微大一点的程序我就控制不住了,写程序又慢\bug又多,
这个怎么处理好?有些地方还不太好测试。
【在 l********a 的大作中提到】 : profile to find bottleneck first
| a***y 发帖数: 2803 | 4 什么程序,要用这么多try...catch?
【在 D*****r 的大作中提到】 : 这也可以profile? : 有个具体问题:怎么处理异常? : 左一个try, 右一个try,稍微大一点的程序我就控制不住了,写程序又慢\bug又多, : 这个怎么处理好?有些地方还不太好测试。
| D*****r 发帖数: 6791 | 5 中间要用网络上的另一个API,每一条调用都得防着各种异常。
还要读写文件……
有目录处理,目录处理的时候报错要给出目录位置。
文件处理出错要给出文件位置。
每一条记录处理出错要给出记录编号
记录处理的时候每次调网络上另一个API的时候也要catch下来给个有意义的报错信息。。
我可能函数写太长了,中间应该分层次多写几个函数
但是现在如果重新调整结构的话,以前手动测过的功能没法保证了,所以一直拖着没改。
函数越写越长……看来最后免不了还得重新写一遍……
多,
【在 a***y 的大作中提到】 : 什么程序,要用这么多try...catch?
| X****r 发帖数: 3557 | 6 Like goodbug mentioned in another thread, readability is the key
for code quality. Everything else follows.
Readability is not only about to make the code understandable and
maintainable to someone else or yourself at later time. More
importantly, it is about to have a clear mind on what the code
does and how it does it while you are writing it. Sometime you
thought you do, but say, if you are unable to describe in one simple
sentence on what function/method does and another on how it does it
for every function or method in your code, then likely you don't,
and need to rework your code.
And then comes into tests. Tests are the first and the last line
of defense on bugs. At least every non-trivial function or method,
and ideally every line of code, should be covered by unit tests.
You also need integration tests on how they work together. If your
code involves user-interface, you may also want automation tests
to make sure the UI works as expected.
As you can see, high quality code are not cheap. You may have to
spend twice or three times of time to write them. But unless it is
disposable code for some one-time thing, it is usually worth the
cost.
【在 c********r 的大作中提到】 : How can I improve my C/C++ coding quality (efficient, reliable)? Reading : code complete, effective C++, etc? are there any other sources I can refer : to or other means I can take? : thx
| C***y 发帖数: 2546 | 7 不用异常,只用返回值
【在 D*****r 的大作中提到】 : 这也可以profile? : 有个具体问题:怎么处理异常? : 左一个try, 右一个try,稍微大一点的程序我就控制不住了,写程序又慢\bug又多, : 这个怎么处理好?有些地方还不太好测试。
| c********r 发帖数: 107 | 8 So how can I quickly learn or develop good coding habits/style so I can
write optimized/reliable code in the first or second time? I am a recent
graduate and would really like to bring my code to an industry standard..
【在 X****r 的大作中提到】 : Like goodbug mentioned in another thread, readability is the key : for code quality. Everything else follows. : Readability is not only about to make the code understandable and : maintainable to someone else or yourself at later time. More : importantly, it is about to have a clear mind on what the code : does and how it does it while you are writing it. Sometime you : thought you do, but say, if you are unable to describe in one simple : sentence on what function/method does and another on how it does it : for every function or method in your code, then likely you don't, : and need to rework your code.
| g*****g 发帖数: 34805 | 9 A test driven approach should help. I am not religious that one must
write tests first, but I'd at least make sure the code has unit tests
on key functions and automatic integration tests on sunnyday cases.
Another thing I want to stress is, don't take the habit of writting
too many comments. Your code should be self-explained. There are cases
that you want to write comments, e.g. public API, sophisticated algorithm.
But most of the time, if you think you'd need a comment otherwise others
or yourself will have trouble to follow. Think of breaking up the function
and use more meaningful function name.
【在 c********r 的大作中提到】 : So how can I quickly learn or develop good coding habits/style so I can : write optimized/reliable code in the first or second time? I am a recent : graduate and would really like to bring my code to an industry standard..
| X****r 发帖数: 3557 | 10 Readability is not just about coding styles. It is also about design
and code structure. Try read more high-quality code, and think
about why they are so written and what and the pros and cons against
alternatives. If you have a chance, let some good programmer to review
your code. Detailed code reviews is the fastest way to learn good coding.
standard..
【在 c********r 的大作中提到】 : So how can I quickly learn or develop good coding habits/style so I can : write optimized/reliable code in the first or second time? I am a recent : graduate and would really like to bring my code to an industry standard..
| s****y 发帖数: 2052 | 11 有人愿意review么。。大家的时间都这么宝贵。。
【在 X****r 的大作中提到】 : Readability is not just about coding styles. It is also about design : and code structure. Try read more high-quality code, and think : about why they are so written and what and the pros and cons against : alternatives. If you have a chance, let some good programmer to review : your code. Detailed code reviews is the fastest way to learn good coding. : : standard..
| a***y 发帖数: 2803 | 12 算法是首先要考虑的,idea对了,再怎么写,方向是对的.
【在 X****r 的大作中提到】 : Readability is not just about coding styles. It is also about design : and code structure. Try read more high-quality code, and think : about why they are so written and what and the pros and cons against : alternatives. If you have a chance, let some good programmer to review : your code. Detailed code reviews is the fastest way to learn good coding. : : standard..
| a****l 发帖数: 8211 | 13 关于注释,我的看法是不应该写解释实现方式的注释,因为正如你所说的,code should
be self-explained,当然有时候你的技巧太高深的话还是写两句吧.注释应该主要是写
程序的用途和假设的.特别是设计时的各种假设,非常有必要在程序中写下来,以备检查.
【在 g*****g 的大作中提到】 : A test driven approach should help. I am not religious that one must : write tests first, but I'd at least make sure the code has unit tests : on key functions and automatic integration tests on sunnyday cases. : Another thing I want to stress is, don't take the habit of writting : too many comments. Your code should be self-explained. There are cases : that you want to write comments, e.g. public API, sophisticated algorithm. : But most of the time, if you think you'd need a comment otherwise others : or yourself will have trouble to follow. Think of breaking up the function : and use more meaningful function name.
|
|