Programming Languages

Introduction

Jim Posen - ECE/CS 2014

Classifying Languages

What properties define/differentiate languages?

Typing Model

  • Static vs dynamic
  • Strong vs weak

Programming Model

  • Functional
  • Procedural
  • Object Oriented

Implementation

  • Compiled
  • Interpreted
  • JIT

Unique Features

  • Macros in Lisp
  • Monads in Haskell
  • Metaprogramming in Ruby
  • Futures in Scala

Beating the Averages

  • Essay by Paul Graham
  • Paul Graham is the man
  • How language choices directly translates to success
  • Caused a semi-revival of Lisp (but not really)
“Lisp is worth learning for the profound enlightenment experience you will have when you finally get it.” -Eric Raymond

Blub Paradox

“As long as our hypothetical Blub programmer is looking down the power continuum, he knows he’s looking down. Languages less powerful than Blub are obviously less powerful, because they’re missing some feature he’s used to. But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn’t realize he’s looking up.”

When to use a language?

Platform Mandate

  • Browsers use JavaScript
  • iOS uses Objective-C
  • Android uses Java
  • Server programming gives you more freedom

Language Fit

  • Statisticians use R
  • Engineers use Matlab
  • Language X may have the best library for Y

Speed/Scalability

  • Development time and execution time are often at odds
  • C is faster than Java is faster than Ruby
  • Ruby is easier than Java is easier than C
  • Some languages have better concurrency models
“If you have a choice of several languages, it is, all other things being equal, a mistake to program in anything but the most powerful one.” -Paul Graham, Beating the Averages

Syllabus

  • Racket Functional programming in Lisp
  • Haskell Purely functional programming, static typing done right
  • Prolog Logical/declarative programming
  • Ruby Object oriented programming done right/UNIX scripting
  • Scala Multiparadigm, concurrent

Getting Set Up

  • Linux virtual machine available (recommended)
    • All languages and environments installed
  • Scripts for OSX and Ubuntu
  • Emacs, vim, and Sublime Text installed
    • IDEs may be available for individual languages

Fundamental tools

Every programmer should be comfortable using:

  1. A shell
  2. A text editor
  3. A version control system

Shells

  • A shell is a command line interface for the terminal
  • Popular ones include bash, zsh, csh, ksh
  • The shell program reads your command line input and executes it
  • Small utilities piped together make this a very powerful paradigm

Terminal crash course

  • Builtins: cd, echo, man
  • Utilities: ls, pwd, mv, cp, mkdir, rmdir, rm, grep, sed, cat, file, less, head, sort
  • Arguments and flags used to modify behavior
  • $ ls
    $ ls -a
    $ ls -al subdirectory
    

Pipes and redirection

Unix processes have IO channels: stdout, stdin, stderr

$ echo "Hello World!" > outfile.txt
$ cat < infile.txt
$ echo "Hello World!" | wc -c

Permissions

  • Files have 9 permissions bits
  • 3 bits for each: owner, group, users
  • 1 bit for read access, 1 bit for write access, 1 bit for execute
$ ls -l file      # shows permissions
$ chmod u+x file  # allow owner to execute file
$ chmod 0644 file # read access for everyone, write access for owner

The Unix file system

  • Tree structure made of directories and files
  • Links, hard and symbolic
  • Shortcuts
    • Home directory ~
    • Root directory /
    • Current directory .
    • Parent directory ..

Text Editors

  • General purpose programs for writing files
  • Popular ones include vim, emacs, Sublime Text
  • Good text editors are extensible and have modes for different file types
  • Some are terminal based, some have a GUI
  • Choose whichever makes you most productive

Version Control

  • A program for managing revisions of the source code for a project
  • Very useful for collaboration
  • Code repositories are often hosted on a server
  • Popular ones include git, mercurial, subversion

Git

  • Distributed version control created for the Linux kernel
  • It’s NOT GitHub!
    • GitHub is a git hosting website
  • Fast, distributed, supports branching

Distributed SCM

  • Everyone has a full copy of the source code
  • A main repository is often hosted on a server
  • Protocol to push, pull, merge branches
  • Easy collaboration

Terminology

  • Repository: project tracked with git
  • Commit: a saved revision of the entire repository
  • Branch: a series of commits forming a feature
  • Master: often the main branch
  • Remote: a remote repository (often exists on a server)
  • Origin: default remote
  • Working tree: current state of all files

Basic git commands

$ git init
$ touch hello_world.txt
$ git add hello_world.txt
$ git status
$ git commit -m “Initial commit.”
$ git push