Saltar al contenido

Comentarios

En esta página

Los comentarios en Zolo sirven para explicar intenciones, deshabilitar código temporalmente y organizar visualmente secciones largas. Existen dos estilos: línea (//) y bloque (/* */).

Un comentario de línea comienza en // y llega hasta el final de la línea. Es el estilo más común para anotaciones cortas junto al código:

Comentarios de línea, bloque y bloque anidado; separadores visuales con --; convenciones TODO/FIXME/NOTE/HACK/SAFETY.

01-comments.zolo
Playground
// ============================================================

// 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)}")

Requiere la CLI o el host de Zolo; ábrelo en el playground o ejecútalo localmente.

Los bloques /* */ pueden anidarse — abrir un bloque dentro de otro sigue siendo parte del comentario externo. Esto facilita comentar secciones que ya contienen comentarios internos sin romper nada.

Las marcas TODO, FIXME, NOTE y HACK son convenciones ampliamente reconocidas por editores y herramientas de análisis estático. Úsalas para señalar trabajo pendiente y decisiones deliberadas.

Desafío

Añade un comentario // TODO: a una función del ejemplo y usa el separador visual // -- Nombre ------ para organizar el archivo en secciones. Observa cómo mejora la lectura solo con la estructura de comentarios.

Consulta también

Buscar en Zolo

9 resultados

enespt-br