Comentários
Nesta página
Comentários em Zolo servem para explicar intenções, desabilitar código
temporariamente e organizar visualmente seções longas. Há dois estilos:
linha (//) e bloco (/* */).
Um comentário de linha começa em // e vai até o fim da linha. É o estilo
mais comum para anotações curtas junto ao código:
Comentários de linha, bloco e bloco aninhado; separadores visuais com --; convenções TODO/FIXME/NOTE/HACK/SAFETY.
// ============================================================
// Comments in Zolo
// ============================================================
// -- Line comments --------------------------------------------
// This is a simple line comment.
// Everything after // until the end of line is ignored by the compiler.
let x = 42
// trailing comment at end of line
// You can use comments to disable code:
// let debug = true
// print("debug mode active")
// -- Block comments -------------------------------------------
/* This is a block comment.
It can span multiple lines.
Useful for describing large sections of code. */
let y = 10
/* inline value */
/* Block comments can be nested:
/* this is a block inside another block */
and this is still part of the outer comment
*/
// -- Visual sections with comments ----------------------------
// Use decorative lines to separate sections of code:
// -- Constants -------------------------------
const PI = 3.14159
const MAX_RETRIES = 3
// -- Helper functions ------------------------
fn helper(x: int) -> int {
return x * 2
}
// -- Main logic ------------------------------
let result = helper(21)
print("Result: {result}")
// -- TODO / FIXME / NOTE --------------------------------------
// Common conventions in comments:
// TODO: implement input validation
// FIXME: this function does not handle negative values
// NOTE: this algorithm has O(n^2) complexity
// HACK: temporary workaround until the parser is fixed
// SAFETY: safe call because we validated bounds above
fn sum(a: int, b: int) -> int {
// TODO: add overflow check
return a + b
}
print("sum: {sum(10, 20)}")
Requer a CLI/host do Zolo — abra no playground ou rode localmente.
Blocos /* */ podem se aninhar — abrir um bloco dentro de outro ainda
faz parte do comentário externo. Isso facilita comentar seções que já contêm
comentários internos sem quebrar nada.
As marcações TODO, FIXME, NOTE e HACK são convenções amplamente
reconhecidas por editores e ferramentas de análise estática. Use-as para
sinalizar trabalho pendente e decisões deliberadas.
Desafio
Adicione um comentário // TODO: a uma função do exemplo e use o separador
visual // -- Nome ------ para organizar o arquivo em seções. Note como a
leitura melhora apenas com estrutura de comentários.
Veja também