This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
Madara coding best practices #311
ClementWalter
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
I'm new to rust and madara both at the same time.
Goal
I am describing here some misunderstandings or patterns that confused me when entering the madara repo. This discovery report could serve as a base for defining madara best practices to smoothen newcomers introduction.
Topics
Imports
I find it very confusing to understand where the things are imported from or defined (unlike python or typescript for example). I’m always asking myself « where is this defined » and « where is this used ».
=> should the star import should be ban (not a good practices in the languages I’ve been used to, not sure about rust) ?
=> even though valid, should we enforce as much as possible the definition of functions/objects in a progressive order (as in interpreted languages) ?
Naming
Test
my_var_str
) instead of shadowingconst MY_CONTRACT_PATH: &[u8] = include_bytes!("../path/to/contract.json");
ie name says it's a path (one expects either a&str
or a dedicate type for filesystem path, but it's a file content)Tests
Hard-coded values mingled into the code
Could be easier to move all config/constant declaration into a static file (json/toml or even rust, but with no logic, just const)
Types
ContractClass
Blockifier defines a struct
ContractClass
as followsand it appears (at least in tests) that we also need the class hash, which could probably be derived from these information. Instead, we have another variable storing only the hash, creating both confusion and a risk for discrepancy
We also have a
with a commented attribute (
abi
). In some other places with also have commented code blocks, for exampleDefinition
Types seem to be defined at different places of the code, whenever it was probably required to have them, which prevents the newcomer (me) from having a clear vision of the types used in the project, with all types being grouped at the same place.
Preludes
We have one
extern crate frame_benchmarking;
which may not be idiomatic from rust 2018 on.Miscellanous
Code ordering
Even though no ordering block declaration is enforced by rust (like defining the
struct
before itsimpl
), I'd find it easier to avoid as much as possible to use yet non defined variables so as to ease the reading of a file (we read from top to bottom, unlike rust).For example, this is confusing to me (see chain_spec.rs):
because I'm facing an unknown
DevGenesisExt
(not defined from top topub type
), need to think about it, where does it come from, eventually resign, to realize that it's defined just below.Error message
Just found this
and the error message doesn't help me much
Beta Was this translation helpful? Give feedback.
All reactions