On this page:
Introduction to Programming (Spring 2011)
1 Introduction
2 Meetings
3 Resources
4 Help
5 How to Solve Your Problems
5.1 Low-level
5.2 Domain-specific
5.3 Ignoring the Design Process
5.3.1 Information
5.3.2 Data
5.3.3 Data Examples
5.3.4 Function Prototype and Contract
5.3.5 Function Purpose
5.3.6 Examples
5.3.7 Template
5.3.8 Coding
5.3.9 Testing
5.3.10 Summary
5.4 High-level
6 Assignments and Turn In Policy
6.1 Turn-in Content
6.2 Turn-in Deadline
6.3 Turn-in Method
6.4 Grading
7 Exams
8 Extra Credit
9 Your Final Grade
10 Other Policies

Introduction to Programming (Spring 2011)

This class is taught by Jay McCarthy.

We meet in TMCB 1170 at 10am-11:40am MWF.

Jay McCarthy’s office hours are 1-4pm MTWRF in 3328 TMCB. Although, feel free to call him on the phone between 8am and 10pm (excluding 5pm to 7pm) on Monday through Saturday at: the phone number behind this link.

There is a mailing list hosted at Google Groups. Use it to ask non-revealing questions and receive answers, as well as general course announcements. If you are nervous about asking questions, you can use anonymous email.

1 Introduction

This course is an introduction to programming. We assume no previous experience with programming.

Nota Bene. This edition of this course is experimental. You’ll get lectures and exercises that have never been seen before. In particular, it is incomplete, but I have an idea of where it will go. If you like knowing exactly where the course is going, sorry. If I make stupid mistakes and we need to do things again, you suffer, etc, I’ll remember that it’s my fault when it comes time to grade. I’ll have surveys every few weeks so that you can help me stay on task and not be too bad.

2 Meetings

The notes column contains links to the notes that I have prepared for you. The plan column contains links to the notes that I have prepared for myself. It is not really meant for your consumption (i.e. it is ugly and acronym heavy), but why bother hiding it from you?

 

 

 

Date

 

Topic

 

Notes

 

Plan

 

Code

 

Audio

 

Screen

 

1

 

4/27

 

Introduction to Programming and Java

 

obj

 

plan

 

code

 

 

 

2

 

4/29

 

Expressions and Functions

 

obj

 

plan

 

code

 

 

 

3

 

5/2

 

Function Composition and Conditionals

 

obj

 

plan

 

code

 

 

 

4

 

5/4

 

Conditionals and Strings

 

obj

 

plan

 

code

 

 

 

5

 

5/6

 

Objects

 

obj

 

plan

 

code

 

 

 

6

 

5/9

 

Objects and Nested Objects

 

obj

 

plan

 

code

 

 

 

7

 

5/11

 

Methods

 

obj

 

plan

 

code

 

 

 

8

 

5/13

 

Mixed Data

 

obj

 

plan

 

code

 

 

 

9

 

5/16

 

Introduction to Lists

 

obj

 

plan

 

code

 

 

 

10

 

5/18

 

More on Lists

 

obj

 

plan

 

code

 

 

 

11

 

5/20

 

Producing Lists; Sorting

 

obj

 

plan

 

code

 

 

 

12

 

5/23

 

Lists of Objects

 

obj

 

plan

 

code

 

 

 

13

 

5/25

 

More Lists of Objects

 

obj

 

plan

 

code

 

 

 

14

 

5/27

 

Trees

 

obj

 

plan

 

code

 

 

 

15

 

6/1

 

Trees and Hierarchy

 

obj

 

plan

 

code

 

 

 

16

 

6/3

 

More on Hierarchies

 

obj

 

plan

 

code

 

 

 

17

 

6/6*

 

Introduction to Mutation

 

obj

 

plan

 

code

 

 

 

18

 

6/8*

 

Program Design with Mutation

 

obj

 

plan

 

code

 

 

 

19

 

6/10*

 

Changing Structure Contents

 

obj

 

plan

 

code

 

 

 

20

 

6/13*

 

More on Mutation with Structures

 

obj

 

plan

 

code

 

 

This schedule may change.

Jay will be absent on days marked with a *. Instead, one of the TAs will teach.

3 Resources

This courses use no textbook. I will be provide links to helpful resources online as appropriate. Many of the Java-specific links will be to parts of Learning the Java Language, a free textbook (with a print edition) from the makers of Java.

If you want to use the CS Department Labs, look at this page. If you are going to use your own computer, you’ll need Java SE Development Kit (Mac users can get it from Apple.)

The other thing you’ll need is a text editor, I recommend Emacs on the lab machines. You can use whatever you want on your own computer. (On Windows, I’d recommend Notepad++.) (On Mac, I’d recommend just using TextWrangler or AquaMacs.)

Once you have these two things, when you want to run some Java code, you need to run javac and java from the command-line. Suppose that "myclass.java" contains:

class MyClass {

    public static void main(String[] args) {

        System.out.println("Hello World!");

    }

}

Then you can compile this with:
  javac myclass.java
(Notice that the name after javac is the same as the file.) And then run it with:
  java MyClass
(Notice that the name after java is the same as the thing in my file after class.)

4 Help

My job is to help you. Please ask for help. (But read section this first.)

Sign up for the Google Group, I may have already answered questions about the assignment.

You can find TAs in 3325 TMCB; however make sure you also consult How to Solve Your Problems, the mailing list, or the professor.

5 How to Solve Your Problems

When you are programming, whether you are a beginner or an expert, you will face difficulties. A programmer’s competance comes from how they deal with these problems. I’d like to help you be a good programmer, so I will push you very hard to solve these problems in a constructive way.

The first step is to understand what kind of problem you are having. For the purposes of this discussion, let’s say there are only four kinds of problems.

5.1 Low-level

The first kind are low-level challenges. For example, the compiler gives an error message you don’t understand; you don’t know the name of the function that computes the square root; etc. In many cases, as your technical programming skills increase you will avoid these problems because you won’t make such errors or you will have intuitively memorized the various functions you care about. Even so, even expert programmers are consistently faced with such challenges.

Some programming courses try to force you to deal with these problems by having explicit memorization assignments, tests, etc. I think this is a waste of time and insulting to you. Instead, I’d like to teach you how most real programmers deal with these problems and allow you to do that. (This is why, for example, there are no closed-resource tests in this class, because real programmers don’t face such constraints.)

When faced with such a problem, a real programmer uses Google to find the answer. They may specialize the search to a programming FAQ site like StackOverflow or the reference for the language they are using. If you want to be a productive programmer, your number two goal should be to be familiar with these resource.

Therefore, I have instructed the TAs to never answer such technical questions for you. Instead, I’ve asked them to help you search for the answer in the appropriate places.

Whenever you find such an answer, please send a email about it to the mailing list. This will count as extra credit.

5.2 Domain-specific

You cannot program in a vacuum. Programs are always about some domain. For example, a simulation of the solar system lives in the domain of physics; an animation lives in the domain of geometry and optics; etc.

Many "programming" problems are actually misunderstanding of the domain. If you don’t know what the area of a circle is, then obviously you can’t write a program to compute it. Many times it is challenging to realize that you are lacking domain knowledge.

In practice, many real programmers are not domain experts in the area they program in. Instead, they interface with their customer (the domain expert) for these problems. Most advice about designing software that people want (i.e. that solves their problems) amounts to "Ask them."

I have tried very hard to not use challenging or unfamiliar domains in this course. Whenever there is doubt, I’ve tried to link to an informative Wikipedia discussion. If I have read you wrong, please let me know so we can change the assignment. Even though you can’t do programming without domains, I believe it is wrong for this to be a class about domains, rather than one that uses domains.

In essence, you should never need to ask a TA about a domain question, because they are all already answered.

5.3 Ignoring the Design Process

The hardest question in life is "What do I do next?" Programming is no different. You start with an empty screen and you have to write down something. What should it be?

This course emphasizes a particular design process that works very well for modular software. It can feel tedious to work through this process and you spend less time than you’d expect typing out code. Yet, experience has shown that programmers who follow such a process solve their problems faster and with less help. Learning to do this will mean that you are self-sufficient programmer.

We’ll talk about this more in class but roughly the process is this:

5.3.1 Information

Look at the problem and identify what information the human beings are providing and what information constitutes a solution. Write this down. For example, the pertinent information for an area finding program is probably the cirle’s radius in meters and its numeric area in meters-squared.

5.3.2 Data

Computers do not process information. They deal only with well-defined kinds of data. You need to decide how to represent the pertinent information as data. For example, you may choose to represent the radius and area as doubles. Write these down as comments or part of the program.

5.3.3 Data Examples

Write down in the programming language syntax examples of data. In some cases, like with numbers, this is as simple as 7.5 or 64.5. In other cases, like with objects, it is more complicated.

5.3.4 Function Prototype and Contract

Write down in the programming language syntax the header for the function you are writing as a transformation from the input data to the answer data. Write a contract comment above it. For example,

// areaOfDisk : double -> double

static double areaOfDisk( double r )

5.3.5 Function Purpose

Rephrase the problem description in terms of the input parameters and write it as a comment above your prototype. For example,

// areaOfDisk : double -> double

// Computes the area of a disk where the radius is 'r'

static double areaOfDisk( double r )

5.3.6 Examples

Write down examples of correct behavior of the program. This can be comments or real code. For example,

// given: 4.0 expect: 50.24

// given: 7.0 expect: 153.86

You will not be able to complete this step unless you understand the domain. It is nice to know that before you’ve started programming.

5.3.7 Template

Take inventory inside the body of the function of what you know about the data independent of the function’s purpose. For example, you know that you can use the values of the parameters:

// areaOfDisk : double -> double

// Computes the area of a disk where the radius is 'r'

static double areaOfDisk( double r ) {

 ... r ...

}

If a parameter’s type is compound, then you know you can access it’s pieces:

static boolean inUnitCircle ( Posn p ) {

 ... p.x ... p.y ...

}

If a parameter’s type is a union, then you know you can distinguish the cases:

static boolean myNot ( boolean b ) {

 if ( b ) {

  ... b ...

 } else {

  ... b ...

 }

}

If a parameter’s type is another complicated kind of data, then you know you should call a function to solve the problem for it:

static int lengthOfBoth ( List x, List y ) {

 ... x.lengthOf() ... y.lengthOf() ...

}

Write these down and leave them in your program, commented out, so you can refer back to them as you program.

5.3.8 Coding

Copy your template and fill in the ...s. Use your examples and domain knowledge to decide what to write. During this step, you will face your greatest number of low-level problems.

5.3.9 Testing

Check if your function has the same behavior as the examples you wrote at the beginning.

5.3.10 Summary

The majority of your problems will come from failure to follow this process through. Therefore, the TAs have been instructed to refuse to answer questions about any step until you’ve completed all the steps below it. Here’s a questionnaire they may ask you:

Have you performed information analysis of the problem?

Have you mapped the information into data?

Have you written your data definition?

Have you coded a class definition for complex data?

Have you written examples of your data?

Have you written a contract for the method you are implementing?

Have you written a purpose statement?

Have you written a method prototype?

Have you written examples of the method’s output?

Have you written a function template?

Have you tested your function?

5.4 High-level

The most serious kinds of problems come when the entire prior discussion is not meaningful to you. You don’t understand what the next step in the design process is or even what I’m talking about. In these situations, I’ve probably done a bad job in class. In these situations, the TAs can try to help you, but probably you should come talk to me and we can figure out if others in the class can benefit from the outcome of our conversation.

6 Assignments and Turn In Policy

Each lecture’s notes has associated exercises. It is your responsibility to do these exercises and return them by the next class. That’s a fast pace. This is a condensed Spring semester though.

6.1 Turn-in Content

When you turn in the exercises for day n, turn in a Zip archive named "n.zip" that contains a folder named n. This folder should contain source file(s) (the ".java" files) for the exercises. Feel free to put all the exercises in one file or use different files. Name them whatever you want. Sometimes your exercises do not obviously require programs, but you may find writing them to be useful in finding the answer.

The folder should also contain a file named "defense.pdf" where you argue that you have done the exercises correctly. The defense should have one section per exercise, where you may make reference to the code that you wrote and argue why it is correct. The best arguments will be based on the congruence between manually worked examples and the behavior you observed when you ran your program.

Exercises that do not have the correct format will receive no credit.

6.2 Turn-in Deadline

As mentioned above, exercises are due before the next class. Late exercises will receive no credit.

6.3 Turn-in Method

Exercise are to be emailed to jay@cs.byu.edu.

The subject line must be: "BYU - Spring 2011 - CS 142 - n", where n is the day number.

Only one email should be sent. If more than one is sent, I will grade the oldest one.

Emails that do not have the correct format will receive no credit.

6.4 Grading

I will grade your execises based on your defense. I will only look at your code to ensure that your defense is actually about your code. This means you do not get credit if you do things correctly but do not adequately argue that you did.

Your grade will be expressed as a real number between 0 and 1.

7 Exams

There are no exams in this course.

8 Extra Credit

There are two kinds of extra credit.

The first, you earn from helping other students. Throughout the class, you will write incorrect programs. Every time the compiler or runtime finds an error in your program, if you find a solution to the error, then email it to the mailing list, you will get extra credit if it is a unique problem. When you send these, make sure you do not reveal your solution to the exercise you are working on; try to isolate the error and its solution as much as possible. I will add this extra credit to your final grade, if it will change your letter grade.

The second, you earn from doing optional exercises that are part of some exercise sets. The principle behind this extra credit is that you may "pay debts" but you may not "take loans". Specifically, if you do optional exercises for day 10, then it can cover mistakes you made in days 1 through 10; but it cannot cover mistakes made after day 10. You may only submit optional exercises within a week of when the required exercises are due. This gives you time to find out you did poorly on an assignment and do a little extra on it. Whenever you do optional exercises, I will dump those extra points back over past homeworks until they run out: you don’t have to specify where you want them to apply. If you submit optional exercises at the same time as required ones, just include them in the normal turn-in. Otherwise, send them with the same subject as the required ones, plus "optional" so I’ll know you aren’t turning in something late or mistaken.

9 Your Final Grade

Your sub-final numeric grade is the average of the assignments due. This means each assignment is worth about 5 percent of your grade.

I will then convert your numeric grade to a letter. As will start at 0.9, Bs will start at 0.8, Cs will start at 0.7, and Ds will start at 0.6. I will remove the "minus" at x + 0.03 and will add a "plus" at x + 0.06.

If you ever want to know your current final grade, just email me.

10 Other Policies

All other policies of BYU apply; in particular, the Honor Code and its relationship to cheating, etc.