Code: From PHP to Jennifer
From PHP to Jennifer: the code
The Jennifer programs behind the slides, plus the PHP side of the comparison tables. Run everything from this folder with Jennifer 0.26.0; only web.j and sql.j need more than that.
declare.j: "Declare before you use". Run:jennifer run declare.jjuggling.j: every row of "No type juggling" and "Numbers keep their promises", with the errors caught and printed so the program runs to the end. Run:jennifer run juggling.jstrings.j: "Strings", plus a raw single-quoted string. Run:jennifer run strings.jarrays.j: "One array becomes two types", prints the three prices in insertion order. Run:jennifer run arrays.jobjects.j: "Objects become values", printsAda has 150. Run:jennifer run objects.jmatch.j: "match, as in PHP 8", printsgone. Run:jennifer run match.jexceptions.j: "Exceptions, without finally", printsfunds: too little. Run:jennifer run exceptions.jimports.jwithutil.j: "include, Composer and Packagist", animportof a local module and the built-injsonlibrary. Run:jennifer run imports.jweb.j: "The web: a server, not a request". Listens on 127.0.0.1:8080 until stopped with Ctrl-C. Run:jennifer run web.j, thencurl http://127.0.0.1:8080/hello/AdaanswersHello, Ada!sql.j: "Databases without PDO", the slide's query with the setup around it (it drops and recreates auserstable with three rows). Needs a PostgreSQL server, for exampledocker run -d --name academy-pg -e POSTGRES_USER=academy -e POSTGRES_PASSWORD=academy -e POSTGRES_DB=academy -p 127.0.0.1:55432:5432 postgres:16. Run:DSN=postgres://academy:academy@127.0.0.1:55432/academy jennifer run sql.j(prints1 Ada,2 Alan,3 Grace); remove the server afterwards withdocker rm -f academy-pg.php/juggling.php.txtandphp/basics.php.txt: the PHP column of the tables and the PHP snippets from "Declare before you use" and "Strings", to compare. They are PHP scripts saved as.txt(the code folder holds no.phpfiles) and need PHP 8, for examplecd php && docker run --rm -i php:8.3-cli php < juggling.php.txt(printsbool(true),int(6),truthy,int(42),float(3.5),int(3),int(-1)andfloat(9.223372036854776E+18)).
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 2.2 KiB | raw |
| arrays.j | 304 B | raw |
| declare.j | 110 B | raw |
| exceptions.j | 276 B | raw |
| imports.j | 301 B | raw |
| juggling.j | 1002 B | raw |
| match.j | 171 B | raw |
| objects.j | 306 B | raw |
| php/basics.php.txt | 284 B | raw |
| php/juggling.php.txt | 341 B | raw |
| sql.j | 928 B | raw |
| strings.j | 279 B | raw |
| util.j | 267 B | raw |
| web.j | 272 B | raw |