• Complain

it-ebooks - Software Construction Lecture Notes (MIT 6.005)

Here you can read online it-ebooks - Software Construction Lecture Notes (MIT 6.005) full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2017, publisher: iBooker it-ebooks, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

No cover
  • Book:
    Software Construction Lecture Notes (MIT 6.005)
  • Author:
  • Publisher:
    iBooker it-ebooks
  • Genre:
  • Year:
    2017
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Software Construction Lecture Notes (MIT 6.005): summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Software Construction Lecture Notes (MIT 6.005)" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

it-ebooks: author's other books


Who wrote Software Construction Lecture Notes (MIT 6.005)? Find out the surname, the name of the author of the book and a list of all author's works by series.

Software Construction Lecture Notes (MIT 6.005) — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Software Construction Lecture Notes (MIT 6.005)" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Software Construction Lecture Notes (MIT 6.005)

From: 6.005: Software Construction

Reading 1: Static Checking
Objectives for Todays Class

Todays class has two topics:

  • static typing
  • the big three properties of good software
Hailstone Sequence

Many readings include optional videos from the MITx version of 6.005.

Play MITx video

As a running example, were going to explore the hailstone sequence, which is defined as follows.Starting with a number n, the next number in the sequence is n/2 if n is even, or 3n+1 if n is odd.The sequence ends when it reaches 1.Here are some examples:

2, 13, 10, 5, 16, 8, 4, 2, 14, 2, 12n, 2n-1 , ... , 4, 2, 15, 16, 8, 4, 2, 17, 22, 11, 34, 17, 52, 26, 13, 40, ...? (where does this stop?)

Because of the odd-number rule, the sequence may bounce up and down before decreasing to 1.Its conjectured that all hailstones eventually fall to the ground i.e., the hailstone sequence reaches 1 for all starting n but thats still an open question.Why is it called a hailstone sequence?Because hailstones form in clouds by bouncing up and down, until they eventually build enough weight to fall to earth.

Computing Hailstones

Heres some code for computing and printing the hailstone sequence for some starting n.Well write Java and Python side by side for comparison:

// Java int n = ; while (n != ) { System.out.println(n); if (n % == ) { n = n / ; } else { n = * n + ; }}System.out.println(n);# Python n = while n != : print(n) if n % == : n = n / else : n = * n + print(n)

A few things are worth noting here:

  • The basic semantics of expressions and statements in Java are very similar to Python: while and if behave the same, for example.
  • Java requires semicolons at the ends of statements. The extra punctuation can be a pain, but it also gives you more freedom in how you organize your code you can split a statement into multiple lines for more readability.
  • Java requires parentheses around the conditions of the if and while.
  • Java requires curly braces around blocks, instead of indentation.You should always indent the block, even though Java wont pay any attention to your extra spaces. Programming is a form of communication, and youre communicating not only to the compiler, but to human beings. Humans need that indentation. Well come back to this later.
Types
Play MITx video

The most important semantic difference between the Python and Java code above is the declaration of the variable n, which specifies its type: int.

A type is a set of values, along with operations that can be performed on those values.

Java has several primitive types, among them:

  • int (for integers like 5 and -200, but limited to the range 231, or roughly 2 billion)
  • long (for larger integers up to 263)
  • boolean (for true or false)
  • double (for floating-point numbers, which represent a subset of the real numbers)
  • char (for single characters like 'A' and '$')

Java also has object types, for example:

  • String represents a sequence of characters, like a Python string.
  • BigInteger represents an integer of arbitrary size, so it acts like a Python integer.

By Java convention, primitive types are lowercase, while object types start with a capital letter.

Operations are functions that take inputs and produce outputs (and sometimes change the values themselves). The syntax for operations varies, but we still think of them as functions no matter how theyre written. Here are three different syntaxes for an operation in Python or Java:

  • As an infix, prefix, or postfix operator. For example, a + b invokes the operation + : int int int.
  • As a method of an object. For example, bigint1.add(bigint2) calls the operation add: BigInteger BigInteger BigInteger.
  • As a function. For example, Math.sin(theta) calls the operation sin: double double. Here, Math is not an object. Its the class that contains the sin function.

Contrast Javas str.length() with Pythons len(str). Its the same operation in both languages a function that takes a string and returns its length but it just uses different syntax.

Some operations are overloaded in the sense that the same operation name is used for different types. The arithmetic operators +, -, *, / are heavily overloaded for the numeric primitive types in Java. Methods can also be overloaded. Most programming languages have some degree of overloading.

Static Typing
Play MITx video

Java is a statically-typed language. The types of all variables are known at compile time (before the program runs), and the compiler can therefore deduce the types of all expressions as well. If a and b are declared as ints, then the compiler concludes that a+b is also an int. The Eclipse environment does this while youre writing the code, in fact, so you find out about many errors while youre still typing.

In dynamically-typed languages like Python, this kind of checking is deferred until runtime (while the program is running).

Static typing is a particular kind of static checking, which means checking for bugs at compile time. Bugs are the bane of programming. Many of the ideas in this course are aimed at eliminating bugs from your code, and static checking is the first idea that weve seen for this. Static typing prevents a large class of bugs from infecting your program: to be precise, bugs caused by applying an operation to the wrong types of arguments. If you write a broken line of code like:

"5" * "6"

that tries to multiply two strings, then static typing will catch this error while youre still programming, rather than waiting until the line is reached during execution.

Static Checking, Dynamic Checking, No Checking

Its useful to think about three kinds of automatic checking that a language can provide:

  • Static checking: the bug is found automatically before the program even runs.
  • Dynamic checking: the bug is found automatically when the code is executed.
  • No checking: the language doesnt help you find the error at all. You have to watch for it yourself, or end up with wrong answers.

Needless to say, catching a bug statically is better than catching it dynamically, and catching it dynamically is better than not catching it at all.

Here are some rules of thumb for what errors you can expect to be caught at each of these times.

Static checking can catch:

  • syntax errors, like extra punctuation or spurious words. Even dynamically-typed languages like Python do this kind of static checking. If you have an indentation error in your Python program, youll find out before the program starts running.
  • wrong names, like Math.sine(2). (The right name is sin.)
  • wrong number of arguments, like
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Software Construction Lecture Notes (MIT 6.005)»

Look at similar books to Software Construction Lecture Notes (MIT 6.005). We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Software Construction Lecture Notes (MIT 6.005)»

Discussion, reviews of the book Software Construction Lecture Notes (MIT 6.005) and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.