Hello, I'm Ganesh Kumar. I'm working on git-lrc: a Git hook for Checking AI generated code.
AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
In my previous post, I explained how empty data is represented in slices.
How Empty Slice is Represented
package main
import "fmt"
func main() {
var s []int
fmt.Println(s, len(s), cap(s))
if s == nil {
fmt.Println("s is nil")
}
}
Output:
[] 0 0
s is nil
len and cap are 0 because the slice is not initialized.
When we initialize a slice, it will have a defined length and capacity.
The underlying pointer will point to the first element of the backing array, and both the length and capacity will be set to the number of elements in that array.
Initializing a Slice with Make
make is a predefined function in Go used to create and initialize slices, maps, and channels.
Reference variables like slices are typically initialized using the make command from Go's built-in functions.
package main
import "fmt"
func main() {
a := make([]int, 5)
fmt.Println(a, len(a), cap(a))
b := make([]int, 5, 10)
fmt.Println(b, len(b), cap(b))
}
Output:
[0 0 0 0 0] 5 5
[0 0 0 0 0] 5 10
This allows you to create a slice with a specific length and capacity.
make([]T, len, cap)
- For
a := make([]int, 5), it creates a slice of length 5 and capacity 5. - For
b := make([]int, 5, 10), it creates a slice of length 5 and capacity 10.
Variable Declaration
You can also initialize a slice directly using a slice literal:
package main
import "fmt"
func main() {
a := []int{1, 2, 3, 4, 5}
fmt.Println(a, len(a), cap(a))
}
Output:
[1 2 3 4 5] 5 5
For this slice, the pointer points to the first element of the underlying array, and the length and capacity are set to the number of elements provided.
Conclusion
We learned about empty slices, initializing slices with make, and declaring slices using literals.
we explored how data is stored in a slice and examined slice modifications to understand how they work under the hood.
π Check out: git-lrc
Any feedback or contributors are welcome! Itβs online, open-source, and ready for anyone to use.
β Star it on GitHub:
HexmosTech
/
git-lrc
Free, Unlimited AI Code Reviews That Run on Commit
AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
See It In Action
See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements
git-lrc-intro-60s.mp4
Why
- π€ AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
- π Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
- π Build a habit, ship better code. Regular review β fewer bugs β more robust code β better results in your team.
- π Why git? Git is universal. Every editor, every IDE, every AIβ¦

Top comments (0)