{"id":503,"date":"2018-01-01T08:00:40","date_gmt":"2018-01-01T08:00:40","guid":{"rendered":"http:\/\/buklijas.info\/blog\/?p=503"},"modified":"2017-12-31T11:23:45","modified_gmt":"2017-12-31T11:23:45","slug":"always-start-with-simple-solution","status":"publish","type":"post","link":"http:\/\/buklijas.info\/blog\/2018\/01\/01\/always-start-with-simple-solution\/","title":{"rendered":"Always start with simple solution (ConfigParser vs. JSON for Python configuration file)"},"content":{"rendered":"

Published on:<\/strong> 01.01.2018<\/p>\n

Conclusion<\/h4>\n

Sometimes perfect is the enemy<\/a> of the good.<\/p>\n

Why use configuration file<\/h4>\n

I had Python program<\/a>, that needed to access device via IP address<\/strong> and to do some diagnostic and commands on it.<\/p>\n

At that time, I was accessing only one device (only one IP address).<\/p>\n

But could see that in future (in few months to one year), I will need to do the same set of command on more devices.<\/p>\n

One solution is to add IP address as a parameter to CLI program.<\/p>\n

In my use case number of IP address that needs to be accessed will never be bigger than 34.<\/p>\n

And writing 34 IP addresses as CLI parameter<\/strong>, that is around 373 letters<\/strong>, is not a nice solution.<\/p>\n

When you need to read it, to see are all IP addressee included, it is not easy to read.<\/p>\n

Python code as configuration was not possible<\/h4>\n

I was distributing my Python code as EXE<\/a>, so use of Python code as configuration was not possible.<\/p>\n

Altho, I think that Python code as the configuration is a good solution if you are executing source code<\/strong>, and only developer (not average user who does not know what Notepad is) will edit it.<\/p>\n

Sometimes perfect is enemy of good<\/h3>\n

Sometimes I do have a problem that I tend to unnecessarily complicate things.<\/p>\n

Because I think about all possible edge cases and all possible future uses.<\/p>\n

And from these two, all possible future uses are the real problem<\/strong>.<\/p>\n

Edge cases can happen, but is there a positive cost benefit to solve them and how?<\/p>\n

This need to be determined on a case by case basis.<\/p>\n

But “all possible future use” is trying to anticipate the future<\/strong>.<\/p>\n

That is impossible<\/strong>.<\/p>\n

From my experience, whenever I add code for future use cases, usually it was waste of time.<\/p>\n

Even when I am the only user, so I can argue to my self that I know will need it.<\/p>\n

Usually, I do not need it.<\/p>\n

So, I have decided to eliminate waste<\/a> when developing software, starting from this project.<\/p>\n

For example, here I needed a configuration file that will have a list of IP addresses, which I will iterate in for loop<\/code>.<\/p>\n

This was the smallest requirement that I needed for my problem.<\/p>\n

But immediately I was thinking that it would be nice to have:<\/p>\n