| This page or section is in question as to whether it is useful or not. You can discuss whether you think it should be deleted or not on its talk page. (August 2021) |
- This article is about the programming feature. For Scratch libraries, see Library.
A Library is a group of classes or functions that are used to program in a specific area. An application programming interface (API) is the interface to the library. Libraries are useful because they abstract away from implementation details and allow programmers to code without needing to understand the inner workings.
Libraries in Scratch
Scratch does not provide the ability to create and use libraries as seen in other programming languages. Scratch uses sprites for organization of code and custom blocks and broadcasts may be used for interacting with library code. However, custom blocks are limiting in that they can only be run from within the sprite they are defined, and broadcasts lack arguments or the ability to run them multiple times in a frame.
Block Packs
Block packs are projects that contain custom blocks for the use in other projects. They (or the sprite they are in) usually can be added to other projects using the backpack.
Engines
Some projects are created as "engines", which may be similar to a Block Pack as mentioned above or it may be multiple sprites interacting with each other to do something complicated, such as a 3D project. Such projects are designed to be remixed or saved as a copy so that they can be modified into a final playable project.
Libraries in Other Programming Languages
C and C++
In C and C++, libraries are accessed using the #include preprocessor directive. Conventionally, header (.h, .hpp) files contain declarations are included, but the source (.c, .cpp) files containing the corresponding definitions are not. To alleviate multiple includes, header files use include guards, the introduction of macros that are used for determining if the file has already been included.
Java
In Java, packages of classes are accessed with the import statement.
Python
In python, packages can be downloaded through the python packages website and accessed with the import statement. When importing, one should strip the .py file extension and just use the name.