zoukankan      html  css  js  c++  java
  • 代码复审

    给结对伙伴叶露婷的代码复审:

    1.变量命名存在些许问题,尽量不要使用拼音,如果需要按照中文意思命名可以采用英语。

    1 public void dictionarystore()
    2 {
    3 String temp;
    4 count jishu;
    5 
    6 foreach (Object o in str)
    7 {
    8 temp = o.ToString().ToLower();
    9 if (table.ContainsKey(temp))
    10 {
    11 jishu = table[temp];
    12 jishu.setnum();
    13 if (jishu.getdanci().CompareTo(o.ToString()) < 0)
    14 {
    15 jishu.setdanci(o.ToString());
    16 }
    17 }
    18 else
    19 {
    20 jishu = new count(o.ToString(), 1);
    21 table.Add(temp, jishu);
    22 }
    23 }
    24 
    25 
    26 }
    27 }


    2.使用了过多的类,但是这些类的存在没有很大的实际意义,本来只有两百行的代码分成这么多个类有些繁琐,可以将一些功能比较薄弱的类归并到其他的类中实现其功能。比如下面这代码的功能是获取文件中的内容,完全可以将内容的获取和分割放在一个类中,这应该是属于同一种处理,也是同一个对象应该提供的功能。不要将一些杂乱的功能归为一个类。面向对象不是简单的分割,而是有原因的。合理确定对象,这样在以后写大型程序的时候能够更易看懂更好管理。

    1 public void dirscanner(String dir)
    2 {
    3 String[] allfile = null;
    4 String[] alldirectory = null;
    5 if (!Directory.Exists(dir) && !File.Exists(dir))
    6 {
    7 Console.WriteLine("该路径无效");
    8 Environment.Exit(0);
    9 }
    10 else if (Directory.Exists(dir))
    11 {
    12 allfile = Directory.GetFiles(dir);
    13 alldirectory = Directory.GetDirectories(dir);
    14 for (int i = 0; i < allfile.Length; i++)
    15 {
    16 dirscanner(allfile[i]);
    17 }
    18 for (int i = 0; i < alldirectory.Length; i++)
    19 {
    20 dirscanner(alldirectory[i]);
    21 }
    22 }
    23 
    24 String houzhui = dir.Substring(dir.LastIndexOf(".") + 1);
    25 if (houzhui == "txt" || houzhui == "cpp" || houzhui == "h" || houzhui == "cs")
    26 {
    27 String text = File.ReadAllText(dir);
    28 str.Append('-' + text);
    29 }
    30 }
    31 }


    3.这里的dictionary的值对的值得类型为一个自己定义的类,有些浪费空间。可以考虑一下还有没有其他的方式,能够同时兼顾时间和空间。

    1 public void dictionarystore()
    2 {
    3 String temp;
    4 count jishu;
    5 
    6 foreach (Object o in str)
    7 {
    8 temp = o.ToString().ToLower();
    9 if (table.ContainsKey(temp))
    10 {
    11 jishu = table[temp];
    12 jishu.setnum();
    13 if (jishu.getdanci().CompareTo(o.ToString()) < 0)
    14 {
    15 jishu.setdanci(o.ToString());
    16 }
    17 }
    18 else
    19 {
    20 jishu = new count(o.ToString(), 1);
    21 table.Add(temp, jishu);
    22 }
    23 }


    4.时间效率方面还行,使用了dictionary很好的改善了时间效率,对文件内容的处理使用了正则表达式和spilt分割,都很得当。功能的实现也很独立,对变量的命名总体上还是合适的,代码比较容易读懂。

  • 相关阅读:
    浅谈大学两年
    vue的基本操作
    JS执行环境,作用域链及非块状作用域
    关于AJAX异步请求
    第一个go程序和基本语法
    Golang
    11.二叉树
    10.排序
    9.算法之顺序、二分、hash查找
    高性能异步爬虫
  • 原文地址:https://www.cnblogs.com/wangzhuo/p/4047149.html
Copyright © 2011-2022 走看看