Next Scripting Framework - The next generation OOP

// = Next Scripting Framework - The next generation OOP :id: c2f600a2-46fd-436d-aa90-59cf99d96833 :author: Andrei Clinciu :website: https://andreiclinciu.net/ :publish_at: 2017-03-13 19:15:00Z :heading_image: /images/blog/old_uploads/next-scripting-framework-825x510.jpg :description: \N :type: article :tags: :keywords: :toc: left :imagesdir: ../assets/

image::{heading_image}[] NSF is a highly flexible Tcl based, object oriented scripting language which can be used to build other OOP languages like NX. + NX is the next generation object oriented programming system. + It;s one of the things that kept me going and developing software in Tcl an obscure yet powerful language. + It’s also per default supported with the file:///home/lostone/Notebooks/CyberProSecurity/Articles_Blog/Tcl/NaviServer.txt[NaviServer] webserver and the OpenACS platform. + I’ve used TclOO for my Codru - LostMVC web framework and then switched and rewrote everything in NSF / NX.

https://next-scripting.org/xowiki/docs/nx/tutorial/index1[A tutorial that scratches the surface of the powerful NX/NSF will help you in getting started.]

It has some unique things which change the way you write OOP programs. It was built on the strengths of XOTcl.

We have https://next-scripting.org/xowiki/docs/nx/api/Class/man[nx::Class] and https://next-scripting.org/xowiki/docs/nx/api/Object/man[nx::Object] + Both are interconnected and form the power of the system.

NX’s power is drawn from the fact that you can create objects directly without having any class. It’s kind of what javascript does with objects but at an extraordinary level. + Those objects can then inherit certain functions via mixin + This is a simple and clean way to generate singletons for example. + We can create new objects dynamically and on the fly. + This means that we can dynamically change the structure of an object and a class while the code is running. + Hot code patching as we may call it. + The power of the system is that we can then pass an object around in a variable (passed by reference). + This way I was able to create some funky stuff.

One of the biggest powers of NX/NSF is it’s introspection functions which allows you to analyze filters, methos, mixins, slots, variables.. and precedence of functions.

== Dynamic Code

NX/NSF support dynamic state changes. Dynamic behavior changes. + Dynamic changes of the class structure and dynamic software composition. + We can also dynamically inject code.

https://next-scripting.org/xowiki/docs/nx/nx-code-evolution/index1[Read more about the dynamic nature of NSF and NX at it’s homepage.]

== Parameters

NX presents us with again something unique. We can implement positional and non positional parameters. + This means we can pass paramters to a function without having to remember the exact position in the function. + Increasing productivity and decreasing bugs.

…. obj function -x 3 -y 134 abcobj function -y 3 -z “Oh yeah” -y 134 abc ….

 

We can easily make the non positional paramters optional.

=== Here are some examples of the beauty of NX.

https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-unknown-method.html?html-content=1[Unknown Method Call] + Whenever a command doesn’t exist you don’t want to give an error. You’d rather try to figure out what the user wants to do! + Or maybe log this somewhere? The possibilities are endless! Thank you Tcl for the unknown construct idea.

Container + https://next-scripting.org/xowiki/file/docs/nx/examples/traits-simple.html?html-content=1[Simple Traits] + https://next-scripting.org/xowiki/file/docs/nx/examples/traits-composite.html?html-content=1[Composite Traits] + https://next-scripting.org/xowiki/docs/nx/api/Class/man[Attributes]

https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-abstract-type.html?html-content=1[Abstract Type] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-add-variable.html?html-content=1[Add variable] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-classes.html?html-content=1[Classes] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-constraint-genericity.html?html-content=1[Constraint Genericity] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-delegates.html?html-content=1[Delegates] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-multiple-distinct.html?html-content=1[Multiple Distinct Objects] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-clone.html?html-content=1[Polymorphic Copy] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-polymorphism.html?html-content=1[Polymorphism] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-serialization.html?html-content=1[Object Serialization] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-single-inheritance.html?html-content=1[Single Inheritance] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-singleton.html?html-content=1[Singleton] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-tokenizer.html?html-content=1[Tokenizer] + https://next-scripting.org/xowiki/file/docs/nx/examples/rosetta-tree.html?html-content=1[Tree]

=== Conclusion

Having used NX and NSF in multiple projects for almost 2 years I can certainly say that it helped me write better software.

Subscribe to my Newsletter

Receive emails about Linux, Programming, Automation, Life tips & Tricks and information about projects I'm working on