If you've been following these tutorials, your main.skink file is probably starting to look like a junk drawer—you know the one, filled with batteries, loose change, and that one key you've been meaning to identify for three years. When your code gets big enough that you can't find anything, it's time to break it up.
Modules: The "Clean Desk" policy
In Skink, we don't just dump everything into one file. We use modules. Every file starts by declaring what module it belongs to. This is the first step in telling the compiler, "Hey, this code belongs to a specific team," and it's how we keep our namespace from becoming a lawless wasteland.
module math_utils
If you want code from one file to be usable in another, you have to be intentional about it. You mark it pub (for public). If it isn't marked pub, it stays private—hidden away so you don't accidentally break it from somewhere else.
// math_utils.skink
module math_utils
pub fn double(x: int) -> int {
return x * 2
}
Importing: Reaching across the aisle
To use that double function, you have to import the file. It’s as simple as telling your main file where to look.
// main.skink
module main
import "math_utils"
fn main() -> int {
// We prefix it with the module name so there's no confusion
result := math_utils.double(7)
print("{result}")
return 0
}
The Standard Library: Don't reinvent the wheel
You don't have to build everything from scratch. Skink comes with a std/ directory full of pre-built tools. Need to pause your program? Use the time module. I use this a lot when I need a runaway process to just sit still for five seconds and let me think.
import "std/time"
fn main() -> int {
time.SleepMs(500) // Give the CPU a quick nap
return 0
}
Compilation: Letting the compiler do the heavy lifting
When you're ready to build, you don't need to list every single file. You just point the compiler at your entry point, and it’ll follow the import breadcrumbs to find everything else.
SKINK_HOME=/path/to/skink-lang skink -o myprogram main.skink
It’s surprisingly smart; just make sure your file paths are clean, or you'll be spending your afternoon chasing "file not found" errors instead of writing actual features.
Exercises
Get your workspace organized before the clutter wins:
- The Shape Split: Take that Rectangle struct from Tutorial 5 and move it into a shapes.skink file with the module shapes.
- The Import: Update your main.skink to import the new shapes module and instantiate a Rectangle.
- The Wall of Privacy: Add an internal helper function to shapes.skink (without the pub keyword) and try to call it from main.skink. Watch the compiler get upset at you—it’s a useful lesson in boundary-setting.
Next
When you're ready to talk about the inevitable—because things will break—we'll tackle Error handling.