{
Super::BeginPlay();
auto AssignParameters = [&]()
{
TileBoxExtends = FVector(TileSizeX / 2, TileSizeY / 2, TileSizeY / 2);
//Cast all room designs.
};
for (auto RoomDesign : RoomDesigns)
{
ARoomActor* CastedRoom = Cast<ARoomActor>(RoomDesign->GetDefaultObject());
CastedRooms.Add(CastedRoom);
}
AssignParameters();
GenerateMap();
if (VisualizeOverlaps || VisualizeVisited)
{
VisualizeTiles();
}
}```
#Is making lambda functions inside function like this good or bad practice?
34 messages · Page 1 of 1 (latest)
the main idea is whenever I make a little complex logic I want to extract as method but I am %100 sure it will be only used for one function and class itself is very complex already. So in these cases I am doing like this
In this case no, probably not
what should I do instead
Just pull it out into another method if you don't want to just put that logic in-line in BeginPlay
Methods don't have to be called by more than one function, they're just a way to develop building blocks for your program
extracting method? But the class is over 1500 line already and 50 function. And %100 this method will only be used in BeginPlay not other place
I can barely navigate to other functions. Still I should extract as method?
this won't significantly impact the size of your file
What strategies are you using to navigate your code?
What IDE are you using
yeah but it gets hard and harder to navigate. I am using Rider. Ctrl F12 is great to find all the functions easily
but over 50 function class is very complex already I don't want to see anymore functions that I only use for one function. GPT4 also suggested this is valid way to handle this scenarios. In C# local functions have totally same idea
I could inline to abstract and never bother to see again but that would make it more bad practice
If you think pulling the logic into another method is a bad idea pulling into a lambda really isn't better 😛
But at the end of the day do whatever you find readable and clear 👍
so, making lambda functions inside function is Always considered bad practice?
in general
Fwiw it sounds like you have bigger issues with this class than this lambda function
😦
Namely it sounds likely that it's trying to do too much
one functionality one main algorithm focus
but I guess it's normal a procedural generation algorithm is normal to be defined just in a class
Why does a class that does procedural generation have a BeginPlay method?
casting the classes and assigning to pointer holder initalizing the main method that does all the procedural generation
Is this also extremely bad practice?
I Found this. Last answer makes sense and justifies my reason to use Lambda function. https://stackoverflow.com/questions/39730224/helper-functions-lambdas-vs-normal-functions
This is unreal engine class. Every class has to have beginPlay and Tick. And also beginplay calling all the functionality
Perhaps we see a different last answer 🙂
If you won't need the two helper functions somewhere else in your code, then use your lambda method , but if you will call one of them again somewhere in your project avoid writing them each time as lambdas