Slide 1

Slide 1 text

Dynamic Languages on USS Matthew Finlayson IBM 8.13.2008 2927

Slide 2

Slide 2 text

Who’s presenting? • Matthew Finlayson • IT Architect • @ IBM Design Center • 10 Years Experience in Open Source • 5 Years Experience on System Z

Slide 3

Slide 3 text

What are dynamic languages?

Slide 4

Slide 4 text

4 Dynamic Languages Characteristics of Dynamic Languages • High level programming language • Dynamic typing rather than Static typing • Strong and weak typing do not matter • Executes at runtime rather than at compilation • Generally Interpreted • Automatic memory management – That’s right, no malloc! • Some dynamic languages – Perl – Python – Ruby – Javascript – Tcl – Smalltalk – Lisp

Slide 5

Slide 5 text

5 Dynamic Languages Dynamic vs. Static Typing • With Static Typed languages checking is done at compile time • Variables know the type of their objects • “Unsafe” operations rejected at compile time • Objects have one immutable type and must be cast to change type • Languages • C, C++, Java • With Dynamic Typed languages checking is done at run time • Objects know their types; variables don't care • “Unsafe” operations rejected at runtime • Objects can change type • Languages • PHP, Perl, Python

Slide 6

Slide 6 text

6 Dynamic Languages Dynamic Languages: Some Strong Typing • Strong Typing • Not associated with static typing • Python Code Example >>> 1 + “1” Traceback (most recent call last): File “”, line 1, in? TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> 1 + 1 2 >>> “1” + “1” '11' >>> 1 + int(“1”) 2 >>> “1” + str(1) '11'

Slide 7

Slide 7 text

7 Dynamic Languages Dynamic Languages: Some Weak Typing • Weak Typing • Not associated with dynamic typing • PHP Code Example

Slide 8

Slide 8 text

8 Dynamic Languages Where does your language fall? Static Dynamic Strong Weak Java Python PHP C++ C Perl Haskell

Slide 9

Slide 9 text

9 Dynamic Languages Pros and cons of static typing • Pros • IDEs can be more helpful: code completion, refactoring • Avoid errors due to mismatched types • May run faster because the compiler can optimize for types • Cons • Lots of machinery to put in place to get a program moving • Code is verbose: you have to manually specify types for variables

Slide 10

Slide 10 text

10 Dynamic Languages Pros and cons of dynamic typing • Pros • Code is less verbose • Faster development cycle edit -> compile -> test -> debug • Since the compiler is not doing error checks and errors must be run explicitly testing is part of development • Cons • Code completion is harder • No type checking at compile time • TESTING IS MORE IMPORTANT • May be lots of implicit code

Slide 11

Slide 11 text

Why use Dynamic Languages on USS?

Slide 12

Slide 12 text

Dynamic Languages Open Source projects on Freshmeat.net

Slide 13

Slide 13 text

Dynamic Languages Book Sales on Programming Languages O‘Reilly book sales in 2007

Slide 14

Slide 14 text

14 Dynamic Languages What work do they do well? • Probably not going to scale to an enterprise level tool • Eg: not for handling banking transactions • Perl good for: • Batch processing • Report generation • Small to midsize projects • PHP is good for: • Web Applications • Easier to maintain code • Small -> Large projects • Python is good for: • All of these things … just not on USS • from gluing together backend systems • to network-aware applications to • desktop and web user interfaces. • embedded devices • controlling large manufacturing systems.

Slide 15

Slide 15 text

Where can I get them?

Slide 16

Slide 16 text

3 Dynamic Languages available on USS • PHP, Perl, and Python • Usually the ‘P’ in Lamp • All three are popular dynamic open source languages • PHP and Perl are both ‘supported’ by IBM

Slide 17

Slide 17 text

17 PHP Getting Perl for z/OS Unix System Services • IBM Ported Tools for z/OS: PHP for z/OS • Provides PHP 5.1.2 for USS • PHP (PHP: Hypertext Preprocessor) is a general purpose language well suited to web development. • Preconfigured / Precompiled to address ASCII/EBCDIC conversion • Unpriced feature of IBM Ported Tools for z/OS • Requires z/OS.e V1.6 or higher • Using IBM's version saves you the pain of compiling it yourself • http://www- 03.ibm.com/servers/eserver/zseries/zos/unix/ported/php/index.ht ml

Slide 18

Slide 18 text

18 Perl Getting Perl for z/OS Unix System Services • IBM Ported Tools for z/OS: Perl for z/OS • Provides Perl 5.8.7 for USS • Perl (Practical Extraction and Report Language) is a popular general purpose language widely used in UNIX environments • Preconfigured / Precompiled to address ASCII/EBCDIC conversion • Unpriced feature of IBM Ported Tools for z/OS • Requires z/OS.e V1.4 or higher • Using IBM's version saves you the pain of compiling it yourself • http://www- 03.ibm.com/servers/eserver/zseries/zos/unix/ported/perl/index.ht ml

Slide 19

Slide 19 text

19 Python Python-Mvs: Z/OS Python Ports • Python 1.4 (old) version was available from IBM • Current version 2.4.1 is available from a third party • Major port issues were due to classic EBCDIC / ASCII pitfalls • Binary and source packages available, no need to build yourself • Not a complete port • Mostly addresses explicit conversion between ASCII/Unicode and EBCDIC • http://www.teaser.fr/~jymengant/mvspython/mvsPythonPort.html

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

21 Perl Features of Perl on z/OS USS • Perl syntax is similar to the bad parts of C, making it familiar for people with C programming skills to learn • Particularly suited for text / batch processing • AMAZINGLY Rich set of API's available • I would love to fill out a bulleted list but it would be huge • Perl for z/OS includes an extension to access DB2 for z/OS via standard perl modules allowing access to DB2 data on z/OS

Slide 22

Slide 22 text

22 Perl Path Considerations for Perl on z/OS • Typically the first line of a php script looks like this: • #!/usr/bin/perl • However the default installation path of php is /usr/lpp/perl/bin/perl • Create a symbolic link from /usr/bin/perl to the default installation path • to ensure compatibility • to prevent script changes between systems

Slide 23

Slide 23 text

23 Perl Running Perl from JCL • JCL, the Job Control Language is the heart of every job running on a z/OS system • Even if a Perl program is running on USS it is quite likely that it will be controlled from within a JCL environment • Running such a program involves more than just starting a task: • Execute the Perl program in the USS environment with output redirection using BPXBATCH • Define characteristics of datasets to hold stdout and stderr, so that these will be available on the z/OS side. • Copy the redirected output to the datasets defined before • Interpret the return code and take appropriate actions

Slide 24

Slide 24 text

Perl Example JCL (1 of 2) //PERLTEST JOB ’TEST’,’USER’,MSGCLASS=M,MSGLEVEL=(1,1), // USER=&SYSUID,NOTIFY=&SYSUID,CLASS=T //***************************************************************** //* // SET SYS=’development’ // SET DIR=’test’ // SET PRG=’db2_test.pl’ //* //***************************************************************** //* //RUNPERL EXEC PGM=BPXBATCH, // PARM=’sh perl /usr/local/&SYS/&DIR/&PRG..pl &SYS..ini’ //* //* Set environment variables //STDOUT DD PATH=’/tmp/&PRG..out’, // PATHOPTS=(OCREAT,OTRUNC,OWRONLY),PATHMODE=SIRWXU //STDERR DD PATH=’/tmp/&PRG..err’, // PATHOPTS=(OCREAT,OTRUNC,OWRONLY),PATHMODE=SIRWXU //* //* Since BPXBATCH can only redirect stdout and stderr into //* HFS-files these will now be copied back to the MVS environment //CPOUT EXEC PGM=IKJEFT01,DYNAMNBR=300,COND=EVEN //SYSTSPRT DD SYSOUT=*

Slide 25

Slide 25 text

Perl Example JCL (2 of 2) //HFSOUT DD PATH=’/tmp/&PRG..out’ //HFSERR DD PATH=’/tmp/&PRG..err’ //STDOUTL DD SYSOUT=*,DCB=(RECFM=VB,LRECL=133,BLKSIZE=137) //STDERRL DD SYSOUT=*,DCB=(RECFM=VB,LRECL=133,BLKSIZE=137) //STDOUTLF DD DSN=&&STDOUTLF, // DISP=(NEW,PASS), // SPACE=(CYL,(20,10),RLSE), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0) //STDERRLF DD DSN=&&STDERRLF, // DISP=(NEW,PASS), // SPACE=(CYL,(20,10),RLSE), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=0) //SYSPRINT DD SYSOUT=* //SYSTSIN DD * OCOPY INDD(HFSOUT) OUTDD(STDOUTL) OCOPY INDD(HFSOUT) OUTDD(STDOUTLF) OCOPY INDD(HFSERR) OUTDD(STDERRL) OCOPY INDD(HFSERR) OUTDD(STDERRLF) //* //* If something went wrong, perform some recovery actions. // IF RC NE 0 THEN ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... // ENDIF

Slide 26

Slide 26 text

Perl Accessing DB2 from Perl on USS • Accessing DB2 • All in all accessing DB2 from within a Perl program running in the USS environment is very straightforward. #!/usr/bin/perl use DBI; use DBD::DB2::Constants; use DBD::DB2; my ($username, $password) = (’DB2USR’, ’SOMEPASSWORD’); my $dbh = DBI -> connect ("dbi:DB2:ENV", $username, $password) or die "Could not connect to database! $!\n" if !defined ($dbh); my $sth = $dbh -> prepare (...); $sth -> execute (...) or die "PANIC!\n"; $sth -> finish; $dbh -> disconnect;

Slide 27

Slide 27 text

27 Perl Finding more information • General Information on PHP • http://www.perl.org • Perl core user documentation • http://www.perl.org/docs.html • Perl user mailing lists • http://lists.cpan.org • Perl-MVS List – General discussion on perl MVS • http://lists.perl.org/showlist.cgi?name=perl-mvs • z/OS Unix Implementation of PHP • http://www- 03.ibm.com/servers/resources/servers_eserver_zseries_zos_unix_perl_pdf_ hpeza200.pdf

Slide 28

Slide 28 text

I wish I had a better picture…

Slide 29

Slide 29 text

29 PHP Features of PHP on z/OS USS • PHP's syntax is similar to C and Perl, making it easy for people with basic programming skills to learn • Particularly suited for web development and can be embedded directly in HTML • Rich set of API's available, including Perl compatible regular expression library • PHP for z/OS includes an extension to access DB2 for z/OS via ODBC allowing access to DB2 data on z/OS

Slide 30

Slide 30 text

30 PHP Path Considerations for PHP on z/OS • Typically the first line of a php script looks like this: • #!/usr/bin/php • However the default installation path of php is /usr/lpp/php/5.1.2/bin/php • Create a symbolic link from /usr/bin/php to the default installation path • to ensure compatibility • to prevent script changes between systems

Slide 31

Slide 31 text

31 PHP Running PHP under IBM HTTP Server (IHS) • Enable .IHS to execute a CGI application • Configure a directory in httpd.conf to allow execution • Exec /cgi-bin/* /usr/lpp/internet/server_root/cgi-bin/* • If not set scripts will be displayed as normal files • Set the PHPRC environment variable • Makes the php.ini file accessable to the .IHS server • Set in .IHS configuration file httpd.envvars • PHPRC=/etc • Restart .IHS server • Set permissions of the php file to 0755

Slide 32

Slide 32 text

32 PHP Using PHP PDO wrapper with DB2 ODBC • z/OS DB2 Version 8.1 is the recommended version for PHP use • PDO provides a data-access abstraction layer • First set up the two following items • z/OS DB2 userid and password • DSNAOINI (DB2 ODBC initialization file) • Set the environment variable DSNAOINI like so: • putenv(“DSNAOINI=user_dir/DSNAOINI”); • user_dir is the directory where you place the DSNAOINI file • Make the following change to /etc/php.ini • [PDO] • pdo.dsn.yourdsnname=”odbc:DSN=DBW9L0C1;UID=userid;PWD=password

Slide 33

Slide 33 text

33 PHP Accessing DB2 through web applications # File: pdo_conn.inc false)); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(Exception $e) { echo “FAILED: “ . $e->getMessage(); exit(0); } ?>

Slide 34

Slide 34 text

34 PHP Query records through PDO w/ Php # File: pdo_conn.inc setAttribute(PDO::ARRT_ERRMODE, PDO::ERRMODE_WARNING); $statement = $dbconn->prepare(“select * from Cust “); $statement->execute(); $response = $statement->fetchAll(); var_dump($response); } catch(PDOException $e) { echo “FAILED: “ . $e->getMessage(); } ?>

Slide 35

Slide 35 text

35 PHP Update records through PDO w/ Php # File: pdo_conn.inc setAttribute(PDO::ARRT_ERRMODE, PDO::ERRMODE_WARNING); $statement = $dbconn->prepare(“update Cust set CustomerTel=? “); $statement->bindValue(1, “98765”); $statement->execute(); } catch(PDOException $e) { echo “FAILED: “ . $e->getMessage(); } ?>

Slide 36

Slide 36 text

36 PHP Finding more information • General Information on PHP • http://www.php.net • PHP core user documentation • http://www.php.net/docs.php • PHP user mailing lists • http://www.php.net/mailing-lists.php • MVS-OE Forum – General discussion on z/OS Unix • http://www-03.ibm.com/servers/eserver/zseries/zos/unix/bpxa1dis.html • z/OS Unix Implementation of PHP • http://www- 03.ibm.com/servers/resources/servers_eserver_zseries_zos_unix_PHP_pdf _hphza200.pdf

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

38 Python Features of Python on z/OS USS • Python syntax is somewhat similar to the others, there are core differences like whitespace delimitation, no braces, etc • Normally well suited to most any task, however on USS only the CORE functionality has been ported. This is due to ASCII EBCIDIC issues • Rich set of API's unavailable, batteries not included… • Can access DB2, only sniff tested, at this point it can only be considered a toy

Slide 39

Slide 39 text

39 Python Accessing DB2 on USS with Python #!/usr/bin/python import DB2 conn = DB2.connect(dsn='sample', uid='db2inst1', pwd='ibmdb2') curs = conn.cursor() curs.execute('select fname, lname from contacts where id=%s'%(id),) one_row = curs.fetchone() many_rows = curs.fetchmany(3) many_rows = curs.fetchall() curs.execute("insert into contacts values (?, ?, ?)", (fname, lname, addr curs.close() conn.close()

Slide 40

Slide 40 text

40 Python Some Discourse • “How important is z/OS? I'm very skeptical of the viability of any OS that uses an encoding that is not a superset of ASCII.” - Guido Van Rossum • “As a non-ASCII platform, z/OS is certainly challenging for people used to modern conventions, and that is exactly why a familiar and easy-to-use tool like Python is so valuable there.” - Lauri Alanko

Slide 41

Slide 41 text

41 Python Finding more information • General Information on Python • http://www.python.org • Python core user documentation • http://www.python.org/doc • Python user user lists • http://python.org/community/lists • z/OS Unix Implementation of Python • http://www.teaser.fr/~jymengant/mvspython/mvsPythonPort.html

Slide 42

Slide 42 text

Conclusion Ready for the enterprise?

Slide 43

Slide 43 text

Dynamic Languages Do they scale? • Size of project eg. lines of code • You can only manage so much complexity in a project • Many dynamic languages hide complexity in the language • The hidden cost here is the level of abstraction • So yes, you’ll have less lines of code for a ‘bigger’ project • IF YOU DO IT THE LANGUAGES WAY • Capacity handling, it needs to scale to X requests per second • Well, it depends on X … • Terrible answer but use it • If you need a certain functionality with a lower upfront cost • You don’t have time to develop scaffolding • Batteries Included comes at the cost of speed – just measure that cost

Slide 44

Slide 44 text

Which should I choose? • Personal preference is a strong factor between these languages • When it comes to core qualities they all add, subtract, divide and fetch URLs for you • Structure and style of the code does vary • Some languages do have features that make them more suited for particular tasks • Bigger differences often come in the libraries and frameworks (quantity and quality) that are available for the language. • A developer must weigh their project needs against the available frameworks, along with their personal preferences

Slide 45

Slide 45 text

Final Thought "From each language, according to its abilities, to each project, according to its needs.*“ – Karl Marx *Oh, except Perl. Perl just sucks, period.

Slide 46

Slide 46 text

Other Materials • PHP • http://www- 03.ibm.com/servers/resources/servers_eserver_zseries_zos_unix_PHP_pdf_hphza2 00.pdf • PERL • http://www- 03.ibm.com/servers/resources/servers_eserver_zseries_zos_unix_perl_pdf_hpeza2 00.pdf • Background Materials • (zAMP presentation) • http://www.share.org/EventDocuments/tabid/323/Default.aspx?document=proceedings/SHARE_in_Orlando/ S8524XX153116.pdf • (open source presentation) • http://ew.share.org/client_files/callpapers/attach/SHARE_in_San_Jose/S9200JE141546.pdf • Dynamic vs. Static • http://townx.org/files/dynamic_languages.pdf

Slide 47

Slide 47 text

Delicious Links • http://delicious.com/mattfinlayson • All my references are publicly available on this page • Feel free to follow up with questions, if I don’t know I’ll try to find someone who does • [email protected] • Thank You!

Slide 48

Slide 48 text

Questions