5 ms·
For me, Redis was the first software written in C which I could easily customize with additional features (as I have low C knowledge). It was written beautifull
by undefined0 11y ago
For me, Redis was the first software written in C which I could easily customize with additional features (as I have low C knowledge). It was written beautifully. I've been learning Rust, I certainly find learning Rust easier than C and I like the fact that I can dive into software written in Rust without worrying about GC. You've done the best of both worlds for me by writing Redis in Rust. With that said, I'm still having an easier time reading Redis in C over your code as you are lacking comments and well named function/variable names. I admire your work nonetheless.
- seppo0010 11y agoThat's a fair criticism, and well taken, but keep in mind I'm learning the language as I go, and most of the commits are just rewriting things because they were suboptimal, not idiomatic, or hard to read. At this stage, I would consider adding comments wasteful. I also have no intention of making this project live as long or have as many users as Redis does.
- deleted 11y ago[deleted]
- illumen 11y agoLearning to write readable code is a good thing I think worth the effort. Can rust be readable?
- seppo0010 11y agoIf you want good examples of Rust code, you should probably look into other repositories. Today I was checking out how Rust's HashMap works and I found it quite readable: https://github.com/rust-lang/rust/blob/master/src/libstd/collections/hash/map.rs#L1115 https://github.com/rust-lang/rust/blob/master/src/libstd/col... You can also look at `mio`, the asynchronous IO library that's popular in Rust: https://github.com/carllerche/mio/blob/master/src/notify.rs#L148 https://github.com/carllerche/mio/blob/master/src/notify.rs#...
- anonfunction 11y agoI would hardly say this is readable: fn search_entry_hashed<'a, K: Eq, V>(table: &'a mut RawTable<K,V>, hash: SafeHash, k: K) -> Entry<'a, K, V>
- rmc 11y agoDepends if you know Rust. The language can do things with types and memory that (say) something like Python or Ruby don't do, which means Rust needs extra syntax to mark those things. Most of the <> or ' are to do with types or memory safety.
- yaongi 11y agoIt's alright.
- pygy_ 11y agoI don't know Rust, and the only thing opaque to me in that line is the `'a` syntax. I suppose it is related to memory safety. In plain English: `search_entry_hashed` is a parametric function. It works in a type safe way on any kind of K and V. It takes as arguments a reference to a mutable hash table, a hash function and a key, and returns an `Entry` object whose precise type depends on the type of the parameters. You could hardly express that more succinctly. You can't understand it by skimming it, but it is a complex definition.
- Tuna-Fish 11y agoYour guess about 'a is correct. 'a is here used to signify that the return value can only be safely used while the value table exists and is not being concurrently modified. This implies that the value is not copied on return, but only a reference into the table is returned.
- pygy_ 11y agoI'm surprised that RawTable isn't parametrized on the type of hash function. Something like this (possibly wrong way to express it, but you get the idea) fn search_entry_hashed<'a, K: Eq, V, H: SafeHash>(table: &'a mut RawTable<K,V,H>, hash: H, k: K) -> Entry<'a, K, V>