Opp 1
Opp 1
Programming Languages
Administrivia
• advances in hardware
Overview
Paradigm
• How programs tend to be expressed in the language
Semantics
• What a program means (mathematically)
Implementation
• How a program executes (on a real machine)
CMSC 330 Spring 2017 19
Syntax
The keywords, formatting expectations, and
“grammar” for the language
• Differences between languages usually superficial
Ø C / Java if (x == 1) { … } else { … }
Ø Ruby if x == 1 … else … end
Ø OCaml if (x = 1) then … else …
• FORTRAN (1954)
• Pascal (1970)
• C (1971)
• LISP (1958)
• ML (1973)
• Scheme (1975)
• Haskell (1987)
• OCaml (1987)
CMSC 330 Spring 2017 26
OCaml
A mostly-functional language
• Has objects, but won’t discuss (much)
• Developed in 1987 at INRIA in France
• Dialect of ML (1973)
Natural support for pattern matching
• Generalizes switch/if-then-else – very elegant
Has full featured module system
• Much richer than interfaces in Java or headers in C
Includes type inference
• Ensures compile-time type safety, no annotations
CMSC 330 Spring 2017 27
A Small OCaml Example
intro.ml:
let greet s =
List.iter (fun x -> print_string x)
[“hello, ”; s; "!\n”]
$ ocaml
Objective Caml version 3.12.1
# #use "intro.ml";;
val greet : string -> unit = <fun>
# greet "world";;
Hello, world!
- : unit = ()
• PROLOG (1970)
• Datalog (1977)
• Various expert systems
#!/usr/bin/ruby
• sh (1971) while line = gets do
• perl (1987) csvs = line.split /,/
if(csvs[0] == “330”) then
• Python (1991) ...
• Ruby (1993)
CMSC 330 Spring 2017 33
Ruby
An imperative, object-oriented scripting
language
• Created in 1993 by Yukihiro Matsumoto (Matz)
• “Ruby is designed to make programmers happy”
• Core of Ruby on Rails web programming framework
(a key to its popularity)
• Similar in flavor to many other scripting languages
• Much cleaner than perl
• Full object-orientation (even primitives are objects!)
“world”
Parser Static
Analyzer
Source
Intermediate
Representation
Compiler / Interpreter
• Portability of programs
• Develop on one computer system, run on another
Programming environment
• External support for the language
• Libraries, documentation, community, IDEs, …
• Orthogonality
• Every combination of features is meaningful
• Features work independently
Meyerovitch
CMSC 330& Rabin,
Spring 2017“Empirical analysis of programming language adoption”, OOPSLA’13
50
Summary
Programming languages vary in their
• Syntax
• Style/paradigm
• Semantics
• Implementation
They are designed for different purposes
• And goals change as the computing landscape
changes, e.g., as programmer time becomes more
valuable than machine time
Ideas from one language appear in others