-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Split up Types.hs and logically organize modules #1793
Conversation
Hm. I'm thinking about the best way to review this, because it's a lot of changes. I feel like going through this commit-by-commit might be the best idea. Of course this means, there should be no rewriting of the history done in here - otherwise it's confusing as hell. But you don't really do that anyway.. just don't start right now, please :D. This way, I can already start reviewing, while this is still WIP. To review:
|
Thanks for picking this up @wolfgangwalther ! Will not touch the history :-) There are a few blurs between the commits, and some decisions that I later changed (like splitting out Some notes:
Edit: |
Yes, I figured - I am kind of jumping between the individual commit and the final result to cross-check whether any of my suggestions have already been addressed in a later commit.
I think putting them where they belong naturally is best.
You did some of that already, didn't you? Was left out of the
Yes. I agree with the approach: Change some of them as you go by, but do it for good in a separate PR afterwards! |
Yes, should not be too difficult to rebase/port, will do that in a separate PR! |
Sorry, a bit lost here. Is the idea to make the modules graph "less connected"? I do see that the refactoring will make the imports clearer and the files smaller, which seems good to me. |
I'm working on summing up the idea behind this (as I understand it) and sketching out the ultimate goal ("What could it look like?"). Should be posting that in a few hours. |
Looking at what I commented on while reviewing, so far, I realized I have kind of a target structure / goal in mind. Before going forward with the review, it might be worth it to take a step back and:
Steve:
The idea is to give the code-base a better internal structure. This would make the modules graph less connected, yes - with a few clearly defined interfaces between core parts of the system. Down the road this might make it easier to add some kind of unit tests, too. Only where we need them of course, but I did already have situations where I thought that would be helpful. I think the current tests are more like integration tests that go through the whole system. The main reason to do this, of course, is to make the code better maintainable. For us and also for beginners, joining the project. Remo:
The reason for this is, that we ultimately need to use nested namespaces / modules (as we already discussed in a few specific cases) and need to re-export symbols at the top level of those namespaces. Only this approach will give the proper structure while keeping the filesizes small enough to manage. We could even add a CI check to avoid adding imports "into" namespaces from "somewhere else", later on. If we follow this idea, I think we can separate out some core functionalities in the following namespaces:
I came up with the following graph, created from scratch: Some of that might not work exactly like that, but the general flow is clear:
I see a lot of similarities in your latest graph @monacoremo, already, so I think we're on the same track here? Other than
Before we talk about what steps we need to take and which scope this PR should have: @monacoremo is this what you have in mind, too? @steve-chavez what do you think about a structure similar to that? We will touch allll files and basically nothing will be where it was before... :D |
Got it, the image makes it clear as day 🌞
I would suggest trying doctests, it's much easier to understand a test when it's close to the function(rather than jumping to another file).
By all means go for it! I can already see that the result would be much better for maintenance. |
Very nice summary @wolfgangwalther ! As I was in deep into exploration mode here, I don't think I could have put it that clearly myself :-)
Yes, exactly! The exact structure will emerge through iteration, but that's the kind of target picture we're going for.
Fully agree! Now that we've pulled everything apart, I'm starting to put sensible modules together, e.g. Config: The challenge is essentially to design nice internal APIs. E.g. with this commit 11d7020 we separate all the query building logic from app, fully encapsulating Statements, DbRequestBuilder, QueryBuilder etc. That will be easier to reason about, and enable further simplification on the query building side.
Would love to try that! Even more important to have nice internal APIs.
Yes, we will need to merge intermediate steps. I think this PR will be mostly about pulling stuff apart, future PRs will converge on a well ordered, stratified structure step by step. |
d3fe45c
to
3e5614a
Compare
rebased, no changes to commit history |
Ok, so for this PR:
Does that align with what you did in all the commits I haven't looked at, yet? If yes, I will review along those lines. |
Pretty much aligned, the reality is a bit more explorative though:
I suggest we leave Parsers, Middleware and Errors for a later PR. I tried to keep renaming minmial - I don't think I touched any functions, main changes are new modules from Types, Query and s/Private.QueryFragment/Query.SqlFragment/ |
Sure. It's just a question of scope - which parts should I comment on now to change for this PR and which one will we keep for later. After looking through a few more commits, I realized you did nest a few modules already (in terms of directory structure). And as you said, also did a few of the re-exports already. Shall we do all of them in this PR, then? Or should I just ignore this for now, and we'll focus on it later? In any case I will comment on naming the modules according to the nesting we want to have later. |
Definitely a later PR, let's see what was done here as proof of concept and ignore :-)
Yes, sounds good! |
Ah, thanks for the summary. I feel this line of separation makes I would move Also have a look at the theoretical graph I posted above - it has WDYT? |
Let me add to my comment before: In my graph I had
|
Alternative naming suggestion, with the same contents:
|
Yes, that's a very good thought! DbRequestBuilder is a bit misnamed then, it is pretty independent from any DB things. Ideally we would have only one type coming out of parsing a request, not an additional intermediary step. And we would have a clear pipeline:
( Then we build a query from it
(note: the request would be so thoroughly parsed that query creation cannot fail) Then we run the query
Then we render a response
So App would become something like (very roughly)
We are still quite distant from that however... I'll move DbRequestBuilder into ApiRequest for now, but we'll not be able to offer a clean request API in this request, as still everything is tied up in App.hs; so App.hs will still directly access that module. Maybe, to make our intention even clearer: Let's move ApiRequest to Request also, so we have
leaving imports as is, and we'll sort out the mess in later PRs. WDYT? |
This is exactly my thought. |
Before you go on another commit-spree, I have currently reviewed everything except:
My understanding is that the last commit is about that However all the other 4 commits seem to make a nice package - and there's actual refactoring involved, not just renaming. Since the commit history has not progressed far beyond that, yet: Do you think it makes sense to make a cut before the You should be able to to just move the fix errors and PgVersion commits in front of that, too, I think. Edit: Maybe it's not really needed, though. I didn't really look at the App commits, yet. If those still fit in the bigger context here and are easy to review, then we don't need to do that. |
73d5955
to
2def566
Compare
So... As said, let's make a cut at this intermediate stage. We've now sketched out some of the intended structure with |
How are we going to proceed with this - should we merge this into I feel like the extra branch might make sense to avoid having the intermediate state on the main branch. It's a lot of changes - and probably not really in a state that's less confusing than before, yet. WDYT? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not check the latest rebase regarding merge-conflicts, I'll have to trust you on that.
Yes, good question. I sketched out some ideas for next steps in #1804. I would argue for merging to main right now:
@steve-chavez , would you be ok with merging to main? |
@monacoremo Sure! Merge time 🚀 |
Bye bye |
Edit: This PR is a first step in refactoring the codebase, see #1793 (comment)
Work in progress, pulling at the
Types.hs
string to see what comes out of it.Modules graph before
Created with
postgrest-hsie-graph-modules
:After
Seems like it needs to get worse before it get's better:
Symbols after
Created with
postgrest-hsie-graph-symbols
: