Nexus is an object-oriented, dynamically-typed, reflective programming language that aims to make the programming experience both agile and intuitive. With an embedded interpreter, natural syntax, versatile paradigm, and comprehensive class library, Nexus is a language that can be applied to a broad range of applications.
The traditional method of programming breaks down a programming task into a collection of data structures and subroutines. This programming paradigm does not scale well in complex software systems. The procedural core grows to the point where it is no-longer possible to comprehend how the system works. Consequently, this lack in comprehension leads to a greater probability of well-concealed bugs.
Object-oriented programming surfaced in the 1960s as the result of research, prompted by increasingly complex sofware. Object-oriented programming defines a collection of cooperating objects, as opposed to a group of tasks. Each object is capable of receiving messages, processing data, and sending messages to other objects. Object-oriented programming emphasizes discrete and re-usable units of programming, which leads to a comprehensive system.
Nexus has been designed from the ground up to support object-oriented programming. The central concept in Nexus is that of an object, and everything is an object, including classes and primitive data types.
Although Nexus primarily supports the object-oriented programming paradigm, it contains the necessary elements for functional and procedural programming as well.
The Nexus language supports functional programming concepts by treating methods as first-class objects. This means that a method object can be used anywhere within a program (passed as an argument to another method). The standard object collection method each demonstrates this functional efficacy. The each method is used to apply an object method to each object within a collection.
Smaller programming tasks benefit from the simplicity provided by the traditional procedural programming paradigm. Nexus can be effectively used as a procedural language when applied to programming tasks that do not require the overhead of object-oriented features.
Nexus provides a global object that accomodates methods that are defined outside the context of an object class. This provides the ability to define and use methods in much the same way as you would a subroutine in traditional languages. The methods become global subroutines in some respects.
Nexus is a fully reflective system, it provides both structural and computational reflection.
Nexus is a structurally reflective system whose structure is defined by objects. The classes and methods that define the system are themselves objects. These structural objects are created at runtime, and can be redefined at runtime as well.
Nexus also provides computational reflection, the ability to observe the computational state of the system. The current activation of a method is accessible as an object. This feature makes it possible to implement state control facilites like continuations and coroutines. To date these facilities have not been implemented.
There are two fundamental flavors of typing: static and dynamic. The difference between the two approaches lies in when types are determined and checked. With static typing, type information is gathered at compile-time and type errors are caught prior to program execution. Dynamic typing maintains type information at run-time and reports type errors as they are encountered.
Nexus is a dynamically-typed language, types are attached to values rather than variables. Dynamic type checking gives Nexus more expressive power. The programmer is less restricted by the type system and more free to write code.
The benefits of the dynamic type system include:The Nexus syntax is simple and comprehensible. It combines syntax inspired by popular programming languages, like Ruby, Lua, and C. The result is a familiar, powerful, and easy to understand syntax that promotes a natural programming experience.
Prominent attributes of the Nexus syntax include:This simple factorial function illustrates how easily you can dicipher its meaning:
method factorial(n) { if {n=0 ? 1; n * factorial(n - 1) } }
Nexus comes with a powerful set of class libraries that cover a variety of domains. Additionally, Nexus provides all of the facilities necessary to build extension libraries.
The standard Nexus library includes:Nexus performs automatic memory management. This removes the burden of allocating and freeing memory for objects, from programming tasks. The Nexus garbage collector automatically collects dead (or unreachable) objects.
Nexus implements a generational mostly-copying collector. A generational collector partitions the heap according to the age of objects, and focuses its attention on younger objects. New objects are allocated in the youngest generation (often called the nursery), and are promoted to an older generation each time they survive a garbage collection. In applications where most allocated objects are short-lived (which is the case in many applications), the generational collector is efficient because most garbage collections only examine a portion of the heap (it saves time by ignoring older objects), and because the spatial locality of objects in the nursery can improve system cache use.
In programming the occurance of errors is a distinct reality. The traditional approach to error handling is return codes. Functions are checked for return values, and if the return code indicates failure, this code is interpreted and passed up the call stack.
The error code scheme has the following disadvantages:
Exception handling is a language construct designed to handle the occurrence of some condition (exception) that changes the normal flow of execution. It addresses the shortcomings of traditional error handling approaches:
Nexus provides language-level support for exception handling. Nexus exceptions provide a means to package information about an error into an object. The resulting object is then propagated up the calling stack until the system finds code that explicitly declares that it knows how to handle the exception type.
Nexus is based on ANSI-C conventions which are easily ported to multiple platforms, including Windows and Linux.
The Nexus project was inspired by years of experience with a wide variety of programming languages. Written and designed from scratch each piece of functionality was carefully researched in order to determine the best possible implementation. In many cases, design aspects and sometimes percise functionality was adopted from other language implementations. This section gives credit where its due.
The basic architecture and design principles of Nexus are based upon the Lua programming language. Although the syntax and semantics of the two languages differ, the basic architecture is similar.
The object-oriented design principles implemented by Nexus are based upon the Ruby programming language. Nexus draws upon the purity and dynamicity of Ruby's object-oriented foundation.
The GUI library uses an abstract layout model based on the IUP portable user interface toolkit developed by Tecgraf. The GUI library implements class libraries for the IM and CD libraries as well, provided by Tecgraf.
The regular expression library is based on the free and portable approximate regex matching library TRE.