What is Slang?
Slang is an object orientated scripting language with a static type system.
Why name it Slang?
Slang stands for scripting language as well as for slang (see
https://en.wikipedia.org/wiki/Slang), since its syntax resembles Java, but with subtile differences.
How stable is it?
Currently it is more of a concept than a real world language because there are still a lot of issues to cope with
(inferior performance compared to major languages and the occational bugs here and there), but it resembles what I
initally wanted to create.
I love the power of native languages like C++ (especially since newer standards cleaned up the language a lot) but
I honor what Java and its ecosystem has brought to the world of software development even though it was still in
its infancy when I first got in contact with it. Slang visually resembles Java but with some additional features
borrowed from C++ that, in my mind, would make a perfect language out of it like operator overloading, RAII and
the magic 'const' word. In Slang you can const everything. Methods, parameters, locals, return values and even
classes (which I call objects; I don't get the classes thing that every OO language does. Since we are object
oriented, shouldn't we be oriented to objects instead of classes..?).
How fast is it?
Not so fast, actually. This is due to its nature of not being a language compiled to binary.
Since Slang isn't that fast - a problem that many interpreted languages share - I implemented an extension system
to be able to extend the language with new features and to enhance the performance of specific tasks.
extensions A collection of extensions which were originally
included in the main project featuring access to System V message queues, pipes, a JSON serializer and extensions
for HTTP servers to be able to access GET and POST data.
extBase64 Base64 encoding/decoding for Slang
extCurl Create cURL requests from Slang
extJson JSON serializer
extMariaDB Connect to a MariaDB database
extMySQL Connect to a MySQL database
extSQLite3 Connect to a SQLite3 database file
As a second option to extend the functionality of Slang (slang) I implemented a package manager (slang-pkg) that is able
to download modules from a central repository (stable) and has
some knowledge about module versions.
System Library The Slang
standard library
MysqlObject MySQL
entity serializer
libBehaviourTree
Behaviour tree module
libCSVReader CSV
reader module
And there's of course a debugger (slang-dbg) to do some basic debugging of Slang scripts. It's able to create
breakpoints, add watches, show the source code of the currently debugged files and store and reload debugging
sessions, so that one doesn't have to add breakpoints and watches again and again.
Using Slang as an application server
Recently slang-app joined the Slang processes family acting as an application server, in case you want to
improve the speed of your web API.
Very early in its history Slang has been used as replacement for PHP on web server's backends due to it's apparent
benefits as a statically typed language, simply by adding "DirectoryIndex index.slang" and "AddHandler cgi-script
.slang" to your Apache WebServer config. Although working like a charm it also brought its limitations with it. Like
firing up a new instance of Slang with every request, which then needed to parse all the script files again and again.
slang-app, together with Apache's CGI features, now allows to use Slang as a pre-initialized environment (meaning:
parsing and initalization is already done), which then is automatically forked by Apache and the correct endpoint method
being executed, thus eliminating the need to re-parse your scripts.
# Example of Apache WebServer config using slang-app with FastCGI as an application server:
ScriptAlias /api/v2 /path/to/your/api/v2/app.fcgi
<Directory "/path/to/your/api/v2">
Options +ExecCGI +FollowSymlinks
AddHandler fcgid-script .fcgi
Require all granted
AllowOverride None
</Directory>
Unfortunately, this approach uses a little bit more memory since all your endpoints currently need to be
integrated into a single script. Below the example of Cryptofox's API version 2 using slang-app.
#!/usr/bin/env -S slang-app --verbose
// Library imports
import libJsonBuilder;
// Project imports
import libs.API;
import libs.Database.Utils;
import Private;
import Public;
public void Main( int argc, string args )
{
}
public void Default()
{
print( "Cryptofox API v2:" );
print( "=================" );
print( "" );
print( "- ping" );
PrivateAPI.Default();
PublicAPI.Default();
print( "- time" );
}
public void Ping()
{
Json.AddElement( "result", "pong" );
print( Json.GetString() );
}
public void Time()
{
Json.AddElement( "iso", strftime( "%Y-%m-%dT%H:%M:%S" ) );
Json.AddElement( "epoch", time() );
print( Json.GetString() );
}