Below are the advantages that we get by preferring .yml files over properties files:-
YML Config File | Properties Config File |
Numbering is not required for lists | Numbering required for lists |
Folding Available in IDE’s | Folding not available in IDE’s |
A duplicate parent property name is avoided | A duplicate parent property name is required |
Numbering is not required for lists
Suppose in your spring boot application you have a property that is a list and contains hundreds of entries. And say for example the 77th entry in the list is creating a problem, so you want to debug your application for just the 77th entry. In order to debug it if you are using property files, you would have numbered the property as 1,2,3,4,5.. this way so what you’ll have to do is to comment out the rest of the properties and rename the 77th property to 0 but if you are using yml file you can save the effort of renaming the indexes by just commenting out the list items that you don’t need because there is inherently no numbering involved in your email list configurations
You can see in the above example that we have to rename the serial number’s in the properties file in order to make the configuration work in Spring.
Folding Available in IDE’s
Suppose that you have a configuration that is of type list and as of now if you don’t want to change. In this case, it is a pain to scroll down the list to go to a configuration that resides after the list has ended. If you were using a yml file instead of a properties file you can simply fold the list so as to iterate to the next property more conveniently as shown in the below diagram. Sweet allows your focus to remain on the property that you want it to remain and avoid your focus from going to properties that you are not analyzing as of now. As an additional advantage, it also tells you the count of the list.
A duplicate parent property name is avoided
It saves the developer lot of reading space and therefore helps them find the relevant property faster. Also if you have to replace a parent value that has an underlying list, you just to replace it in one place instead of many.
You can see for yourself that the file on the left is more cannonical, structured and easier on the eye’s to scroll.
nice!!