Recently, I am learning the MIT 6.005 – Software Constrction, preparing for my coming job. I will note some important knowledge here.
Belows are the main ideas related to the goal of this course:
- Safe from bugs
- Easy to understand
- Ready for change
To acheive these three things, I summarized some main points after finishing the first reading lesson.
Static Checking
Two different checking strateges:
- Static checking: Checking at compile time.
- Dynamic checing: checking at execute time.
Here are some rules of thumb for what errors you can expect to be caught at each of these times.
Static checking
- Syntax errors
- Misspelled names
- Wrong number of arguments
- Wrong argument types
- Wrong return types
Dynamic checking
- Specific illigal argument values. For example, the expression x/y is erroneous when y is zero.
- Illigal conversions
- Out of range indices
- Calling a method on a bad object reference (None in Python, or undefined or null in TypeScript)
Mutating values
Good programmers try to avoid things that change, because they may change unexpectedly.
It’s good practice to use const
as many as possible. Sometimes it helps moving the error checing from execute time to compile time.
Note:
ForArrays
, pushing elements to the arrays doesn’t change the address of it, so can addconst
to the array.
Documenting assumptions
Writing the type of a variable down documents an assumption about it.
Programs have to be written with two goals in mind:
- Communicating with the computer.
- Communicating with other people.
Tesing
Software engineering is not hacking. The good way is to write a little bit at a time, testing as you go. In a future class, we’ll talk about test-first programming.