Is it wrong to do this

Hi every one! This is my first post so here goes. In this section of the video we are asked to create a method to retrieve the length of the hidden word. I did it a little differently which I will explain in a second but I want to know if doing it this way could cause problems or is not considered good coding practice.

So basically I created a getter called “FString GetMHWL()” and as you see it is a FString instead of an int32 like the example in the video. MHWL just stands for my hidden word length. I declared it in the .h file and defined it in the.cpp as one would normally do with a getter and it returns string value of the private variable myHiddenWord. To get the length of the variable I wrote this in main.cpp, " const FString WORLD_LENGTH = BCGame.GetMHWL(); " which takes the string value in GetMHWL and places it into the string variable " WORD_LENGTH". Now if I want to know the length I used the “.length()” method at the end of WORLD_LENGTH.length.() , like so, and it prints the number of characters in the string.
This was slightly different from the video but it works just fine, so i’m wondering if it was ok to write it this way? Just because it works doesn’t mean its proper. Any thought? I may want to code other things this way in the future but if its a bad habit I would like to know. Thanks!

of course it’s work fine. you can also get this variable in type char like this char GetMHWL(); it’s not wrong, but in general length() method we are using for the loop for checking, matching, calculating or something like for(int i=0; i < word.length(); i++) { } like this. In terms of your practice is bad. In general word length is an integer type.

Privacy & Terms