Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality. A module interface expresses the elements that are provided and required by the module. The elements defined in the interface are detectable by other modules. The implementation contains the working code that corresponds to the elements declared in the interface. Modular programming is closely related to structured programming and object-oriented programming, all having the same goal of facilitating construction of large software programs and systems by decomposition into smaller pieces, and all originating around the 1960s.
Create file a.ez
and paste there following content:
var add.=({
return(args[0].get().+(args[1].get()));
});
log(add(5 ,7));
Run it with easypt -file a.ez
It would be better to divide it into two files:
a.ez
:
var add.=({
return(args[0].get().+(args[1].get()));
});
b.ez
:
log(a.add(5 ,7));
(Now it’s a.add
, huh? That’s because all local variables in some_file.ez
are added as children to Root.some_file
node.)
Command easypt -file a.ez -file b.ez
works like a charm, but easypt -file b.ez -file a.ez
doesn’t and throws exception:
Exception at: ..Root.import
Exception at: ..Root.b
Exception at: ..Root.b.callOperator
Exception at: ..Root.b
Exception at: ..Root
Exception at: .
NotFoundException: Cannot find a in .
That’s because the fact that a
must be executed before b
.
-entryPoint
Try running command easypt -entryPoint "log(\"Hello there!\");"
(\"
quote escaping works at least in Windows cmd, if you don’t see Hello there!
output try something shell independent e.g. easypt -entryPoint log(1234);
)
As you can see -entryPoint
argument is executed (in EntryPointBlockCallable
node that is not attached as child to Root
for your curiosity) as normal code (called after last file from -file
).
You might have heard about something called main function in other languages. In Easypt it is done as following:
a.ez
:
var add.=({
auto return.=(args[0].get().+(args[1].get()));
});
b.ez
:
var main.=({
log(a.add(5 ,7));
});
Now this two files project can be executed with the far more beautiful command:
easypt -file b.ez -file a.ez -entryPoint b.main();
For advanced:
This command is also corect:
easypt -file console -entryPoint "console.writeLine(console.read());"
Many programming languages and other computer files have a directive, called import or include, that causes the contents of a second file to be available in the original file. […] They are often used to define the physical layout of program data, pieces of procedural code and/or forward declarations while promoting encapsulation and the reuse of code. The include directive allows libraries of code to be developed which help to:
- ensure that everyone uses the same version of a data layout definition or procedural code throughout a program.
- easily cross-reference where components are used in a system.
- easily change programs when needed (only one master file to change).
- save time by not needing to code extensive data layouts (minor, but useful).
From Wikipedia, modified (marked with italic) to match Easypt
import
import
function works in the same way as -file
argument. In fact -file
is handled by calling import
. See example:
lib.ez
:
var add.=({
return(args[0].get().+(args[1].get()));
});
source.ez
:
import("lib.ez");
var main.=({
log(lib.add(5 ,7));
});
Run it with command:
easypt -file source.ez -entryPoint source.main();