Writing Scala Programs. Command Line There are three common operating systems: Windows (various flavors; I recommend Windows 7) UNIX or Linux (basically.

Slides:



Advertisements
Similar presentations
The Linux Operating System Lecture 6: Perl for the Systems Administrator Tonga Institute of Higher Education.
Advertisements

The Beauty and Joy of Computing Lecture #18 Besides Blocks I: Intro to Python Amazon Dash is Not an April Fools Joke UC Berkeley EECS Head TA Michael Ball.
VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006.
1 Gentle Introduction to Programming Tirgul 1: Shell and Scala “hands on” in the lab.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Introduction to VBA. This is not Introduction to Excel We’re going to assume you have a basic level of familiarity with Excel If you don’t, or you need.
Methods. Why methods? A method gives a name to something that you want to do, so you don’t have to think about how to do it, you just do it The name should.
Introduction to Python Kris Kneubuhler SE NPUG July 17 th 2014.
Lesson 4 Computer Software
A First Program Using C#
CS110/CS119 Introduction to Computing (Java)
10-Sep-15 Classes. Classes and objects Scala is an Object-Oriented (O-O), functional language Object-Oriented (O-O) means it’s built around “objects”
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Introduction to Computing Concepts Note Set 11. Other ways of interacting with Java programs There are: ▫ GUI programs ▫ Web-based applets (GUI programs.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
CENT 305 Information Systems Security Linux Introduction.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Chapter 5 Creating an Image Map.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Agenda Review Unix Review Algorithms Your first program Compiling programs What are functions? What is Object Oriented Programming? Variables Data Types.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
The Scala API Application Programmer’s Interface.
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Development Tools © Copyright 2014, Fred McClurg All Rights Reserved.
Chapter 3 The Visual Basic Editor. Important Features of the VBE Alt-F11 will open the Visual Basic Editor. The Code window is to the right, Project Explorer.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Chapter Three The UNIX Editors.
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
Agenda Computer Languages How to Write a Simple C Program
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Compare and Contrast : Blackboard & a Personal Web Page www3.ltu.edu/~s_schneider/howto/faculty.htm You’ll find this presentation (and another) here :
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
Practical Kinetics Exercise 0: Getting Started Objectives: 1.Install Python and IPython Notebook 2.print “Hello World!”
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
Intoduction to Andriod studio Environment With a hello world program.
Learning Aim B.  In this section, you will consider the resources necessary for designing your website.  You will also think about any constraints that.
Today’s Agenda ML Development Workflow –Emacs –Using use –The REPL More ML –Shadowing Variables –Debugging Tips –Boolean Operations –Comparison Operations.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Perl Subroutines User Input Perl on linux Forks and Pipes.
 Prepared by: Eng. Maryam Adel Abdel-Hady
 Prepared by: Eng. Maryam Adel Abdel-Hady
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Clojure.  Follow instructions on lynda.com  Can install all this in other ways, but this is the easiest way to get a development environment working.
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
Introduction to the Command Line for Data Analysts Gus Cavanaugh
The eclipse IDE IDE = “Integrated Development Environment”
Development Environment
Department of Computer Engineering
Instant Scala.
Python Let’s get started!.
Introduction to Python
Guide To UNIX Using Linux Third Edition
CompSci 230 Software Construction
CSE 341: Programming Languages Section 1
CSE 341: Programming Languages Section 1
IDE’s and Debugging.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Review of Previous Lesson
Input and Output Python3 Beginner #3.
Presentation transcript:

Writing Scala Programs

Command Line There are three common operating systems: Windows (various flavors; I recommend Windows 7) UNIX or Linux (basically the same thing) Mac OS X, built on top of UNIX All have a “command line” or “shell” interface Mac: Use the Terminal application Windows: Two choices. From the Start menu, type: cmd, to get the DOS interface (not recommended) powershell, to get a better interface PowerShell has many conveniences, including some UNIX-like commands You can copy the PowerShell icon to your Start menu for easier access Once everything has been installed properly, you can type scala at the command line to enter the Scala REPL 2

Minor points Little things add up! “Watch the pennies and the dollars will take care of themselves.”—Benjamin Franklin Syntax coloring is when your editor uses different colors for keywords, strings, numbers, etc. You can ignore the colors; you’ll soon start to notice when they indicate errors Other editor features you should learn to use: Parenthesis matching Automatic indentation Indent/dedent large blocks of code Use a good font, so that you don’t even have to think about distinguishing a 1 (one) from an l (lowercase L) or a | (vertical bar) My favorite is Consolas (compare 1 and l, for example) Not so minor: RSI, Repetitive Strain Injury, is an occupational hazard for programmers Learn at least the very basics of ergonomics 3

Editors You should get a good editor and get familiar with its features The following work on both Mac and Windows, and have syntax coloring for Scala Sublime Text 2 or newer—recommended by Atomic Scala Excellent, but it will nag you occasionally to pay for it Oddly, it has no way to access a printer (to make paper copies) jEdit is a longtime favorite of mine For the Mac, TextMate is a free alternative to Sublime Text 2 For Windows, Notepad++ is a fine editor but does not come with Scala syntax coloring If you are already familiar with Eclipse, there is a Scala plugin for it 4

The REPL REPL stands for “Read-Eval-Print-Loop” You can enter expressions directly in the REPL, and the result will be printed (That’s the “P” in REPL) scala> "Hello from the REPL!" res1: String = Hello from the REPL! This tells you that the REPL has put your result in a val named res1 that you can use later, and that res1 is a String You can also use print and println in the REPL, but usually you don’t need to scala> println("Hello from the REPL!") Hello from the REPL! The result of calling println is “unit” Unit is, and the REPL usually doesn’t print it You can give commands to the REPL, such as :help, :load, and :quit To load a program from a file into the REPL, use :load For example, to load the program Hello.scala, enter :load Hello.scala 5

More about the REPL Because the REPL is designed for trying things out, it lets you redeclare a val : scala> val x = 1 x: Int = 1 scala> x = 2 :8: error: reassignment to val x = 2 ^ scala> val x = 2 x: Int = 2 You can’t do this in a “real” program In the REPL, if an expression seems to be complete, it will be executed if (x < y) min = x // will execute as soon as you hit Enter else min = y // then this will be an error You can avoid this problem by using :paste (see :help ) 6

Programs A program must contain a main method inside an object: object HelloWorld { def main(args: Array[String]) { println("Hello, World!") } } Running the program from the (PowerShell) command line: PS C:\Users\dave\Scala programs> scala HelloWorld.scala Hello, World! Loading and running the program from the Scala REPL: scala> :load HelloWorld.scala Loading HelloWorld.scala... defined module HelloWorld scala> HelloWorld.main(Array()) Hello, World! Note: Array() is a required argument to the method 7

Scripts A script is a file containing any number of Scala expressions to be executed On the file: val hello = "Hello, Scala!" println(hello + " (scripted)") Running the script from the (PowerShell) command line: PS C:\Users\dave\Scala programs> scala ScriptDemo.scala Hello, Scala! (scripted) Running the script from the REPL: scala> :load ScriptDemo.scala Loading ScriptDemo.scala... Hello, Scala! (scripted) How this works: Scala turns your script into a program by creating an object containing a main method, and putting your script inside that main method Scripts are useful for small, simple programs that you might want to run from the command line 8

9 The End