1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

32
1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    218
  • download

    2

Transcript of 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

Page 1: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

1

Gentle Introduction to Programming

Tirgul 1: Shell and Scala “hands on” in

the lab

Page 2: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

2

Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:

• Command line arguments• Debugger

• Home work – practice Shell commands

Page 3: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

3

Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:

• Command line arguments• Debugger

• Home work – practice Shell commands

Page 4: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

4

Your Account, Basic Linux Commands

• User’s account: to log in select session: GNOME• Web browser • Open the “system handouts” file from the course’s site (in the session’s section)• Shell / Console

Page 5: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

5

Basic Linux Commands

Page 6: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

6

Security (chmod)

Page 7: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

7

Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:

• Command line arguments• Debugger

• Home work – practice Shell commands

Page 8: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

8

Using the Interpreter• Type “scala” from the console• Start trying some basic commands:

• println(“hello world!”)• val x = 5• var y = 1.4

• Define a function that receives two integers and return their sum. Use it on several inputs.

Page 9: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

9

Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:

• Command line arguments• Debugger

• Home work – practice Shell commands

Page 10: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

10

Eclipse• Type “eclipse35 &” from the console• Use a workspace located on your account• How to solve common technical problems:

• “Clean” your eclipse by removing the .eclipse directory (rm –R .eclipse, from your root)• Start a new workspace / remove the old one

Page 11: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

11

Open Eclipse – Set Workspace

Page 12: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

12

Open Eclipse

Page 13: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

13

Define New Project

Page 14: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

14

If you don’t find the Scala new project…

File New Project

Page 15: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

15

New Object

Page 16: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

16

Write Some Code

Page 17: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

17

Run

output

Page 18: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

18

Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:

• Command line arguments• Debugger

• Home work – practice Shell commands

Page 19: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

19

Understanding Compiler MessagesOpen the interpreter, try the following lines of code, and try to understand what the compiler means, and how to solve it

val x = 5

x = 6

Println(“123”)

val f = (x : Int => x + 1)

if x > f(x) x = 9

val f = (x : int) => x + 1

Page 20: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

20

And In Eclipse

• Select and copy a program of your choice to Eclipse• How are compilation errors marked in Eclipse?• Perform compilation errors purposely and see how the compiler’s errors look like:

• Change an upper-case letter to lower case• Remove a closing brackets

• Where are the compiled files?

Page 21: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

21

Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:

• Command line arguments• Debugger

• Home work – practice Shell commands

Page 22: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

22

Command Line Arguments In Eclipse

Page 23: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

23

Command Line Arguments In Eclipse

Page 24: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

24

Usage Example

?

Fibonacci.scala

Page 25: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

25

Example: Prime

• Write a program that receives from the command line arguments a list of numbers, and prints out for each whether it is prime

• Use the prime code that is published, and wrap it as a function• Notice, that the number of arguments is not known in advance!

Page 26: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

26

The Debugger

• Some programs may compile correctly, yet not produce the desirable results

• These programs are valid and correct Scala programs, yet not the programs we meant to write!

• The debugger can be used to follow the program step by step and may help detecting bugs in an already compiled program

Page 27: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

27

Debugger – Add Breakpoint

• Right click on the desired line

• “Toggle Breakpoint”

Page 28: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

28

Debugger – Start Debugging

breakpoint

debug

Page 29: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

29

Debugger – Debug Perspective

Page 30: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

30

Debugger – Debugging

Current state

Current location

Back to Scala perspective

Page 31: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

31

Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:

• Command line arguments• Debugger

• Home work – practice Shell commands

Page 32: 1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.

32

Home Work - Shell