Software developers all have their favourite programming
languages. We're all influenced by our history, what we're familiar with
and what we've emotionally invested ourselves in. But when it comes to what
makes one language better than another, there are a lot of theories and not
all of those theories are correct.
Java developers may boast that Java is the best because it's
the most popular language right now...and people wouldn't be using it if it
wasn't the best. Perl developers brag that their language does what you want
not what you type, second guessing the typist and hiding details. The Ruby
language minimizes physical keystrokes, allowing a person to type more words
per minute.
However, if a good computer language is one that gets the most
work done and minimizes costs, then as programs get large, the best language
is a software engineering language: one that eases code reuse, reduces
maintenance time and gives guarantees to code correctness. Out of these ideas
come strong typing, good error checking, readability, data abstraction,
polymorphism and all those other ideas they talk about in computer science
classes. As I've quoted
elsewhere, one study showed that a software engineering language can reduce development
costs (and, by implication, time) on large projects in half
(Zeigler study).
It is ironic that business with large proprietary software
collections are unlikely to chose languages the reduce costs on such collections,
opting instead to hire "gurus" in whatever language is fashionable at the time.
This was brought back to me in a recent conversation with a tech lead at a
prominent Canadian company who insisted that it really didn't matter what
programming language the company chose as long as they adopted good coding
standards and enforced peer reviews because, in his view, good programmers are
always productive and never make mistakes.
So with my Business Shell version 2.0 nearing time for release,
this is a good chance to compare it with another popular language,
PHP, and ask
if a good language really makes no difference.
First off, the Business Shell is
more than just a programming language. With PHP, if you want documentation
generation tools or a debugger, these are all separate add-on packages. With
the Business Shell, documentation management and debugging help are functions
of the interpreter itself.
Figure 1: Development Tools
Second, the Business Shell is an ensamble tool designed to
work as part of a solution with a team of other development tools throughout
a business. That's what I refer to as ABEE and I've gone to great efforts
to keep the shell compatible with these tools and the international standards
they are based on. PHP stands alone and has many features that are incompatible
with other development standards.
Figure 2: Business Shell ABEE Standard
So now let's look at a simple CGI program written in PHP
and the Business Shell and compare basic features. This is a script written
in PHP and Bush that returns a list of users from a MySQL database table.
Documentation. In the Business Shell, documentation
is a part of the language by design. In PHP, documentation can only be typed in comments.
#!/usr/local/bin/bush
pragma annotate( "File: example.bush" );
pragma annotate( "Author: Ken O. Burtch" );
pragma debug;
pragma ada_95;
pragma restriction( no_external_commands );
procedure example is
REMOTE_ADDR : constant string := "";
pragma import( shell, REMOTE_ADDR );
begin
pragma debug( `put_line( standard_error,
source_info.source_location & ": started" );` );
cgi.put_cgi_header( "Content-type: text/plain" );
-- Database query
mysql.connect( "test", "dbuser", "xyz123" );
mysql.prepare( "SELECT username FROM users" );
mysql.execute;
pragma assert( mysql.end_of_query = false );
-- Return the data
put_line( "usermachine: " & REMOTE_ADDR );
while not mysql.end_of_query loop
mysql.fetch;
put_line( "username: " & mysql.value(1) );
end loop;
mysql.clear;
end example;
Figure 3: Documentation
Standards compliance. In the Business Shell, coding
standards can be specified as a part of the language. These provide guarantees
that a script meets certain conditions. With the restriction pragma, for example,
Bush guarantees that there are no calls to operating system commands, meaning the
script is portable across operating systems. In PHP, standards can
only be enforced through peer review and there's no guarantees except my manually
examining the program.
#!/usr/local/bin/bush
pragma annotate( "File: example.bush" );
pragma annotate( "Author: Ken O. Burtch" );
pragma debug;
pragma ada_95;
pragma restriction( no_external_commands );
procedure example is
REMOTE_ADDR : constant string := "";
pragma import( shell, REMOTE_ADDR );
begin
pragma debug( `put_line( standard_error,
source_info.source_location & ": started" );` );
cgi.put_cgi_header( "Content-type: text/plain" );
-- Database query
mysql.connect( "test", "dbuser", "xyz123" );
mysql.prepare( "SELECT username FROM users" );
mysql.execute;
pragma assert( mysql.end_of_query = false );
-- Return the data
put_line( "usermachine: " & REMOTE_ADDR );
while not mysql.end_of_query loop
mysql.fetch;
put_line( "username: " & mysql.value(1) );
end loop;
mysql.clear;
end example;
Figure 4: Standards Compliance
Debugging Statements. In the Business Shell, debugging
statements are a part of the language. They can be isolated and can be enabled
or disabled without editing the source
code. (Though in the case of a CGI script where command line options are not
configurable in the web browser, you may have to edit a single "pragma debug"
for a move to production.) In PHP, debugging statements must be controlled with
multi-line if's or deleted manually, both dangerous practices: the programmer runs
the risks of deleting the wrong lines, missing lines or adding typos to the source
code during moves to production.
In this example, removing "pragma debug" immediately hides all
debugging statements and asserts without further editing the source code.
[June 17/08: KB: Actually, since Bush is a shell, you can probably
put the pragma debug in your .profile startup file on your development environment.]
#!/usr/local/bin/bush
pragma annotate( "File: example.bush" );
pragma annotate( "Author: Ken O. Burtch" );
pragma debug;
pragma ada_95;
pragma restriction( no_external_commands );
procedure example is
REMOTE_ADDR : constant string := "";
pragma import( shell, REMOTE_ADDR );
begin
pragma debug( `put_line( standard_error,
source_info.source_location & ": started" );` );
cgi.put_cgi_header( "Content-type: text/plain" );
-- Database query
mysql.connect( "test", "dbuser", "xyz123" );
mysql.prepare( "SELECT username FROM users" );
mysql.execute;
pragma assert( mysql.end_of_query = false );
-- Return the data
put_line( "usermachine: " & REMOTE_ADDR );
while not mysql.end_of_query loop
mysql.fetch;
put_line( "username: " & mysql.value(1) );
end loop;
mysql.clear;
end example;
Figure 5: Debugging
Variables and Types. In the Business Shell, all variables
are declared and have a specific type (unless you explicitly use the universal
types, but these are intended for the command line). In PHP, with no declarations
and variables with constantly changing types, when you read a script you can never be sure if a variable
is spelled correctly or what type of data it contains. The widespread use of
associative arrays, which are accessed with string values, makes debugging even worse.
In this example, Bush guarantees that REMOTE_ADDR exists, is a string,
and has a value in the environment or the script will not run.
#!/usr/local/bin/bush
pragma annotate( "File: example.bush" );
pragma annotate( "Author: Ken O. Burtch" );
pragma debug;
pragma ada_95;
pragma restriction( no_external_commands );
procedure example is
REMOTE_ADDR : constant string := "";
pragma import( shell, REMOTE_ADDR );
begin
pragma debug( `put_line( standard_error,
source_info.source_location & ": started" );` );
cgi.put_cgi_header( "Content-type: text/plain" );
-- Database query
mysql.connect( "test", "dbuser", "xyz123" );
mysql.prepare( "SELECT username FROM users" );
mysql.execute;
pragma assert( mysql.end_of_query = false );
-- Return the data
put_line( "usermachine: " & REMOTE_ADDR );
while not mysql.end_of_query loop
mysql.fetch;
put_line( "username: " & mysql.value(1) );
end loop;
mysql.clear;
end example;
Figure 6: Variables
The Small Stuff. The things everyone takes for granted
as evils we have to live with in contemporary programming:
Slash-Star Comments. Known for being un-nestable. Removed from Bush by design.
Curly Braces. Known for being hard to read and debug. Bush uses keywords for blocks.
Optional Blocks. Known for making code maintenance difficult. Bush requires blocks for all compound statements.
Single and Double Quotes. In PHP, they're interchangeable and lead to many arguments on how to use them. In Bush, each type of quote has a unique purpose and properties.
Readability. PHP relies heavily on punctuation symbols and shifted keyboard characters. Bush favours simple English words for basic constructs (though it also has some common short-cuts if they are enabled, especially for working on the command line). Great for those 2 am debugging sessions.
Namespaces. PHP has thousands of global functions. Bush divides standard functions into packages.
These scripts are roughly the same size. But are they truly
of equivalent value to a business?
The example used here was very short: there are many more
features in the Business Shell to handle reuse, maintenance and correctness.
And many of these choices I cannot take credit for as they are based on the
software engineering language standard that Bush is using. As programs
become larger, these features have an increasingly important role in keeping
down development costs and programming time.
Still, there are people who will say, like the tech lead I
spoke with, that all programming languages are the same and they have no effect
on productivity (see also
Business Shell: Critics Say "I don't get it"). But studies...and common sense...suggest otherwise. Look for more exciting features in the
upcoming Bush 2.0.
« Truth Humility Communication Nobility Freedom Purity
Excellence Right Support Courage Compassion Quality Honesty Trust
Cooperation Challenge Education »
PegaSoft Canada - A Linux Association Since 1994