+ All Categories
Home > Documents > Programming - Universiteit Twentefehnkera/portfolio/p4wci... · 2019. 11. 14. · Textbook:...

Programming - Universiteit Twentefehnkera/portfolio/p4wci... · 2019. 11. 14. · Textbook:...

Date post: 07-Feb-2021
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
43
PROGRAMMING We create identity 1
Transcript
  • PROGRAMMING We create identity 1

  • INTRODUCTION

    The course Lecture Tuesdays 10:45 to 12:30

    Tutorial Thursday 8:45 to 12:30 or Fridays 12:45 to 17:30

    Blackboard

    Textbook: Learning Processing, by Daniel Shiffman

  • INTRODUCTION

    The people Lecturers Ansgar Fehnker (Coordinator) Angelika Mader Marcus Gerhold

    Student Assistants Margot Rutgers Oliver Horst Carmen Burghardt Thijs Dortmann Marrit Schellekens Wybe Westra Dennis Vinke Lukas Bos

  • INTRODUCTION

    The students

  • NASA High Speed Flight Station "Computer Room", Dryden Flight Research Center, 1949

    COMPUTING

    PresenterPresentation NotesThis is NASA's compter room in the late 1949.Where is the computer? Computer referred until the mid 21st century to humansThey performed calculations.Often followed simple instructions to perform one step in a bigger project.

  • From: Grier, D.A.; , "The Math Tables Project of the work projects administration: the reluctant start of the computing era," Annals of the History of Computing, IEEE , vol.20, no.3, pp.33-50, Jul-Sep 1998

    COMPUTING

    PresenterPresentation Notes An example worksheet of the "Math Tables" projectA large project to compute for tables of higher mathematical functions for science and administration.These tables (logarithmic tables) were distributed like dictionaries. The Math Tables project was also employed to compute ballistic trajectories in WWII.

  • COMPUTING

    From: Grier, D.A.; , "The Math Tables Project of the work projects administration: the reluctant start of the computing era," Annals of the History of Computing, IEEE , vol.20, no.3, pp.33-50, Jul-Sep 1998

    PresenterPresentation NotesComputing projects were giant undertakingsDifferent task to be performed by different groupsComputingSpecial computing Machine operatorsTypistsClerksBookbindersSupervisors and planning Note, it was a government project.

    Need for mechanization.

  • COMPUTERS

    Glen Beck (background) and Betty Snyder (foreground) with ENIAC, 1947 to 1955

    PresenterPresentation NotesThe first computer were large machines using first switches, then tubes, later transistors.

    They could be "programmed" to perform scientific computations.

    "Programming" meant to reconnect the wires of the machine, to suit the task.

    "Programming" a computer could take several days.

    Planning of the rewiring even weeks or months.

  • UNIVERSAL TURING MACHINE

    Turing's insight:

    "It is possible to invent a single machine which can be used to compute any computable sequence.

    If this machine U is supplied with a tape on the beginning of which is written the S.D ["standard description"] of some computing machine M, then U will compute the same sequence as M."

    Turing 1936

    PresenterPresentation NotesThe first insight: Whatever is computable by mechanical means, can be computed by a Turing Machine.Many have tried to disprove this conjecture. They proposed "better" computing machines.All of them have been shown to be equivalent to (or less) to a Turing Machine. The second insight:Whatever you can do with a computer, you can do with a programmable computer.No need to rewire. Use a program (what Turing called "S.D.").Invention of "software".

  • STORED PROGRAM COMPUTER

    EDVAC, 1949

    PresenterPresentation NotesTuring idea shaped the ideas of "Stored Program Computers".The program is an input, just like the data. The program is data.Programming determines what a computer does.No wires on the outside necessary.

  • PROGRAMMING LANGUAGES

    Evolution of programming languages

    Go to http://www.digibarn.com/collections/posters/tongues/ComputerLanguagesChart-med.png for a full-size copy of this chart.

    PresenterPresentation NotesProcessing is only one of many programming languages.

    There are many others, some extinct by now, other stil alive, and a few new ones that a growing quickly.

    Processing is a dialect of Java, which itself draws on previous languages such a C, C++, and Simula.

    http://www.digibarn.com/collections/posters/tongues/ComputerLanguagesChart-med.png

  • PROGRAMMING

    PresenterPresentation NotesThis course teaches you "programming".It  teaches how to start  with a description of a problem, and how to arrive at a solution.It teaches the fundamental concepts of programming.It teaches you how to do it well, safe, and responsibly. 

  • PROCESSING LANGUAGE

  • PROCESSING LANGUAGE

    Aim and purpose

    For electronic arts, new media, and visual design

    A dialect of Java

    Designed by Casey Reas and Benjamin Fry

    Popularized by Processing Foundation (Reas, Fry and Shiffman)

    Textbook and additional material Learning Processing (Shiffman)

    https://processing.org/http://learningprocessing.com/

  • SETUP AND DRAW

    Setup

    This method gets executed once Use it to setup the canvas Use it to create shared data structure Use it for everything you want to do at the

    beginning

    Draw

    This method will be repeated as long as the program runs Use it to deal with interaction and animation

  • SETUP AND DRAW

    Setup

    This method gets executed once Use it to setup the canvas Use it to create shared data structure Use it for everything you want to do at the

    beginning

    Draw

    This method will be repeated as long as the program runs Use it to deal with interaction and animation

    • mousePressed, called when mouse is pressed• KeyPressed, called when a key is pressed

    Other standard methods

  • VARIABLES

    Predefined

    mouseX, mouseY pmouseX, pmouseY width, height keyCode keyPressed mousePressed mouseButton

    Basic Types

    int float double (rarely used in processing) bool char

  • VARIABLE DECLARTIONS

    A variable is used to store information. It can contain one piece of information at a time.

    Creating a variable is called declaring a variable.

    When declaring variables, the programmer specifies the type of information to be stored.

    The compiler will set aside that space in memory and give it the name we choose.

    Initialization is putting a value into a variable when the variable is created.

    Initialization is not required. But usually a good idea.

    PresenterPresentation NotesWhen you declare a variable the ‘name’ with be used for the memory.

    Now you can use ‘name’ for the content. You do not need to know the machine code name of the memory location. The compiler does it for you.

    The book uses “definition”. It is however more common to call it “declaration”.

  • VARIABLE DECLARATION

    int numSegments;

    type

    name – use a nice meaningful

    one

  • VARIABLE DECLARATION

    int numSegments = 5;

    type

    name – use a nice meaningful

    one

    intitialisation

  • DATATYPES

    There are different types of data.

    Every variable contains only data of one type.

    Common basic types

    int integers ….,-1,0,1,2, ….

    float floating point numbers 1.0, 3.14, -2.1

    char characters a,b,c,…, A,B,C,…,!,@,#,$,...

    boolean true and false

    PresenterPresentation NotesThere is also a type ‘float’ for floating point numbers. More about this next week.

  • LITERALS

    Literals are specific values used in the program. Like 1, 3.4, true, or ‘z’. They have a type, too. There is for example a difference between

    the integer 2

    the floating point number 2.0

    the character ‘2’.

  • THE ASSIGNMENT STATEMENT

    There is an important difference between a variable definition and an assignment statement:

    int numSegments = 6; // Variable definition

    ...

    numSegments = 8; // Assignment statement

    The first statement is a declaration of numSegments.

    The second statement is an assignment statement.An existing variable’s contents are replaced.

  • THE ASSIGNMENT STATEMENT

    The = in an assignment does not mean the left hand side is equal to the right hand side as it does in math.

    = is an instruction to do something:copy the value of the expression on the right

    into the variable on the left.

    Consider what it would mean, mathematically, to state:

    numSegments = numSegments + 2;?

  • ARITHMETIC

    For type float use +, -,*, / with the usual meaning

    For type int use +,-,* with the usual meaning.

    Division / will be integer division. The result will be integer if numerator and divisor are integer.

    Another useful operator is modulo % Computes the remainder of division

    Useful for integer values that are bound and repeat.

    For other type +,-,*,/ may or may not be defined. Result may be surprising. Check what they mean before using them.

    11/4 is 2. Not 2.75.

    e.g. 60 minutes

  • ARITHMETIC

    x = (3 + x)*(7 + y) + z;

    y = abs(x - z) % 50;

    z = (x – y)/2;

    computed top to bottom

    left of = is variables that gets a new value

    right of = the expression to

    compute the new value

    not all operation

    defined for all types

    some operations behave different

    for different types, e.g.

    integer division

  • VARIABLE NAMES

    When you define a variable, you should pick a name that explains its purpose.

    For example, it is better to use a descriptive name, such as numSegments,

    than a terse name, such as ns.

    Use common Java/Processing camelCase style for variables.

    You do this for yourself, and your colleagues.

    PresenterPresentation NotesA good variable name is not too long, but explains its purpose.

    It is common in C++ to use the underscore character _ in the place of blank spaces.

    For example page_num would be a name for the page number.

  • COMMENTS

    Comments are explanations for human readers of your code(other programmers).

    The compiler ignores comments completely.

    float canVolume = 0.355; // Liters in a 12-ounce can

    Comment

  • COMMENTS

    Comments can be written in two styles: Single line:

    float canVolume = 0.355; // Liters in a 12-ounce can

    The compiler ignores everything after // to the end of line

    Multiline for longer comments:

    /*This program computes the volume (in liters)of a six-pack of soda cans.

    */

  • CONSTANTS

    In Processing you can declare CONSTANTS.

    static final int ITEM_SIZE = 20;

    Common in Java. Rarely done in Processing.

    A good idea, also in Processing

    It tells that this value should not/cannot change

    It gives an explanatory NAME to a value. Makes code less obscure. Use ALL_CAPS for the name.

    Needs initial value

  • SCOPE

    Every pair of curly brackets {} defines a Local Scope. Scopes can be nestedEach variable that is declared exists From the point of declarationUntil the end of the scope

    You cannot use a variable outside of its scope.Declarations outside of any {} are in Global Scope.Variables in global scope can be used everywhere.

    Which may sound good, but is a bad idea.

    a.k.a block

  • SCOPE

    float topX;

    float topY;

    void setup(){…topX = width/2;topY = height/2;…

    }

    void draw(){float bottomX;float bottomY;…bottomX = topX + width/10;bottomY = topY + height/10;

    topX = (topY + 1)% 200;

    topY = (topY + 1) % 100;

    }

    global variables

    for shared or persistent

    data

    local variables

    for transient data or values

  • SCOPE

    It is considered good practice to minimize the scope

    Few global variables. Except for data that has to be shared. Global constants are ok. Most variables should be local.

    Global variables make understanding and debugging difficult.

  • EXAMPLES

    Learning Processing http://learningprocessing.com/exercises/chp03/exercise-03-07-absolute-value http://learningprocessing.com/exercises/chp03/exercise-03-07-absolute-value http://learningprocessing.com/examples/chp03/example-03-06-interactive-zoog http://learningprocessing.com/examples/chp04/example-04-08-zoogvars

    http://learningprocessing.com/exercises/chp03/exercise-03-07-absolute-valuehttp://learningprocessing.com/exercises/chp03/exercise-03-07-absolute-valuehttp://learningprocessing.com/examples/chp03/example-03-06-interactive-zooghttp://learningprocessing.com/examples/chp04/example-04-08-zoogvars

  • STYLE

    Programs must be written for people to read, and only incidentally for machines to execute.

    - H. Abelson and G. Sussman

  • STYLE

    Great software, likewise, requires a fanatical devotion to beauty.

    - Paul Graham

  • STYLE

    A good programUses layout to convey the

    structure.Different components are

    easily recognized.The code adheres to a given

    coding guideline. All output is spelled correctly,

    with a proper layout

    A poor program The layout is coincidental, It is difficult to identify the

    structure. Names are cryptic. No discernible effort. Spelling mistakes, poorly

    formatting of output.

  • STYLE

    Make yourself familiar with professional style guides

    Using a good IDE will help to program in style.

    They will automatically “fix” many problems in your code.

  • TOPICS COVERED

    Getting Started

    Setup and draw

    Variables mouseX, mouseY other system variables variable declaration types

    Arithmetic

    Predefined methods abs, max, delay …

    Topics Look for examples Look at manual

    Programming as communication Style Naming Comments Constants

  • ADMIN

    Lectures: Tuesday 11:45 to 12:39

    Tutorials: Thursdays 8:45 to 12:30 or Friday 12:30 to 17:30

    Assessment: Week 4 tutorial project assessed in week 5 (1/10)Multiple choice test (3/10) Final project (6/10)

  • TUTORIAL ETIQUETTE

    The tutorial and lab sessions are there for practicing programming

    They are an opportunity to get help and advice or to help and advise

    Don’t use the lab time for other purposes (like facebook)

    Wastes valuable time for multitasking

    It is distracting to you, and others

    Creates a poor learning environment

    If it turns out that your are using lab time and space for non-related issues, you may be asked to leave.

  • ADVICE

    This is (not) a difficult course… Students who do well do these things

    Attend lectures regularly Attend tutorials regularly Including doing prep work before tutorial Keep up with the textbook Ask questions Ask for help

    Programming is a practical subject. Besides book knowledge you need to learn by doing.

  • GOOD LUCK

    ProgrammingIntroductionIntroductionIntroductionComputing Computing ComputingComputersUniversal Turing MachineStored Program ComputerProgramming LanguagesProgrammingProcessing LanguageProcessing languageSetup and DrawSetup and DrawVariablesVariable DECLARTIONSVariable DeclarationVariable DeclarationData TypesLiteralsThe Assignment StatementThe Assignment StatementArithmeticArithmeticVariable NamesCommentsCommentsConstantsScopeScopeScopeExamplesStyleStyleStyleStyleTopics COVEREDAdminTutorial EtiquetteAdviceGood Luck


Recommended