dimitarvp

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. :slight_smile:

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 Access is too much? I mean, you can work pretty easily with it without having to use Access and the Kernel functions 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. :023:

Showing Posts 1 to 10

ityonemo

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 @moduledoc and into code comments.

A property test would also make me more confident :slight_smile: though it is a well known data structure that it’s easy to verify you’ve done correctly.

axelson

axelson

Scenic Core Team

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

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 :slight_smile:

Update: I ran dialyzer and made a pr that seems to fix the error.

Qqwy

Qqwy

TypeCheck Core Team

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 children is 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 use trie.children rather 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 Access is 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

dimitarvp OP

Imagine loading all tags in your DB in the Trie:

Tag
|> Repo.all(select: [:name])
|> Trie.put_words()

And then when people want to put tag(s) on an object you have an autocomplete controller action that does this:

Trie.search(params["tag"])

…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

dimitarvp OP

PR accepted. Thanks!

dimitarvp

dimitarvp OP

Agreed, I’ll add a bit more real-world examples similar to what I pasted to you above.

dimitarvp

dimitarvp OP

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

dimitarvp OP

@ityonemo / @Qqwy I see no reason not to make property tests indeed. Save for the fact that it usually takes me a few hours. :003:

dimitarvp

dimitarvp OP

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.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews