30
Programming for AmI MOTIVATIONS AND GOALS Why AmI needs programming? Defining the goals and requirements of software development for AmI

Programming for AmI - PoliTO

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Programming for AmI - PoliTO

Programming for AmI MOTIVATIONS AND GOALS

Why AmI needs programming? Defining the

goals and requirements of software

development for AmI

Page 2: Programming for AmI - PoliTO

3/6/2014 Programming for AmI

Ambient Intelligence systems: digital

environments that pro-actively, but sensibly,

support people in their daily lives.

2

Page 3: Programming for AmI - PoliTO

How?

• By blending systems and devices in the

environment

• By adding software to coordinate the home

components and make them behaving as a

single organism.

• By designing this organism to be « interactive»,

«supportive» and «sensible»

3/6/2014 Programming for AmI 3

Page 4: Programming for AmI - PoliTO

Software

• Goal

– coordinate the home components

– Make them «interactive», «supportive» and «sensible»

• Functional Requirements

– Focus on features

– Effectively tackle «intelligence» design

– Solve «real» problems

– Avoid / Limit programming idiosynchrasies

3/6/2014 Programming for AmI 4

Page 5: Programming for AmI - PoliTO

Solution

• Python:

– Solve «real» problems

– Smooth learning

– Avoid focusing on mathematical abstraction, only

– Limit distraction from

• Low-level syntax issues

• Compilation

• Counter-intuitive concepts

3/6/2014 Programming for AmI 5

Page 6: Programming for AmI - PoliTO

Python AN OVERVIEW

A short overview of Python, including a bit of

history, justfication for its adoption in the

Ambient Intelligence: Technology and Design

course, and basic programming concepts

Page 7: Programming for AmI - PoliTO

What is Python?

• Python is an easy to learn, powerful

programming language.

• It is an ideal language for scripting and rapid

application development in many areas on

most platforms.

3/6/2014 Programming for AmI 7

Page 8: Programming for AmI - PoliTO

Identikit

• First Appeared in 1991

• Designed by Guido van Rossum

• General purpose

• High level

• Emphasis on code readability and conciseness

3/6/2014 Programming for AmI 8

Page 9: Programming for AmI - PoliTO

High level languages

• Near to human-level abstraction

– Short, expressive, easy to read

• Portable

– Can be executed on different platform with few or none changes

• Must be translated into low-level code for

actual execution

3/6/2014 Programming for AmI 9

Page 10: Programming for AmI - PoliTO

Hello world (high level)

3/6/2014 Programming for AmI 10

print ‘Hello world’

Page 11: Programming for AmI - PoliTO

Low level languages

• Directly executable

– No translation needed

• Typically more efficient

– They are designed for very specific hardware

• Platform dependent

– Must be re-written for execution on different platforms

• Difficult to write (and read)

– Near to the machine code

3/6/2014 Programming for AmI 11

Page 12: Programming for AmI - PoliTO

Hello world (low level)

3/6/2014 Programming for AmI 12

Page 13: Programming for AmI - PoliTO

Interpreted languages

• Line by line translation and execution

3/6/2014 Programming for AmI

Source code

Code Interpreter

Result

13

Page 14: Programming for AmI - PoliTO

Compiled languages

• Completely translated into low-level code

before execution

3/6/2014 Programming for AmI

Source code

Code Interpreter

Object code

Executor Result

14

Page 15: Programming for AmI - PoliTO

Python is interpreted

• Two ways to use the interpreter:

• Interactive mode

– Type the program and the interpreter displays the result

• Script mode

– Store the code in a file, and use the interpreter to execute the contents

3/6/2014 Programming for AmI

>>> 1+1

2

python myscript.py

15

Page 16: Programming for AmI - PoliTO

PYTHON INSTALL

Getting started

3/6/2014 Programming for AmI 16

Page 17: Programming for AmI - PoliTO

Linux vs Windows

• High Level

– Available for both platforms

• Linux / Unix

– Typically pre-installed

– Already used for several tasks

• Windows

– Should be explicitly installed

• Mac

– Typically pre-installed

3/6/2014 Programming for AmI

We will use

GNU / Linux

17

Page 18: Programming for AmI - PoliTO

Windows Installation

• Check the latest 2.7.x

version • http://www.python.org

• Download the .msi

installer • follow the wizard

throughout installation

• Open-up a terminal • Win(+R) > cmd

• python --version

3/6/2014 Programming for AmI 18

Page 19: Programming for AmI - PoliTO

Integrated Development Environment (IDE)

A software application that provides

comprehensive facilities to computer programmers for software development.

An IDE normally consists of a source code editor,

build automation tools and a debugger.

Most modern IDEs offer Intelligent code

completion features.

3/6/2014 Programming for AmI 19

Page 20: Programming for AmI - PoliTO

Python IDE

• Some choices available

• We use PyDev

– http://pydev.org/

• Installed as an extension of the Eclipse IDE

– http://www.eclipse.org/

3/6/2014 Programming for AmI 20

Page 21: Programming for AmI - PoliTO

PyDev Installation

• Download Eclipse 4.3.2 standard

– https://www.eclipse.org/downloads/

– Check your os version (Linux/Windows/Mac, 32/64bit)

– Unzip the eclipse file where you want-it to be installed

• tar -xvfz eclipse-standard-kepler-SR2-linux-gtk-x86_64.tar.gz (on Linux)

• eclipse-standard-kepler-SR2-win32.zip

3/6/2014 Programming for AmI 21

Page 22: Programming for AmI - PoliTO

PyDev Installation 2

• Open the eclipse preferences

– Window > Preferences > Install/Update > Available Software Sites

• Add the PyDev update site

– http://pydev.org/updates

• Install the new software

– Help > Install New Software...

3/6/2014 Programming for AmI 22

Page 23: Programming for AmI - PoliTO

PyDev Installation 3

• Select the

just created update site

• Select PyDev

for Eclipse

3/6/2014 Programming for AmI 23

Page 24: Programming for AmI - PoliTO

Hello world!

3/6/2014 Programming for AmI 24

Page 25: Programming for AmI - PoliTO

Hands on

3/6/2014 Programming for AmI

Define a script for saying «Hello!» to the whole AmI course. Do it using the interactive interpreter and then by writing a script file

print (‘Hello AmI 2014!’) if __name__ == '__main__': print('Hello World!')

25

Page 26: Programming for AmI - PoliTO

Hands on

3/6/2014 Programming for AmI

Define a script for computing the sum of 2 numbers. Do it using the interactive interpreter and then by writing a script file

>>>13+22 if __name__ == '__main__': print(13+22)

26

Page 27: Programming for AmI - PoliTO

What is a program?

A program is a sequence of instructions that specifies how to perform a computation.

• Basic instructions – input:

• Get data from the keyboard, a file, or some other device.

– output: • Display data on the screen or send data to a file or other device.

– math: • Perform basic mathematical operations like addition and multiplication.

– conditional execution: • Check for certain conditions and execute the appropriate code.

– repetition: • Perform some action repeatedly, usually with some variation.

3/6/2014 Programming for AmI 27

Page 28: Programming for AmI - PoliTO

Programming

the process of breaking a large, complex task into smaller and smaller subtasks until the subtasks are simple enough to be performed with one of these basic instructions.

• error-prone – Syntax error

• An error in a program that makes it impossible to parse (and therefore impossible to interpret).

– Semantic error • An error in a program that makes it do something other than what the

programmer intended

– Runtime Error • An error that is detected while the program is running.

3/6/2014 Programming for AmI 28

Page 29: Programming for AmI - PoliTO

Programming 2

– bug:

• An error in a program.

– debugging:

• The process of finding and removing any of the three kinds of programming errors.

3/6/2014 Programming for AmI 29

Page 30: Programming for AmI - PoliTO

Questions? 01PRD AMBIENT INTELLIGENCE: TECHNOLOGY AND DESIGN

Dario Bonino

[email protected]