Deploy 42
In the context of 42 and AdamsTowel, there are three things that can be deployed: Executable programs, Towels and Modules.
(1/5)Deploy Towels
A towel is about the most massively useful thing a programmer can have.
A towel has immense psychological value, and you should always know where your towel is.
All the classes that we have used up to now without defining them, are defined in AdamsTowel.
They are all normal classes/libraries.
You can code without a towel, but this means starting from first principles,
which could be quite unpleasant; especially since the only
primitive things that 42 offers are Library literals
(code as first class entities), the constant
Towels are libraries providing standard functionalities and types, such as number, boolean, string and various kinds of decorators and system errors.
However, we do not expect all 42 programs to reuse the same exact towel. For hygienic reasons, in real life everyone tends to use their own towel. For similar reasons, any sizeable 42 program will use its own towel.
We expect different programs to use massively different libraries for what in other languages is the standard library. That is, there is no such thing as 'the 42 standard library'.
Using multiple Towels
Towels shines when multiple towels are used at the same time.
Different code parts build upon different set of classes. That is, by introducing multiple towels in nested scopes, the names of the other scopes areStaining Towels
If you are writing a sizeable program, or many similar programs, it make sense to enrich a towel with some pre loaded libraries and basic classes.
If you have write access to a github project under
A Stained Towel is a towel that looks like another but it is enriched by adding more things, either at the bottom.
In our example,
(2/5)Module deployment
If you start writing in 42, you will soon feel the need
to factorize your project into libraries that can
be independently tested, deployed and loaded.
We call those library
In 42 it is easy to code with multiple modules, and modules can be much smaller than usual third party libraries and frameworks in other languages.
In 42 it is possible to employ a programming model where every developer (or every pair of developers in a pair programming style) is the only one responsible of one (or more) modules and their maintenance process, while the group leader gives specifications and tests to be met by the various module developers and will glue all the code together.
Modules can be deployed in a way similar to towel deployment;
The following example code deploys a Module
using
If there were any nested classes unreachable from public classes inside
The deployed library can be imported as usual.
For example the main
All the deployed code is closed code.
Towels are closed because they contain all the code to implement strings, numbers and so on.
Modules are also closed. They have abstract classes/methods
for each of the original towel concepts (before staining), and they can be rebound
to a multitude of towels.
In particular all stained versions of the same towel are compatible.
Every needed nested library
that was not present in the original towel, will be made private.
On the other side, all the classes in the original towel will
be made abstract by
Thus, in our example,
(3/5)Deploy programs
We can run our applications inside 42, but we can also deploy them as Jars, so that they can be run as a Java application.
In 42 libraries can be directly manipulated, and
one possible manipulation is to convert them in
another format, like an executable jar or a native program
and then save the result somewhere, such as on the website where the users can download it.
For example, we could rework the code of the former chapter as follows:
>model ) ) } //.. Tast = DeployGit.jar(ToJar() on=Url"github.com/Bob/Modules42/MyApplication.jar" writer=GW.#$of(token=Secret.#$of(),message=S"..")) ]]>As you can see, we are wrapping the application code into a trait, including a second reuse of
When 42 is used to deploy an application as a Jar, you can see the whole 42 execution as a comprehensive compilation framework,
encompassing all the tools and phases that could possibly be needed into a single cohesive abstraction.
Such jar can be run with the following command
In this example we reuse AdamsTowel both outside
A 42 project testing and deploying
A common way to use 42 is to have a folder with the name of your project, containing
a folder
(4/5)Towel embroidery: Define and deploy our own towel
Towel embroidery it is like adding your initials to your towel.
While we can simply add to the end by staining, embroidery is much more powerful.
The most common embroidery tool
is
Num]:{@AbstractTowel{ "en.wikipedia.org/wiki/International_System_of_Units"}} Load$={ class method Introspection.Nested.List _baseDeps() class method Introspection.Nested.List baseDeps() = this._baseDeps().withAlso(\[ Info(Unit); Info(SI); ]) } } Secret = {...} GW = Load:{reuse [L42.is/GitWriter]} LoadDeploy = Load:{reuse [L42.is/Deploy]} DeployGit = LoadDeploy.with(writer=GW) DeployRicherTowel = DeployGit.towel( Organize:RawCode ['Load.baseDeps()->'Load._baseDeps()] [hide='Load._baseDeps()] on=Url"github.com/Bob/Modules42/SITowel.L42" writer=GW.#$of(token=Secret.#$of(),message=S"..")) ]]>Now
By using semantic URIs as ontological nodes, we can create a basis for other libraries when trying to infer the meaning of our added types. In the example above we used wikipedia links to relevant concepts. This may not be the best solution, devising a good solution for this problem would require very intense research in the area of Ontological mapping.
(5/5)Deployment: programs, libraries and towels; summary
- 42 is a metaprogramming tool. It is natural to use 42 either as a language (to run a program) or as a compiler (to deploy programs, libraries and towels).
- Indeed we expect all sizeable 42 projects to use 42 as a compiler, to produce some reusable artefacts.
-
The distinction between towels (that do not need
« » ) and modules is introduced not by 42, but by« » ; radically different towels may provide different meaning for the concepts of deploying and loading libraries/towels. -
Application developers can freely stain and embroider towels;
in this way they can adapt
« » to serve them better. However, library developers need to carefully consider the effect of embroidery.