TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Criticizing Hare language approach for generic data structures

151 点作者 ayende大约 3 年前

20 条评论

formerly_proven大约 3 年前
&quot;Bring your own datastructures&quot; is likely one of the C carry-overs for Hare. If you think about many &quot;classic&quot; C applications, a lot of them basically only exist around&#x2F;for one or a few data structures (e.g. most servers, many utilities etc.). In that context BYODS is somewhat defensible: If you don&#x27;t care to implement the data structure, why does your application exist in the first place?<p>But that&#x27;s not &quot;modern&quot; applications, which often deal with a ton of data structures. C applications that do so usually have a few &quot;template headers&quot; lying around (indeed, certain operating systems ship with them), though one of the most frequently used data structures in C is of course the intrusive linked list. Which is not a good data structure to use in most cases. Why is it used so much in C? Because it is easiest to implement. Why does that matter? Because C makes implementing generic data structures tedious. Is it a good idea to replicate that model?<p>qed.
评论 #31259014 未加载
评论 #31266454 未加载
评论 #31258898 未加载
评论 #31258777 未加载
socialdemocrat大约 3 年前
Why do people spend so much energy shooting down a language nobody uses? If you don’t like it you don’t have to use it. I would hate to be the creator of Hare and get so much crap for simply daring to exist.<p>He is making a language he likes and wants to use. There are probably some people who like it and find it useful. Good for them! A lot of us have dreams of building our own language. He is following his passions and people are just lining up to be Debbie Downers.<p>Now I almost feel like I need to learn more Hare to give the guy some encouragement and positive feedback on things done right. Be the glass half full guy.<p>Well I won’t. I think Zig will be the last C-like language I invest time in. It is so easy to get sucked into something new that will never go mainstream.
评论 #31260211 未加载
评论 #31259992 未加载
评论 #31260645 未加载
评论 #31259922 未加载
评论 #31260454 未加载
评论 #31262202 未加载
grnmamba大约 3 年前
The primary reason I prefer working in C++ over C is that, for all of C++&#x27;s faults, it ships with a solid collection of containers and algorithms in the standard library. unordered_map may suck compared to other implementations, but it&#x27;s a vast improvement over linked lists or home-grown hashmaps.<p>Anyone can write a hash map, in the same way that anyone can write an HTTP server over a weekend. Doesn&#x27;t mean it will be production quality.<p>Glibc&#x27;s obstack doesn&#x27;t count, it&#x27;s non-standard and the only type it supports is (of course) void*, which is a bad interface.
评论 #31259320 未加载
nynx大约 3 年前
It’s unfortunate that people are trying to revive a better version of the past, when the world has moved on and the past ultimately really wasn’t that great.<p>C is a terrible language for building things in the modern world. Not including the progress over the last 4 decades in your new language is a mistake.
评论 #31259258 未加载
评论 #31258917 未加载
thecompilr大约 3 年前
That reminds me that I had to reimplement basic hashmaps in C at least three times in my career. What a waste of time.
评论 #31258846 未加载
评论 #31259390 未加载
评论 #31258942 未加载
flohofwoe大约 3 年前
This reads like a rant of a person caught too much in their own bubble, a bubble in which hash maps seem to be of extreme importance. I&#x27;ve coded a lot of C in the past few years, and I can count the number of times when I would have actually needed a proper high performance hash map with all bells and whistles on one hand. A piece of code where hash map lookups are so frequent that it becomes a performance bottleneck is either badly designed, or a special case which needs a very careful implementation.<p>Builtin hash maps are convenient for &quot;dictionary languages&quot; like Python or Javascript, but beyond that they are highly specialized and tailored to specific data sets and hardware properties.
评论 #31260007 未加载
评论 #31261795 未加载
rieTohgh6大约 3 年前
TreeMap as a fallback for bucket and&#x2F;or some king of random salt for hashes had to be introduced due to security issues (DoS) - I doubt anybody would remember about such stuff when making own hashmap implementation.
评论 #31259395 未加载
_trackno5大约 3 年前
I don&#x27;t get this guy. He&#x27;s just raging.<p>I agree a hashmap is not simple and Hare&#x27;s post is a bit naive, but I don&#x27;t get what&#x27;s his problem with the language not providing a default implementation. It&#x27;s part of the language&#x27;s design. It&#x27;s targeting people that most likely won&#x27;t need a hash table. It&#x27;s not aiming to be a high-level batteries-included language like Java.
评论 #31259445 未加载
评论 #31258915 未加载
评论 #31258943 未加载
评论 #31259080 未加载
评论 #31259954 未加载
jordemort大约 3 年前
I&#x27;m so bored with all this reactionary tech. I don&#x27;t understand the urge to reinvent everything from first principles while ignoring the last 30 years of advances in computing. I was alive back then. Things weren&#x27;t actually better.
评论 #31269824 未加载
thrower123大约 3 年前
We seem to be very worked up over a virtually unknown new C-replacement language that&#x27;s more likely than not to fizzle and become yet another 0.1% also-ran.
评论 #31259408 未加载
tialaramex大约 3 年前
Yesterday, while reading about Hare, I discovered the problem this blog post alludes to (Hare&#x27;s own module code just assumes if the hash for two modules was identical, they&#x27;re the same module) and I reported it to Hare&#x27;s developer list.<p><a href="https:&#x2F;&#x2F;lists.sr.ht&#x2F;~sircmpwn&#x2F;hare-dev&#x2F;%3C20220503143516.19e61ad8%40totoro.tlrmx.org%3E" rel="nofollow">https:&#x2F;&#x2F;lists.sr.ht&#x2F;~sircmpwn&#x2F;hare-dev&#x2F;%3C20220503143516.19e...</a><p>I was sort of expecting Drew to... fix it? I mean, what you&#x27;d hope for is an updated blog post with a mea culpa in it, but I&#x27;m not setting my expectations so high. Fixing the bug seems like a pretty basic place to start though.
评论 #31259540 未加载
dathinab大约 3 年前
it can&#x27;t be understated how insanely hard it is to get maps right and that not getting them right (e.g. not having them or problematic implementations) is prone to produce subtle security vulnerabilities in large projects. Most times DoS attack vector not cought by normal (D)DoS protection (especially with micro services they can be nasty).
guerrilla大约 3 年前
What&#x27;s the problem? People will just use libraries. Why does it need to be part of the base language? Seems like that made C++ quite a mess in fact, while NPM-like ecosystems have done well.
评论 #31258742 未加载
评论 #31258739 未加载
评论 #31258733 未加载
ddevault大约 3 年前
Thanks for writing this up, though I feel that it may be a bit premature since at this point hardly anyone has any real experience writing Hare code. Regardless, I understand that this is a contentious design decision of Hare, so I would be happy to explain in it in more detail.<p>We have discussed adding first-class maps to the language many times. We recognize the value in this feature and have tried to come up with a good way of doing it that fits within the design constraints of the language, but it has several design issues. There are three key problems: finding a good way of hashing arbitrary data structures (or arbitrarily limiting the kinds of keys the map can store), finding a good way of determining equality of arbitrary data structures, and dealing with memory allocation semantics. Hare does not have generics, and the alternative is a hands-free approach to hashing and equality, which has some troubling limitations, some of which are very unintuitive and non-obvious (which conflicts with our values for explicitness). The allocation problem is also troublesome: Hare uses manual memory management, and any hash map solution which involves magic behind-the-scenes allocations has serious design conflicts with Hare&#x27;s principles.<p>This article criticizes a sample of a hash map implemented for the build driver. This hash map is used to store a mapping of module details keyed on the module&#x27;s namespace. It is true that it is a fixed size map, and that collisions can easily be found for the fnv32 hash. These constraints limit the ability for this hash map design to generalize. However, this is not <i>supposed</i> to generalize. It&#x27;s designed to be a special-purpose hash map for this specific use-case, and takes the simplest approach which is sufficient to this specific problem. As the author notes, there are many approaches to hash maps and there is no one-size-fits-all solution. So far as hash collisions are concerned, these are very unlikely in this use-case. This is not a hash map where hash flooding is a concern, and accidental collisions are so unlikely as to be a negligible risk. If this were not the case, it is easily fixed by just comparing each bucket entry by the namespace rather than by the hash. For use-cases where these things do matter, I would be interested in seeing something like siphash end up in the Hare standard library.<p>Recall that Hare is designed to be similar to C in terms of scope and goals. C also provides no general-purpose hash map, and little by way of other data structures (though some attempts exist, none of them good). Each of these approaches and concerns comes with different needs and trade-offs, and Hare places responsibility for evaluating these needs and trade-offs into the capable hands of the programmer. This is a reflection of Hare&#x27;s values, which are distinct from the values of some other languages mentioned in the OP - Rust, Go, Zig, C++, etc.<p>Thanks for providing me the opportunity to clarify this here, though perhaps this merited a blog post rather than an overlong HN comment. I understand that this is a design decision which appears especially confusing from the outside, but know that it was made through careful deliberation and discussion.<p>Oh-- and a map-like thing for net::uri would be nice to have as a convenience function in the future. We need to implement the basic approach using the most fundamental design and then build the convenience on top of it, in order to accommodate all use-cases and leave the trade-offs for the user to make.
评论 #31259008 未加载
评论 #31258810 未加载
评论 #31258930 未加载
评论 #31258866 未加载
评论 #31258920 未加载
specialist大约 3 年前
My future perfect &quot;practical&quot; programming language will have type inference, strong typing, and intrinsics for misc data structures. In other words, looks kinda like JavaScript, behaves kinda like Java.<p>This:<p><pre><code> foo = { &quot;apples&quot; : 100, &quot;bananas&quot; : 20 } bar = [ 100, 200, &quot;oops&quot; ] &#x2F;&#x2F; error </code></pre> Instead of this:<p><pre><code> foo = new hashmap&lt;string,int&gt; foo.put( &quot;apples&quot;, 100 ) foo.put( &quot;bananas&quot;, 20 ) bar = new array&lt;int&gt; bar.add( 100 ) bar.add( 200 ) bar.add( &quot;oops&quot; ) &#x2F;&#x2F; error </code></pre> I believe, but cannot yet prove, this would eliminate 98% of the (popular) pressure (desire for concision) for adding generics.
YeGoblynQueenne大约 3 年前
Is there any field or subject where people don&#x27;t routinely take a dump on each other&#x27;s work? Or am I just being overseinsitive, too easily vexxed?
roxaaaane大约 3 年前
It&#x27;s 2022
urschrei大约 3 年前
Is it too late to rename the language to Ostrich?
fbanon大约 3 年前
Sounds a bit... hare-brained. :^)
duped大约 3 年前
It&#x27;s easy to flame young language projects, I don&#x27;t find that compelling. I don&#x27;t find the original description compelling either but that&#x27;s not to say there won&#x27;t be some kind of support for generic programming or correct hash tables in their standard library (with all the bells and whistles that you need, like randomized insertion order, reasonably fast performance, perhaps optimization for ordinal keys like a btree).<p>What does throw me off about some language projects is the rejection of &quot;complexity&quot; either in a compiler implementation or language feature <i>because</i> it is &quot;complex&quot; - despite decades of research and experience in <i>other</i> languages that some of those features are actually super useful (and also ways to get them wrong or right!). I&#x27;m not sure if this is where Hare has landed on generic programming, but it&#x27;s an ethos I see in a lot of &quot;C but not C&quot; languages that I don&#x27;t think is a sound approach to language design.