languages and tools SA BY machine code assembly section .text global main main: mov mov mov mov int mov mov int eax, ebx, ecx, edx, 0x80 4 1 msg len eax, 1 ebx, 0 0x80 ;system call number (sys_write) ;first argument: file handle (stdout) ;second argument: pointer to message to write ;third argument: message length ;call kernel ;system call number (sys_exit) ;first syscall argument: exit code ;call kernel section .data msg len db equ "Hello, world!", 0xa $ - msg NASM (Netwide Assembler) GAS (Gnu Assembler) MASM (Microsoft Macro Assembler) assembler hello.asm (source) linker hello.o (object file) hello (executable) assembler foo.asm foo.o linker assembler baz bar.asm bar.o dynamic linking (linking at runtime) .so (Linux) .dll (Windows) high-level low-level • precise control • efficiency • expressiveness • portability compiler compiler foo.c foo.o linker compiler baz bar.c bar.o assembler foo.asm foo.o linker compiler baz bar.c bar.o interpreter interpreter hello (source) interpreter foo bar 88 + 5 2 – 9 8 * (-3 + 5) 88 + 5 2 – 9 8 * (-3 + 5) 93 88 + 5 2 – 9 8 * (-3 + 5) -7 88 + 5 2 – 9 8 * (-3 + 5) 16 as foo 1 + 2 1 + foo 4 compiler hello.java (source) virtual machine hello.class (bytecode) VM with JIT (Just-in-time) compiler hello.java (source) hello.class (bytecode) (machine code) Type error: function factorial n as val 1 while (gt n 1) # error when n is not a number as val (mul n val) as n (sub n 1) return val (factorial true) # improper type Static typing: function num:factorial num:n as num:val 1 while (gt n 1) as val (mul n val) as n (sub n 1) return val (factorial true) type # improper Static typing: function num:factorial num:n as num:val 1 while (gt n 1) as val (mul n val) as n (sub n 1) return val (factorial (foo)) as list:foo (list “hello” 14 8) as num:bar (get foo 1) # unknown type as numList:foo (numList 5 14 8) as num:bar (getNum foo 1) polymorphism (accepts varied number and/or types of inputs) (print “hello”) (print 100) (print false) function foo a b if (isNum a) … else … (foo 3 true) (foo “hello” true) function foo a b if (isNull b) … else … (foo 3 true) (foo “hello” null) function foo a b if (isNull b) … else … (foo 3 true) (foo “hello”) function num:foo num:a bool:b … function bool:foo str:a bool:b … function str:foo str:a … function num:foo num:a bool:b … function bool:foo str:a bool:b … function str:foo str:a … # illegal function num:foo str:a … # illegal function num:foo num:a bool:b … function bool:foo str:a bool:b … function str:foo str:a … (foo “hello”) (foo 3 true) function num:foo num:a bool:b … function bool:foo str:a bool:b … function str:foo str:a … as str:x (foo “hello”) function foo a if (isNum a) … else … as bar 4 if x as bar false (foo bar) function num:foo bool:a … function num:foo num:a … as num:bar 4 if x as bar false (foo bar) # illegal function num:foo bool:a … function num:foo num:a … (foo (ack)) Weak typing: • Possible to modify any bytes of data in any way. Strong typing: • Operations only treat a piece of data appropriately to its type. paradigms • imperative (do modify state) • functional (don’t modify state) • procedural (action-centered design) • object-oriented (data-centered design) • syntax • semantics • libraries • idioms • tools • compiler • linker • interpreter • text editor • debugger • profiler • version control • IDE (Integrated Developer Environment) C • 1970’s • static, compiled to machine code • “portable assembly” #include <stdio.h> int main() { printf(“Hello, world!\n"); return 0; } C++ • 1980’s • superset of C (almost) • C with OOP #include <iostream> int main() { std::cout << "Hello, world!\n"; return 0; } Objective-C • 1980’s • superset of C • C with OOP • mostly used by Apple #import <stdio.h> int main() { printf(“Hello, world!\n”); return 0; } Java • 1990’s by Sun Microsystems • static • OOP • C-style syntax • compiled to bytecode, run by VM • JVM (Java Virtual Machine) public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } } using System; C# class ExampleClass { static void Main() { Console.WriteLine("Hello, world!"); } } • 2001 by Microsoft • static • OOP • C-style syntax • compiles to bytecode, run by VM • CLR (Common Language Runtime) Visual Basic • 1990’s by Microsoft • now basically C# with different syntax Module Module1 Sub Main() Console.WriteLine("Hello, world!") End Sub End Module Perl • 1990’s • dynamic • OOP (weak) • interpreted print "Hello, world!\n"; Python • 1990’s • dynamic • OOP • interpreted • indentation-sensitive print("Hello, world!\n”) Ruby • 1990’s • dynamic • OOP • interpreted • generate webpages puts “Hello, world!\n” PHP • 1990’s • dynamic • OOP (weak) • interpreted • generate webpages <?php Print "Hello, World!"; ?> Javascript • 1990’s • dynamic • OOP (prototypes) • interpreted • C-style syntax • embedded in webpages alert(“Hello, world!\n”); Fortran • 1950’s • static • compiled • many revisions • science and engineering program hello print *, “Hello World!” end program hello Lisp • 1950’s • dynamic (print “Hello, world!\n”) • interpreted • prefix notation • meta-programming (macros) • dialects (Common Lisp, Scheme, Clojure) efficiency 1) assembly, C, C++, Objective-C, Fortran 2) Java, C# 3) Perl, Python, Ruby, PHP, Javascript • CPU • libraries • capabilities portability • functional languages (Haskell, Scala, ML, F#) • logic languages (Prolog) • shell languages (BASH) • scripting languages (Perl, Python) • data languages (HTML, XML) • query languages (SQL) • domain-specific languages • graphical languages created by (Brian Will) http://brianwill.net/