Operating System - HP-UX
1833827 Members
2301 Online
110063 Solutions
New Discussion

hard coding hostname for an application

 
SOLVED
Go to solution
navin
Super Advisor

hard coding hostname for an application

Hi,
Could you please educate me ,what does it mean
hardcoding an ip or hostname for an application.
Thanks for your time.
Learning ...
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: hard coding hostname for an application

As I interpret the expression, harcoding is using a literal expression rather than an environment variable, such as 140.140.140.140 rather than $IP for an IP address.


Pete

Pete
RAC_1
Honored Contributor

Re: hard coding hostname for an application

Do you want to run application on only the host where the hostname matches??? So as to avoid to copy it on other hosts and run there???

In that case have you looked at i4admin?? man i4admin, you can bind application to run on specific host only. Rather to a cpu.

hostname can be changed, so you will have to change the application also.

man i4admin and reated commands.

Anil
There is no substitute to HARDWORK
Sundar_7
Honored Contributor
Solution

Re: hard coding hostname for an application

here is an example of hardcoding

HOST="navinhost"
if [[ "$HOST" = "navinhost" ]]
then
..
fi

In the above example you are basically hardcording the hostname.

HOST=$(hostname)
if [[ "$HOST" = "navinhost" ]]

The above excerpt is preferred over hardcoding for couple of reasons

1) easily portable -you can use the same code in more than one machine without any need to edit and customize the code for specific nodes

2) any changes to the system that could effect the inputs to the application would not mean you have to rewrite the application - In the above ex, if you have hardcoded the hostname, whenever the hostname is changed, then you have to edit and make changes to the code.
Learn What to do ,How to do and more importantly When to do ?
W.C. Epperson
Trusted Contributor

Re: hard coding hostname for an application

Pete's given the gist of it, but we can probably be a lot more helpful with a little more information about the problem or context.
"I have great faith in fools; self-confidence, my friends call it." --Poe
A. Clay Stephenson
Acclaimed Contributor

Re: hard coding hostname for an application

"Hardcoding" whether it's a hostname, IP address, or any other value simply means embedding that value into the program or script so that it is not configurable. The practice is generally discouraged. There are several methods for "softcoding" values: 1) pass the data on the command line 2) set and export environment variables 3) store the data in a configuration file. The advantage of "softcoding" is that these values can be easily changed without having to change the source code and/or compile the program.


If it ain't broke, I can fix that.
navin
Super Advisor

Re: hard coding hostname for an application

Thanks for taking time to reply.Useful informations.Thanks again.
Learning ...