{"action":"created","issue":{"url":"https://api.github.com/repos/wujr5/c-and-cpp-language-learning/issues/2","labels_url":"https://api.github.com/repos/wujr5/c-and-cpp-language-learning/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/wujr5/c-and-cpp-language-learning/issues/2/comments","events_url":"https://api.github.com/repos/wujr5/c-and-cpp-language-learning/issues/2/events","html_url":"https://github.com/wujr5/c-and-cpp-language-learning/issues/2","id":108169076,"number":2,"title":"计科：week1 代码风格检查","user":{"login":"wujr5","id":7693440,"avatar_url":"https://avatars.githubusercontent.com/u/7693440?v=3","gravatar_id":"","url":"https://api.github.com/users/wujr5","html_url":"https://github.com/wujr5","followers_url":"https://api.github.com/users/wujr5/followers","following_url":"https://api.github.com/users/wujr5/following{/other_user}","gists_url":"https://api.github.com/users/wujr5/gists{/gist_id}","starred_url":"https://api.github.com/users/wujr5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wujr5/subscriptions","organizations_url":"https://api.github.com/users/wujr5/orgs","repos_url":"https://api.github.com/users/wujr5/repos","events_url":"https://api.github.com/users/wujr5/events{/privacy}","received_events_url":"https://api.github.com/users/wujr5/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/wujr5/c-and-cpp-language-learning/labels/%E8%AE%A1%E7%A7%91%E7%8F%AD","name":"计科班","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-09-24T16:47:58Z","updated_at":"2015-11-09T14:15:30Z","closed_at":null,"body":"# week1 代码风格检查\r\n\r\n[Sicily]: http://soj.sysu.edu.cn/index.php\r\n\r\n## 一、用cpplint.py进行代码风格检查\r\n\r\n> Sicily系统没有在编程风格上作要求，只要你的代码能运行，输入输出没问题，就可能可以通过。但是这样会写出可能可读性很差的代码。因此我们TA强烈要求同学们一定要注意自己的代码编写的风格。\r\n\r\n下面介绍一个工具的使用来进行代码风格检查。\r\n\r\n### 步骤1：安装python\r\n\r\n教程：[安装python][]\r\n\r\n> 要注意的是，教程中说的系统变量就是python的安装路径。\r\n\r\n[安装python]: http://jingyan.baidu.com/article/7908e85c78c743af491ad261.html\r\n\r\n### 步骤2：检查python是否安装成功\r\n\r\n1. 打开命令行窗口（win键+R；输入`cmd`；回车）如下：\r\n![](http://ww3.sinaimg.cn/large/ed796d65gw1ewaf0z4ppoj20he091myl.jpg)\r\n2. 如果安装成功，在命令行窗口输入`python`将会出现以下的输出：\r\n![](http://ww2.sinaimg.cn/large/ed796d65gw1ewaf4k6m5yj213s0lw0vr.jpg)\r\n\r\n\r\n### 步骤3：下载cpplint.py\r\n\r\n点击下载[cpplint.py][]\r\n![](http://ww1.sinaimg.cn/large/ed796d65gw1ewafi54dw8j21740om75z.jpg)\r\n\r\n[cpplint.py]: http://pan.baidu.com/s/1bn0mqN9\r\n\r\n### 步骤4：代码风格检查\r\n\r\n1. 把`cpplint.py`文件复制到你的程序代码所在的目录。比如：\r\n![](http://ww1.sinaimg.cn/large/ed796d65gw1ewafkpn599j20wl0p4wk4.jpg)\r\n\r\n2. 打开命令行窗口，方法就是步骤2的第一点。导航到代码所在目录。\r\n![](http://ww1.sinaimg.cn/large/ed796d65gw1ewafoanusrj213s0c642m.jpg)\r\n> `cd`命令的含义是打开目录，`dir`命令的含义是查看该目录下地文件和文件夹\r\n\r\n3. 运行命令  \r\n\t```\r\n\tpython cpplint.py --filter=-whitespace/tab filename.c\r\n\t```\r\n\t> 注意`finename.c`是你的源代码的文件名\r\n\t\r\n\t然后就会有如下的输出：\r\n\t![](http://ww4.sinaimg.cn/large/ed796d65gw1ewagjny36xj213s0lwwim.jpg)\r\n\t> 注意错误，如`test.c:7:  Line ends in whitespace.  Consider deleting these extra \tspaces.  [whitespace/end_of_line] [4]`。`test.c`指的是文件名，`7`指的是行号，后面的\t`Line ends in whitespace.  Consider deleting these extra spaces.  [whitespace/\tend_of_line] [4]`指的是代码中出现的错误。\r\n\r\n### 步骤5：根据输出的改善代码\r\n\r\n根据输出的错误，逐行改进代码。直到错误数目为0。如`Total errors found: 0`：\r\n![](http://ww2.sinaimg.cn/large/ed796d65gw1ewagnwjvq7j213s0lw40r.jpg)\r\n\r\n### 步骤6：提交到Sicily\r\n\r\n把通过google style的cpplint.py测试的代码，也就是`Total errors found: 0`，再把代码提交到Sicily。\r\n\r\n## 总结\r\n\r\n进行google style风格检测的目的是让同学们写出可读性良好的代码。按照上面的流程编写代码，能帮助你养成良好的编程习惯。希望同学们重视。\r\n\r\n有任何问题欢迎评论。我们会持续改进。\r\n\r\n## 参考\r\n\r\n1. [cmd命令行大全][]\r\n2. [google style guide][]\r\n3. [cpplint][]\r\n\r\n\r\n[cmd命令行大全]: http://jingyan.baidu.com/article/f0e83a25f2659a22e59101b5.html\r\n[google style guide]: https://github.com/google/styleguide\r\n[cpplint]: https://en.wikipedia.org/wiki/Cpplint"},"comment":{"url":"https://api.github.com/repos/wujr5/c-and-cpp-language-learning/issues/comments/155075008","html_url":"https://github.com/wujr5/c-and-cpp-language-learning/issues/2#issuecomment-155075008","issue_url":"https://api.github.com/repos/wujr5/c-and-cpp-language-learning/issues/2","id":155075008,"user":{"login":"SchroDeCat","id":13759192,"avatar_url":"https://avatars.githubusercontent.com/u/13759192?v=3","gravatar_id":"","url":"https://api.github.com/users/SchroDeCat","html_url":"https://github.com/SchroDeCat","followers_url":"https://api.github.com/users/SchroDeCat/followers","following_url":"https://api.github.com/users/SchroDeCat/following{/other_user}","gists_url":"https://api.github.com/users/SchroDeCat/gists{/gist_id}","starred_url":"https://api.github.com/users/SchroDeCat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SchroDeCat/subscriptions","organizations_url":"https://api.github.com/users/SchroDeCat/orgs","repos_url":"https://api.github.com/users/SchroDeCat/repos","events_url":"https://api.github.com/users/SchroDeCat/events{/privacy}","received_events_url":"https://api.github.com/users/SchroDeCat/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T14:15:30Z","updated_at":"2015-11-09T14:15:30Z","body":"%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\；C:\\Python34；"}}