Home

Published

- 4 min read

Notes on MITx: 6.005.1x Software Construction in Java (Week 1)

img of Notes on MITx: 6.005.1x Software Construction in Java (Week 1)

MITx has introduced a new course named “Software Construction in Java”. Designed for advanced developers, the course will instruct on general principles of software development with the goal of creating good code that is:

  • Safe from bugs with correct behavior now and in the future
  • Easy to understand by other developers
  • Ready for change with architectural patterns that allow for modifications without extensive rewrites.

Over the next couple of weeks, I will complete this course and will publish my notes and thoughts on the material. You can also take the course at https://www.edx.org/course/software-construction-java-mitx-6-005-1x

Why am I taking this course?

I have worked with Java in the past. I do not like using the language. However, I was thoroughly impressed with the MIT Python course as it taught valuable concepts that are applicable to any programming language. I am taking this Java course in the hope of learning broader software development principles, with the use of Java as the language of instruction.

Lecture 1: Overview + Static Typing

In the first lecture, I largely skipped over the video segments as they appeared to be focused on introducing the concept of Java’s static typing, which I was already familiar with.

Lecture 2: Code Review

The second lecture takes a look at good coding practices.

Code Review

Lecture Notes: The objectives of a code review are twofold:

  1. Enhance the quality of the code
  2. Improve the programmer’s skills

Personal Note: In practice, many programming projects often skip the code review stage due to budget restrictions, time constraints, and personal emotions. It’s important to keep in mind that code reviews may hurt the feelings of other programmers who view their work as impeccable. This can lead to an increase in the production of poor-quality code, making the project difficult to maintain and unreliable. If it’s feasible for your project, conducting code reviews is highly recommended, and it’s important to have a well-defined plan in place so that the reviewed programmer can learn from their mistakes.

Style Standards

Lecture Notes: You can find good style guides at https://github.com/google/styleguide

Personal Note: ach programmer has their own preferred style for formatting and reading code. However, universities, including this one, do not provide a standard style guide, leading to a lack of enforcement. In large projects, this can become problematic with version control systems causing conflicts and difficulties. Style guides should not be manually enforced, as this would be time-consuming and create unnecessary work. Instead, they should be implemented as part of the build process. This prevents individual styles, eliminates merge issues, makes management easier, and is more psychologically beneficial for programmers, as the machine rather than another developer is the one rejecting the code. The best practice is to perform a check on each code commit prior to it being accepted into the repository, ensuring that all developers follow the same rules. (You can find more information on this topic by searching for “git hooks” and “java checkstyle”).

Code Smells

  • Adhere to the DRY (Don’t Repeat Yourself) principle
  • Provide comments where necessary
  • Implement a “fail fast” approach
  • Eliminate the use of “magic numbers”
  • Assign a single purpose to each variable
  • Utilize descriptive and meaningful names
  • Refrain from using global variables
  • Return results instead of printing them
  • Utilize white space for improved readability.

Personal Note: Although the lecture covers various methods to prevent typical mistakes made by beginners, these are just a few examples of various code smells. I personally use the IntelliJ IDE, which includes a feature called “Code Inspector.” It scans your code and provides suggestions to address a range of code smells. Ideally, good code should not contain any obvious code smells.

Homework

For the “Java Tutor” homework, you must use an Eclipse plugin. Unfortunately, this requires using Eclipse along with a custom-built plugin, which has resulted in frequent crashes of Eclipse and repeated questions from the plugin. The “Java Tutor” is not very strong, with questions that are mostly “fill in the blanks” and only have a single correct answer. Often, the titles of the related materials links give away the correct answer, and if you enter the wrong answer, you can simply click “Show Answer,” copy the solution, and move on without any consequences.