How often do you use recursion in Phoenix Framework
Well Elixir is an immutable language so any time you iterate over anything you’re using recursion
But other than that in the context of Phoenix, you might need recursive components if you need to render a data structure that is inherently recursive, like a “file tree” type of structure. I have done this a couple of times now and it works great.
The miserable part is dealing with recursive data structures in postgres. Don’t even get me started on that…
Hey @garrison how do you feel about recursive data structures in postgres?
Well by sheer chance I think I just answered your question in that other thread about recursive queries…
But more generally, dealing with trees in an RDBMS sucks. There’s no way to actually query a tree (you get back rows, making a tree is your problem!). You can use that weird ltree thing but then you pretty much lose any semblance of referential integrity, and at that point why not just dump your data into a JSON column and call it a day? (Frankly this is the only sane solution anyway).
But if for whatever reason your data is actually an integrated part of your application, and it needs to stay in its own little rows with nice happy foreign keys, then you better be prepared to write recursive CTEs for everything. Want to query a folder’s contents? Recursive CTE. Want to delete a folder? Recursive CTE. Want to move a folder without allowing the user to move it into its own parent (for surely then we would all be doomed)? ReCuRsIvE CtE!
And writing recursive CTEs is torture. I’ve written a bunch of them and I can still hardly read them.
All this because I just had to have nested folders in an RSS reader… but I must admit they are nice, and when I go live I think people are really going to like them Tags just don’t hit the same.
Ha, well I was kidding since you said don’t get you started
But ya, agreed they aren’t the most understandable things. I only used them in a semi-similar but simpler situation to yours. Didn’t realize you’d need them to delete and query! I had more of a branching timeline and stored the body text in an FTS table so never ran into what you’re talking about wrt deleting and moving—hat indeed sounds painful.
Thanks for the responses so far. They’ve been really helpful in clearing some concepts. I have a Java, C, Python and Python background and coming to the fact there is no concept of loops in Elixir. However, are there really good resources I can use to learn to build with Phoenix?
Hello!
While there are differences as you’ve already started to notice, you may find some “comfort” on constructs like Enum.map
, Enum.filter
, etc, which are operationally very similar to Python, and there is also for
which is relatable to list comprehensions in Python.
In Elixir/functional programming, a mental model worth developing is that of thinking about computing in terms of transformations. You’re always transforming some input into some output, and you use the language constructs to describe the operations involved in that transformation.
Well, what are you interested in building / what motivates you? Do you prefer written content, video, or something else?
I’ve started using the phoenix framework and I noticed it actually comes with a lot of useful functionalities. I’m currently working on a phoenix project
Nice! If you haven’t yet, I suggest the official guides as a starting point Overview — Phoenix v1.7.14.
Once you get the basics of Phoenix, you may also consider learning about LiveView, which is a different way of developing a web application, different than traditional frameworks like Rails and Django, and different than doing backend APIs + frontend JS SPAs with React/Vue/Angular/Svelte/etc: Welcome — Phoenix LiveView v0.20.17.
When going through the guides, you may choose to follow a slightly different order of topics, for instance you can approach them in a more progressive order or pick the topics that calls your attention.
You don’t have to learn/use LiveView to enjoy the many possibilities Phoenix opens up, like realtime presence notification, and more.
There are also books and videos (both on YouTube and paid courses), a non-exhaustive list can be found at Community — Phoenix v1.7.14.