Yash-Varshney / tools-python

A Python library to parse, validate and create SPDX documents.
http://spdx.org
Apache License 2.0
0 stars 0 forks source link

convertor: separate "to" / "from" logic #7

Open zvr opened 4 years ago

zvr commented 4 years ago

instead of having an:

 if inflle
    if outfile
         result=
elif infile
      if outifle # repeating the same logic
          result =

split if into 2 separate:

if infile
      informat=...
elif infile
      informat=...

 if outfile
      outformat=...
 elif outfile
       outformat=...

 # then, depending on informat and outformat, you find out what to call (a dict would be handy)
zvr commented 4 years ago

This way it would also be easier to handle user-specified formats (see #8).

Yash-Varshney commented 4 years ago

@zvr I used the method because it was very easily readable and easy to understand, also I was not able to completely understand your method.

zvr commented 4 years ago

I meant that you should separate the computation of the input format from the computation of the output format. The way you have it now, you need to repeat the code for computing the output format in all cases of input. Remember: don't duplicate code, because then you have to change all instances and it's easy to miss one.

Yash-Varshney commented 4 years ago

@zvr I've made the following changes, please look for it and tell if its okay.