Scripting Languages that Begin with - PowerPoint PPT Presentation

About This Presentation
Title:

Scripting Languages that Begin with

Description:

Scripting Languages that Begin with P : Perl, PHP and Python Les LaCroix, 79 Associate Director of Network Services Carleton College – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 26
Provided by: LesL240
Category:

less

Transcript and Presenter's Notes

Title: Scripting Languages that Begin with


1
Scripting Languages that Begin with P Perl,
PHP and PythonLes LaCroix, 79Associate
Director of Network ServicesCarleton College
2
This program is brought to you by the letter
Pand the numbers
5, 4 and 2
3
Who is this guy?
  • lt15 years as Network/Systems Administrator small
    programs (lt10,000 lines of code)
  • lt10 years Software Engineer moderate
    (100,000-500,000 lines of code) to large systems
    (gt1,000,000 lines)
  • Programmed in C, C, Fortran, Basic, Pascal,
    assembly languages, Java, Perl, PHP, Python

4
Who is this guy?
  • Worked in an AI group
  • Won a technology innovation award while employed
    for a major computer manufacturer for designing a
    hardware configurator calculus

5
What are scripting languages?
  • Early scripting languages ran commands in
    batches (e.g. DOS .BAT files, Unix shells sh,
    csh)
  • More recent languages are just high-level,
    practical programming languages
  • Scripting languages are the bread and butter
    tools of network, system and web administrators

6
Where did these particular languages come from?
  • Larry needed to create reports from a bug
    tracking system
  • Rasmus wanted to track users visiting is online
    resume
  • Guido wanted hobby project to keep him busy
    during the week around Christmas

7
Common features
  • Typeless
  • Similar available basic data types
  • numbers
  • strings
  • arrays
  • associative arrays (a.k.a. hashes or dictionaries)

8
Common features
  • Dynamically sized structures (strings, arrays,
    hashes)
  • C-like structs emulated with hashes
  • Classes, objects, methods
  • Can be thought of as interpreted languages (as
    opposed to compiled)
  • Portability

9
What are they good for?
  • Prototyping/Rapid development
  • Small programs (lt100,000 lines)
  • Web development

10
What are they not so good for?
  • Writing efficient code
  • Software engineering moderate (100,000-500,000
    lines) to large programs
  • no argument checking or type checking
  • encapsulation is a convention, not enforced
  • Distributing applications where you want to
    protect the source code

11
Common features
  • Extensibility in C
  • Common extensions
  • file-level input/output
  • math functions
  • command call-out (system, pipes)
  • network service connectivity (e.g. databases,
    LDAP, IMAP)
  • CGI parsing, web server integration

12
Perl
  • Larry Wall created Perl because awk didnt cut it
  • Perl is to awk as Picard is to Kirk
  • Perl is great with strings
  • Strings are good a very common administration
    practice is to take the human-readable output of
    one program and munge it into a script

13
Perl
  • Perl 5.4 has been around for years relatively
    few innovations in 5.5 and 5.6
  • Took off with Web/CGI
  • OOP, extensibility as an afterthought.
    (Implementation is reasonable anyway.)

14
Perl
  • There is more than one way to do it.
  • accommodates multiple programming paradigms
  • can lead to obfuscated coding (see later
    examples)
  • Perl Poetry poems have been written in Perl and
    have appeared in non-computer publications (e.g.,
    The Economist)

15
Why is Perl good with strings?
  • Simple, built-in operations for string
    transliteration, replication, and
    regular-expression pattern matching (with or
    without substitution)
  • transliteration variable tr/A-Z/a-z/
  • replication variable x 5
  • r.e. matching variable /pattern/
  • with subs. var s/pattern/replacement/

16
Examples
  • reverse the letters of each word in a string,
    leaving everything else intact
  • v s/\w/reverse()/eg
  • exchange first two words in the string, leaving
    spacing and punctuation intact
  • v s/(\w)(\W)(\w)/321/

17
So what?
  • Simple operations are trivial
  • Complex patterns can be expressed as terms with
    spacing and coding to make things legible.
    (Other languages insist that patterns are
    fundamentally strings.)

18
So what?
  • Matching is always a multi-valued operation (did
    anything match, what matched, what came before
    and after, and were there submatches)
  • Results imported transparently into local name
    space or expression stack. Other languages have
    baggage to get to any of it just in case you
    wanted to get to all of it.

19
PHP
  • Started as a macro language for HTML
  • Feels like a toy language
  • Clumsy string manipulation, OOP, extensibility
  • Wonderfully integrated with HTML seamless
    intermixing of PHP and HTML

20
Example PHP program
  • ltHTMLgtltHEADgtltTITLEgtSample PHP Programlt/TITLEgtlt/HE
    ADgtltBODYgtltPgtThe day of the week islt?php
    current_date getdate(time()) print
    current_dateweekday?gtlt/Pgtlt/BODYgtlt/HTMLgt

21
Python
  • Designed by a credible programming language
    designer
  • Objects, classes, exception handling and
    extensibility are core features, not add-ons
  • All things are First Class Objects None,
    numbers, strings, compound data types, functions,
    classes, bound methods

22
Python
  • Used for RAD (Rapid Application Development), GUI
    programming, Web programming, system
    administration
  • Not great at string handling
  • Very good with class inheritance, object
    persistence

23
Python
  • There are fewer ways to do it
  • language specifically reduces the number of
    different, natural ways to code an expression
  • Program block structuring enforced by indentation
    rather than punctuation or keywords
  • Supposedly leads to more readable programs

24
Sample Python program
  • Mail all Python source files (.py) in the
    current directory to me!/usr/local/bin/python
    import glob, osfor filename in
    glob.glob(.py) print filename
    os.system(mail me_at_carleton.edu -s s lts
    (filename,filename))

25
Conclusion
  • Use the best tool dont drive a screw with a
    hammer
  • Avoid religious wars no one is ever completely
    wrong or right
  • Have fun
  • Write home often
Write a Comment
User Comments (0)
About PowerShow.com