Software Design – Advantages of Hard-Coding Data Values

architectural-patternsArchitecturedesigndynamic-data

I'm a self-taught, novice-ish coder, so I apologize if I don't nail the programmer lingo.

I'm working on a project in which I am providing data, which will be continually updated, to developers who will essentially create a tool to generate reports from queries on the data.

It seems that everyone involved thinks that they need to hard-code data values (not the schema, but the domains/values themselves) into the report-generation program.

For example, suppose we were reporting on personnel; the report would be split into categories, with a heading for each department, and then under each department heading will be subheadings of job titles, and then under each subheading will be a list of employees. The developers want to hard-code the departments and job titles. On the other hand, I would think that they could/would query out those things at runtime, sort records by them, and generate report headers dynamically based on what values are there.

Since the list of potential values will change over time (e.g., departments will be created/renamed, new job titles will be added), the code will need to be continually updated. It seems to me that we could skip the code maintenance steps and dynamically organize the reports.

Since I am not a developer, I'm wondering what I'm missing. What advantages might there be to hard-coding values into a tool like this? Is this typically how programs are designed?

Best Answer

Wikipedia:

Hard coding (also hard-coding or hardcoding) refers to the software development practice of embedding what may, perhaps only in retrospect, be considered an input or configuration data directly into the source code of a program or other executable object, or fixed formatting of the data, instead of obtaining that data from external sources or generating data or formatting in the program itself with the given input.

Hard-coding is considered an antipattern.

Considered an anti-pattern, hard coding requires the program's source code to be changed any time the input data or desired format changes, when it might be more convenient to the end user to change the detail by some means outside the program.

Sometimes you cannot avoid it but it should be temporary.

Hard coding is often required. Programmers may not have a dynamic user interface solution for the end user worked out but must still deliver the feature or release the program. This is usually temporary but does resolve, in a short term sense, the pressure to deliver the code. Later, softcoding is done to allow a user to pass on parameters that give the end user a way to modify the results or outcome.

  • Hardcoding of messages makes it hard to internationalize a program.
  • Hardcoding paths make it hard to adapt to another location.

The only advantage of hardcoding seems to be fast deliver of code.

Related Topic