on master help sign in
Update code organization in contributor's guide
62420fdHarendra Kumar
CONTRIBUTING.md+27−21
@@ -89,24 +89,30 @@ Specifically,
89
89
90### Organization
90### Organization
91
91
92−Use this simple rule to organize functions in a file or even modules in the
92+Use this simple rule to organize functions in a file: `Define before first
93−cabal file - `Define before first use` or in other words use the `bottom up
93+use`. In other words, use the `bottom up style` to organize functions.
94−style`. Note that this rule does not apply in choosing `let` vs `where`
94+
95−clauses. Use of `let`s leads to bottom up and use of `where`s leads to top
96−down style. But we do not encourage `let` over `where`, you can freely use
97−`where` clauses. Also note that this is not possible in mutually recursive
98−code.
99−
100−One big benefit of this rule is easier type error debugging. It allows you to
95+One big benefit of this rule is easier type error debugging. Using a single
101−cut a part of the code tree cleanly by commenting out the code in a file from
102−any point in the file up to the end of the file by just using a single comment
96+block comment, at any point in the file up to the end of the file, you can cut
103−block and the uncommented code still compiles. That way we can incrementally
97+the tail and still cleanly compile the remaining head portion of the file.
104−increase the uncommented portion by just sliding the beginning of the comment
98+
105−further down in the file and compile the file. This way it is very easy to
99+It is very helpful when we make significant changes to the file. We can start
106−incrementally compile the code and figure out the type errors in a smaller yet
100+compiling a minimal head portion of the file and keep expanding the head by
107−complete code, this reduction in the scope of type inferencing makes it really
101+just moving the start of commented block further down. This keeps the scope of
108−easy to figure out even hard to understand type errors.
102+type inference minimal and type errors can be discovered incrementally by
109−
103+increasing the scope a little bit at a time. If you use type signatures on all
104+top level declarations then you do not even need to comment out the code. This
105+organization results in a better order of type errors which makes it easier to
106+fix them and when necessary use elimination method by commenting out some code.
107+
110−Similalrly when you put modules in the cabal file in dependency order you can
108+Similarly when you put modules in the cabal file in dependency order you can
111−do the same there, just comment out a tail of the module list and the rest will
109+do the same there, just comment out a tail of the module list and your library
112−still compile.
110+will still compile.
111+
112+Note that this rule does not apply in choosing `let` vs `where` clauses. Use of
113+`let`s leads to bottom up and use of `where`s leads to top down style. But we
114+do not encourage `let` over `where`, you can freely use `where` clauses.
115+
116+Also note that this is not possible in mutually recursive code. The mutually
117+recursive code has to be considered a single block.
118+