So, you’ve managed to print "Hello, world!" without crashing your machine. Excellent. Now comes the part where we actually make the computer remember things. Welcome to variables and types—the stuff that keeps our programs from just being gloriously useless static messages.
Declaring variables: To infer or not to infer
In Skink, we like to keep things tidy. If the compiler can figure out what a variable is, I usually let it. It saves typing, and frankly, I have enough to worry about to be spelling out int every five seconds.
module main
fn main() -> int {
x := 10 // The compiler knows this is an int
y := 3.14 // This is obviously a float
name := "Skink" // And yes, that's a string
print("{x} {y} {name}")
return 0
}
Sometimes, though, you want to be explicit. Maybe you’re feeling pedantic, or maybe you just want to be absolutely sure the compiler doesn't guess wrong and ruin your afternoon. Use var for that:
var count: int = 10 var price: float = 3.14 var label: string = "item"
The usual suspects: Common types
Here’s the catalog of things you can hold in your virtual hands. It’s pretty standard stuff, but that’s a good thing—I don't need my programming language to be "exciting" when I'm trying to debug a memory leak. I need it to be boring and predictable.
| Type | Example | Description |
| int | 42 | A signed integer. For when you need to count things. |
| float | 3.14 | Floating-point number. Use for precision (until it stops being precise, which it inevitably will). |
| bool | true | The classic true or false. Binary life. No grey areas allowed. |
| string | "hello" | Text. Handle with care, strings are where bugs go to hide. |
| byte | byte(65) | A single byte. Sometimes you just have to work at the metal level. |
Constants
If you have a value that shouldn't change—like the MAX_RETRIES for a connection that keeps dropping because the router is acting up again—use const. It’s a good way to tell your future self, "don't touch this, it's brittle."
const MAX_RETRIES = 5
Arrays: A row of things
Arrays are just boxes in a line. We start counting at 0—because why make life easy for the human when we can make it logical for the CPU?
scores := [85, 92, 78] first := scores[0] // Grabs the 85
Type casting
Sometimes you have a float but you need an int. Don't sweat it. You can force a conversion, though keep in mind that when you shove a float into an int, it’s going to lose whatever was after the decimal point. It’s a bit like rounding down your age; it feels good, but it's technically losing data.
value := 3.7 rounded := int(value) // That's a 3 now. Simple.
Putting it together
Let’s calculate something small. Something that actually computes.
fn main() -> int {
width := 10
height := 4
area := width * height
print("Area: {area}")
return 0
}
Exercises
Don't just read it—get your hands dirty:
- The Age Check: Store your age in a variable and print a sentence that includes it. See if the interpolation handles it gracefully.
- Temperature Log: Create an array of three floating-point temperatures. Print just the first one. Bonus points if you find a way to print the last one without crashing.
- The Truncation Test: Take a float value, cast it to an int, and print both. Does the result surprise you, or is it exactly what the manual promised?
Next
When you're ready to make your code stop just running top-to-bottom like a mindless drone, we'll look at Control flow.