# Conditionally Disabling Code with Comptime in Zig

**URL:** <https://ziggit.dev/t/conditionally-disabling-code-with-comptime-in-zig/5972>\
**Category:** Media\
**Tags:** blog-post, comptime\
**Created:** [September 12, 2024, 8:43pm UTC](https://ziggit.dev/t/conditionally-disabling-code-with-comptime-in-zig/5972 "2024-09-12T20:43:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [September 12, 2024, 8:43pm UTC](https://ziggit.dev/t/conditionally-disabling-code-with-comptime-in-zig/5972/1 "2024-09-12T20:43:14Z")

</div>

[Mitchell Hashimoto](https://mitchellh.com/) latest blog post: [Conditionally Disabling Code with Comptime in Zig](https://mitchellh.com/writing/zig-comptime-conditional-disable)

---

<div class="post-metadata">

**Author:** ![kristoff](https://ziggit.dev/user_avatar/ziggit.dev/kristoff/32/9_2.png) [@kristoff](https://ziggit.dev/u/kristoff)\
**Post date:** [September 12, 2024, 10:24pm UTC](https://ziggit.dev/t/conditionally-disabling-code-with-comptime-in-zig/5972/2 "2024-09-12T22:24:43Z")

</div>

great post

---

<div class="post-metadata">

**Author:** ![wmedrano](https://ziggit.dev/letter_avatar_proxy/v4/letter/w/d9b06d/32.png) [@wmedrano](https://ziggit.dev/u/wmedrano)\
**Post date:** [September 13, 2024, 12:32am UTC](https://ziggit.dev/t/conditionally-disabling-code-with-comptime-in-zig/5972/3 "2024-09-13T00:32:58Z")

</div>

> **Importantly, this means I can use the `adwaita` library in the runtime conditions as well as the code block and I won’t get compiler errors** if the library isn’t available or isn’t the right version or if I reference types that only exist in newer versions of the library.

This has been a double edged sword (ok, maybe just a stick) for me. The unused codepaths are gracefully avoided, but I have a hard time cleaning up real unused code after a refactor.

We’ll probably get some good automated tools to catch real unused code eventually though.

---

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [September 13, 2024, 3:39pm UTC](https://ziggit.dev/t/conditionally-disabling-code-with-comptime-in-zig/5972/4 "2024-09-13T15:39:33Z")

</div>

> [@wmedrano](#):
>
> This has been a double edged sword (ok, maybe just a stick) for me. The unused codepaths are gracefully avoided, but I have a hard time cleaning up real unused code after a refactor.

I’ve found [kcov](https://github.com/SimonKagstrom/kcov) helpful for that. It’s very simple to use with Zig, and whether you have 100% line coverage or not (I encourage this) it will show uncompiled code as blank lines, that is, it doesn’t count code which doesn’t end up in the binary for coverage, one way or the other.

Clearly one still has to distinguish between e.g. platform-specific code which just didn’t happen to compile, and actual stranded/dead code. But that should be fairly obvious, especially if it’s your own repo.
