changed 5 years ago
Linked with GitHub

Week 2

SE: Intro

  • SE: application of a systematic, disciplined, quantifiable approach to the development, operation, and maintenance of software.
  • Compare Software Engineering with Civil Engineering in terms of how work products in CE (i.e. buildings) differ from those of SE (i.e. software).
Buildings Software
Visible, tangible Invisible, intangible
Wears out over time Does not wear out
Change is limited by physical restrictions (e.g. difficult to remove a floor from a high rise building) Change is not limited by such restrictions. Just change the code and recompile.
Creating an exact copy of a building is impossible. Creating a near copy is almost as costly as creating the original. Any number of exact copies can be made with near zero cost.
Difficult to move. Easily delivered from one place to another.
Many low-skilled workers following tried-and-tested procedures. No low-skilled workers involved. Workers have more freedom to follow their own procedures.
Easier to assure quality (just follow accepted procedure). Not easy to assure quality.
Majority of the work force has to be on location. Can be built by people who are not even in the same country.
Raw materials are costly, costly equipment required. Almost free raw materials and relatively cheap equipment.
Once construction is started, it is hard to do drastic changes to the design. Building process is very flexible. Drastic design changes can be done, although costly
A lot of manual and menial labor involved. Most work involves highly-skilled labor.
Generally robust. E.g. removing a single brick is unlikely to destroy a building. More fragile than buildings. A single misplaced semicolon can render the whole system useless.
  • Comment on this statement:
    Building software is cheaper and easier than building bridges (all we need is a PC!).
Depends on the size of the software. 
Manpower required for software is very costly. 
On the other hand, we can create a very valuable software 
(e.g. an iPhone application that can make million dollars in a month) 
with a just a PC and a few days of work!
  • Justify this statement:
    Coding is still a ‘design’ activity, not a ‘manufacturing’ activity. You may use a comparison (or an analogy) of Software engineering versus Civil Engineering to argue this point.
Arguments to support this statement:

1. If coding is a manufacturing activity, we should be able to do it using 
robotic machines (just like in the car industry) or low-skilled laborers 
(like in the construction industry).

2. If coding is a manufacturing activity, we wouldn’t be changing it so much 
after we code software. But if the code is in fact a ‘design’, yes, we would 
fiddle with it until we get it right.

3. Manufacturing is the process of building a finished product based on the 
design. Code is the design. Manufacturing is what is done by the compiler 
(fully automated).

However, the type of ‘design’ that occurs during coding is at a much lower level
than the ‘design’ that occurs before coding.
  • List some (at least three each) pros and cons of Software Engineering compared to other traditional Engineering careers.
pros:
1. pay well
2. work environment is clean and well lighted
3. easy to find a job

cons:
1. stressful
2. must stay on the cutting edge of technology in order to keep skills relevant 
and up to date
3. no break on weekends :(
  • Which one of these is not included in Brook’s list of ‘Woes of the Craft’?
    c
 a. Need for perfection when developing software
 b. Requiring some amount of tedious, painstaking labor
 c. Ease of copying and transporting software makes it difficult to keep track 
 of versions
 d. High dependence on others
 e. Seemingly never ending effort required for testing and debugging software
 f. Fast moving industry making our work obsolete quickly

Java: Intro

  • Java is directly related to both C and C++. Java inherits its syntax from C. Its object model is adapted from C++.
  • Java is both compiled (generates machine code from source code before executing the program) and interpreted (the interpreter executes the program directly, one statement at a time).
  • Instead of translating programs directly into machine language, the Java compiler generates byte code. Byte code is portable, so it is possible to compile a Java program on one machine, transfer the byte code to another machine, and run the byte code on the other machine. That’s why Java is considered a platform independent technology, aka WORA (Write Once Run Anywhere). The interpreter that runs byte code is called a “Java Virtual Machine” (JVM).
  • Java technology is both a programming language and a platform.
  • 4 platforms of the Java programming language:

Java Platform, Standard Edition (Java SE): Contains the core functionality of the Java programming language.
Java Platform, Enterprise Edition (Java EE): For developing and running large-scale enterprise applications. Built on top of Java SE.
Java Platform, Micro Edition (Java ME): For Java programming language applications meant for small devices, like mobile phones. A subset of Java SE.
JavaFX: For creating applications with graphical user interfaces. Can work with the other three above.

  • HelloWorld in Java:
public class HelloWorld { public static void main(String[] args) { // generate some simple output System.out.println("Hello, World!"); } }

public is an access modifier that indicates the method is accessible from outside this class. Similarly, private access modifier indicates that a method/attribute is not accessible outside the class.
static indicates this method is defined as a class-level member.
void indicates that the method does not return anything.

  • Java use the term method instead of function. In particular, Java doesn’t have stand-alone functions. Every method should belong to a class. The main method will not work unless it is inside the HelloWorld class.
  • In most cases (i.e., there are exceptions), the name of the class has to match the name of the file it is in, so this class has to be in a file named HelloWorld.java.
  • The library files needed by the HelloWorld code is available by default without having to "include" them explicitly.
  • There is no need to return 0 at the end of the main method to indicate the execution was successful. It is considered as a successful execution unless an error is signalled specifically.

Java: Data Types

  • byte (8 bits): an integer in the range -128 to 127 (inclusive).
  • short (16 bits): an integer in the range -32,768 to 32,767 (inclusive).
  • int (32 bits): an integer in the range -2^31 to 2^31-1.
  • long (64 bits): An integer in the range -2^63 to 2^63-1.
  • float (32 bits): a single-precision 32-bit IEEE 754 floating point. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead.
  • double (64 bits): a double-precision 64-bit IEEE 754 floating point. For decimal values, this data type is generally the default choice. This data type should never be used for precise values, such as currency.
  • boolean: has only two possible values: true and false.
  • char (16 bits): The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
  • Use the keyword final to indicate that the variable value, once assigned, should not be allowed to change later i.e., act like a ‘constant’. By convention, names for constants are all uppercase, with the underscore character ( _) between words.
final double CM_PER_INCH = 2.54;

Java: Control Flow

  • Enhanced for loops:
for (int i = 0; i < values.length; i++) { int value = values[i]; System.out.println(value); }

We could rewrite the loop like this:

for (int value : values) { System.out.println(value); }

RCS: Init, Commit

  • Revision control: the process of managing multiple versions of a piece of information.
  • Revision control software will track the history and evolution of your project, which makes it easier for you to collaborate when you're working with other people.
  • It can help you to recover from mistakes.
  • It will help you to work simultaneously on, and manage the drift between, multiple versions of your project.

RCS: Revision Control Software are the software tools that automate the process of Revision Control i.e. managing revisions of software artifacts.

Revision: A revision (some seem to use it interchangeably with version while others seem to distinguish the two here, let us treat them as the same, for simplicity) is a state of a piece of information at a specific time that is a result of some changes to it e.g., if you modify the code and save the file, you have a new revision (or a version) of that file.

Repository (repo for short): The database of the history of a directory being tracked by an RCS software (e.g. Git).

  • The repository is the database where the meta-data about the revision history are stored.
  • Suppose you want to apply revision control on files in a directory called ProjectFoo. In that case you need to set up a repo (short for repository) in ProjectFoo directory, which is referred to as the working directory of the repo. For example, Git uses a hidden folder named .git inside the working directory.
  • You can have multiple repos in your computer, each repo revision-controlling files of a different working directly, for examples, files of different projects.
  • In a repo, we can specify which files to track and which files to ignore. Some files such as temporary log files created during the build/test process should not be revision-controlled.
  • Committing saves a snapshot of the current state of the tracked files in the revision control history. Such a snapshot is also called a commit (i.e. the noun).
  • When ready to commit, we first stage the specific changes we want to commit. This intermediate step allows us to commit only some changes while saving other changes for a later commit.
  • Each commit in a repo is a recorded point in the history of the project that is uniquely identified by an auto-generated hash e.g. a16043703f28e5b3dab95915f5c5e5bf4fdc5fc1.
  • We can tag a specific commit with a more easily identifiable name e.g. v1.0.2

Working directory: The directory the repo is based in is called the working directory.

Commit: Saving the current state of the working folder into the Git revision history.

Stage: Instructing Git to prepare a file for committing.

RCS: Fork, Clone

  • Remote repositories are copies of a repo that are hosted on remote computers.
  • You can clone a remote repo onto your computer which will create a copy of a remote repo on your computer, including the version history as the remote repo.
  • You can push new commits in your clone to the remote repo which will copy the new commits onto the remote repo. Note that pushing to a remote repo requires you to have write-access to it.
  • You can pull from the remote repos to receive new commits in the remote repo. Pulling is used to sync your local repo with latest changes to the remote repo.
  • A fork is a remote copy of a remote repo. If there is a remote repo that you want to push to but you do not have write access to it, you can fork the remote repo, which gives you your own remote repo that you can push to.
  • A pull request is mechanism for contributing code to a remote repo. It is a formal request sent to the maintainers of the repo asking them to pull your new code to their repo.

IDEs: Basic Features

  • Professional software engineers often write code using Integrated Development Environments (IDEs). IDEs support most development-related work within the same tool (hence, the term integrated).
  • An IDE generally consists of:
    • A source code editor that includes features such as syntax coloring, auto-completion, easy code navigation, error highlighting, and code-snippet generation.
    • A compiler and/or an interpreter (together with other build automation support) that facilitates the compilation/linking/running/deployment of a program.
    • A debugger that allows the developer to execute the program one step at a time to observe the run-time behavior in order to locate bugs.
    • Other tools that aid various aspects of coding e.g. support for automated testing, drag-and-drop construction of UI components, version management support, simulation of the target runtime platform, and modeling support.
  • Which of these are features available in IDEs?
    all
 a. Compiling
 b. Syntax error highlighting
 c. Debugging
 d. Code navigation e.g., to navigate from a method call to the method 
 implementation
 e. Simulation e.g., run a mobile app in a simulator
 f. Code analysis e.g. to find unreachable code
 g. Reverse engineering design/documentation e.g. generate diagrams from code
 h. Visual programming e.g. Write programs using ‘drag and drop’ actions 
 instead of typing code
 i. Syntax assistance e.g., show hints as you type
 j. Code generation e.g., to generate the code required by simply specifying 
 which component/structure you want to implement
 k. Extension i.e., ability add more functionality to the IDE using plugins

Code Quality: Coding Standards

  • One essential way to improve code quality is to follow a consistent style. That is why software engineers follow a strict coding standard (aka style guide).
  • The aim of a coding standard is to make the entire code base look like it was written by one person.
Select a repo