0

I have a php script that generates php and javascript wrapper classes that handle json marshalling based on a configuration file.

My initial plan was to have a single config file that generates all the classes used by the application. However, my team lead suggested I use a separate file for each feature, to avoid creating a gigantic config file, and create a directory that defines json objects that are shared by multiple features

I compared it to struts-config.xml where all the definitions are in one file. Another example is a data dictionary that is used to generate DB access classes and the SQL to generate those tables; in previous jobs, there was always a single file that defined all the db tables, so I didn't even give it much thought since that is what I was used to.

He compared it to idl (it's a lot like idl), and we do not hold all the idl definitions in one place.

So I'd like arguments for and against using a single file. Here are some:

Single file

  • Good

    • You can see all the json objects in one place (this is the core of our web API and it's used for documenting the server Ajax calls)
    • You only need a single makefile (or ant target)
  • Bad

    • File can be hard to edit once it gets too big

Multiple Files

  • Good
    • JSON only used for a single feature is not exposed (private to a project)
  • Bad
    • Once a JSON object is used by two features, it needs to be moved to a different file

Any feedback is appreciated and please ask me to clarify if you want to chime in but are not quite sure what I am talking about.

Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217

3 Answers3

0

Programming or not I think the below principles are good suggestions. So apply these two to your situation and you will answer yourself ;-)

Single Responsibility Principle Cohesiveness: Group related things together

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
  • In response to feedback (yours and within my company) , I am not using a single file. However, I'm creating a separate folder to contain all the json definitions, within that folder, there's one folder for common definitions, and folders for each project specific definition. However, this does duplicate the directory structure (common, project specific folders) from other places (as in within code igniter controllers and models folders). So.... Pangea, please provide some feedback if you have any. – Ruan Mendes Nov 02 '10 at 18:31
0

To keep configuration separate from code, I created a folder outside of the web folder (htdocs) containing the configuration files, and they mimic the folder structure within htdocs. The files compiled from the configuration files are then moved within the place where they are going to be used. So I think I made everybody happy. All the configuration files are within a separate folder but they are still organized by features. So it's cohesive that all the config files are in one place, while still grouping each of the config files by feature. Sorry for a confusing question...

Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
0

There is another solution can match both good points.

Using config file support 'import' another config like javascript.


For Example, yaml config format.

here is a link, How can I include a YAML file inside another?.

It shows how 'single large config file' include 'multiple small config file'.

If 0.yaml was:

file1: !include include.d/1.yaml
file2: !include include.d/2.yaml

the result is

  file1:
    name: "1"
  file2:
    name: "2"

At all above:

config file '0.yaml' is the 'single large config file'

and both '1.yaml' and '2.yaml' is the 'multiple small config file'.

1.yaml and 2.yaml is make up of 0.yaml.

It can simply using equation as below to express

1.yaml + 2.yaml = 0.yaml
Bejson
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 27 '21 at 09:21