• 软件工程UML第二次作业-代码的优化


    博客班级 <填写这份作业所在的博客班级的链接>
    作业要求 https://edu.cnblogs.com/campus/fzzcxy/2018SE2/homework/11199
    作业目标 <实现自身代码的优化和重构,学会Issue的提出>
    作业源代码 https://gitee.com/huang-cy/software-engineering-uml
    学号 <211814113>

    1. 问题分析

    1.1 对别人的第一次作业提出Issue
    1.2 重构自己第一次作业
    1.3 在Gitee上,对别人的代码提出Pull Requests(附加)

    2. Issue的提出

    2.1 First

    • 码云地址:https://gitee.com/xu-qianlong/personal
    • 改进建议:
      • 分数计算的占比有一些问题。编程题最高分题目调为95,在计算的时候也应该进行调整,将100 -> 95。同理附加题 100 -> 90。
      • 代码整体观看体感感不佳,将grap进一步模块化,可读性会强很多。
    • Issue截图:

    2.2 Second

    • 码云地址:https://gitee.com/daydreamer1/personal
    • 提出建议:将代码相同的一块,定义成变量,增加可读性和简洁性。 比如这样定义 eg Element QuestionType = es.get(i).child(1).child(0).toString()
    • Issue截图:

    2.3Third

    2.4 Fourth

    2.5 Fifth

    3.重构代码

    3.1别人提出的Issue

    • 对代码进行注释
    • 使用选择器代替子元素查找

    3.2 自己的优化

    • 对 properties 问价加载的代码进行优化

    3.3 代码优化

    • properties 文件的加载。

    • Properties con = new Properties();
              con.load(new FileInputStream("UML/src/first/total.properties"));
              Enumeration fileName = con.propertyNames();
              //加载配置 properties 文件
      
              beforeTotal = Integer.parseInt(con.getProperty("before"));      //读取课前自测总分
              baseTotal = Integer.parseInt(con.getProperty("base"));          //读取课堂完成总分
              testTotal = Integer.parseInt(con.getProperty("test"));          //读取课堂小测总分
              programTotal = Integer.parseInt(con.getProperty("program"));    //读取编程题总分
              addTotal = Integer.parseInt(con.getProperty("add"));            //读取附加题总分
              System.out.println(beforeTotal);
      
    • 子元素查找换成选择器查找 - > 优化例子。

    • Elements allElement = allDocument.getElementsByClass("interaction-row");
              Elements smallElement = smallDocument.getElementsByClass("interaction-row");
              int sumScore = 0;
              for(int i = 0;i < allElement.size();i++){
                  if(allElement.get(i).toString().contains("课前自测")){
                      System.out.println(allElement.get(i).toString());
                      System.out.println(allElement.get(i).toString());
                      Elements span = allElement.get(i).getElementsByTag("span");
                      for(int j = 0;j < span.size();j++){
                          if(span.get(j).toString().contains("经验")){
                              Scanner sc = new Scanner(span.get(j).text());
                              sumScore += sc.nextInt();
                              break;
                          }
                      }
                  }
                }
      

    4. 小结

    • 对代码要实现的功能尽量模块化,减少 main() 函数的代码,方便维护。
    • 使用相对路径代替绝对路径,增加代码可移植性
    • 子元素查找效率太低,尽量不使用。
  • 相关阅读:
    win7 安装 memcached
    Nginx执行php显示no input file specified的处理方法
    Nginx配置SSI
    Windows Services
    如何安装mysql服务
    windows下nginx+php简单配置
    Thread Safe(线程安全)和None Thread Safe(NTS,非线程安全)之分
    php常用方法总结
    弹出框以及提示插件lghdialog.js的使用
    webservice的简单示例的实现步骤
  • 原文地址:https://www.cnblogs.com/SakuraHCY/p/13701813.html
Copyright © 2020-2023  润新知