📜 ⬆️ ⬇️

We program "at the level of an operating system"

bs Immediately discard issues of performance, security and optimality. For this sketch they are not important.

Recent topics about programming in the bat file language have reminded one such concept. It is of course written in jest, but why not. Maybe someone in my head and something will turn. ;)

I do not pretend to authorship - probably this idea has already been invented by someone earlier.
')
So. Take, for example, a program in C. We write, compile, and get a black box of a binary code. It runs in a separate area of ​​memory and is inaccessible to a simple man in the street (well, except that armed with a debager).

For a program in a scripting language, about the same thing - although the source code is at hand, but what happens in the memory of the interpreter is a dark forest.

And do not turn it all out? At the level available to the OS user. At the file system level. :)

Let it be an object oriented program.
Create a directory:
.../bin/test_prg/
The object will become a subdirectory:
.../bin/test_prg/converter/
Its properties will be just ordinary files:
.../bin/test_prg/converter/count.txt
.../bin/test_prg/converter/format.txt
His methods will be small programs:
.../bin/test_prg/converter/init.bin
.../bin/test_prg/converter/to_png.sh

Each method will perform its minor task and complete. The input will receive a list of argument files on the command line, and the result will be the file created. What will happen inside the method - while it does not matter - we will leave the black box. It is important that it will modify the properties of the object (file) as needed.

An example of running a method from another object:
: .../bin/test_prj/image/
in the property .../bin/test_prj/image/new.jpg save the original image
run the method ../convert/to_png.sh new.jpg
get the file with the standard name of the desired type “return.png” in the current directory and
we copy in property:
.../bin/test_prj/image/done.png

Alternatively, you can simply use the stdout redirect ../convert/to_png.sh new.jpg >done.png .

Or simpler example:
../math/add a.txt b.txt >c.txt

What happened? Now the insides of the "program" become visible without any special tools. It becomes a resident of the OS consisting of its elements, and not something foreign, sucked to it through the umbilical cord API. :))

Something like this was laid down in the mechanism of environment variables. And a bit like the CGI implementation.

Is there any good in this joke? Who knows.
Of the benefits - this approach preserves the state of the program when restarting the OS. It remains only to run the desired method for the event.
Well, as a simple visual aid for learners, programming can also be useful.

ps. Protected methods can be protected by the access rights of the OS itself. And objects belong to individual users of the OS (methods run on their behalf). Although for this illustration you can do without it.

Source: https://habr.com/ru/post/75682/


All Articles