faq | docs | tutorials | guide | reference | contact | home  


LANGUAGE COMPARISON

The FGL environment provides the best-of-breed of procedural and object-oriented languages for the creation of standalone and web-based applications. The following examples compare FGL source code to a variety of languages, including PHP, Python, and ASP. Specific comparative examples include:

  1. Hello World [FGL,PHP,Python,ASP]
  2. Session/Server Data [FGL,PHP,Python]
  3. Conditional Logic [FGL,PHP,Python]
  4. Forms Processing [FGL,PHP,Python]
  5. Object Processing [FGL,PHP,ASP]

Additional information comparing specific aspects of FGL to other languages is available in the products and community sections of this web site.


Hello World:

FGL:

<html>
<body>
<[ ! "Hello world" ]>
</body>
</html>
- or -
<[
    ! webHeader( )
    ! "Hello world"
    ! webFooter( )
]>
- or -
// console version
print( "Hello World" )

PHP:

<html>
<body>
<?php echo "Hello World"; ?>
</body>
</html>

Python:

<html>
<body>
<%= "Hello World" %>
</body>
</html>

ASP:

<html>
<body>
<% Response.Write("Hello World!") %>
</body>
</html>

Session/Server Data:

FGL:

<[ ! session.data( "HTTP_USER_AGENT" ) ]>


PHP:

<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>	


Python:

<%= req.subprocess_env["HTTP_USER_AGENT"] %>

Conditional Logic:

FGL:

<[
    if ( session.IsMicrosoft( ) )
        ! "<h3>session.IsMicrosoft( ) returned true</h3>"
        ! "<center><b>You are using Internet Explorer</b></center>"
    else
        ! "<h3>session.IsMicrosoft( ) returned false</h3>"
        ! "<center><b>You are not using Internet Explorer</b></center>"
    end
]>
- or -
<[
    if ( session.IsMicrosoft( ) )
        <%
        <h3>session.IsMicrosoft( ) returned true</h3>
        <center><b>You are using Internet Explorer</b></center>
        %>
    else
        <%
        <h3>session.IsMicrosoft( ) returned false</h3>
        <center><b>You are not using Internet Explorer</b></center>
        %>
    end
]>
- or -
<[
    IsMS = session.IsMicrosoft( )
    ! "You are " + ( IsMS ? "" : "not" ) + " using IE"
]>
- or -
<[
    IsMS = strati( "MSIE", session.data( "HTTP_USER_AGENT" ) )
    ! "You are " + ( IsMS ? "" : "not" ) + " using IE"
]>


PHP:

<?php
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) {
?>
<h3>strstr must have returned true</h3>
<center><b>You are using Internet Explorer</b></center>
<?php
} else {
?>
<h3>strstr must have returned false</h3>
<center><b>You are not using Internet Explorer</b></center>
<?php
}
?>


Python:

<% if req.subprocess_env["HTTP_USER_AGENT"].count("MSIE"): %>
<h3>count() must have found "MSIE" at least once</h3>
<center><b>You are using Internet Explorer</b></center>
<%/%>
<% else: %>
<h3>"MSIE" does not occur in the HTTP_USER_AGENT variable</h3>
<center><b>You are not using Internet Explorer</b></center>
<%/%>

Forms Processing:
Using the following form:
<form action="action.xxx" method="POST">
 Your name: <input type="text" name="name">
 Your age: <input type="text" name="age">
 <input type="submit">
</form>

FGL:

    Hi <[ ! session.var( "name" ) ]>.
    You are <[ ! session.var( "age" ) ]> years old.
- or -
<[
    name = session.var( "name" )
    age = session.var( "age" )
]>
    Hi <[ ! name ]>.
    You are <[ ! age ]> years old.
- or -
<[
    name = session.var( "name" )
    age = session.var( "age" )
    ! "Hi " + name + " You are " + age + " years old."
]>


PHP:

    Hi <?php echo $_POST["name"]; ?>.
    You are <?php echo $_POST["age"]; ?> years old.


Python:

    Hi <%= form["name"] %>.
    You are <%= form["age"] %> years old.

Object Processing:

FGL:

LIBRARY \fgl\libs\oracle.flb

CLASS oracle_object
  PRIVATE:
    local user, pass, db
    
  PUBLIC:
    local err
    
    METHOD new( user, pass, db )
        ::user = user
        ::pass = pass
        ::db = db
        ::err = null
        return( 1 )
    END

    METHOD db_open( )
        if ( ! OracleLogon( ::user, ::pass, ::db ) )
            ::err = OracleError( )
            return( 0 )
        end
        return( 1 )
    END
        
    METHOD db_close( )
        if ( ! OracleLogoff( ::db ) )
            ::err = OracleError( )
            return( 0 )
        end
        return( 1 )
    END
    
    METHOD command( cmd, params )
    	local rval = OracleCommand( ::db, cmd, params )
    	::err = OracleError( )
    	return( strempty( ::err ) ? rval : ::err )
    END
    
END

dbobj = new( "oracle_object", "smr", "pass", "mydata.db" )
if ( ! dbobj.open( ) )
    println( "Oracle error: " + dbobj.err )
    return( 0 )
end

! dbobj.command( "SELECT", "CUSTOMER_ID, NAME" )
dbobj.close( )

Click here to see a more complex FGL object example (database object wrapper)...


PHP:

class oracle_object {
  protected $theDB;
  protected $user;
  protected $pass;
  protected $db;

  function __construct($u, $p, $d) {
    $this->user = $u;
    $this->pass = $p;
    $this->db = $d;
  }

  function db_open () {
    $theDB  =  @OCILogon($this->user,  $this->pass,  $this->db);
    db_check_errors($php_errormsg);
  }

  function db_close() {
    @OCILogoff($theDB);
    db_check_errors($php_errormsg);
  }

  function __destruct () {
    print ("so long...");
  }

}


ASP:

Imports System
Imports System.Data
Imports System.Data.OracleClient
Imports Microsoft.VisualBasic

Class oracle_object

  Public Shared Sub Main()

    Dim oraConn As OracleConnection = New OracleConnection("Data 
    	Source=MyOracleServer;Integrated Security=yes;")

    Dim oraCMD As OracleCommand = New OracleCommand("SELECT 
    	CUSTOMER_ID, NAME FROM DEMO.CUSTOMER", oraConn)

    oraConn.Open()

    Dim myReader As OracleDataReader = oraCMD.ExecuteReader()

    Do While (myReader.Read())
      Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", 
      	myReader.GetInt32(0), myReader.GetString(1))
    Loop

    myReader.Close()
    oraConn.Close()
  End Sub
End Class

#####