0

Is there a specific term to call the process of modifying hard-coded codes into soft-coded codes? I have to report what I am doing to the Project manager, shall I just put "modifying hard-coded codes into soft-coded codes"?

Example of "hard-coded codes"

int random(){
return 42;
}

Example of "soft-coded codes"

int random(){
return Random.nextInt();
}

hard coded codes might fulfill requirements for a set of inputs, but it is not flexible.

EDIT: Accepted as Code Refactoring.

closed as primarily opinion-based by gnat, gbjbaanb, Martijn Pieters, user40980, Eric King Apr 7 '14 at 20:52

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Define "soft-codes" and "hard-codes" please. That is not standard terminology. – Oded Apr 7 '14 at 8:47
  • 1
    Soft-codes are codes that are written when you're Softcoding, Hard-codes are codes that are written when you're Hardcoding. Make sense? en.wikipedia.org/wiki/Hard_coding en.wikipedia.org/wiki/Softcoding Edited with example. – Mc Kevin Apr 7 '14 at 9:03
  • put "enabling configuration options", though this assumes that's what you're doing - if you're just altering the codebase to put the '42' behind a facade, then I doubt it is useful work - do the refactoring as you use those values during other tasks. – gbjbaanb Apr 7 '14 at 9:42
  • You just used the terms in their own definitions and then asked if it makes sense. – Brandon Apr 7 '14 at 14:50
2

It depends on whenever you are changing behavior of the program as a whole. If you are changing a behavior then it is either "Bug Fixing" or "Adding a new feature". In your example, random always returning 42 could be considered bug so replacing it with Random.nextInt() is fixing this bug. On the other hand, if you are replacing hard-coded values with values that are supplied from the outside. For example replacing hard-coded values with values read from config file is adding new feature of being able to configure the software from the outside.

On the other side, if you are not changing behavior of the program and just cleaning up the code, then that is called Refactoring. And it is generally done to increase quality of code without changing what the program does.

  • how about this: considering an example of factorial, which takes in an integer, instead of performing an algorithmic approach, the code uses an if else statement to check for say: 100 values, just barely enough to survive the input range. What would you call that when changing it to an algorithmic one? – Mc Kevin Apr 7 '14 at 9:22
  • @McKevin If it doesn't change the outside-visible behavior (eg. the factorial is never called for 101st value) then I would call it refacotring. – Euphoric Apr 7 '14 at 9:28
  • @McKevin: Assuming It was done for performance rather than readability, I would probably call that optimizing. If it was done for readability, I would probably call it code cleanup. I usually use refactoring to refer to more architectural changes (things like extracting functions or splitting classes). – Brian Apr 7 '14 at 14:49
0

It is called "binding time." So, the contrast is between early binding and late binding. If you hard code a number then you bind very early in the process; if you load the number from a file at run time, you are late binding. In general, the later you bind, the easier the code is to test and maintain.

Here is a good discussion: http://en.wikipedia.org/wiki/Late_binding

Not the answer you're looking for? Browse other questions tagged or ask your own question.