Introduction to Programming: Variables and Objects. HORT Lecture 7 Instructor: Kranthi Varala

Similar documents
Introduction to Python: Data types. HORT Lecture 8 Instructor: Kranthi Varala

Software Development. Integrated Software Environment

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

CSI32 Object-Oriented Programming

Principles of Programming Languages. Lecture Outline

An Introduction to Python (TEJ3M & TEJ4M)

Functions, Scope & Arguments. HORT Lecture 12 Instructor: Kranthi Varala

1) What is the first step of the system development life cycle (SDLC)? A) Design B) Analysis C) Problem and Opportunity Identification D) Development

Lecture 01 & 02 Computer Programming

Programming 1. Lecture 1 COP 3014 Fall August 28, 2017

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

Lecture 15: Iteration and Recursion

Computing Seminar Introduction Oct

Chapter 1. Preliminaries

Programming. leads to programming languages. leads to operating systems

Chapter 1. Preliminaries

Chapter 1 Preliminaries

Programming 1 - Honors

INFS 214: Introduction to Computing

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala

Technology in Action. Chapter Topics (cont.) Chapter Topics. Reasons for Software Programming. Information Systems 10/29/2010

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011


CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

Programs are: CMPSCI 105/119/120: Programming, Flowchar<ng, and Running Program Flowcharts

Copyright 2005 Department of Computer & Information Science

Introduction to Java Programming

Technology in Action. Chapter Topics. Scope creep occurs when: 3/20/2013. Information Systems include all EXCEPT the following:

Shell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

Software II: Principles of Programming Languages. Why Expressions?

Computers in Engineering COMP 208. Computer Structure. Computer Architecture. Computer Structure Michael A. Hawker

Stating the obvious, people and computers do not speak the same language.

PROBLEM SOLVING AND PYTHON PROGRAMMING

CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution


Python for Earth Scientists

Programming Languages and Program Development Life Cycle Fall Introduction to Information and Communication Technologies CSD 102

COMPILER DESIGN LECTURE NOTES

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Chapter 5. Names, Bindings, and Scopes

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

CHAPTER 1 Introduction to Computers and Java

Software Concepts. It is a translator that converts high level language to machine level language.

SOEE1160: Computers and Programming in Geosciences Semester /08. Dr. Sebastian Rost

Introduction. CS 2210 Compiler Design Wonsun Ahn

Chapter 12 : Computer Science. Class XI ( As per CBSE Board) Program Execution. New Syllabus Visit : python.mykvs.in for regular updates

CIS 194: Homework 3. Due Wednesday, February 11, Interpreters. Meet SImPL

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

A Set Of Machine Language Instructions For A Program Is Called Source Code >>>CLICK HERE<<<

Scientific Computing

Chapter 7. Expressions and Assignment Statements ISBN

34. Recursion. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Working with JavaScript

C H A P T E R 1. Introduction to Computers and Programming

Chapter 2 Working with Data Types and Operators

Chapter 7. Expressions and Assignment Statements

Contemporary Multilevel Machines

Programming Languages, Summary CSC419; Odelia Schwartz

Introduction to Scientific Computing Languages

Chapter 7. Expressions and Assignment Statements

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Introduction to Scientific Computing Languages

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

Python Lists and for Loops. Learning Outcomes. What s a List 9/19/2012

Problem Solving and Program Design - Chapter 1. Cory L. Strope

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Chapter 11 Program Development and Programming Languages

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

COMPUTER ORGANIZATION & ARCHITECTURE

Python Input, output and variables

A NET Refresher

Ruby: Introduction, Basics

Introduction to computing, architecture and the UNIX OS. HORT Lecture 1 Instructor: Kranthi Varala

Intermediate Representations

CSC 101: Lab Manual#9 Machine Language and the CPU (largely based on the work of Prof. William Turkett) Lab due date: 5:00pm, day after lab session

Computer Organization and Assembly Language. Lab Session 01

Expressions and Assignment Statements

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

Computational Physics Operating systems

Welcome to Computer Organization and Design Logic CS 64: Computer Organization and Design Logic Lecture #1 Winter 2018

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CS 360 Programming Languages Interpreters

Cost of Your Programs

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

Chapter 8 Algorithms 1

Appendix A: Objectives and Courseware Locations

Chapter 11 Introduction to Programming in C

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Table of Contents EVALUATION COPY

From High Level to Machine Code. Compilation Overview. Computer Programs

CISC 124: Introduction To Computing Science II

CSCI 334: Principles of Programming Languages. Lecture 2: Lisp Wrapup & Fundamentals. Higher-Order Functions. Activity

BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1

Welcome to Computer Organization and Design Logic

CPSC 3740 Programming Languages University of Lethbridge. Control Structures

Transcription:

Introduction to Programming: Variables and Objects HORT 59000 Lecture 7 Instructor: Kranthi Varala

What is a program? A set of instructions to the computer that perform a specified task in a specified manner. The task of writing a functional, error-free and cohesive set of instructions is called programming. Two major components of Programming: Logic What are my set of instructions? Syntax How do I convey them to the CPU?

Logic Programming logic is an exercise in how to break down a complex real-world problem into a set of mathematical notations. Independent of programming language used. Divide a complex task into a series of simpler tasks. Divide each task into a set of simple, sequential instructions. Arrange simple tasks in the most efficient order to accomplish complex task.

Syntax Programming syntax is a predetermined set of rules in which the instructions need to be provided. Usually unique to each programming language. Once the logic is established, convert the instructions into the syntax prescribed. Constraints imposed by the syntax may required adjusting the logic.

Programming languages Simply put, a language understood by the computer. Computers are not truly intelligent (Yet!). So, the instructions need to be extremely detailed and precise. At the lowest hardware level, a computer operates on bits (1 and 0), called binary code. Modern programming languages are closer to how humans think/talk.

Low level vs. High level languages Programming languages range from low level (close to binary) to high level (close to human language). Order of languages: High-level --> Assembly --> Machine/Binary Low-level languages are extremely hard to learn and lack portability, but make optimal use of hardware. High-level languages are easier to learn and generalize, but are poorer at using hardware resources.

High-level languages Common high-level languages are Java, C, C++, Python, Perl etc. Code written in a high-level language is interpreted and converted into low-level language by an intermediate layer that is either a compiler or and interpreter. The Compiler and interpreter differ in the timing of generation of machine code.

Compiled vs Interpreted Some languages have a compiler that converts your program (Source code) into a binary, executable file (Distributed code). E.g., C, C++, Fortran, Java etc. Other languages maintain the source code as is until the time of execution. Upon execution, the interpreter converts source code to machine code on-the-fly. E.g., Python, Perl, Ruby, Javascript etc.

Compiler Converts entire source code into machine code at the compilation stage. Optimizes the source code to use hardware resources better. Compilation process can be lengthy and computationally intensive, depending on the source code. Compilers can be told to generate different machine codes for different hardward platforms e.g., Mac vs PC vs Linux. Optimized machine code is faster, but not portable.

Interpreter Interpreter resides on the target machine and accepts source code as input. Reads through the code one line at a time and converts instructions in that line to machine code. Lacks the optimization step included in compilers and hence program execution is often slower than compiled programs. Source code is highly portable, since the interpreter is integrated in the target platform. Languages that rely on interpreters are often called Scripting languages.

Machine code is the ultimate result By BrokenSphere (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html) or CC BY- SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons All source code HAS to be eventually converted into machine code

Stages of programming Develop the logic Write code Compile/Interpret Test with data Debug code

Pseudocode A high level description of the problem and the programmatic solution that helps develop the overall logic and the subdivision of tasks. Informal way of writing code that does not worry about the syntax of the programming language. Follows a loose set of rules that allow logical grouping of functions.

Pseudocode Example Problem: Calculate the average length of all protein sequences. PseudoCode (Simplest): Read all Protein sequences Calculate length of each sequence Calculate the mean of all lengths

Pseudocode Example Problem: Calculate the average length of all protein sequences. PseudoCode (Simple): Open protein sequence file Loop over protein sequences Read each sequence Calculate length of current sequence Add length to sum variable Calculate the mean length by dividing sum/ no. of sequences

Pseudocode Example PseudoCode (Detailed): Create mean length variable; set to 0 Create No. of sequences variable; set to 0 Create sum variable; set to 0 Ask user input for name of sequence file Open protein sequence file (if exists) Loop over protein sequences Read each sequence Calculate length of current sequence Add sequence length to sum variable Increment No. of sequences by 1 Calculate value of mean as Sum/No. of sequences. Output value of mean

Other examples Print the following patterns: 1. * 2. * 3. * ** ** ** *** *** *** **** **** **** ***** ***** ***** Find all 5 letter words in a file and print only those that start with a vowel. Exchange the value of 2 variables (integers) without using a third variable.

Documentation Always document your code with as much detail as possible. For each variable, when created, write a comment explaining the intended use of the variable. For each loop, write a comment describing what the loop is expected to iterate over. For each function, write a comment explaining the expected input and expected output of function. For each stage of the program, write a long comment describing the current stage, expected input and outcome of this stage.

Variables and Objects Variables are the basic unit of storage for a program. Variables can be created and destroyed. At a hardware level, a variable is a reference to a location in memory. Programs perform operations on variables and alter or fill in their values. Objects are higher level constructs that include one or more variables and the set of operations that work on these variables. An object can therefore be considered a more complex variable.

Data types All variables are empty when created. Since variables have no implicit value, they can store many different forms of values. Example values of variable: Var = TRUE Var = 523243 Var = 42.2524 Var = Hi there Var = Reference to Var2

Implicit vs. Explicit data types Some languages require each variable to be defined as a single data type, e.g. integer, float, string etc. Explicit data typing prevents nonsensical operations such as multiplying two strings. Compiled languages, such as C, Java etc., typically use explicit data types, since it allows improved optimization Other languages allow all variable to be any one of the implicit data types. With implicit data typing, a variable can change its data type within the same program. Scripting languages, such as Python, Perl etc., often use implicit data types.