I have a question about hard coding.

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

I learned that hardcoding is hardcoded by putting a value directly into a variable.

Then, are the values within the limited conditions hardcoded? For example,

            if (dplctChk > 1) {

                resultMap.put("returnCd", "FAIL");

                resultMap.put("returnMsg", "Duplicated product is already registered.");



                return resultMap;

            }



            if(re == 1){

                resultMap.put("returnCd", "SUCC");

                resultMap.put("returnMsg", "Processed successfully.");

Is returnCd and returnMsg hardcoding here?


2022-09-20 14:30

1 Answers

Hardcoding is called hardcoding, which fixes values that need to be changed appropriately without any basis.

For example, suppose there was an method.

public function setResultMap(resultMap, code, message)
{
    resultMap.put('returnCd', code);
    resultMap.put('returnMsg', message);
    return resultMap;
}

But I didn't know this method existed

if (re == 1) {
    resultMap.put("returnCd", "SUCC");
    resultMap.put("returnMsg", "Processed successfully.");
}

If you did, this is hard coding.

You can't do this. Because I know you're trying to manipulate the returnCd property of resultMap, but you might be able to manipulate the returnCd property by typo. Isn't it because someone made the setResultMap method and defined the factor to use it only by substituting variables? But you can't hardcode "returnCd".

It's kind of like this. I don't know if you understood.


2022-09-20 14:30

If you have any answers or tips


© 2022 pinfo. All rights reserved.