美文网首页
💻 6.005.1x - Week 1

💻 6.005.1x - Week 1

作者: 秋衣队长 | 来源:发表于2019-01-03 10:41 被阅读0次

目录

  • I. Intro —— 写java的初体验,解了problem set 0
  • II. Testing —— 不同test的区别
  • III. Specification —— 不同spec的区别,以及如何写好
  • IIII. Snapshot Diagram —— 不同符号的含义

I. Intro

1. Coding Descipline
  • Safe from bugs
  • Easy to understand
  • Ready for change
2. Java语法memo
  • 继承

以官网doc的例子。Mountain / Road / Tandem Bike三种,都是Bicycle,但是增加了不同的feature。因而,OOP中,允许继承。此时,Bicycle是其他三者的superclass;Mountain / Road / Tandem Bike则是subclasses。

Bicyle的继承
Syntax用了```extends``,继承写起来,大概长这样👇:
public class MountainBike extends Bicycle {
        
    // the MountainBike subclass has
    // one field
    public int seatHeight;

    // the MountainBike subclass has
    // one constructor
    public MountainBike(int startHeight, int startCadence,
                        int startSpeed, int startGear) {
        super(startCadence, startSpeed, startGear);
        seatHeight = startHeight;
    }   
        
    // the MountainBike subclass has
    // one method
    public void setHeight(int newValue) {
        seatHeight = newValue;
    }   

}
  • if语句: "?"
if ( a > b ) {
    max = a;
} else {
    max = b
}

简写成

max = (a > b) ? a: b;
3. Problem set 0心得
  1. 做problem set 0的时候,放弃了最后三题,看不懂atan的数学问题。希望后面的problem set不要出现一样的...🤦‍♂️。
  2. 有一个之前完全没有注意的,就是magic number。忽然就声明了一个数字,其实违反了easy to understand。合适的方法是,声明一个变量,然后comment它的含义。有时候需要final它。
  3. unit test的重要性,下assert,做好每个unit的debug。
  4. floatdouble区别在于32bit和64bit,所以用 double更安全。
  5. 前面那个javadoc,也从没写过,好像挺方便的。写javadoc,有一个关键的准则,是:NEVER talk about local variables of the method or private fields.
    NEVER talk about local variables of the method or private fields.

模板大概是:

/**
brief description, what is this method for?
@param parameterName What is the parameter for?
@return value What is the value meaning?
**/

II. Testing

1. Residual defect rates
  • 1 - 10 defects/kloc: Typical industry software.
  • 0.1 - 1 defects/kloc: High-quality validation. The Java libraries might achieve this level of correctness.
  • 0.01 - 0.1 defects/kloc: The very best, safety-critical validation. NASA and aerospace companies can achieve this level.

kloc : 1000 lines of source code.

2. Testing
  • Test-first programming. Write tests before you write code.
  • Partitioning and boundaries for choosing test cases systematically.
  • White box testing and statement coverage for filling out a test suite.
  • Unit-testing each module in isolation as much as possible.
  • Automated regression testing to keep bugs from coming back.
2.1 Unit Tests

Testing modules in isolation leads to much easier debugging.

2.2 Regression Testing

Regression意味着,在改bug-A或者增加feature-B的时候,又多了新的bug-B。在test-first debugging中,把之前的bug-A的test case增加到test suite中,这样写完B后,可以确定A不会再发生。

3. 心得

之前对unit test没啥概念,意味只要分模块写code就好。但是,每个模块的debugging和test case,要考虑到模块中,也就是test-first programming的重要性。Write tests before you write code.


III. Specification

1. underdetermined specs & nondeterminism 定义
  • deterministic spec: 1 input → 1 output
  • under-deterministic spec: 1 input → >1 outputs
  • under-deterministic spec can have determined implementation
2. declarative vs. operational specs 定义
  • operational specs → spec中写了method运行的步骤
  • declarative specs (better) → spec不提供内部的步骤,只提供outcome的properties
3. 好的specs长什么样?
  • better spec👍 → weaker precondition🔽 & stronger postcondition🔼
4. 如何写好spec?
  • brief & clear & structured
  • coherent inputs
  • no global variables & no printing (instead of returning)
  • no making internal helper methods public (helper method only for local use)

IIII. Snapshot Diagram

  1. → variable
  2. ⇒ final
  3. → ⚪
  4. → ⭕(double circles)
  5. List


    Lists
  6. Set


    Set
  7. Map


    Map

6.005.1x,自学的第一个礼拜。💻🔨
整个版面乱成一锅粥。或许应该再开一个post,来整理知识点吧。🤦‍♂️

Ronn Liu 🙋‍♂️
2019/01/01 - 2019/01/06 📌

相关文章

网友评论

      本文标题:💻 6.005.1x - Week 1

      本文链接:https://www.haomeiwen.com/subject/qfnxrqtx.html