dimitarvp
Hey community,
Lately I’ve noticed that my very small Trie library that I used in two hobby projects for live prefix searching and autocompletion is sitting in GitHub gathering dust.
I’d like to see if it can be brought into a state where even a few people would use it.
To that end, I’d like to ask anyone who is willing to clone the repo, run the tests, run mix dialyzer (there’s an error there that I couldn’t decipher and fix yet so advice is welcome) and check the docs, to give me their worst criticism. ![]()
A few things I’d be interested to hear:
- Is this library giving you a good way to use a quick prefix search (or autocompletion) after you feed the data structure a list of words? (via
Trie.put_words) - Do you think my implementation deviates from the official meaning of the Trie data structure?
- Are the comments / docs good enough? Are they hard to read? Do they even make sense?
- Do you feel the test coverage is good?
- Do you have any code criticism? Bad variable names? Too short / too long functions? Bad algorithms? (That was like my 3rd or 4th Elixir coding exercise but please, do not be gentle; I need honest feedback.) Anything at all that you dislike? Please share it.
- Do you think me insisting on integrating this data structure with
Accessis too much? I mean, you can work pretty easily with it without having to useAccessand theKernelfunctions that make use of it. Just interested in your opinion if that support is adding code weight without much benefit to it.
I don’t claim anything about the coding quality or the scope of this miniature project. This was one of my very first Elixir projects. I’d definitely approach specs and guards much more strictly now and I’m very likely to have chosen different function names but outside of that I am generally satisfied by the little thing. I still use it in those two hobby projects and haven’t had problems with it.
But please, do your worst and rip it apart if you decide to spare the time (the only file is 373 lines long as of the time of writing this post). I’ll be grateful.
Thanks for reading. ![]()
Trending in Discussions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ityonemo
On a first glance, it’s really nice. My only nitpick is that your t type should probably be
__MODULE__and probably opaque, to reflect your comment about not counting on internals, and correspondingly move it out of@moduledocand into code comments.A property test would also make me more confident
though it is a well known data structure that it’s easy to verify you’ve done correctly.
axelson
I don’t have time to look at the code right now but I was wondering if you could give an example or two of when you would want to use this library instead of the built-in data structures.
aenglisc
I don’t really like that public and private functions are intermixed. I personally prefer to have all the public functions and the documentation at the top of the module with the implementation being separate. In fact I like making separate modules for documentation and implementation using delegates, but that might be my personal kind of madness
Update: I ran dialyzer and made a pr that seems to fix the error.
Qqwy
One tip I have is to move some of the shorter testing functions to doctests, which will help to improve the documentation. Besides this kind of data structure being very testable with property-based testing, as @ityonemo already mentioned, I think that some more code examples in the documentation would be helpful.
As for the code: There are some places where I would prefer a function call written on one line rather than split over many lines, but I believe the Elixir formatter has some heuristics that do not agree with my opinion here.
One of the things I have a question about is why in (almost?) every place you pattern-match on the struct, you also pattern-match on that
childrenis a map (%__MODULE__{children: %{} = children}). I think it would be better to make your type opague and just leave those matches out. In many cases you can also just usetrie.childrenrather than pattern-matching on the struct’s fields in the function head at all; that is only really useful if you have different clauses you want to do depending on the contents of children.I think integrating it with
Accessis not too much, and probably a good idea, because it means that it is easier to integrate it with existing programs that use the Access protocol.dimitarvp
Imagine loading all tags in your DB in the
Trie:And then when people want to put tag(s) on an object you have an autocomplete controller action that does this:
…and then put the results in a response (in my case JSON).
That was my original idea and that’s what I am using my own library for.
dimitarvp
PR accepted. Thanks!
dimitarvp
Agreed, I’ll add a bit more real-world examples similar to what I pasted to you above.
dimitarvp
I understand. I have seen at least 4 schools of thought on that topic and I personally optimise for reading the code top-to-bottom: as you are scrolling and inspecting the code, you stumble upon a public function with almost no body that calls a private function; you then proceed to find it just a few coding lines below it.
Your remark is valid and in my case I haven’t done it your way because I don’t feel the code is very big as to warrant such a separation.
dimitarvp
@ityonemo / @Qqwy I see no reason not to make property tests indeed. Save for the fact that it usually takes me a few hours.
dimitarvp
Good idea. Noted in the GitHub issues.
At certain point I gave up and just wrote code however I wanted and then run
mix format. Even if I don’t like some of its choices – like you – I prefer to have the coding style standardised. Bonus points for having standard git diffs as well.Agreed. This was one of my first Elixir projects and looking at the code now I definitely went overboard with pattern-matching paranoia. Also noted in the GitHub issues.
Agreed.
Going to fix that even if I don’t feel it’s a major problem. Noted in GitHub issues.
That’s what I thought back then and needed the sanity check. Thank you.