License stuff

Dear programmers,

When I look at code, in 99% of the cases each file starts with a copy-pasted license.
Instead each file should start with a short description what the file is for. Which is almost never there. So let’s start with a description and put the license downstairs :slight_smile:

Best wishes, Eric

4 Likes

Or just put the license in a LICENSE file and don’t repeat it in each file at all. That’s what the vast majority of projects do these days, adding at most an SPDX-License-Identifier, though even that is rare.

7 Likes

To slightly hijack the thread, what happened to the idea that imports might be better off relegated to the bottom of the file too? It’s Zig, so it’s fine for them to be at the very end.

fn main(init: std.process.Init) !void { ... }

...

const std = @import("std");
// dozen more imports
2 Likes

Nothing I guess.
Still it feels a bit weird to do it.

3 Likes

Works. Some people do it, some people hate it. Personal preference.

1 Like

I started doing it and I love it. My current ordering style is:

  • struct fields
  • public constants
  • heap of all other decls (functions, types, public, private; intermixed based on “vibes” - I usually try to put related things close together)
  • imports (including aliases like const assert = std.debug.assert; all sorted with :sort -i)

Ultimately, it doesn’t matter too much - you can either find stuff via ZLS, or if you don’t want/have that, an underrated property of Zig is that it is very greppable - you can just find things by searching for const MyType, fn init, etc.


EDIT: Back on topic, I personally don’t put license headers in my files, just a LICENSE file in the project root. Lately I’ve been thinking about putting the SPDX-License-Identifier thing in all files, but definitely not a whole big header like the GPL would prefer you to do.

3 Likes

I’m not a fan of that, as I’m a bit paranoid. Whenever I look at a project, the first thing I do is open zig.zon to understand what dependencies it contains. This can lead to me not even looking further into the actual source code because there are simply too many dependencies. Then, when I look at the modules, I always check the @import statement first to get a rough overview. But these are just my personal preferences after over 40 years of software development.

4 Likes

This is how I do it now, except for executables. I’m satisfied with it.

I had an LLM look at the main codebases for finding spidy-ids last summer, and they’ll turn them up anywhere, not just at the top of a file.

It blithely insisted they would only find them at the top of the file until I had it check, btw. Don’t trust clankers.

If all files in your project repository are covered by the same license (and copyright declaration, if applicable), then I agree that a LICENSE file is enough.

However, if your repository contains files with different license terms, like vendored headers and source files copied from other projects, then please consider declaring license information on a file-by-file basis using short machine-readable header comments like

// (c) 2026 John Doe
// SPDX-License-Identifier: MIT

or, alternatively, license declaration manifest files like REUSE.toml. This makes it easier for downstream users of your project audit the licenses of their dependencies (for aspects like GPL compatibility) and helps them Do The Right Thing with regard to license text reproduction and attribution requirements when distributing binaries.

3 Likes

Yeah agree. It’s nice when you can grep for spdx identifiers in mixed license repos.