4 ms·
Wrong syntax is (and must be) an error. Totally different. The Problem in Go and Zig is that they put theory over practice: No compiler warnings is a good idea
by Phil_Latio 2y ago
Wrong syntax is (and must be) an error. Totally different. The Problem in Go and Zig is that they put theory over practice: No compiler warnings is a good idea in theory, but fails in practice for things like unused variables or unused imports. Defending that makes it even worse and begs the question what other treasures they have burried in their language design. This thread is a testament to that.
- riwsky 2y agoForbidding unused imports was a direct response to the practical difficulty of compiling google-scale C++ binaries: https://go.dev/talks/2012/splash.article#TOC_5 https://go.dev/talks/2012/splash.article#TOC_5. In theory, programmers can just be disciplined enough or set up CI lints for unused imports. In practice…
- swiftcoder 2y agoI'm sure the rest of us all benefit from arcane doctrine required to scale up a 25,000 engineer, 40,000 commit/day monorepo.
- throwawaymaths 2y agoYou do. The zig compiler and stdlib can iterate faster across a team of mostly by numbers volunteer developers with varying degrees of skill and across global timezones because of the discipline that the compiler imposes.
- em-bee 2y agoi prefer a language that doesn't even need to declare imports. why can't the compiler figure them out on its own?
- 8n4vidtmkvmk 2y agoI think you're being sarcastic, but ambiguity is the obvious answer. Your IDE can help you resolve these though.
- em-bee 2y agoi am absolutely serious. pike for example does not need imports. if a reference is not found in the local namespace the compiler will find it in the module path and resolve it by itself. there is no ambiguity because each module has a unique name. we accept type inference but don't do the same for module references? why? pike does have an import statement, but its effect is to include all members of a module into the namespace instead of just resolving the ones that are really used. and instead of speeding things up, using import on modules with lots of members may actually slow things down because the namespace is loaded up with lots of unused references. sometimes import is used to help readability, but that's rarely needed because you can solve the same with a simple assignment to a variable. if you can show me an example where import resolves an ambiguity, i'll try to show how pike solves the problem without import.
- 8n4vidtmkvmk 2y agoI don't know how it works in Zig. In JavaScript, you can have lots of things with the same name, so you need to explicitly import them and you can give them an alias at the same time if there's a clash. I believe Python is the same. In C++, you have to #include the thing you want to use somewhere, not necessarily in the same file you use it, it just has to end up in the same compilation unit. If two files define the same name, you'll end up with a compilation error. In very large projects, sometimes you won't notice this until some transitive dependency includes the other thing. I'm personally a fan of explicit imports. I imagine this helps IDEs resolve references without having to scan 1000s of files to resolve them, and it helps build tools pull in only the needed files. Regarding speed (of execution), in JS we have tree-shaking so if you import a file but don't use all of its members, those excess/used members will be dropped from the final bundle (saving on both bundle size and run-time parsing). Plus it means I don't have to spend much time thinking of a super/globally unique name for every thing I define.
- em-bee 2y agoin python every module has a unique name: import math foo = math.pi the compiler can obviously find math in the import statement. why can't it find math.pi directly? pike can.
- Phil_Latio 2y agoThis is nonsense argument, because there are more pragmatic solutions: Turn warnings into errors for release builds, or if there is only one build type, have a policy that requires developers to remove all warnings before committing code.
- 082349872349872 2y agoI'm not sure I see the total difference between matching parens and matching defs and refs. Sure, saying "an open paren must have a matching close" is quantitatively different from "a def must have at least one matching ref", but is it really qualitatively different?
- xigoi 2y agoA language that allows you to arbitrarily omit parentheses would be impossible to parse. That’s not the case for unused variables.
- 082349872349872 2y agoNot impossible: some lisps allowed arbitrary omission of close parens (upon finding a closing square bracket). https://news.ycombinator.com/item?id=29093339 https://news.ycombinator.com/item?id=29093339 http://arclanguage.org/item?id=20979 http://arclanguage.org/item?id=20979
- em-bee 2y agoHTML allows to omit closing tags for <p>, <li> and others