350 likes | 485 Views
Pike UppLYSning. nilsson@pike.ida.liu.se. Short History. LPC µLPC Cendio Roxen IS pelab. Evolved language. Pragmatic Lack of basic features Many complex/powerful features Skewed feature focus. Commercially Driven. Shorter development time Failure prevention measures
E N D
Pike UppLYSning nilsson@pike.ida.liu.se
Short History • LPC • µLPC • Cendio • Roxen IS • pelab
Evolved language • Pragmatic • Lack of basic features • Many complex/powerful features • Skewed feature focus
Commercially Driven • Shorter development time • Failure prevention measures • Wide platform/system support • Skewed feature focus
Focus • Bitmap graphics • Text processing • Network • Database
Pike vs. Other Languages • C • Java • LISP • Python • C#
Source Code • du –hs : 27M • find . | wc -l : 2680 • cvs annotate | wc -l : 610372 • Aprox. Development cost: $1 million
Hello world int main(int argc, array argv) { write(“Hello world!\n”); return 0; }
Programming Paradigms • Imperative • Functional • Object Oriented
Imperative Programming • Program blocks (if, for, while, case) • Case fall through • Labeled breaks • Symbol scopes (lexical closure) • x,y;
Functional Programming • Recursion • Well defined execution order a = x() || y(); i = i++; • Infix operators are functions `+(1,2,3) • x?y:z
OO-programming • Multiple inheritance • Named inheritance • Operator overloading • Modifiers • Type comparisons are done according to the implements-principle (looks-like). • All programs are objects
Hello world, again void create() { write(“Hello world!\n”); exit(0); }
Code environment • C-like syntax • White space insensitive • CPP-like preprocessor • Version management • Symbols may use Unicode-characters.
Coding environment • Emacs cc-mode & font-lock-mode supports Pike. • Incremental Pike front end (Hilfe) • Unused unbug
float • IEEE float-simulation • NaN, Inf • Special compilation needed for double precision.
int • Arithmetic: +, -, *, /, % • Bitwise: |, &, ^, ~ • Logical: <, >, ==, <=, >=, ! • 0 is false • Pike has no maxint.
string string a = “hello \n \” \007 \x4711 world”; string b = #”Line one and line two”; • Shared strings • Character range -0x80000000 – 0x7fffffff • Operators: +, -, *, /, %, |, &, ^ • Index operators: [a], [a..b]
mapping ([ “a” : 12, “b” : 22, “c” : 18 ]) • Operators: +, -, |, &, ^, ->, [a] • m_delete, indices, values • foreach(m; string index; int value)
arrays • Operators: +, -, &, |, ^ • Index operators: [a], [a..b] • Aggregate operators: ->, () • Splice operator: @
Array mappings • map(words, sizeof); • sizeof(words[*]); • map(words, `+, “\n”); • words[*]+”\n”; • row1[*]+row2[*]
multiset • Unordered array • multiset primes = (< 1, 2, 3, 5, 7, 11 >);
Funktions int square(int x) { return x*x; } int add(int first, int … rest) { return `+( first, @rest ); }
Programs class A { int a; void create(int _a) { a = _a; } } class A (int a) { }
Variabeltyper • Untyped variables (mixed) • Simple variable types (int) • Complex variable types (int|float) • Specified variable types (int(0..1))
Specified types • object(Stdio.File) = Stdio.File • array(int|string) • function(int, void|string : void) • array(mapping(string:int(0..127))|float)
Strict Types • Strict types (#pragma strict_types) • Runtime type checking (pike –rt) • Soft casts int(0..30) y = fac(x); int(0..30) y = [int(0..30)]fac(x);
Memory Management • Automatic & adaptive • Reference count • Advanced GC • Cyclic references • Weak references • Reference creation during destruction
Optimizations • Tree optimization • Strength reduction • Tail recursion • Peephole optimization • Native machine code generation
Why? • Easy to learn (C/Java resemblance) • Powerful data types • Competitive speed and functionality • Bug-suppressing • UNIX-like abstraction • “clean” code
Why not? • Non-standard language • Less support/knowledge/documentation • Less modules than some bigger languages
More Information • pike.ida.liu.se