Conditions | 2 |
Total Lines | 64 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | #!/usr/bin/env python3 |
||
17 | def __init__(self, |
||
18 | config_file=None, |
||
19 | verbose=False, |
||
20 | yes=False, |
||
21 | mute=False, |
||
22 | dry_run=False, |
||
23 | import_file=None, |
||
24 | dump_name=None, |
||
25 | keep_dump=None, |
||
26 | host_file=None, |
||
27 | clear=False, |
||
28 | force_password=False, |
||
29 | use_rsync=False, |
||
30 | use_rsync_options=None, |
||
31 | reverse=False, |
||
32 | config=None, |
||
33 | args=None): |
||
34 | """ |
||
35 | Initialization |
||
36 | :param config_file: |
||
37 | :param verbose: |
||
38 | :param yes: |
||
39 | :param mute: |
||
40 | :param dry_run: |
||
41 | :param import_file: |
||
42 | :param dump_name: |
||
43 | :param keep_dump: |
||
44 | :param host_file: |
||
45 | :param clear: |
||
46 | :param force_password: |
||
47 | :param use_rsync: |
||
48 | :param use_rsync_options: |
||
49 | :param reverse: |
||
50 | :param config: |
||
51 | :param args: |
||
52 | """ |
||
53 | if config is None: |
||
54 | config = {} |
||
55 | |||
56 | info.print_header(mute) |
||
57 | system.check_args_options( |
||
58 | config_file, |
||
59 | verbose, |
||
60 | yes, |
||
61 | mute, |
||
62 | dry_run, |
||
63 | import_file, |
||
64 | dump_name, |
||
65 | keep_dump, |
||
66 | host_file, |
||
67 | clear, |
||
68 | force_password, |
||
69 | use_rsync, |
||
70 | use_rsync_options, |
||
71 | reverse |
||
72 | ) |
||
73 | system.get_configuration(config, args) |
||
74 | system.check_authorizations() |
||
75 | process.create_origin_database_dump() |
||
76 | transfer.transfer_origin_database_dump() |
||
77 | process.import_database_dump() |
||
78 | helper.clean_up() |
||
79 | remote_client.close_ssh_clients() |
||
80 | info.print_footer() |
||
81 |