"hard-wired" in C++
-
Does anyone mind briefly explaining what hard wired means in C++??? sorry if im asking childish questions :laugh: Thanks guys :)
This is probably referring to values being 'hard coded'. So if you have explicitly defined a numeric or string in your code, then it is termed as being 'hard-coded'. The flip side of this is to construct your coding so that your values are user-defined, or can be obtained from an external source.
#define PI 3.142 float calc(int a, int b) { return (a * b * PI); }
So in the above example, I have hard-coded the value of pi. In this case the accuracy of my calculations are fixed. If I needed to increase the accuracy of pi at a future date, I need to edit and recompile my code. This may not be a problem now, but can cause some problems in certain circumstances. Hard coding string values are also widely mentioned and can be extremely difficult for multi-lingual software. In cases where your program messages, logs, reports and UI text may change (due to language changes for example), you do not want to hard-code text strings when writing your code. One way around this is to use the string resource files that de-couple this process.
I Dream of Absolute Zero
-
Does anyone mind briefly explaining what hard wired means in C++??? sorry if im asking childish questions :laugh: Thanks guys :)
-
Does anyone mind briefly explaining what hard wired means in C++??? sorry if im asking childish questions :laugh: Thanks guys :)
Adding to what other have posted, here are some examples of hardwired code: void main(void) { double cylinder_volume=5.5*3.1415*3.1415*7.9; printf("The total cylinder area is %.15g\n", cylinder_volume*4.0); long total_people_to_invite=10.0; printf("The total invitations is %d\n", total_people_to_invite); } This code is hardwired to the extreme. Compare to the next code example: #define PI 3.1415912 void main(void) { double cylinder_radius=5.5; double cylinder_height=7.9; double cylinder_top_area=cylinder_radius*PI*PI; double cylinder_volume=cylinder_top_area*cylinder_height; double total_cylinders=4.0; printf("The total cylinder area is %.15g\n", cylinder_volume*total_cylinders); long singers=1; long bartenders=3; long dancers=5; long cooks=1; long total_people_to_invite=singers+bartenders+dancers+cooks; printf("The total invitations is %d\n", total_people_to_invite); } This code is not as hardwired. Still, it could be coded to be even more flexible and reusable. For example, the area computation of a circle (used for the cylinder_top_area) could be implemented as a function which takes the radius. In general, the sense of "hardwired" code is related simultaneously to how clear it is to read it, understand it, change it, and re-use it. The easier it is to acomplish those things *SIMULSTANEOUSLY* the less hardwired the code is. In the above example all the predefined quantities could even come from some external configuration file, making changes easy even without recompilation. For the above example, this could be too much. So "hardwired" is not a clearly defined concept, but you see that if for such a simple example as the cylinder volume and invitation count external files had to be opened to read configuration parameters then, clearly, reading and understanding would be harder. I hope this helps, Rilhas