In the Beginning was the Word

In the beginning was the Word, and the Word was with God, and the Word was God, The same was in the beginning with God, says the Bible.

Well, we don't know how the universe and life was created, but languages play an essential part of the mystery. DNA, scripture, mathematics, programming languages, artificial intellegence, you name it. Languages are one of the foundations of intelligence that's for shure.

With the invention of higher programming languages, coding was detached from the hardware and a general program syntax, using natural language elements, variables, arrays, objects, arithmetic or Boolean expressions, subroutines and functions, etc., to was developed. Since then, there hasn't been something really new in the implementation of deterministic algorithms concernig the general language syntax.

AI software is another topic, as it is more a model to depict the human mind with a neural network of statistic equations and not a programming language to exactly implement an algorithm.

C became the most used compiler language, because of its efficiency and being a part of the Unix tool chain. Even Javascript, Java's JRE and Python are written in the C resp. C++ anguage. Not to forget the Unix-Shell being the anchestor of various interpreter languages like Bash, Perl, Php, etc, which are also written in C resp. C++.

Basicaly, a C programm performs some actions and outputs some text. As websites are made of HTML texts, you might want to embedded pieces of code in these texts, maybe stored in a database. This is easier achieved with languages using special characters to denote variables, functions and objects like Perl.

Printing a text in C, Perl and Shell
# C program, printing the variable Text.
int main() {
  char Text[] = "Hello World!";
  printf ("\%s", Text);
}

# Perl script, printing an embedded string.
my $Text = "Hello World!";
print "$Text\n";

# Shell script, printing an embedded string.
Text="Hello World!"
echo "$Text"

The most notable difference is that Shell, PHP and Perl uses special characters to denote variables, functions and objects, while the compiler languages, Python and Java, don't, what looks pretty nice. Javascript is something in between. Well, you can look at a program as a piece of code that prints a text or a piece of text with embedded variables and function calls that is evaluated and printed by a program. With web sites the later might be a more appropriate solution, because the main purpose of a web site is to deliver text and media files, but this depends on the actual application, of cource.

A usual application process takes some non critical actions and simply sends an HTML text to the client via a HTTP server. So, C and Java with their strict type and function parameter declarations seems like shooting sparrows with cannons. The effort to change function names, calls and parameter definitions in all sources of a big project doesn't justify the trade-off of typedefs and function prototypes.

Language purists will tear their hair out, but from my experience, errors because of prototype clashes are of no real concern with webserver programming, especially as many interfaces between the components and programs, like HTTP, CGI and database connections can't be prototyped by a programming language, anyway. However, function parameters can and should be checked by the function's code.

Perl function definition without parameter prototypes.
#!/usr/bin/env perl

sub Example { # Perl function definition without parameter prototypes.

  # Copy function call parameters to the hash %p.
  my %p = @_;

  # Copy function call parameters to the global hash %s.
  for (my $i = 0; $i < $#_; $i=$i+2) { $s->{$_[$i]} = $p{$_[$i]}; }

  # Assamble text from %s.
  my $Text = '';
  for (my $i = 0; $i < $#_; $i=$i+2) { $Text .= $s->{$_[$i]} . ", " }
  return $Text;
}

# Function calls without and with parameters.
print "Example call output: @{[ Example ]}\n";
print "Example (param1 => 'param1',) call output: @{[ Example (param1 => 'param1',) ]}\n";
print "Example (param1 => 'param1', param2 => 'param2') call output: @{[ Example (param1 => 'param1', param2 => 'param2',) ]}\n";
__END__

> perl Example.pl
Example call output: 
Example (param1 => 'param1',) call output: param1, 
Example (param1 => 'param1', param2 => 'param2') call output: param1, param2,

Note, that no type declarations are needed and that the 'Example' function's output is embedded in a string with the Perl bracketed expression '@{[ Example() ]}'. Bracketed expressions makes Perl a native interpreter for (HTML) text with embedded variables and function calls. Consequently, changing a variable, function and object name in a project's sources, boils down to find and replace all occurences of their names, and adding a parameter to a single function call doesn't require to change all the other calls of that function, indeed.

People might complain that Perl code is not human readable, a once write and then forget language hard to maintain and not suitable for big projects. Well, any language you don't know looks like hieroglyphs. Agreed, it takes a while to learn, how easy it is to define an array, hash or object with Perl and its special characters and operators. Readability and maintainability has little to do with the programming language. Programming is a talent, like with any other profession. Attempting to force programmers to write clean and verbose code doesn't always lead to readability and maintainability,

Anyway, there are various languages each having their own area, scope, advantages and limitations. After all, I find that all the modern programming languages are quite similar. In one ore another way, they are offsprings of C and its predessors.

Why is the Maxscape Webserver Library written in Perl?

The simple answer is that, the Maxscape project goes back to the year 1992 when Perl was the best choice for CGI programming because there was nothing else to consider.

Perl was the first language introducing some new, moderne features to programming. No need to declare the type of variables when it can be guessed out of the context. Bracketed expressions, as a native way to embed variables, objects and function calls within strings generated dynamicaly on-the-fly, giving a native way to embed code in a text, for example, stored in a database.

# Embedded Perl code in a text stored in a database evaluated at run-time.
...
print "... <p>@{[ $MyObject->MyMemberFunction (Text => "Welcome...") ]}</p> ...";
...

It has inspired all other interpreter languages like PHP, Java, Javascript, Python, a.s.o. in one or another way that came later.

A more complex answer is that Perl is still the best choice, at least for an application server framework like Maxscape. Web programming and Perl have things in common. Both are much about text processing and networking. There is nothing better than Perl regular expressions and its string manipulation abilities. Perl and its CPAN modules greatly supports the implementation of network protocols.

Perl has also some features that other languages simply don't have or don't support in a native way. Perl is an interpreter language that allows to generate code stored in a database to be evaluated or executed at runtime on-the-fly. No unnecessary declarations, distracting from the real algorithm like typedefs, structs, prototypes a.s.o. are imposed. I know, language purists will contradict, but the possibility of adding a parameter to a function without changing all the existing function calls are saving a lot of time. I mean, a website is not an atomic plant where security is important.

The decision to use special characters to denote variables, which is borrowed from the Unix-shell interpreter, allows to easily parse text with embeded variables and (member) function calls thus being a perfect interpreter for dynamicliy generated software embeded in a text maybe stored in a database. I am still wondering, how one can be so ingenious to release such a language in 1987.

Because Perl is open source software, it is possible to compile the interpreter from the sources to add special features like encryption of Perl sources and to statically bind module and libraries to the Perl executable.

Perl is portable to many operating systems and has a huge CPAN library of usefull and well supported language extensions, components and modules. Perl is used and supported by a hudge community.

There is a discussion about why Perl has lost some importance for web development compared to Java, Python, PHP, Ruby, JavaScript and C#. Some opinions blame this on the Perl language itself. I think that it has more to do with the companies management policy, available platforms and frameworks, development and operation environment and tools, developer knowledge, the only rudimentary support of Perl on smart phones, as well as that front-end developers need to know Javascript, anyway, so why learn Perl, if there are a back-end servers like Node.js, which can be coded in the same language.

Larry Wall - 5 Programming Languages Everyone Should Know.


PHP, Javascript, Java, Python and Perl

Perl was never designed to be a language for web development, though it was widely used in the beginning of the Internet. There was literaly nothing else available, Bash and C are not suitable for web programming.

PHP stepped into that gap, because it was explicitly designed for the web, has many web applications and is supported by a hugh community. It is by far the most used server-side programming language. All other languages have small to tiny market share, noadays.

From its early days, used for some browser gimmicks taking ages to implement, Javascript has become a robust and reliable language for front-end and back-end software and is now one of the foundations of the web.

Installation and setup of a Node.js source distribution and running a Node.js application is painless, though compilation and build took 12 hours on my labtop! Oh man, I love the beauty of this code.

Application Server Example Scripts.
// Node.js 'Hello, World!' server application:
// ===========================================

const http = require('http');

const hostname = '0.0.0.0'; // or replace with your desired IP address
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Nodejs server at http://' + hostname + ':' + port + '/ says: Hello, World!
');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

# Start the Node.js server and enter in your browser's location 'http://0.0.0.0:3000/'.
> node index.js

# =================================================================
# Equivalent Maxdaemon HTTPD configuration via the SCGI interface:
# =================================================================

# Configure 'hello.scgi' in '/maxdaemon/etc/maxdaemon-localhost.conf'
# with the 'AddScript' directive within the 'VirtualHost' entry.
...
<VirtualHost localhost:8000>
...
AddScript scgi-script    $MaxdaemonHome/hello.scgi 10000 3
...
</VirtualHos>
...

# SCGI script '/maxdaemon/hello.scgi':
======================================
...
use Maxdaemon::Daemon::SCGI_Client;

my $SCGI_Interface = Maxdaemon::Daemon::SCGI_Client->new;
$SCGI_Interface->cloneProcess ();

my $Header  = "Content-type: text/html$::CRLF";
my $Content = "Maxdaemon server at http://$hostname:$port/ says: Hello, World!";

while (my $Client = $SCGI_Interface->accept)
{
  print $Header . $::CRLF . $Content;
}

# Start the Maxdaemon server and enter in your browser's location
# 'http://localhost:8000/hello.scgi'.
> maxdaemon -c localhost start

# Maxdaemon CGI interface script example:
# ==========================================

my $hostname = 'localhost';
my $port     = 8000;
my $CRLF     = "\015\012";

my $Header   = "content-type: text/html$CRLF";
my $Content  = "Maxdaemon server at http://$hostname:$port/ says: Hello, World!";

print $Header . $CRLF . $Content;

# Maxdaemon CGI interface script with HTML skeleton:
# ==================================================

my $hostname = 'localhost';
my $port     = 8000;
my $CRLF     = "\015\012";

my $Header   = "Content-type: text/html$CRLF";
my $Content  = qq(<!doctype html>
<html>
  <body>
    <p>Maxdaemon server at http://$hostname:$port/ says: Hello, World!</p>
  </body>
</html>>
);

print $Header . $CRLF . $Content;
<--
Template main element with embedded Perl variables and object member function calls
using Maxscape's run-time system objects. Note, that category, template and page
elements are stored in the application server's content database. 
-->

<html>
<head>

$::WebServer->{'WebServer.default.content-type'}

@{[ $Page->ElementContent (Name => 'Category.Meta') ]}
@{[ $Page->ElementContent (Name => 'Page.Meta') ]}

<title>@{[ $Page->ElementContent (Name => 'Title') ]}</title>

<style type="text/css">
@{[ $Page->ElementContent (Name => 'Category.CSS') ]}
@{[ $Page->TemplateContent (Name => 'Template.CSS.Float', Type => 'parsed') ]}
@{[ $Page->ElementContent (Name => 'Page.CSS.Float') ]}
@{[ $Page->TemplateContent (Name => 'Template.CSS.PulldownMenu', Type => 'parsed') ]}
</style>

<script type="text/javascript">
@{[ $Page->ElementContent (Name => 'Category.Javascript') ]}
@{[ $Page->ElementContent (Name => 'Page.Javascript') ]}
</script>
</head>

<body>
@{[ ($Page->ElementContent (Name => 'Page.Header') ?
       $Page->ElementContent (Name => 'Page.Header')
     :
       $Page->TemplateContent (Name => 'Template.Page.Header')
     )
]}

<div class="PageRow">
  <div class="PageColumnMiddle">
    <main>

    @{[ $Page->simpleElementLoop () ]}

    </main
  </div>
</div>

@{[$Page->ElementContent (Name => 'Page.Trailor') ]}

</body>
</html>

The above text can be fetched from the content database and be evaluated by the following function:

# Perl code to parse the above template text.
...
sub parseText {
  my ($Page) = shift;
  my ($Text) = @_;

  $Text =~ s/([\%])/\\%/gs;

  $Text = eval (qq%{ return qq{$Text}; }%);
  if ($@) {
    return $Page->setError (Text => "parseText eval error: $@ in page $Page->{Category}/$Page->{Page}.");
  }
  return $Text;
}
...

Isn't that wonderfull? Just, store an HTML document in a database, fetch it at run-time on request, evaluate the embeded Perl code on the fly and send it back. Websites are all about text processing and that's where Perl is at its best.

Shell, Bash, Tcsh, Find, Grep, Sed, vi, Make, Rpm, Cvs, Git, ..

Interactive terminals using command line shells, as well as Shell/Bash/Tcsh scripts to deal with the computer's operating system are the most underestimated languages of all. They are wonderful tools for OS, host management tasks and interactive terminal command line prompts and the powerful foundation of all OS and network administration. Not to mention all of these great (Unix) tools and utilities.

Next ∙ Previous ∙ Top ∙ Join ∙ Contact © Maxscape