6 ms·
Hamster - Efficient, Immutable, Thread-Safe Collection classes for Ruby
- alttab 14y agoHow many people do multi threading in ruby? I'm assuming this is mostly for jruby?
- cookrn 14y agoGreat question. It's starting to gain a more mainstream following. Here are a few resources: * https://github.com/celluloid/celluloid https://github.com/celluloid/celluloid * https://github.com/mperham/sidekiq https://github.com/mperham/sidekiq (built on Celluloid) * https://github.com/puma/puma https://github.com/puma/puma * http://tenderlovemaking.com/2012/06/18/removing-config-threadsafe.html http://tenderlovemaking.com/2012/06/18/removing-config-threa...
- myndpage 14y agoDon't forget Rubinius! No GIL neither.
- mrinterweb 14y agoRubinius 2 when it comes out.
- SeoxyS 14y agoI use threading in MRI ruby quite often… maybe I'm the odd man out here.
- guns 14y agoThreading in MRI is still entirely appropriate for juggling IO. So that makes two of us.
- alttab 14y agoI guess I jumped to quickly to the conclusion that more work would be done in Ruby. I suppose it works for IO. I like non-blocking libraries like em-http-request and event machine for these things. If I wanted to do concurrent programs, I usually chose C :)
- regularfry 14y agoI use it quite a bit, across all 4 major interpreters. Not used Hamster yet, though.
- getsat 14y agoI use it with YARV all the time (usually with the "parallel" gem) to get a Nx speedup on easily parallelisable operations like processing a set of input files, sending HTTP requests to APIs using threadsafe cURL handles, and so on.
- mrinterweb 14y agoAnother decent place to find out more about multi-threaded ruby or to post info about it is http://ruby.io/ http://ruby.io/
- mitchellh 14y agoAs of git HEAD at the time of this comment (5edce74): 1499 lines of Ruby code. 19 lines of comments. Nope, nope, nope. I would never touch this library. Good amount of tests, but the moment this library doesn't work as expected and you need to jump into the code, you're completely screwed. Not usable.
- burke 14y agoWhat part of the code isn't self-explanatory that a comment would be able to band-aid? It's all very clean. Comments for comments' sake are much worse than no comments at all.
- mweibel 14y agodidn't look at the code but if it's good code, why would you need more comments? Good code explains itself.
- nirvdrum 14y agoDo you have an example of good code that explains rationale or "why" without comments? I rarely come across code and can't figure out what it's doing, but I routinely come across code and can't figure out why it's doing something. And I haven't found a good way to deal with that outside of comments or some external documentation. I'd love to see examples of code that's able to overcome this.
- mweibel 14y agoWell done code has good variables, good method/function naming and small methods/functions. If you have those 3 parts, you won't need any comments because it's self explanatory. Comments often tend to explain the same thing as the code exactly does and what you see w/o looking at the comment. Also, they tend to be forgotten - if someone changes the code, he/she often doesn't change the comment. As a result, you'll have an outdated comment which can confuse you. I recommend "Clean Code"[1] for more info on this subject. Beside other chapters, there's a chapter about what's a good and what's a bad comment. [1]: http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=sr_1_1?ie=UTF8&qid=1341586548&sr=8-1&keywords=clean+code http://www.amazon.com/Clean-Code-Handbook-Software-Craftsman...
- kristianp 14y agoHmm, I assumed this would have to be written in C so that it could use multiple threads in parallel in MRI, but it seems not. Then I remembered concurrent != parallel.
- scotth 14y agoYou forget that MRI isn't the only Ruby implementation. JRuby has no GIL.
- josteink 14y agoNot to be a pedant, but wouldn't thread-safe automatically follow immutable? If a structure is immutable, how would you be able to fuck it up, even if you abuse it via threading? I would argue the relation is so strong, that something which isn't thread-safe cannot be immutable. But there may ofcourse be something which I'm missing. Different languages and platforms handling different key concepts differently etc. Is there some properties of Ruby which makes this possible, or gives you a need for a double-guarantee, or is the declaration here simply redundant?
- deleted 14y ago[deleted]
- asynchrony 14y agoConsider a balanced tree that only exposes an immutable interface but uses destructive updates internally when rebalancing. In principle it would be immutable, though it wouldn't necessarily be threadsafe without additional work.
- josteink 14y agoFrom my point of view, that would not be something I considered a immutable data-structure. But I guess at this point we are starting to argue technicalities and it's getting quite outside the scope of this submission. I'll just take a mental note with regard to immutable evidently being a lossy concept ;)
- dlikhten 14y agoImmutable simply means there is no way to change the data once you are given the object. That does not mean the impl is a clone. In any case, ruby is really missing something as good as this. Very nice stuff. Wish that it did not require "new" syntax compared to ruby's nice [ ] and { }. But whatever. This is a problem that will exist on any collection innovation.
- sirclueless 14y agodef dup self end Weehee, immutability is great at some things.
- exDM69 14y agoIs it just me or is anyone else annoyed about Ruby people calling their hash table based dictionaries a "hash"? As a non-Ruby programmer, I always get confused when people talk about hashes and you can never be quite sure if it's a dictionary or an integer hash value.
- pwmanagerdied 14y agoRuby's influenced by Perl which has been using that name forever.
- keymone 14y agofrom http://en.wikipedia.org/wiki/Hash http://en.wikipedia.org/wiki/Hash Hash may refer to: http://en.wikipedia.org/wiki/Hash_table http://en.wikipedia.org/wiki/Hash_table i'm sure it's not just you though, people get annoyed over whole bunch of things
- exDM69 14y agoI first started hearing the word used that way about at the same time as Ruby started becoming more popular.
- regularfry 14y agoThey use the same name in Perl. I presume that's where Ruby got it from.