zoukankan      html  css  js  c++  java
  • 软件工程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() 函数的代码,方便维护。
    • 使用相对路径代替绝对路径,增加代码可移植性
    • 子元素查找效率太低,尽量不使用。
  • 相关阅读:
    删除MFC单文档默认菜单栏的两种方法
    mfc更改背景色
    (转)VC单选按钮控件(Radio Button)用法
    转:MFC 基于对话的程序界面显示完全后立即执行一个函数
    转:vc6以上如何给MFC对话框添加OnInitDialog函数
    常用网址
    2010年春季学期C语言程序设计答疑安排
    rdlc导出Excel
    SQL Server查询表的结构
    C# WinForm开发系列 WebBrowser
  • 原文地址:https://www.cnblogs.com/SakuraHCY/p/13701813.html
Copyright © 2011-2022 走看看