标签:alt tee 巴巴 set oid setw 代码 get operation
一:合作者和地址
cooperation:201631072420 201631083122
address:https://gitee.com/Siy1015/WordCount0.0
二:代码互审:
审查情况:
1.制表符和space的未使用,阅读性差,编码风格差
2.注释要么没有,要么很少,基本起不到作用
3.命名不规范,接口不统一
解决方式:
1.通过查阅阿里巴巴公司 java 规范制定了统一的命名规则
2.制定统一的接口,规范命名
3.分工完成自己负责的模块
代码改进:
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; class WordCount { private int charCount; private int wordCount; private int lineCount; public WordCount(int charCount,int wordCount,int lineCount) { this.charCount=charCount; this.wordCount=wordCount; this.lineCount=lineCount; } public int getCharCount() { return charCount; } public void setCharCount(int charCount) { this.charCount = charCount; } public int getWordCount() { return wordCount; } public void setWordCount(int wordCount) { this.wordCount = wordCount; } public int getLineCount() { return lineCount; } public void setLineCount(int lineCount) { this.lineCount = lineCount; } //main public static void main(String[] args) { WordCount WC=new WordCount(0,0,0); String inputFile="file.c"; String outputFile="result.txt"; for(int i=0;i<args.length;i++) { if(args[i].endsWith(".c")) inputFile=args[i]; if(args[i].equals("-o")) outputFile=args[i+1]; } WC.wc(inputFile); for(int i=0;i<args.length;i++) { switch(args[i]) { case "-c": { System.out.println(inputFile+",字符数:" + WC.getCharCount()); break; } case "-w": { System.out.println(inputFile+",单词数:" + WC.getWordCount()); break; } case "-l": { System.out.println(inputFile+",行数:" + WC.getLineCount()); break; } case "-o": { String outTxt=""; for(int j=0;j<args.length;j++) { if(args[j].equals("-c")) outTxt=outTxt+"\r\n"+inputFile+",字符数:" + WC.getCharCount(); if(args[j].equals("-w")) outTxt=outTxt+"\r\n"+inputFile+",单词数:" + WC.getWordCount(); if(args[j].equals("-l")) outTxt=outTxt+"\r\n"+inputFile+",行数:" + WC.getLineCount(); } File outputName = new File(outputFile); outputName.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(outputName)); out.write(outTxt); out.flush(); out.close(); break; } } } } public void wc(String inputFile) throws IOException { String lineString = null; String[] buffer; File dir=new File(inputFile); BufferedReader bf = new BufferedReader(new FileReader(dir)); while((lineString=bf.readLine())!=null) { buffer=lineString.split(",| "); for(int i=0;i<buffer.length;i++) { if(!buffer[i].equals("")) wordCount++; } lineCount++; charCount+=lineString.length(); } bf.close(); }
运行截图:
三:性能测试和优化:
使用JProfiler测试了代码性能,项目太小,且不存在耗时的输入输出或联网操作,故测试的性能优秀。
四:总结
结对编程让我们体会到了team的重要性,各司其职,也发现彼此之间的问题,比如命名接口不统一等,如果代码风格差,阅读他人代码很难受,静态代码检查可以统计错误和警告,相对而言提升了容错率。
标签:alt tee 巴巴 set oid setw 代码 get operation
原文地址:https://www.cnblogs.com/wajp/p/9825092.html