3 ms·
While this is pretty neat, it reminds me a lot of Perl tie, which is kinda considered an anti-pattern in modern Perl (though there are places where it still mak
by SwellJoe 9y ago
While this is pretty neat, it reminds me a lot of Perl tie, which is kinda considered an anti-pattern in modern Perl (though there are places where it still makes sense and is still used). Any data structure in Perl can be connected to a wide variety of backing stores using tie: http://perldoc.perl.org/perltie.html http://perldoc.perl.org/perltie.html
It was introduced in Perl 5.0, so it's been around for about a quarter century, and it's generic in the sense that there are tons of backends that use the tie interface. BerkeleyDB and gdbm and flat files and probably any DBD SQL database are among the backing store options. But, again, a lot of people think it should be avoided in the general case, even though it seems like a really nice simple solution to a common problem (I've got these hashes/arrays/whatever, and I want to save them on disk so they're persistent and shareable).
This implementation can't delete keys (yet?) which seems to limit its utility for general purpose tasks. I also wonder about reliability. When I first started reading I assumed it'd be used for small things, but he's working with a 32GB file shared across multiple processes. That's a lot of opportunity for data corruption.
- mycelium 9y agoYou insinuate without providing the reasons behind it. I say this because diskhash and tie look like extremely useful things used carefully. This sort of thing solves exactly a problem I have right now. > Perl tie, which is kinda considered an anti-pattern in modern Perl ... a lot of people think it should be avoided in the general case, even though it seems like a really nice simple solution to a common problem Why? Any links to blog posts? > When I first started reading I assumed it'd be used for small things, but he's working with a 32GB file shared across multiple processes. That's a lot of opportunity for data corruption. I've used something similar and data corruption because of size is low on my list of concerns. If your storage layer fails in this manner silently, you have much bigger problems.
- SwellJoe 9y agoIt's not an opinion I hold strongly, it's just something I've noticed. I've seen more than one talk where someone apologized for implementing something with 'tie'. Here's one blog post about it (still opinion): http://www.skrenta.com/2007/05/tie_considered_harmful.html http://www.skrenta.com/2007/05/tie_considered_harmful.html And, this article from the Modern Perl site itself has mixed opinions on the subject, but comes down on the side of not using it, in the general case, but knowing how and when to use it can be really valuable (Tie is the last subject covered on the page): http://modernperlbooks.com/books/modern_perl_2014/11-what-to-avoid-in-perl.html http://modernperlbooks.com/books/modern_perl_2014/11-what-to... I'm not trying to say there's no place for it. Tie in Perl has been used for really cool stuff.
- mycelium 9y agoAppreciate the response and reasoning!