Modules vs Scripts, what's the diff?

Hello community,

Reading libr’as documentation we can read that

But still from a product point of view it’s hard to grasp the differences and wgat part of business logic should be defined where.
Is there a caritative soul able to explain (like i’m 5!) how modules and scripts are related ? How are they different if both need to be created and compiled ?

I understand that a custom transaction script will invoke a (custom) module

But why dont we just define everything on the custom script ?

Thanks !

Here is what the Move paper says on transaction scripts:

Move adds flexibility to Libra via transaction scripts. Each Libra transaction includes a transaction script that is effectively the main procedure of the transaction. A transaction script is a single procedure that contains arbitrary Move code, which allows customizable transactions. A script can
invoke multiple procedures of modules published in the blockchain and perform local computation on the results. This means that scripts can perform either expressive one-off behaviors (such as paying a specific set of recipients) or reusable behaviors (by invoking a single procedure that encapsulates the reusable logic).

Essentially, a transaction script is like a main procedure and modules are libraries of reusable code that the main procedure can use.

But why dont we just define everything on the custom script ?

This question is somewhat similar to saying for (e.g.) Java: “why don’t we define everything in main and not allow classes”?

  • If there were only transaction scripts and no modules, it would not be possible to create custom resources or “smart contracts” (because scripts cannot define resources).
  • If there were only modules and no transaction scripts, even code that the transaction submitter intends to execute a single time would need be published on the blockchain forever. This would discourage useful one-off behaviors.
1 Like