Lecture 6 - Computer Science

Lecture 6 - Computer Science

The University of North Carolina at Chapel Hill COMP 144 Programming Language Concepts Spring 2002 Lecture 6: Introduction to Scripting Languages with Python Felix Hernandez-Campos Jan 23 COMP 144 Programming Language Concepts Felix Hernandez-Campos 1 Origin of Scripting Languages Scripting languages originated as job control languages 1960s: IBM System 360 had the Job Control Language Scripts used to control other programs

Launch compilation, execution Check return codes Scripting languages got increasingly more powerful in the UNIX world Shell programming, AWK, Tcl/Tk, Perl Scripts used to combine components Gluing applications [Ousterhout, 97] COMP 144 Programming Language Concepts Felix Hernandez-Campos 2 System Programming Languages System programming languages replaced assembly languages Benefits: The compiler hides unnecessary details, so these languages have a higher level of abstraction, increasing productivity

They are strongly typed, i.e. meaning of information is specified before its use, enabling substantial error checking at compile time They make programs more portable SPLs and ALs are both intended to write application from scratch SPLs try to minimize the loss in performance with respect to ALs E.g. PL/1, Pascal, C, C++, Java COMP 144 Programming Language Concepts Felix Hernandez-Campos 3 Higher-level Programming Scripting languages provide an even higher-level of abstraction The main goal is programming productivity Performance is a secondary consideration

Modern SL provide primitive operations with greater functionality Scripting languages are usually interpreted Interpretation increases speed of development Immediate feedback Compilation to an intermediate format is common COMP 144 Programming Language Concepts Felix Hernandez-Campos 4 Higher-level Programming They are weakly typed I.e. Meaning of information is inferred Less error checking at compile-time

Run-time error checking is less efficient, but possible Weak typing increases speed of development More flexible interfacing Fewer lines of code They are not usually appropriate for Efficient/low-level programming Large programs COMP 144 Programming Language Concepts Felix Hernandez-Campos 5 Typing and Productivity [Ousterhout, 97] COMP 144 Programming Language Concepts

Felix Hernandez-Campos 6 Python Guido van Rossum created Python in the early 90s Named after Monty Pythons Flying Circus Python is easy to learn Simple, clean syntax Elegant object-orientation Good documentation Friendly community Python is powerful Efficient high-level data structures are part of the language It has a very comprehensive set of standard libraries

It is easy to implement new functions in C or C++ COMP 144 Programming Language Concepts Felix Hernandez-Campos 7 Feeding a 26-foot python The python absolutely refused to eat anything, and while it is possible for a snake to refrain from food for a considerable period, there is an end even to the endurance of a snake. The authorities decided that extreme measures must be taken. The snake was firmly grasped by twelve men, and food, consisting of two rabbits and four guinea pigs, was pushed into its mouth by the aid of a pole. He was then put back into the cage to allow the processes of digestion to resume. (SciAm, 1902) COMP 144 Programming Language Concepts Felix Hernandez-Campos 8 IDLE

Integrated Development Environment We will follow a short tutorial: One Day of IDLE Toying http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/inde x.html Download IDLE+Python 2.2: http://www.python.org/2.2/ COMP 144 Programming Language Concepts Felix Hernandez-Campos 9 Built-in Data Structures: Numbers Integers, floating-point numbers, complex numbers, arbitrarily long integers 345 3.45 3+45j 5980273857389025087345L

Operators +, , *, /, **, %, abs(), floor(), COMP 144 Programming Language Concepts Felix Hernandez-Campos 10 Built-in Data Structures: Strings Quotes sequences of characters Comp 144\nProgramming Language Concepts Pythons tricks Raw mode rComp 144\nProgramming Language Concepts Operators

Concatenation + Programming + Language + Concepts Repetition * COMP144 * 5 COMP 144 Programming Language Concepts Felix Hernandez-Campos 11 Built-in Data Structures: Strings Positional operators

Index Slice Length string[i] string[i:j] len(string) Formatting (extended printf notation) This is %s %.1f % (python, 2.2) name = python ver = 2.2 This is %(name)s %(ver).3f % vars() COMP 144 Programming Language Concepts Felix Hernandez-Campos 12

Built-in Data Structures: Lists Ordered collection of objects They can contain any type of object They are mutable E.g. [] Empty list [1, 2, 3.0] Three-element list [1, [2, 4], 3.0] Nested list Operators Access Deletion Length list[index] del list[index]

len(list) COMP 144 Programming Language Concepts Felix Hernandez-Campos 13 Built-in Data Structures: Lists Operators Concatenation + [1, 2] + [3, 4] + [5] Repetition * [1, 2] * 5

Positional operators Index Slice Length list[i] list[i:j] len(list) Generation Ranges range(start,end,step) COMP 144 Programming Language Concepts Felix Hernandez-Campos 14

Reading Assignment John K. Ousterhout, Scripting: Higher-Level Programming for the 21st Century, 1997 http://home.pacbell.net/ouster/scripting.html Guido van Rossum and Fred L. Drake, Jr. (ed.), Python tutorial, PythonLabs, 2001. Read chapters 1 to 2 http://www.python.org/doc/current/tut/tut.html Try some examples in IDLE COMP 144 Programming Language Concepts Felix Hernandez-Campos 15 Additional References Mark Lutz and David Ascher, Learning Python, OReally, 1999.

Guido van Rossum and Fred L. Drake, Jr. (ed.), Python Reference Manual, PythonLabs, 2001. http://www.python.org/doc/current/ref/ref.html COMP 144 Programming Language Concepts Felix Hernandez-Campos 16

Recently Viewed Presentations

  • WomenDiscover Maximized Generosity. Increased Impact. For internal use

    WomenDiscover Maximized Generosity. Increased Impact. For internal use

    Activate - Be in community with other women passionate about creating change. ... Women make up 63% of the people in the church pews of mainline denominations. Women are more generous than men - We are 40% more likely to...
  • Noel Pearson - EnglishSchmenglish

    Noel Pearson - EnglishSchmenglish

    Composer: Noel Pearson. ... he is able to present his arguments in a formal and educated way and is greatly aided with his lawyer background. Throughout the speech, he is able to incorporate personal perspectives, priceless views which have indeed...
  • Lean Canvas Template

    Lean Canvas Template

    MM-DD-2017. Iteration #1. Cost Structure. Revenue Streams. Problem. Solution. Key Metrics. Key activities you measure. Unique Value Proposition. Unfair Advantage
  • Word problems. - Primary Resources

    Word problems. - Primary Resources

    Word Problems. Addition and Subtraction. Year 4 At a dance there are 15 boys and 17 girls. How many altogether? Strategy- Addition. 15+17= 32 There are 24 people on the bus. 17 more get on.
  • HEALTH SCIENCES DENTAL TERMINOLOGY 3rd  Katelyn Dombroski  Cuyahoga

    HEALTH SCIENCES DENTAL TERMINOLOGY 3rd Katelyn Dombroski Cuyahoga

    Public Health. 3rd - Cleveland Heights HS Jasmine Angel, Shariah Bell, Destiny Jones, Kaitlynne Nelson. 2nd - TRHS Sierra Corbett, Emily Croyle, Amber Patterson, Jenna Stout
  • Chapter 7: Leader-Member Exchange Theory Overview LMX Theory

    Chapter 7: Leader-Member Exchange Theory Overview LMX Theory

    LMX theory . validates. our experience of how people within organizations relate to one another and the leader. LMX theory is the only leadership approach that makes the . dyadic relationship . the centerpiece of the leadership process. LMX theory...
  • KS2 lesson Microorganisms and MicroTrumps 23 6 16

    KS2 lesson Microorganisms and MicroTrumps 23 6 16

    Some microbes are harmless, some useful and some dangerous. Match the microbes to how they get into your body and the problems they cause. Microbe Definition How does it spread Yeast Vomiting and diarrhoea Sharing food with someone who has...
  • ab initio and Evidence-Based Gene Finding

    ab initio and Evidence-Based Gene Finding

    Evidence based improvement of ab initio gene predictions ... be sure to pick the right ortholog Look at synteny with properly distant species (mouse or rat); evidence for a transposition suggests a pseudogene Chimp BAC analysis Worksheet in your folder,...