I start coding a simple application: I transform markdown files in folders into documentation.
My architecture is very flat. My code looks like a series of unit function called one after the other.
def main():
config = get_user_config(os.getcwd())
sources_dir = config['sources_dir']
for root, dirnames, filenames in os.walk(sources_dir):
for filename in fnmatch.filter(filenames, '*.md'):
markdown_file_path = os.path.join(root, filename)
html_block = transform_html_into_markdown(markdown_file_path)
wrapped_html = '{{% extends "base.html" %}}{{% block content %}}{0}{{% endblock %}}'.format(html_block)
html = render_html(wrapped_html, config)
html_file_path = get_html_file_path(markdown_file_path, sources_dir)
write_html_file(html_file_path, html)
What I really like:
- I can unit test every function. Code is simple to understand, no fancy stuff.
- Each function is in its own module.
What I do not like:
- My
main()
method is growing until I create two functions to rule them all. I have the impression of hiding the dust under the carpet. - If I want for instance increase the number of process doing some calculation, I will probably need some hard refactoring.
- Everything is synchronous.
Do you have some idea to improve my code? Should I try something else?
main(){}
function become huge, I used to separate in two functionsmain(){a(); b();}
and so on. \$\endgroup\$