TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Zig, Rust, and Other Languages

139 pointsby tim_swabout 1 year ago

11 comments

coldteaabout 1 year ago
&gt;<i>Zig is not a mature language. But it has made enough useful choices for a number of companies to invest in it and run it in production. The useful choices make Zig worth talking about.Go and Rust are mature languages. But they have both made questionable choices that seem worth talking about.</i><p>Well, Zig&#x27;s native string type support, or lack thereof, is also a questionable choice. It&#x27;s not like Zig did all the right choices and only Go and Rust made questionable ones.
评论 #39722605 未加载
评论 #39722603 未加载
评论 #39722600 未加载
评论 #39722579 未加载
评论 #39722626 未加载
khaledhabout 1 year ago
Nim is also a strong player as a systems programming language. In terms of memory management, it&#x27;s configurable, and by default you get ARC (no GC). I&#x27;ve written a hobby kernel (if you can call it that) in Nim[1] as well as Zig[2], and I found Nim to be much more ergonomic and approachable. The fact that Zig requires weaving an allocator through most calls that may allocate gets in the way of what I&#x27;m trying to do. I&#x27;d rather focus on core logic and have ref counting take care of dropping memory when appropriate.<p>One thing I wish Nim had though is true sum types with payloads. I think there&#x27;s an RFC for that, but it&#x27;s a shame it&#x27;s not in the language yet.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;khaledh&#x2F;axiom">https:&#x2F;&#x2F;github.com&#x2F;khaledh&#x2F;axiom</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;khaledh&#x2F;axiom-zig">https:&#x2F;&#x2F;github.com&#x2F;khaledh&#x2F;axiom-zig</a>
评论 #39722412 未加载
评论 #39722300 未加载
slilyabout 1 year ago
&gt; People have been making jokes about node_modules for a decade now, but this problem is just as bad in Rust codebases I&#x27;ve seen<p>I agree... but I think this is more indicative of a cultural problem than a language design&#x2F;standard library scoping problem. A compact standard library is more resistant to scope creep. I don&#x27;t want every language to end up like C++, and I think keeping the scope of the standard library small helps avoid that. On the other hand, popular third-party libraries that provide common functions have too many third-(fourth-?)party dependencies. Keeping dependency trees small should be a priority for such tools, but convenience trumps all right now so it isn&#x27;t valued as it should be.
评论 #39722545 未加载
评论 #39722343 未加载
评论 #39722884 未加载
评论 #39722880 未加载
alchemioabout 1 year ago
Just a correction: most std C functions don’t allocate. strdup does but it was only recently adopted into the standard, it was previously an extension.<p>Similarly zig’s stdlib shouldn’t allocate behind your back, except for thread spawn where it does: <a href="https:&#x2F;&#x2F;github.com&#x2F;ziglang&#x2F;zig&#x2F;blob&#x2F;5cd7fef17faa2a40c8da23f0ef2485df0af39ed4&#x2F;lib&#x2F;std&#x2F;Thread.zig#L666">https:&#x2F;&#x2F;github.com&#x2F;ziglang&#x2F;zig&#x2F;blob&#x2F;5cd7fef17faa2a40c8da23f0...</a><p>Generally speaking, it’s as mentioned just a convention. A zig library might not allow its users to pass allocators for example.<p>In C++, stl containers can take an allocator as a template parameter. Recent C++ versions also provide several polymorphic allocators in the stdlib. You can also override the global allocator or a specific class’ allocator (override placement new).
评论 #39721957 未加载
评论 #39722608 未加载
thayneabout 1 year ago
WRT the standard library. There are tradeoffs. Yes, a big standard library that has everything you need is great, as long as it is well designed, well maintained, and has some mechanism to prevent the whole thing bloating every executable.<p>But executing well on that is difficult for a number of reasons:<p>- the release cycle of the standard library is (usually) tied to the compuler, which often means it can&#x27;t evolve quickly.<p>- backwards compatibility is a much bigger deal for the standard library. Which means if you have a big library you will eventually have a big pile of deprecated APIs you will probably never be able to actually remove. It also feeds into the next point - new development in stdlib can be hindered by the need to get it right the first time. - the creators of the language probably aren&#x27;t experts in every area. Which means in order to include say, a good compression library you either need to recruit someone who is an expert to write and maintain the package in your stdlib, or link to a library in another language, and the latter is still really an external depency. - a large stdlib is a large maintenance burden<p>Python has a large standard library, but it has parts that are deprecated and&#x2F;or largely abandoned, including packages for technologies that are no longer widely used. And its http packages are rarely used directly because third party packages like requests or urllib3 are better.<p>Go&#x27;s standard library that is praised here isn&#x27;t perfect either. The log and flag packages are often insufficient, and the implementation of net.IP is suboptimal [1].<p>I think probably the best balance is to start with a fairly small standard library, and when community libraries for key functionality become popular and stable, then pull them in to the standard library or otherwise make them official. And maybe have official libraries that are external to the stdlib and maybe have less rigid backwards compatibility garantees that can move faster than the language itself.<p>[1]: <a href="https:&#x2F;&#x2F;tailscale.com&#x2F;blog&#x2F;netaddr-new-ip-type-for-go" rel="nofollow">https:&#x2F;&#x2F;tailscale.com&#x2F;blog&#x2F;netaddr-new-ip-type-for-go</a>
评论 #39728096 未加载
评论 #39723615 未加载
dupedabout 1 year ago
&gt; People have been making jokes about node_modules for a decade now, but this problem is just as bad in Rust codebases I&#x27;ve seen.<p>Just w.r.t the issue of size (not of scale) - cargo caches sources in ~&#x2F;.cargo so they&#x27;re not shared by every project on the system. Additionally, rustc uses dead code elimination by design so there&#x27;s not nearly as bad an issue as in JS where it&#x27;s not possible to tree shake out every unused class or method.<p>Most of the bloat of target directories are stale incremental build artifacts, because cargo does not do any automatic cleanup.
评论 #39725177 未加载
评论 #39728040 未加载
rwbtabout 1 year ago
There&#x27;s also Odin[0] too. I experimented them all and Odin is pretty nice. Nim is also good too but a lot more features.<p>But - I concluded that language matters a lot less compared to APIs. Yes, the language should have enough good features to let the programmers express themselves, but overall well designed APIs matter a lot more than language. For example -tossing most of the C stdlib and following a consistent coding style (similar to one described here -[1]), with using Arenas for memory allocation, I can be just as productive in C.<p>[0] - <a href="https:&#x2F;&#x2F;odin-lang.org" rel="nofollow">https:&#x2F;&#x2F;odin-lang.org</a> [1] - <a href="https:&#x2F;&#x2F;nullprogram.com&#x2F;blog&#x2F;2023&#x2F;10&#x2F;08&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nullprogram.com&#x2F;blog&#x2F;2023&#x2F;10&#x2F;08&#x2F;</a>
lamontcgabout 1 year ago
&gt; Similarly, if you go looking for compression support in Rust, there&#x27;s none in the standard library.<p>I have no idea why that is considered a criticism.<p>Compression support is the kind of thing which is going to evolve over time and compression formats will change and performance and APIs of different libraries will get better.<p>You avoid the problem where the compression library in the std library is the one that experienced programmers tell all the noobs that they should never use.
评论 #39728234 未加载
评论 #39727903 未加载
Arnavionabout 1 year ago
&gt;Zig is practically alone in that if you write the next() method and and don&#x27;t pass an allocator to any method in the next() body, nothing in that next() method will allocate.<p>It&#x27;s not quite as simple as that. This can allocate just fine:<p><pre><code> fn next(self: *Self) { self.array_list.append(5); } </code></pre> ... where `array_list` is of type `std.ArrayList(u32)`. `std.ArrayList(T)` takes an allocator at construction time (`array_list = std.ArrayList(u32).init(allocator);`) and stores it as a field, so its methods don&#x27;t need to take an allocator parameter.<p>(And yes, there is a version of `std.ArrayList(T)` called `std.ArrayListUnmanaged(T)` that does *not* take an allocator in its constructor and does take an allocator in all its methods that need to allocate.)
评论 #39724301 未加载
Thaxllabout 1 year ago
Zig does not have a good package manager, does it?
评论 #39722465 未加载
评论 #39722689 未加载
评论 #39731386 未加载
评论 #39724367 未加载
评论 #39722431 未加载
eviksabout 1 year ago
&gt; 3 years? 68 lines of code. Is it not safer at this point to vendor that code?<p>Why, though? There is no bitrot or build flakiness with unnecessary changes if no changes happen, so what&#x27;s the actual argument for this? Why is it missing from the article?