Writing Good Code in Flow-Wing
Style Conventions
- File extension:
.fg - Indentation: 4 spaces
- Variable names:
camelCase - Type names:
PascalCase - Function names:
camelCase
Naming
/; Good
var userName: str = "Alice"
type Point = { x: int, y: int }
class HttpClient {
init() -> nthg {
}
}
/; Avoid
var un: str = "Alice"
type point = { X: int, Y: int }
File Organization
- One module per file
bringimports at the top- Types and classes before functions
fg_main()at the bottom (or omit for simple scripts)
Error Handling
Always check Err::Result return values:
bring file
bring Err
fun loadData() -> nthg {
var content: str, werr: Err::Result = file::readText("data.txt")
if (werr.isErr()) {
println("Failed: " + werr.getMessage())
return :
}
/; use content ...
}
loadData()
Debugging
- Use
print()for quick inspection - Use
io::printLog()for structured logging - Compile with
--emit=irto inspect generated LLVM IR - Run with
make run-aot-debug FILE=your.fgfor debug mode