Skip to content
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

improve modularity of framing_sv2 #846

Closed
plebhash opened this issue Apr 13, 2024 · 1 comment
Closed

improve modularity of framing_sv2 #846

plebhash opened this issue Apr 13, 2024 · 1 comment
Assignees
Labels
refactor Implies refactoring code

Comments

@plebhash
Copy link
Collaborator

plebhash commented Apr 13, 2024

I started working on #845 and the first crate I started was framing_sv2. The goal there is to document the code. Which means I first need to understand it.

But the code structure of src/framing2.rs is very confusing.

Basically, impl blocks for different structs are mixed together without a coherent structure.

As one example amongst many, take the Sv2Frame struct: it's impl block starts on line 17, while the struct itself is declared only on line 68 (after a declaration of trait Frame). Then, the impl Frame block for Sv2Frame happens on line 104, after declarations of NoiseFrame struct.

A refactor bringing a more structure and improving code readability is needed.

Structs and Enums like NoiseFrame, Sv2Frame and EitherFrame, as well as the Frame trait, should each get their own file under the framing module.


Note: opposed to what has been argued before, IMHO file size (e.g.: number of lines) should not be the main criteria for code modularization.

Logical cohesion and readability must always come first.

If some logical entity has very few lines, but does something very specific, it already deserves its own file.

@plebhash plebhash added the refactor Implies refactoring code label Apr 13, 2024
@plebhash plebhash self-assigned this Apr 13, 2024
@Fi3
Copy link
Collaborator

Fi3 commented Apr 13, 2024

I don't agree in framin2 we define EitherFrame that is either an Handshake frame or a plain Sv2Frame both impl the trait Frame that is public. The file is less the 400 loc. In how many file do you want to split it? Following the above suggestion I would say at least 4, on for the Frame trait, one for the HandShakeFrame struct one for the Sv2Frame struct and one for EtitherFrame enum. Having 4 file with few lines of code for 4 things that are more or less the same thing, and maybe put them undeer another module called frame will only increase the complexity of the crate adding nothing. I

@Fi3 Fi3 closed this as completed Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Implies refactoring code
Projects
None yet
Development

No branches or pull requests

2 participants