+ All Categories
Home > Documents > 6.S096 Lecture 7 { Intro to Projects -...

6.S096 Lecture 7 { Intro to Projects -...

Date post: 23-Mar-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
23
6.S096 Lecture 7 – Intro to Projects Unit testing, third-party libraries, code review Andre Kessler January 24, 2014 Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 1 / 13
Transcript
Page 1: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

6.S096 Lecture 7 – Intro to ProjectsUnit testing, third-party libraries, code review

Andre Kessler

January 24, 2014

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 1 / 13

Page 2: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Outline

1 Best Practices

2 Final Project

3 Structure of a Large Project

4 Unit Testing

5 Code Reviews

6 Wrap-up

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 2 / 13

Page 3: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Best Practices

Best Practices

If you haven’t already, look at our standards page.

General Important Points

Write in a clear and consistent coding style.

Code should be self-documenting.

Keep your headers clean.

Don’t expose your class’ private parts.

Use const wherever possible.

Write portable code.

Don’t leak memory!

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 3 / 13

Page 4: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Final Project

Final Project

Groups of 2-4 people; 3 recommended

Writing an interactive n-body gravity simulation- details to cometomorrow

External libraries: using OpenGL, gtest framework

Lots of room for hacking independently and getting cool additionalfeatures!

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 4 / 13

Page 5: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Final Project

Final Project

Groups of 2-4 people; 3 recommended

Writing an interactive n-body gravity simulation- details to cometomorrow

External libraries: using OpenGL, gtest framework

Lots of room for hacking independently and getting cool additionalfeatures!

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 4 / 13

Page 6: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Final Project

Final Project

Groups of 2-4 people; 3 recommended

Writing an interactive n-body gravity simulation- details to cometomorrow

External libraries: using OpenGL, gtest framework

Lots of room for hacking independently and getting cool additionalfeatures!

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 4 / 13

Page 7: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Final Project

Final Project

Groups of 2-4 people; 3 recommended

Writing an interactive n-body gravity simulation- details to cometomorrow

External libraries: using OpenGL, gtest framework

Lots of room for hacking independently and getting cool additionalfeatures!

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 4 / 13

Page 8: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Structure of a Large Project

How are projects different?

We’ll have lots of programmers, a large amount of code, manyupdates over time.

Need a revision control system. Examples: git, SVN, CVS, Mercurialare some free ones.

We said many updates over time: lots of potential for bugs. Codeshould be tested.

Need a unit testing framework. Examples: gtest, cppunit.

Still want to be able to build our code in one go (“make”).

May want to use an integrated development environment, or IDE.Examples: Microsoft Visual Studio, Eclipse, XCode.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 5 / 13

Page 9: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Structure of a Large Project

How are projects different?

We’ll have lots of programmers, a large amount of code, manyupdates over time.

Need a revision control system. Examples: git, SVN, CVS, Mercurialare some free ones.

We said many updates over time: lots of potential for bugs. Codeshould be tested.

Need a unit testing framework. Examples: gtest, cppunit.

Still want to be able to build our code in one go (“make”).

May want to use an integrated development environment, or IDE.Examples: Microsoft Visual Studio, Eclipse, XCode.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 5 / 13

Page 10: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Structure of a Large Project

How are projects different?

We’ll have lots of programmers, a large amount of code, manyupdates over time.

Need a revision control system. Examples: git, SVN, CVS, Mercurialare some free ones.

We said many updates over time: lots of potential for bugs. Codeshould be tested.

Need a unit testing framework. Examples: gtest, cppunit.

Still want to be able to build our code in one go (“make”).

May want to use an integrated development environment, or IDE.Examples: Microsoft Visual Studio, Eclipse, XCode.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 5 / 13

Page 11: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Structure of a Large Project

How are projects different?

We’ll have lots of programmers, a large amount of code, manyupdates over time.

Need a revision control system. Examples: git, SVN, CVS, Mercurialare some free ones.

We said many updates over time: lots of potential for bugs. Codeshould be tested.

Need a unit testing framework. Examples: gtest, cppunit.

Still want to be able to build our code in one go (“make”).

May want to use an integrated development environment, or IDE.Examples: Microsoft Visual Studio, Eclipse, XCode.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 5 / 13

Page 12: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Structure of a Large Project

How are projects different?

We’ll have lots of programmers, a large amount of code, manyupdates over time.

Need a revision control system. Examples: git, SVN, CVS, Mercurialare some free ones.

We said many updates over time: lots of potential for bugs. Codeshould be tested.

Need a unit testing framework. Examples: gtest, cppunit.

Still want to be able to build our code in one go (“make”).

May want to use an integrated development environment, or IDE.Examples: Microsoft Visual Studio, Eclipse, XCode.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 5 / 13

Page 13: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Structure of a Large Project

How are projects different?

We’ll have lots of programmers, a large amount of code, manyupdates over time.

Need a revision control system. Examples: git, SVN, CVS, Mercurialare some free ones.

We said many updates over time: lots of potential for bugs. Codeshould be tested.

Need a unit testing framework. Examples: gtest, cppunit.

Still want to be able to build our code in one go (“make”).

May want to use an integrated development environment, or IDE.Examples: Microsoft Visual Studio, Eclipse, XCode.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 5 / 13

Page 14: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Structure of a Large Project

Structure of a Large Project

|-- build ...

| ‘-- project |-- Makefile

|-- include |-- src

| ‘-- project | |-- gcd.cpp

|-- install | ‘-- rational.cpp

| |-- bin |-- test

| |-- include | |-- project-test.cpp

| |-- lib | ‘-- rationalTest.cpp

| ‘-- test ‘-- third_party

|-- make ‘-- gtest

| |-- all_head.mk

| |-- all_tail.mk

| |-- project.mk

| ‘-- project-test.mk

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 6 / 13

Page 15: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Structure of a Large Project

Separation of build and source

Have a clean build.

Since this is definitely under revision control, we want to keep ourdirectories free from clutter

Hence, all object (.o) files will go in the bin/ directory.

Third-party libraries live in their own directory third party/gtest

or whatever.

Headers for our project named “project” are deployed to the installdirectory.

Be able to build in one step

We have an upper-level Makefile so that we can still just make ourproject.

However, that’s been split up into more modular sub-makefiles(make/*.mk).

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 7 / 13

Page 16: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Unit Testing

Unit Testing and Test-Driven Development

Testing your source code, one function or “unit” ofcode at a time.

Test-driven development: write the tests first and then write codewhich makes the tests pass

Decide how you want the interface to work in general, write sometests, and go develop the specifics.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 8 / 13

Page 17: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Unit Testing

gtest: the Google C++ Testing Framework

Highly cross-platform, available from here.

Runs your full suite of tests (potentially each time you compile)

Tests are very portable and reusable across multiple architectures

Powerful, but very few dependencies.

Example from their primer:

ASSERT_EQ(x.size(), y.size()) << "unequal length";

for (int i = 0; i < x.size(); ++i) {

EXPECT_EQ(x[i], y[i]) << "differ at index " << i;

}

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 9 / 13

Page 18: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Code Reviews

Code Reviews

Why do code review?

Two pairs of eyes are better than one. Catch bugs early.

Forces someone to read it. If your code wasn’t readable, they’ll letyou know and help you improve it.

According to Steve McConnell in Code Complete:In a software-maintenance organization, 55 percent of one-linemaintenance changes were in error before code reviews wereintroduced. After reviews were introduced, only 2 percent of thechanges were in error. When all changes were considered, 95 percentwere correct the first time after reviews were introduced. Beforereviews were introduced, under 20 percent were correct the first time.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 10 / 13

Page 19: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Code Reviews

Code Reviews

Why do code review?

Two pairs of eyes are better than one. Catch bugs early.

Forces someone to read it. If your code wasn’t readable, they’ll letyou know and help you improve it.

According to Steve McConnell in Code Complete:In a software-maintenance organization, 55 percent of one-linemaintenance changes were in error before code reviews wereintroduced. After reviews were introduced, only 2 percent of thechanges were in error. When all changes were considered, 95 percentwere correct the first time after reviews were introduced. Beforereviews were introduced, under 20 percent were correct the first time.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 10 / 13

Page 20: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Code Reviews

Code Reviews

Why do code review?

Two pairs of eyes are better than one. Catch bugs early.

Forces someone to read it. If your code wasn’t readable, they’ll letyou know and help you improve it.

According to Steve McConnell in Code Complete:In a software-maintenance organization, 55 percent of one-linemaintenance changes were in error before code reviews wereintroduced. After reviews were introduced, only 2 percent of thechanges were in error. When all changes were considered, 95 percentwere correct the first time after reviews were introduced. Beforereviews were introduced, under 20 percent were correct the first time.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 10 / 13

Page 21: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Code Reviews

Tips for effective code review

Most important features for the code: correctness, maintainability,reliability, and performance. Consistent style is good, but those otherpoints come first!

Keep your review short and to the point.

Check the code for compliance with the class coding standards.

Take the time for a proper review, but don’t spend much more thanan hour; additionally, don’t review much more than about 200 lines ofcode at once.

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 11 / 13

Page 22: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Code Reviews

Examples

Let’s see some examples...

Pimpl idom...

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 12 / 13

Page 23: 6.S096 Lecture 7 { Intro to Projects - MITweb.mit.edu/6.s096/www/lecture/lecture07/lecture-07.pdf · 2014-01-24 · Headers for our project named \project" are deployed to the install

Wrap-up

Wrap-up & Monday

Third assignment due Saturday 1/25 at midnight.

Final project to be released Saturday 1/25 at 6pm.

Class on Mon. 1/24 is in 26-100 (!) at 2pm.

Concerns of large projects

Questions?

I’m available after class or on Piazza.

Office hours immediately after class today, 4-5pm.

Office hours 5-7pm Mon, Tues in 26-142

Andre Kessler 6.S096 Lecture 7 – Intro to Projects January 24, 2014 13 / 13


Recommended