function main()
{
// top-level landmark
}
The brace creates a strong horizontal break before the file’s primary behavior.
JavaScript formatting / applied
Formatting is not decoration. It gives every kind of code a known address, makes names carry shape, and lets control flow read from top to bottom.
function users_group_by_role(users)
{
const out = {};
for (const user of users) {
out[user.role] ??= [];
out[user.role].push(user);
}
return out;
}
module.exports = users_group_by_role;
Before reading a line, you should already know where dependencies, policy, behavior, helpers, and execution live.
#!/usr/bin/env node
const cli = require('@vbarbarosh/node-helpers/src/cli');
const fs = require('node:fs');
const REPORT_LIMIT = 31;
cli(main);
function main()
{
// public behavior
}
function format_percent(value)
{
return `${value}%`;
}
The unusual part is intentional: module-level declarations form landmarks; nested behavior stays visually compact.
function main()
{
// top-level landmark
}
The brace creates a strong horizontal break before the file’s primary behavior.
function main()
{
function limit_print(limit) {
console.log(limit);
}
}
Nested declarations, callbacks, and control flow keep the brace on the declaration line.
A function is a verb phrase. Data is a noun phrase. The assignment reads like a small, testable sentence.
Imperative verb markers announce an operation.
users_group_by_role(users)functionusers_index_by_id(users)functionitems_sort_by_time(items)functionNoun shape and plurality announce what is stored.
users_by_roleRecord<role, User[]>user_by_idRecord<id, User>items_sorted_by_timeItem[]const users_by_role = users_group_by_role(users);
usersPlural: one key can return many users._by_roleData lookup: bracket access, or .get() on a Map; never a function call._group_by_Verb marker: this side performs the grouping.The result is longer by line count and shorter by interpretation time. Shape, mutation, and exit are all exposed.
const group = (arr) =>
arr.reduce((acc, x) => {
(acc[x.role] ||= []).push(x);
return acc;
}, {});
const result = group(users);
module.exports = group;
function users_group_by_role(users)
{
const out = {};
for (const user of users) {
out[user.role] ??= [];
out[user.role].push(user);
}
return out;
}
module.exports = users_group_by_role;
No accumulator protocol to mentally execute. The loop says what exists, what is missing, what changes, and what leaves.
The plural parameter states the incoming collection.
outThe local return container has one conventional name.
for...of and singular user expose cardinality.
outThe constructed result exits once, at the bottom.
Explicit construction makes the output contract reviewable. A spread silently couples it to every future source field.
The output grows whenever item grows.
return {...item, index};
The output changes only when this code changes.
return {uid: item.uid, parent_uid: item.parent_uid, index};
A library ends with one export. A script hands main to cli(main); after globals.
A script declares main first; a library uses a domain-first function name.
Plurality, _by_, and _sorted_by_ agree with the value.
Guards return early; loops are explicit; deep pipelines are gone.
out?The caller gives it the domain name after the function returns.
Dependencies, object fields, helpers, and execution are visible.