scientific programming

28
scientific programming a language comparison or why python is really the best

Upload: charo

Post on 11-Jan-2016

43 views

Category:

Documents


0 download

DESCRIPTION

scientific programming. a language comparison or why python is really the best. determine. programming languages. how you think what you can think of what problems you can solve. Languages shape the way we think, or don't. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: scientific programming

scientific programminga language comparisonor why python is really the best

Page 2: scientific programming

programming languages how you think

what you can think of

what problems you can solve

determine

Languages shape the way we think, or don't. Erik Naggum

Page 3: scientific programming

criteriaprototyping (scripting, light-weight syntax, succinctness, repl)

libraries (plotting, algebra, stats, optimization, ml, bioinformatics)

performance(execution speed)

multiplatform(windows, linux, mac)

scalability ( OO, encapsulation, immutability, static type system)

support(documentation, googliness, news groups)

concurrency (threading, actors, stm)

ide(Eclipse, Intelli J, Visual Studio, ...)

se short se betr me

Page 4: scientific programming

Assembly Modula 2 APL Haskell

Forth Perl LOGO Mathematica

Ada Fortran KEE Lisp Groovy R

Basic C++ Pascal Matlab

Scala Python Java C

bias

If you only have a hammer, you tend to see every problem as a nail. A. Maslow

Page 5: scientific programming

C/C++ JavaPerl RubyPython FortranRAPL Matlab ScalaHaskellClojure

386 languagespicked

http://en.wikipedia.org/wiki/List_of_programming_languages

There is no programming language, no matter how structured, that will prevent programmers from making bad programs. Larry Flon

Page 6: scientific programming

C/C++

#include <stdio.h>

int add(int a, int b) { return a+b;}

main() { printf("%d",add(1,2));}

fast

huge number of libraries

low level language

no memory management

no REPL, not for scripting

related: Objective-C, D

C is quirky, flawed, and an enormous success. Dennis M. Ritchie

Page 7: scientific programming

C#define _ -F<00||--F-OO--;int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO(){ _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_ _-_-_-_}

http://en.wikipedia.org/wiki/International_Obfuscated_C_Code_Contest

calculates pi by looking at its own area

obfuscated

Page 8: scientific programming

java

class Calc { public static int add(int a, int b) { return a+b; }

public static void main(String[] args) { System.out.println(add(1,2)); }}

object oriented

fast

JVM

huge set of libraries, biojava

no REPL, not for prototyping

related: C#

Software and cathedrals are much the same – first we build them, then we pray. Sam Redwine

Page 9: scientific programming

perl

sub add { $_[0] + $_[1]; }

the “Swiss Army Chainsaw”

designed for sys-admin jobs

huge number of libraries, bioperl

complex syntax

doesn't scale well

related: AWK, sed, sh

One day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" Larry Wall

Page 10: scientific programming

perl

@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{ @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&& close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print

http://en.wikipedia.org/wiki/Just_another_Perl_hacker

obfuscated

Though I'll admit readability suffers slightly... Larry Wall

Page 11: scientific programming

ruby

def add(a,b) a+bend

"the better perl"

light-weight, consistent syntax

object oriented, functional

web development

good community

bioruby

slow

Page 12: scientific programming

python

def add(a,b): return a+b

light-weight syntax

dynamic/duck typing

multi-paradigm

many scientific libraries, biopython

good support

doesn't scale well

related: Ruby

There should be one - and preferably only one - obvious way to do it.

t = arange(0.0, 1.0, 0.01) s = cos(4*pi*t)+2plot(t, s)

Page 13: scientific programming

fortran

INTEGER FUNCTION add(a,b) INTEGER, INTENT(IN): a,b add = a+bEND FUNCTION

old (1957) but alive

many versions: 66, 77, 90, 95, 2003

fast, compiled

many numeric/scientific libraries

not a scripting language

In the good old days physicists repeated each other's experiments, just to be sure. Today they stick to FORTRAN, so that they can share each other's programs, bugs included. E.W. Dijkstra

Page 14: scientific programming

R

add <- function(a,b) a+b

strong for stats & plotting

large number of libraries

slow

mediocre IDE

not really for scripting

related: Splus, SAS, SPSS freqs <- c(1, 3, 6, 4, 9)barplot(freqs)

Page 15: scientific programming

APL

R ← ADD XR ← +/X

array programming language

old (1964), alive but declining

special character set

many scientific/numeric libraries

related: J, K

http://en.wikipedia.org/wiki/APL_%28programming_language%29

APL code that calculates prime numbers within 1 to R

Page 16: scientific programming

matlab

function add(a,b)a+b

array programming language

high quality code, documentation

many scientific libraries

expensive

doesn't scale well

string/file processing is awkward

related: Mathematica, Maple, Octave

x = -pi:0.1:pi; y = sin(x);plot(x,y)

Page 17: scientific programming

haskell

add a b = a + b

purely functional, lazy

static inferred typing

very clean syntax

does it scale?

small community

related: OCaml, ML, F#

qsort [] = []qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)

Page 18: scientific programming

scala

def add(a:Int,b:Int) = a+b

combines OO and FP nicely

static typing with inference

scales well

JVM based

new, little but growing support

related: F#, Groovy

With great power comes great responsibility!

spiderman

Page 19: scientific programming

scala

def ++[B >: A, That](that: Traversable[B]) (bf: CanBuildFrom[List[A], B, That]): That

def qsort: List[Int] => List[Int] = { case Nil => Nil case x::xs => qsort(x filter (xs >)):::x::qsort(x filter (xs <=))}

quicksort , ++

Page 20: scientific programming

clojure

(defn add [a b] (+ a b))

prefix notation

JVM based

incanter library

concurrency supported

probably doesn't scale well

related: lisp, scheme

Lisp isn't a language, it's a building material. Alan Kay

Page 21: scientific programming

clojure

(use '(incanter core charts latex))(doto (function-plot (fn [x] ($= x ** 3 - 5 * x ** 2 + 3 * x + 5)) -10 10) (add-latex 0 250 "x^3 - 5x^2 + 3x +5") view)

incanter

Page 22: scientific programming

C 1340 6.9Java 697 17.4C++ 395 1.7C# 241 0.7Perl 66 14.9Python 186 30.6Ruby 118 1.7R 296 47.5Fortran 62 0.007Matlab 30 5.6Scala 64 0.007Haskell 10 1.4

"X language"

kilo-hits, June 2010

"X bioinformatics"

googliness

Why bother with subroutines when you can type fast? Vaughn Rokosz

Page 23: scientific programming

summary

C/C++ Java Perl Ruby Python Fortran R APL Matlab Scala

prototyping X X + + + X + + + 0

libraries + + + 0 + + + 0 + +

performance ++ + X XX X ++ X + + +

multiplatform X ++ + + + X + + + ++

scalability + ++ XX + 0 + 0 X X ++

support + + + + + + + X + 0

IDE ++ ++ + + + + 0 ? ++ 0

concurrency 0 + ? ? 0 0 ? + ? ++

File not found. Should I fake it ? (Y/N)

Page 24: scientific programming

??questions

The most important thing in a programming language is the name. A language will not succeed without a good name. I have recently invented a very good name, and now I am looking for a suitable language. Donald E. Knuth

Page 25: scientific programming

speed

http://shootout.alioth.debian.org/

2008, 12 benchmarks, linux

Page 26: scientific programming

www.tiobe.com, 2010

Page 27: scientific programming

www.tiobe.com

Page 28: scientific programming

http://www.tiobe.com

http://en.wikipedia.org/wiki/List_of_programming_languages

http://stackoverflow.com/questions/1348896/what-is-the-best-functional-language-for-scientific-programming

links