4 ms·
IMO tree-shaking and similar stuff must be not an afterthought, but instead built into language and tooling from the day one.
by vbezhenar 3y ago
IMO tree-shaking and similar stuff must be not an afterthought, but instead built into language and tooling from the day one.
- fransje26 3y agoDo you happen to know languages that implement that? I vaguely remember remember some Zig post on the topic, but I don't remember if it was an idea exploration, or an implemented feature.
- marcosdumay 3y agoI can't name any language that was born with it. Most have it on the standard tools, but I don't think any language was born with it.
- rootext 3y agoDart compiler does it, as I know.
- kyrra 3y agoOne nice thing about go is that it ships with an AST package for parsing go code. It allows building of tooling really easily. https://pkg.go.dev/go/ast https://pkg.go.dev/go/ast
- icholy 3y agoSeems like you're conflating two separate things here. The Go compiler has a DCE pass which prevents unused code from ending up in the binary. The linked blog-post describes a tool for identifying unused code in your codebase. Two completely separate use-cases.
- BoppreH 3y agoI agree that "changes the generated binary" and "displays information to the user" are separate use cases, but the compiler already does both. There's even a compiler error for unused imports and variables. Doesn't seem far-fetched to ask for the compiler to warn on unused types/functions too.
- icholy 3y agoIt's not that simple. The Go compiler uses a main package as its entry point when compiling a binary. A module can have a many main packages each using different subsets of the library packages. So there are two choices here: 1. The Go compiler complains about code which is unused by the current main package. 2. The Go compiler tries to find/compile all main packages every-time. Both of these options suck.
- mschuster91 3y agoAnd then, people start using reflection (Java), vtables/dynamic lookups (C, C++), eval (JS, PHP) and similar constructs (a lot of languages have them), and suddenly tree-shaking falls apart. Tree shaking shouldn't be necessary in 2024 anyway.
- icholy 3y agoCalling vtables "reflection" is a stretch.
- mschuster91 3y agoI was merely listing stuff that can break or severely restrict tree-shaking.
- icholy 3y agoApologies, I misread your comment. But can you elaborate on your statement that tree-shaking (more commonly referred to as dead-code-elimination) is no longer required?
- mschuster91 3y agoTree shaking was mostly a thing invented in the NodeJS ecosystem for websites to save transfer traffic and thus lead to faster page loads, as well as save a bit of RAM. Even budget phones routinely have more than 4GB of RAM, and high-speed Internet access is the norm, so you can get away with a lot more inefficiency than just a few years ago.