Pair programming - statistical character

Address operational requirements https://www.cnblogs.com/harry240/p/11524113.html
Github Address https://github.com/1517043456/WordCount.git
Twinning partner blog https://www.cnblogs.com/isHao/

A, PSP table

  PSP is a model of Carnegie Mellon University (CMU) for software engineers, experts proposed: Personal Software Process (PSP, personal development process, also known as the Personal Software Process).

PSP2.1 Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan 20 30
.Estimate Estimated how much time this task requires 400 600
Development Develop 300 350
.Analysis The demand analysis (including learning new technologies) 30 30
· Design Spec Generate design documents 20 30
· Design Review · Design Review (and his colleagues reviewed the design documents) 10 30
· Coding Standard · Code specifications (development of appropriate norms for the current development) 20 20
· Design · Specific design 30 30
· Coding · Specific coding 300 500
· Code Review · Code Review 30 60
· Test · Test (self-test, modify the code, submit modifications) 60 30
Reporting · Report 30 60
· Test Report · testing report 60 30
· Size Measurement · Computing workload 30 30
·Postmortem & Process Improvement Plan · Hindsight, and propose process improvement plan 30 30
total 1370 1640

Second, the process of twinning

  After finished first understand the problem, we first discuss how to complete this project, we must first determine what features are complete, needs analysis to better roll up its sleeves and dry fuel. After our analysis, we decided to start to function in order to achieve the purpose, until after the function realization, then consider the reusability of code efficiency of the code and so on. We then discuss the decision to use Alibaba to develop the manual specification, then the discussion will involve how much class, which functions will be used. After the development of the code specifications, each to start their own original code design, after both were done according to code specifications developed peer review, and finally merge code, formed a preliminary version, followed by commissioning amend and improve the code, unit test form the final version. Here is the junction of the picture recording process:


Third, the problem-solving ideas

1, the basic functions

  The basic function of the subject is divided into four steps. First, the statistics file character without regard to Chinese characters, the second is the number of effective lines in the entire file statistics, Third, through the -minstruction to calculate the effective number of phrases, the four word count is the total number of files and the number of occurrences and recorder output. We use different methods to improve the different functions will be implemented, the following is the class and the way we create:

在这里插入图片描述

  • PrintFile categories: a high occurrence frequency of an output of 10 words to the file output.txt.
  • PrintWord categories: statistical output for high-frequency words, and sorting.
  • StatisticsFile class: statistics for the number of words in the input file and the file has a few lines.
  • StatisticsWord class: This file contains the statistics for the number of words.

    2, a flowchart of the program

      After we discussed the overall design flow chart is as follows:
    在这里插入图片描述

Fourth, the implementation code portion

1, the regular expression statistics

  Total number of regular expression characters, and word count.

/**
         * 统计字符总数
         * */
        public static int signFile(string fileName)
        {
            string argex2 = "[a-zA-Z]{4,}[a-zA-Z0-9]*";
            int signNumber = 0;
            int sum = 0;
            string allText = File.ReadAllText(fileName);
            signNumber = Regex.Matches(allText, @"\d").Count;//统计数字
            signNumber = signNumber + Regex.Matches(allText, @"\s").Count;//统计空白字符
            signNumber = signNumber + Regex.Matches(allText, @"\w").Count;//统计任何单词字符
            sum = Regex.Matches(allText, argex2).Count;
            Console.WriteLine("字符数为:" + signNumber);
            Console.WriteLine("单词数量为:" + sum);
            return signNumber;
        }

2, the statistics the number of rows

  To count the number of lines of the file by the ReadLine method SreamReader.

/**
         * 统计文件行数
         **/
        public static int lineFile(string fileName)
        {
            int rows = 0;//文件行数
            StreamReader streamReader = new StreamReader(fileName, Encoding.Default);
            while (streamReader.ReadLine() != null)
            {
                rows++;
            }
            streamReader.Close();
            Console.WriteLine("该文件行数为:" + rows);
            return rows;
        }

3, statistics phrase

  Achieve statistical phrase by the following method.

/**
         * 统计词组
         * */
        public static int sumWord(string fileName, int m)
        {
            int instructionM = m;
            int number = 0;
            int last = 0;
            Dictionary<string, int> keyValuePairs = new Dictionary<string, int>();
            StreamReader reader = new StreamReader(fileName, Encoding.Default);
            String path = null;
            string s = null;
            while ((path = reader.ReadLine()) != null)
            {
                s += (path + "\n");
            }
            string[] words = Regex.Split(s, @"\W+");
            foreach (string word in words)
            {
                if (keyValuePairs.ContainsKey(word))
                {
                    keyValuePairs[word]++;
                    number++;
                }
                else
                {
                    keyValuePairs[word] = 1;
                    number++;
                }
            }
            if (number > instructionM)
            {
                last = number - instructionM;
                Console.WriteLine("词组个数为:" + last);
            }
            else
            {
                Console.WriteLine("不存在这样的词组");
            }

            return last;


        }

4, ordering

  The frequency of occurrence of the word sorts, and at the same time ordering with given frequency dictionary.

 foreach (KeyValuePair<string, int> entry in keyValuePairs)//统计单词总量
            {
                wordKey[i] = entry.Key;
                wordValue[i] = entry.Value;
                i++;
            }
            for (int j = 0; j < i; j++)//排序
            {
                for (int x = j + 1; x < i; x++)
                {
                    if (wordValue[j] < wordValue[x])
                    {
                        int value = 0;
                        value = wordValue[j];
                        wordValue[j] = wordValue[x];
                        wordValue[x] = value;
                        string key = null;
                        key = wordKey[j];
                        wordKey[j] = wordKey[x];
                        wordKey[x] = key;
                    }
                }
            }
            string[] result = new string[instructionN];
            for (int j = 0; j < instructionN; j++)
            {
                result[j] = wordKey[j] + ":" + wordValue[j];
                // Console.WriteLine( ss1[j] );
            }
            var queryResults = from ni in result//字典序排序并输出
                               orderby ni
                               select ni;

            foreach (var item in queryResults)
            {

                //Console.WriteLine(item);
                File.AppendAllText(o, item + "\r\n");
            }

V. Code peer review process

  由于一些功能没有实现,所以我们互审主要基于代码的格式和已实现功能的纠错。
  1. 命名变量、函数时不要随意取名,最好有相关意思,采用阿里巴巴规范命名法。避免过多地描 述和可要可不要的修饰词。
  2. 尽量使代码简明易读,无二义性。
  3. 在复杂的表达式中,用括号清楚地表示逻辑优先级。
  4. 断行,每个“{” “}”独占一行,一一对应。
  5. 给出关键的注释。

代码规范

  我们在互审过程中,发现了我们代码不规范带来的烦恼。所以我们决定规定好代码规范。可以给我们带来以下好处。

  • 规范的代码可以促进团队合作
  • 规范的代码可以减少bug处理
  • 规范的代码可以降低维护成本
  • 规范的代码有助于代码审查
  • 养成代码规范的习惯,有助于程序员自身的成长

  代码规范链接:https://www.jianshu.com/p/d7e87107073c

六、建立单元测试

  初步单元测试结果如下:


在这里插入图片描述


  改进后单元测试结果如下:


在这里插入图片描述

七、效能测试及性能改进

  本次性能分析,主要是从算法入手和设计入手。首先在初步完成项目后,我们就进行了一次项目性能分析,来查看哪里的优化效率和算法。





  可见,当我们为了完成功能,将所有代码写到一起时,有的代码重复率十分高,消耗也大,耦合度也大。因此我们进行了相应的优化和改进。





  当我们将代码进行整理后,代码的重复率下降,耦合性降低,同时也通过注入对象的方式减少了类实例化的开销。





  改进后单个类效能测试如下:


在这里插入图片描述

总结

  本次结对编程的项目我个人感觉还是比较难的,很多东西还是一如既往的不懂,然后一如既往的查资料,虽然做了很多天,仍然有些功能没能实现。在和队友商量后也没有解决,只把自己能做的写了出来。在编程过程中,通过代码互审,互相找到了对方代码的不足,并改正。很多之前不知道的东西在此次作业中出现,由于并不了解,所以做的很粗糙。在此次作业中深刻地认识到了自己的差距,会在之后的学习中更加努力,争取以后的作业不会出现此次情况。

  此次结对1+1<2,由于自身的原因,且并没有真正领略到结对编程的含义,导致大多数代码是两个人各自完成,最后再来对照纠错,以及并不熟悉别人的想法导致效率的低下,结对编程比较要求两个人的水平相近。

Guess you like

Origin www.cnblogs.com/xnch/p/11646350.html