+ All Categories
Home > Documents > Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Date post: 30-Dec-2015
Category:
Upload: sophie-cummings
View: 216 times
Download: 1 times
Share this document with a friend
32
Programming Languages Programming Languages Informatics I101 Informatics I101 March 22, 2004 March 22, 2004 John C. Paolillo John C. Paolillo
Transcript
Page 1: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Programming LanguagesProgramming Languages

Informatics I101Informatics I101

March 22, 2004March 22, 2004

John C. PaolilloJohn C. Paolillo

Page 2: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

ComputersComputers

• Programmable, general-purpose deviceProgrammable, general-purpose device– performs any desired computationperforms any desired computation

– the program is an arrangement of logical relations of the program is an arrangement of logical relations of bitsbits

• How does one accomplish the programming?How does one accomplish the programming?– Hard-wiring (ENIAC)Hard-wiring (ENIAC)

– Machine instructions (“code”)Machine instructions (“code”)

Page 3: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Interacting with ComputersInteracting with Computers

• OriginallyOriginally– Computer instructions are binary numbersComputer instructions are binary numbers

• ““machine code”machine code”

• Low-level languages (“assembly language”)Low-level languages (“assembly language”)– Easily-remembered mnemonics translated Easily-remembered mnemonics translated

directly into machine codedirectly into machine code

Page 4: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.
Page 5: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.
Page 6: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.
Page 7: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.
Page 8: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.
Page 9: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

High-Level LanguagesHigh-Level Languages

• CompiledCompiled– Translated into machine code in two-stepsTranslated into machine code in two-steps

• compile (into “relocatable object code”)compile (into “relocatable object code”)

• link (with various resources into machine code)link (with various resources into machine code)

– Not interactiveNot interactive

• InterpretedInterpreted– Translated into machine code and executed Translated into machine code and executed

directlydirectly

Page 10: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Some High-level LanguagesSome High-level Languages

CompiledFORTRAN

PascalCC++

TeXPerl, Java

Interpreted

LISPPascal

Unix Shell lgsDOS .BAT filesJavaScript, C#PHPPostscript

PurposeScientific,Other applications

Interactive Shells

Web support

Typesetting

Page 11: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.

Page 12: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

D.C. Engelbart’s system with mouse; Bootstrap Alliance

Page 13: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

D.C. Engelbart’s original mouse, 1964; Bootstrap Alliance

Page 14: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

D.C. Engelbart’s original mouse, 1964; Bootstrap Alliance

Page 15: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

User Interface LanguagesUser Interface Languages

• Command-line systemsCommand-line systems– UNIXUNIX– DOSDOS– VAX, TOPS-20VAX, TOPS-20– MULTICSMULTICS

• Graphic User InterfacesGraphic User Interfaces– Windows, Icons, Menus and Pointers (WIMP)Windows, Icons, Menus and Pointers (WIMP)

• Xerox StarXerox Star• MacOSMacOS• WindowsWindows• X-WindowsX-Windows

Page 16: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.
Page 17: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

What’s in a High-level What’s in a High-level Language?Language?

• Commands and built-in functionsCommands and built-in functions• Sequence/order of executionSequence/order of execution• Variables (to hold values) and assignmentVariables (to hold values) and assignment• Operators (especially for arithmetic)Operators (especially for arithmetic)• Constructs for defining Constructs for defining

– Data structuresData structures– Algorithms (programs, subroutines, functions)Algorithms (programs, subroutines, functions)

• Control structuresControl structures– if/then/else, loopsif/then/else, loops– Recursion (through the program stack)Recursion (through the program stack)

Page 18: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.
Page 19: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

<?php     // Solution to chart portion of PHP exercise 2.     // John Paolillo, October 2003.     $ncol = sizeof($_GET) ; // $_GET holds the histogram     $mx = max($_GET) ;       // maximum value     $wd = 400 ;              // width     $ht = 200 ;              // height     $cw = $wd / ($ncol + 2) ; // column width     $hh = $ht - 2 * $cw ;    // maximum height (pixels)     $ccc = $cw/2 ;       // half-width (for labels)     $b = $ht - $cw ;         // bottom line

$image = imagecreate($wd,$ht) ;     // First color defined (red) is automatically the picture background.     $red = imagecolorallocate($image, 255, 0, 0) ;     $wht = imagecolorallocate($image, 255, 255, 255) ;     ksort($_GET) ; // Sort the bars by key value while (list($key,$val) = each($_GET)) { $t = $b - ($hh * $val / $mx) ; // Bar height

$l = $l + $cw ;     // Bar left $r = $l + $cw ;      // Bar right

imagefilledrectangle($image,$l,$t,$r,$b,$wht) ; imagestring($image,1,$l+$ccc,$ht-$ccc,"$key",$wht) ; } // Chart title     imagestring($image,1,$cw,$ccc,

"Distribution of Amino Acids in Peptide",$wht) ; // Output as PNG & clean up.     header("Content-type: image/png") ;     imagepng($image) ;     imagedestroy($image) ; ?>

Page 20: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Programming ParadigmsProgramming Paradigms

• ProceduralProcedural– Step-wise proceduresStep-wise procedures

• FORTRAN, BASIC, C, PascalFORTRAN, BASIC, C, Pascal

• FunctionalFunctional– Mathematical functionsMathematical functions– Function composition, no assignmentsFunction composition, no assignments

• Scheme, XSLTScheme, XSLT

• Object-OrientedObject-Oriented– Algorithms and data “encapsulated” togetherAlgorithms and data “encapsulated” together– Objects arranged in a hierarchy of inheritanceObjects arranged in a hierarchy of inheritance

• SmallTalk, C++, SmallTalk, C++,

• Logic ProgrammingLogic Programming– Logical relationsLogical relations

• PrologProlog

Page 21: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Procedural: PHPProcedural: PHP

function factorial($n) {function factorial($n) {

if ($n == 1) {if ($n == 1) {

return 1 ;return 1 ;

} else {} else {

return n * factorial(n-1) ;return n * factorial(n-1) ;

}}

}}

Page 22: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Procedural: PostscriptProcedural: Postscript

/factorial/factorial

{ dup 1 gt { dup 1 gt

{ dup 1 sub factorial mul } if{ dup 1 sub factorial mul } if

} def} def

Page 23: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Functional: LISPFunctional: LISP

(defun fact (x)(defun fact (x) (if (<= x 0) 1 (* x (fact (- x 1))))) (if (<= x 0) 1 (* x (fact (- x 1)))))

Page 24: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Functional: APLFunctional: APL

XX

Page 25: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Functional: JFunctional: J

factorial=. 1:`(]*factorial@<:) @. * factorial=. 1:`(]*factorial@<:) @. *

Page 26: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Functional: XSLTFunctional: XSLT

<xsl:template name=“factorial”><xsl:template name=“factorial”> <xsl:param name=“val”/><xsl:param name=“val”/> <xsl:choose><xsl:choose> <xsl:when test=“$val=‘1’”><xsl:when test=“$val=‘1’”> <xsl:value-of select=“1”/><xsl:value-of select=“1”/> </xsl:when> </xsl:when> <!-- end base case --><!-- end base case --> <xsl:otherwise> <xsl:otherwise> <xsl:variable name=“factless”><xsl:variable name=“factless”> <xsl:call-template name=“factorial”><xsl:call-template name=“factorial”> <xsl:with-param name=“val” select=“$val - 1”/><xsl:with-param name=“val” select=“$val - 1”/> </xsl:call-template></xsl:call-template> </xsl:variable></xsl:variable> <xsl:value-of select=“$val * $factless”/><xsl:value-of select=“$val * $factless”/> </xsl:otherwise> </xsl:otherwise> <!-- end recursive case --><!-- end recursive case --> </xsl:choose></xsl:choose></xsl:template></xsl:template>

Page 27: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Object-Oriented: PrographObject-Oriented: Prograph

Page 28: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Logic Programming: PrologLogic Programming: Prolog

factorial(1,1) :- !.factorial(1,1) :- !.

factorial(N,FactN) :- factorial(N,FactN) :-

M is N - 1,M is N - 1,

factorial(M,FactM),factorial(M,FactM),

FactN is M * FactM.FactN is M * FactM.

Page 29: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.
Page 30: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

http://www.digibarn.com/collections/posters/tongues/ComputerLanguagesChart-med.png

Page 32: Programming Languages Informatics I101 March 22, 2004 John C. Paolillo.

Recommended