https://martimm.github.io/gnome-gtk3/content-docs/tutorial/Application/sceleton.html , abbreviated:
In Raku, it is important that the main program is kept small. This is because all code, program and modules are parsed and compiled into an intermediate code which will be executed by a virtual machine. Most of the time that will be MoarVM but there is also a JVM and later possibly others. Anyways, before running, the compiled modules are saved into .precomp directories but not the program. This means that the program always get parsed and compiled before running and that is the reason to keep it small.
use UserAppClass; my UserAppClass $user-app .= new; exit($user-app.run);
Well, you can’t get smaller than this …, or maybe use this one-liner;
exit(UserAppClass.new.run)
.The rest of the code is defined in the UserAppClass.
Very good.
Now, our program needs to accept arguments.
sub MAIN
does parsing arguments and generating$*USAGE
gratis, so we would utilizesub MAIN
.
We putsub MAIN
into ause
d by.raku
program.rakumod
but we get the.raku
program ignorant of the arguments. Andsub MAIN
is not executed when in a module.
We putsub MAIN
into the.raku
program so that it understands arguments but it is no longer small.Furthermore, embedded
POD
for the program is probably expected to reside in the.raku
program.
PutPOD
into ause
d by.raku
program.rakumod
and we get thePOD
somewhat hidden.
PutPOD
into the.raku
program and again it is no longer small.Also, are there any naming conventions for such an approach?
Say, you have a programReport when your coffee is ready
. Itssub MAIN
is incoffee-ready.raku
, and youuse
aQueryCoffeeMachine.rakumod
.
You change the layout of your files and now for the same programReport when your coffee is ready
you have acoffee-ready.raku
launcher, acoffee-ready.MAIN.rakumod
withsub MAIN
's functionality in it and aQueryCoffeeMachine.rakumod
.
I believeQueryCoffeeMachine.rakumod
stays intact,
I feelcoffee-ready.raku
should also keep the name despite changing its contents
but how shouldcoffee-ready.MAIN.rakumod
be named?