I always see people say that they cannot “hard code”
What does it mean, I searched on google but I still don’t get it.
I always see people say that they cannot “hard code”
What does it mean, I searched on google but I still don’t get it.
(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)
Definition straight from Google: "fix (data or parameters) in a program in such a way that they cannot be altered without modifying the program."
Hard coding means you tell the program exactly what to do. You can think of soft coding (the opposite of hard coding) as an AI program, where the computer sort of teaches itself.
Here’s a very simple example to demonstrate the differences.
Say you have a game with 3 doors, and the objective is for the player to find which door has the prize behind it. If you were to hard code this system, you may create a variable that tells the program that door 2 will always have the prize. local doorWithPrize = 2
. The only way to change this outcome would be to manually change that variable inside of the code.
But that wouldn’t be very fun, would it? The player would quickly realize that the prize is behind the same door every time, and would always pick door 2. This is where you need to move into a bit of soft coding, where the program is influenced by an outside factor; randomness. local doorWithPrize = math.random(1, 3)
.
So let me help you as well as with an example
Hard coding is when you embed the data you are going to use right into your source code. So you can’t change it without modifying the actual code.
local p = Instance.new("Part")
p.Position = Vector3.new(6.73, 5.246, 9.52)
The numbers you have put in are hard-coded because, you typed them right into your code. What if you want to change this position? It means you will have to change up the numbers.
The opposite of hard coding is soft coding. Now say you have a reference part. You will position your part wherever the reference part is. So you move it around to the new place in studio.
local p = Instance.new("Part")
p.Position = workspace.Reference.Position -- no more need to modify this code ever again!
You are now getting it from the part’s Position
property as opposed to hardcoding its position.
You’re still hardcoding 3
in your last example.
Hardcoding:
function getDoor()
return math.random(1, 3)
end
Paramaterizing:
function getDoor(numDoors)
return math.random(1, numDoors)
end
So when people say that they cannot hard code what does that mean?
They generally mean you shouldn’t. When you hard code you are constantly changing your code all the time.
SOURCED FROM GOOGLE
hard-code
verb
COMPUTING
gerund or present participle: hard-coding
“software that hard-coded the size of the structures”
I saw that, I didn’t really understand it
If you type a number into a script directly, you have hard coded that number.