Scientific programming a language comparison or why python is really the best.

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

    20-Dec-2015
  • Category

    Documents

  • view

    226
  • download

    2

Transcript of Scientific programming a language comparison or why python is really the best.

scientific programminga language comparisonor why python is really the best

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

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

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

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

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

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

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

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

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

ruby

def add(a,b) a+bend

"the better perl"

light-weight, consistent syntax

object oriented, functional

web development

good community

bioruby

slow

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)

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

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)

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

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)

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)

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

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 , ++

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

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

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

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)

??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

speed

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

2008, 12 benchmarks, linux

www.tiobe.com, 2010

www.tiobe.com

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