{"id":83813,"date":"2020-05-08T18:19:10","date_gmt":"2020-05-08T10:19:10","guid":{"rendered":"http:\/\/4563.org\/?p=83813"},"modified":"2020-05-08T18:19:10","modified_gmt":"2020-05-08T10:19:10","slug":"%e5%85%b3%e4%ba%8e%e6%96%ad%e8%a8%80%e7%9a%84%e4%b8%80%e4%b8%aa%e7%96%91%e9%97%ae%ef%bc%8c%e5%b8%8c%e6%9c%9b%e5%8f%af%e4%bb%a5%e5%92%8c%e6%87%82%e7%9a%84%e4%ba%ba%e8%ae%a8%e8%ae%ba%e4%b8%80%e4%b8%8b","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=83813","title":{"rendered":"\u5173\u4e8e\u65ad\u8a00\u7684\u4e00\u4e2a\u7591\u95ee\uff0c\u5e0c\u671b\u53ef\u4ee5\u548c\u61c2\u7684\u4eba\u8ba8\u8bba\u4e00\u4e0b\uff0c\u8bf7\u4e0d\u541d\u8d50\u6559\u3002"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5173\u4e8e\u65ad\u8a00\u7684\u4e00\u4e2a\u7591\u95ee\uff0c\u5e0c\u671b\u53ef\u4ee5\u548c\u61c2\u7684\u4eba\u8ba8\u8bba\u4e00\u4e0b\uff0c\u8bf7\u4e0d\u541d\u8d50\u6559\u3002               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mitu9527 <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4eca\u5929\u5728\u8bfb\u300a\u7a0b\u5e8f\u5458\u4fee\u70bc\u4e4b\u9053\u300b\u4e00\u4e66\u4e2d\u7684 \u65ad\u8a00\u5f0f\u7f16\u7a0b \u5c0f\u8282\uff0c\u5176\u4e2d\u63d0\u5230\u4e86\u89c2\u70b9\uff1a \u4fdd\u6301\u65ad\u8a00\u5e38\u5f00 \u3002\u5373\u65ad\u8a00\u4e0d\u4f46\u8981\u5728\u5f00\u53d1\u548c\u6d4b\u8bd5\u671f\u95f4\u5f00\u542f\uff0c\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u540c\u6837\u8981\u5f00\u542f\u3002<\/p>\n<pre><code>\u4e24\u4f4d\u5927\u5e08\u7ed9\u51fa\u7684\u7406\u7531\u5927\u6982\u662f\uff1a\u5728\u5f00\u53d1\u548c\u6d4b\u8bd5\u671f\u95f4\uff0c\u65ad\u8a00\u5f88\u53ef\u80fd\u4e0d\u4f1a\u88ab\u89e6\u53d1\uff0c\u4f46\u662f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4e00\u5207\u7686\u6709\u53ef\u80fd\uff0c\u4f60\u4e0d\u80fd\u56e0\u4e3a\u5728\u5f00\u53d1\u548c\u6d4b\u8bd5\u671f\u95f4\u901a\u8fc7\u4e86\u65ad\u8a00\uff0c\u5c31\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u628a\u65ad\u8a00\u7ed9\u53bb\u9664\u3002\u4ed6\u4eec\u8ba4\u4e3a\u5c31\u7b97\u65ad\u8a00\u5b58\u5728\u6027\u80fd\u95ee\u9898\uff0c\u90a3\u4e48\u4e5f\u53ea\u9700\u8981\u5173\u95ed\u90a3\u4e9b\u771f\u6b63\u4f1a\u5f71\u54cd\u6027\u80fd\u7684\u65ad\u8a00\u3002  \u6211\u6700\u65e9\u662f\u901a\u8fc7\u300a\u4ee3\u7801\u5927\u5168 2 \u300b\u4e2d\u7684 \u9632\u5fa1\u5f0f\u7f16\u7a0b \u90a3\u7ae0\u77e5\u9053\u4e86\u65ad\u8a00\uff0c\u5176\u4e2d\u5173\u4e8e\u65ad\u8a00\u7684\u4e00\u4e2a\u89c2\u70b9\u662f\uff1a\u65ad\u8a00\u4e3b\u8981\u662f\u7528\u4e8e\u5f00\u53d1\u548c\u7ef4\u62a4\u9636\u6bb5\uff0c\u5728\u751f\u6210\u4ea7\u54c1\u4ee3\u7801\u65f6\u4e0d\u5e94\u8be5\u628a\u65ad\u8a00\u7f16\u8bd1\u5230\u76ee\u6807\u4ee3\u7801\u4e2d\uff0c\u4ee5\u514d\u964d\u4f4e\u6027\u80fd\u3002\u540e\u6765\u6211\u5728 PHP \u5b98\u65b9\u624b\u518c\u4e2d\u4e5f\u770b\u5230\u4e86\u540c\u6837\u7684\u89c2\u70b9\u3002\u8fd9\u79cd\u89c2\u70b9\u5df2\u7ecf\u5148\u5165\u4e3a\u4e3b\uff0c\u5e76\u4e14\u6df1\u5165\u6211\u5fc3\u3002  \u73b0\u5728\u53cc\u65b9\u63d0\u51fa\u4e86\u521a\u597d\u76f8\u53cd\u7684\u89c2\u70b9\uff0c\u5e76\u4e14\u53cc\u65b9\u90fd\u662f\u6bd4\u8f83\u6743\u5a01\u7684\uff0c\u800c\u6211\u81ea\u5df1\u5728\u65ad\u8a00\u7f16\u7a0b\u8fd9\u5757\u7ecf\u9a8c\u53c8\u6bd4\u8f83\u5c11\uff0c\u6ca1\u529e\u6cd5\u81ea\u884c\u5224\u65ad\u8be5\u600e\u4e48\u505a\uff0c\u6240\u4ee5\uff1a  \u60f3\u8bf7\u95ee\u90a3\u4e9b\u6709\u601d\u8003\u8fc7\u8be5\u95ee\u9898\u7684\u4eba\uff0c\u4f60\u7ad9\u54ea\u4e00\u8fb9\uff1f\u7ad9\u90a3\u4e00\u8fb9\u7684\u7406\u7531\u662f\u4ec0\u4e48\uff1f  \u5e0c\u671b\u6709\u8fd9\u5757\u7ecf\u9a8c\u7684\u4eba\u80fd\u5206\u4eab\u4e0b\u4f60\u7684\u60f3\u6cd5\uff0c\u5e2e\u52a9\u6211\u548c\u6ca1\u8fd9\u5757\u7ecf\u9a8c\u7684\u4eba\u5c11\u8d70\u4e00\u70b9\u5f2f\u8def\uff0c\u8c22\u8c22\uff01 <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>15<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1532597\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cigarzh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u7684\u7a0b\u5e8f\u8981\u662f\u9ad8\u7cbe\u5c16\u884c\u4e1a\uff0c\u6bd4\u5982\u822a\u7a7a\u822a\u5929\u5565\u7684\uff0c\u5f00\u65ad\u8a00\u4e5f\u53ef\u4ee5\u7406\u89e3\uff0c\u751a\u81f3\u8fd8\u6709\u66f4\u53d8\u6001\u4e1c\u897f\u6765\u4fdd\u8bc1\u6b63\u786e\u6027<\/p>\n<p>\u522b\u7684\u5c31\u7b97\u4e86\u5427\uff0c\u522b\u7ed9\u81ea\u5df1\u627e\u4e0d\u75db\u5feb                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532598\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhm1620 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u60f3\u8c61\u4e00\u4e0b\u4f60\u534a\u591c\u7761\u7684\u6b63\u9999\uff0c\u6536\u5230\u4e86\u4e00\u6761\u8fd0\u7ef4\u53d1\u7684\u8b66\u544a\u544a\u8bc9\u4f60\u670d\u52a1\u5668\u5b95\u673a\u4e86\uff0c\u4f60\u706b\u6025\u706b\u71ce\u722c\u8d77\u6765\u4e00\u770b\uff0cassert \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532599\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             C++\u6709 invariant \u8fd9\u4e2a\u6982\u5ff5\uff0c\u53ef\u4ee5\u53bb\u4e86\u89e3\u4e00\u4e0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532600\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : littlewing <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u90a3\u6211\u4e3a\u4ec0\u4e48\u4e0d\u7528\u5176\u4ed6\u53ef\u63a7\u7684\u5f02\u5e38\u5904\u7406\u65b9\u5f0f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532601\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : luozic <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u79cd\u9700\u8981\u7684\u662f\u8f6c\u6362\uff0c\u5728\u6d4b\u8bd5\u548c sit \u73af\u5883\u662f\u65ad\u8a00\uff0c\u5728\u7ebf\u4e0a\u81ea\u52a8\u5207\u6362\u4e3a log to metrics \u5e73\u53f0\u3002\u5f53\u7136\u9ad8\u5b89\u5168\u6027\u548c\u6b63\u786e\u6027\u8981\u6c42\u7684\u90e8\u5206\u6a21\u5757\u662f\u8981\u505a\u5f62\u5f0f\u5316\u9a8c\u8bc1\u7684\uff0c\u5982\u679c\u771f\u6709\u94b1\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532602\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : msg7086 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u65ad\u8a00\u4e00\u822c\u662f\u7528\u5728\u7279\u522b\u91cd\u5927\u7684\u9519\u8bef\u4e0a\u3002\u6bd4\u5982\u7cfb\u7edf\u5e38\u91cf\u88ab\u4fee\u6539\uff0c\u6216\u8005\u5185\u5b58\u5b58\u50a8\u7684\u6570\u636e\u81ea\u884c\u6539\u53d8\u4e86\u7b49\u7b49\uff0c\u8fd9\u79cd\u4e00\u51fa\u73b0\u5c31\u610f\u5473\u7740\u6574\u5957\u7cfb\u7edf\u5fc5\u987b\u505c\u673a\u6392\u67e5\u7684\u60c5\u51b5\u3002<br \/>\u4e00\u822c\u4e1a\u52a1\u5bf9\u8fd9\u79cd\u8981\u6c42\u4e0d\u9ad8\u5427\uff0c\u7528\u5f02\u5e38\u5904\u7406\u6211\u89c9\u5f97\u591f\u7528\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532603\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : laike9m <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u65ad\u8a00\u662f assert \u5417\uff1f\u90a3\u5f53\u7136\u8981\u5e38\u5f00\u4e86\uff0c\u4e0d\u5f00\u7684\u8bdd\u52a0\u5b83\u5e72\u561b\u3002\u52a0\u65ad\u8a00\u662f\u4e3a\u4e86 fail fast\uff0c\u4e0d\u9690\u85cf\u95ee\u9898\u3002\u5f53\u7136\uff0c\u56e0\u4e3a\u65ad\u8a00\u4e00\u65e6 fail \u4e00\u822c\u4f1a\u5bfc\u81f4\u6574\u4e2a\u7a0b\u5e8f\u6302\u6389\uff0c\u6240\u4ee5\u52a0\u65ad\u8a00\u9700\u8981\u8c28\u614e\uff0c\u4e00\u822c\u53ea\u52a0\u5728\u201c\u5982\u679c\u6761\u4ef6\u4e0d\u6ee1\u8db3\uff0c\u7a0b\u5e8f\u5373\u4f7f\u7ee7\u7eed\u8dd1\u4e0b\u53bb\u4e5f\u6ca1\u6709\u610f\u4e49\u201d\u7684\u5730\u65b9\u3002\u5176\u5b83\u9884\u671f\u4f1a\u51fa\u9519\u7684\u5730\u65b9\u7528\u5f02\u5e38\u6765\u5904\u7406\u3002<\/p>\n<p>\u4e24\u7bc7\u6587\u7ae0\u4f9b\u53c2\u8003<br \/>http:\/\/pgbovine.net\/programming-with-asserts.htm<br \/>https:\/\/blog.regehr.org\/archives\/1091                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532604\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : mitu9527 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @cigarzh @laike9m @littlewing @luozic @msg7086 @wutiantong @zhm1620 \u8c22\u8c22\u5206\u4eab\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532605\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jdhao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8981\u770b\u8bed\u8a00\uff0c\u8b6c\u5982\u5bf9\u4e8e Python\uff0c\u5982\u679c\u5f00\u542f\u4e86 optimize \u6a21\u5f0f\uff0c\u90a3\u4e48 assert \u8bed\u53e5\u662f\u4e0d\u4f1a\u8fd0\u884c\u7684\u3002\u5982\u679c\u8981\u68c0\u67e5\u67d0\u4e2a\u4e1c\u897f\u662f\u5426\u6709\u6548\uff0c\u5e94\u8be5\u4f7f\u7528 if \u52a0\u4e0a raise \u6765\u5904\u7406\u6216\u8005\u4f7f\u7528\u5f02\u5e38\u6355\u83b7\uff0c\u5e76\u4e0d\u63a8\u8350\u4f7f\u7528 assert \u6765\u68c0\u67e5\u3002<\/p>\n<p>\u53c2\u8003<br \/>1. https:\/\/stackoverflow.com\/questions\/5142418\/what-is-the-use-of-assert-in-python<br \/>2. https:\/\/stackoverflow.com\/a\/20076295\/6064933                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532606\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : macha <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u7684\u4e60\u60ef\u662f\u6253\u4e2a error \u65e5\u5fd7\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532607\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : namelosw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Runtime \u7684 assert \u5176\u5b9e\u4e00\u822c\u53eb invariant \u3002\u6bd4\u5982\u7528 React \u5076\u5c14\u5c31\u53ef\u4ee5\u770b\u5230\u629b\u3002<\/p>\n<p>\u4e0a\u90fd\u8bf4\u5f53\u673a\u4e4b\u7c7b\u7684 crash\uff0c\u4e5f\u4e0d\u4e00\u5b9a\uff0cinvariant \u4e5f\u53ef\u4ee5 handle\uff0c\u4e3b\u8981\u770b\u76ee\u7684\u662f\u4ec0\u4e48\u3002<\/p>\n<p>\u9700\u8981 Case by case \u6743\u8861\u4e00\u4e0b\u4e00\u4e2a invariant \u88ab\u7834\u574f\uff0c\u5230\u5e95\u662f\u7ee7\u7eed\u8fd0\u884c\u7684\u635f\u5931\u5927\uff0c\u8fd8\u662f\u505c\u4e0b\u6765\u635f\u5931\u5927\u3002<\/p>\n<p>\u53e6\u5916\u5c31\u662f invariant \u7684\u53e6\u5916\u4e00\u4e2a\u76ee\u7684\u662f\u66b4\u9732\u8fd9\u4e2a\u95ee\u9898\uff0c\u8bb0\u4e0b\u6765\u5c31\u53ef\u4ee5\u4fee\u4e86\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532608\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jinzhongyuan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u8fd8\u4ee5\u4e3a\u662f\u8bf4\u7684 Spring \u63d0\u4f9b\u7684 Assert \u5462\uff0c\u6211\u5fc3\u60f3\u90a3\u4e2a\u597d\u50cf\u53ef\u4ee5\u968f\u4fbf\u52a0                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532609\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : vitoliu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e1a\u52a1\u65ad\u8a00\u7684\u76ee\u7684\u4e00\u822c\u662f\u5199\u5728\u7279\u6b8a\u903b\u8f91\u524d\uff0c\u786e\u4fdd\u540e\u7eed\u903b\u8f91\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u770b\u4e2a\u4eba\u4e60\u60ef\uff0c\u6211\u4e0d\u7ecf\u5e38\u5e94\u7528\uff0c\u6709\u65f6\u5019\u6539\u522b\u4eba\u7684\u4ee3\u7801\u7684\u65f6\u5019\u4f1a\u52a0\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532610\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : duzhanguan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @laike9m \u4f60\u4ece\u54ea\u627e\u7684\u8fd9\u4e9b\u535a\u5ba2                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532611\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : laike9m <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @duzhanguan \u4ee5\u524d\u770b\u8fc7\u7684\uff0c\u4e0d\u662f\u73b0\u627e\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e\u65ad\u8a00\u7684\u4e00\u4e2a\u7591\u95ee\uff0c\u5e0c\u671b\u53ef\u4ee5\u548c\u61c2\u7684&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/83813"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83813"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/83813\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83813"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}