Top Banner
What is Programming? Aspects of Programming, Computer Languages, Objects and Object- Oriented Programming
23

What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Dec 22, 2015

Download

Documents

Diane Hopkins
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

What is Programming?Aspects of Programming, Computer

Languages, Objects and Object-Oriented Programming

Page 2: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Many Aspects of Programming● Programming is controlling

o computer does exactly what you tell it to

● Programming is teachingo computer can only “learn” to do new things if you tell it how

● Programming is problem solvingo always trying to make computer do something useful, e.g. finding an optimal travel route

● Programming is creative o must find a good solution out of many possibilities

● Programming is modellingo describe salient (relevant) properties and behaviors of a system of components (objects)

● Programming is abstractiono identify important features without getting lost in detail

● Programming is concreteo must provide detailed instructions to complete task

● Programming is a crafto A bit like architecture, engineering - disciplined and creative craft for building artifacts

Page 3: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

● Model of complex systemo model: simplified representation of salient features

of something, either tangible or abstracto system: collection of components that work closely

together

What’s a Program?

Page 4: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

● Sequences of instructions expressed in specific programming languageo syntax: grammatical rules for forming instructionso semantics: meaning/interpretation of instruction

What’s a Program?

Page 5: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

What’s a Program?

● Instructions written (programmed/coded) by programmero coded in a specific programming languageo programming languages allow you to express yourself more precisely than

natural (human) languageo as a result, programs cannot be ambiguous

● Real world exampleso Banner, word processor, video game, ATM, smartphone, browser

● Executed by computer by carrying out individual instructions

Page 6: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Java Programs

● CS15 and CS16 use Javao Java was developed by Sun Microsystems (now part

of Oracle)o it is meant to run on many “platforms” without

change, from desktop to cell phoneso platform independence works quite wello But Java isn’t sufficient by itself: many layers of

software in a modern computer

Page 7: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

The Computer Onion● Layers of Software

o cover hardware like an onion covers its coreo make it easier to use computerso organized into libraries and programs

Your Java Program

X/Windows

Linux

hardware (PC)

In CS15, we only deal with the outermost layers

Page 8: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Two Views of a ProgramSoftware layers hidden by user interface

programmer’s view

user interface

user’s view

Page 9: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Programming Languages

● Machine languageo machine is short for computing machine (i.e., computer)o computer’s native languageo sequence of zeroes and ones (binary)o different computers understand different sequenceso hard for humans to understand:o 01010001...

Page 10: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Programming Languages

● Assembly languageo mnemonics for machine languageo low level: each instruction is minimalo still hard for humans to understand:

ADD.L d0,d2o you’ll learn assembly language in CS33

Page 11: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Programming Languages

● High-level languageso FORTRAN, C, C++, Java, Python, JavaScript, Scheme,

Racket, Pyret, ML, etc.o high level: each instruction is composed of many low-

level instructionso closer to english and high school algebrao easier to read and understand:o hypotenuse = Math.sqrt(leg1 * leg1 + leg2 * leg2);

Page 12: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

● In CS15, code in a high-level language, Java

● But each type of computer only “understands” its own machine language (zeroes and ones)

● Thus must translate from Java to machine language○ a team of experts programmed a translator, called a “compiler,” which

translates the entirety of a Java program to an executable file in the computer’s native machine language.

Running Compiled Programs

● Two-step process:o compilation: your program executableo execution: run executableo machine executes your program by “running” each machine language

instruction in the executable fileo not quite this simple “underneath the covers” – “Java bytecode” is intermediate

Page 13: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Object-Oriented Programming● OOP: Now the dominant way to program, yet it is over 40

year old! (Simula ‘67 and Smalltalk ‘72 were the first OOPLs)o Dr. Alan Kay received ACM’s Turing Award, the “Nobel Prize of Computing,” in

2003 for Smalltalk, the first complete dynamic OOPL

● OOP was slow to catch on, but since the mid-90’s everybody’s been doing it!

● OOP emphasizes objects, which often reflect real-life objectso have both properties and capabilitieso i.e., they can perform tasks: “they know how to…”

● Look around you… name that object!

Page 14: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

OOP as Modeling

● In OOP, model program as collection of cooperating objectso program behavior is determined by group interactionso group interactions are determined by individual objects

● In OOP, objects are considered anthropomorphico each is “smart” in its specialtyo e.g., bed can make itself, door can open itself, menu can let

selections be pickedo but, each must be told when to perform actions by another object - so

objects must cooperate to accomplish task

Page 15: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

OOP as Modeling

● Each object represents an abstractiono a “black box”: hides details you do not care abouto allows you as the programmer to control programs’ complexity - only

think about salient features

● So, write programs by modeling problem as set of collaborating componentso you determine what the building blocks areo put them together so they cooperate properlyo like building with smart Legos, some of which are

pre-defined, some of which you design!

Page 16: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Example: Tetris

● What are the game’s objects?● What do those objects know how

to do?● What properties do they have?

Page 17: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Example: Tetris (cont.)

● What are the game’s objects?o piece, board

● Capabilities: What do those objects know how to do?

○ board■ be created■ remove rows■ check for end of game

○ piece■ be created■ fall■ rotate■ stop at collision

Page 18: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

● Properties: What attributes and components do they have?

○ board■ size■ rows

Example: Tetris (cont.)

○ piece■ orientation■ position■ shape■ color

Page 19: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Software Development: A 5-Step Process

Page 20: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Software Development: A 5-Step Process

1. Analysisa. English description of what the system models to meet user requirement/specification

2. Designing the systema. “Divide et impera” - divide and conquer: system is composed of smaller subsystems which

in turn may be composed of even smaller subsystems (diagrams often helpful)

3. Implementing the design (in Java for CS15)a. if design is good, most of the hard work should be done

4. Testing and Debugginga. testing: submitting input data or sample user interactions and seeing if program reacts

properlyb. debugging: process of removing program bugs (errors)

5. Maintenancea. in a successful piece of software, keeping a program working and current is often said to

be 80% of the effort

Page 21: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Software Development: A 5-Step Process

Good Program:● solves original problem● well structured, extensible, maintainable, efficient,... and met deadline and budget

constraints…

Other development processes exist (e.g., extreme programming)

Page 22: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Announcements• To register for the class, go to the website and click on the registration link on the

homepage by Sunday at 6pm, so you can attend lab next week.

• Introductory lab sessions will begin next week in the Sunlab. Meeting times are:

Tuesday— 5:00PM-6:30PM, 6:30PM-8:00PM, 8:00PM-9:30PM

Wednesday— 6:00PM-7:30PM, 7:30PM-9:00PM, 9:00PM-10:30PM

Thursday-10:30AM-12PM, 4:00PM-5:30PM, 5:30PM-7:00PM, 7:00PM-8:30PM

We will email a form where you will be able to register for a session, so check your email!

• Bring your signed collaboration contract to the first lab. They are available on the website.

• Please also bring a laptop to the first lab, if you would like to work from home. We will be setting up remote access on personal computers during this lab.

Page 23: What is Programming? Aspects of Programming, Computer Languages, Objects and Object-Oriented Programming.

Announcements• Check the course website at http://www.cs.brown.edu/courses/cs015 and your email regularly.

• TA Hours begin on Tuesday 9/9

• Tonight at 7:30 in Salomon 101 (right here), the CS Department is hosting a Welcome to Brown CS Event. “Come learn about life in the CIT, how the CS department operates, how and when to seek help, and how to get involved in research and TAing.”

• If you are undecided about which CS intro course to take, this document is a good reference:http://cs.brown.edu/courses/cs015/docs/Course.pdf