TripleX LevelDifficulty vs Difficulty

Hello,

I’m trying to understand why or how “LevelDifficulty” in our main function changes to “Difficulty” in the print introduction. Function parameters are kind of confusing so far.

Never mind. I watched the end of lesson 28 again and it seems that LevelDifficulty in our main function is passed to Playgame as (int Difficulty) through the use of an argument…inside the (). It is also passed to the printintroduction function through argument also. I kind of get it now but it’s still a difficult concept to grasp in the beginning. I have no idea how I would have come up with this on my own, haha!

…also you can change “Difficulty” everywhere in your code to “LevelDifficulty” and it will still work the same. I’m assuming they changed it to “Difficulty” to show that you can pass anything as an argument and it doesn’t need to be the exact same name. It also saves a little more space and makes the code cleaner.

Some people agree with this, some people do not. It is not forbidden or considered a pad practice to use the same name in the variable you are passing and the name the function is internally going to use. Some people find it easier, especially when they are handling small programs, because they know what the variable is referring to.

Some people on the other hand, do not. You will see many coding standards stating that you must not use the same variable names. If you do a quick search, you will not find an answer. Other people say they hate it, other people praise it.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms