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 MAINdoes parsing arguments and generating$*USAGEgratis, so we would utilizesub MAIN.
We putsub MAINinto aused by.rakuprogram.rakumodbut we get the.rakuprogram ignorant of the arguments. Andsub MAINis not executed when in a module.
We putsub MAINinto the.rakuprogram so that it understands arguments but it is no longer small.Furthermore, embedded
PODfor the program is probably expected to reside in the.rakuprogram.
PutPODinto aused by.rakuprogram.rakumodand we get thePODsomewhat hidden.
PutPODinto the.rakuprogram 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 MAINis incoffee-ready.raku, and youuseaQueryCoffeeMachine.rakumod.
You change the layout of your files and now for the same programReport when your coffee is readyyou have acoffee-ready.rakulauncher, acoffee-ready.MAIN.rakumodwithsub MAIN's functionality in it and aQueryCoffeeMachine.rakumod.
I believeQueryCoffeeMachine.rakumodstays intact,
I feelcoffee-ready.rakushould also keep the name despite changing its contents
but how shouldcoffee-ready.MAIN.rakumodbe named?