이 글은 클린 코드를 작성하기 위해 안좋은 패턴과 수정해야하는 패턴을 정리한 내용을 다루고 있습니다.
❌ Bad
void X1();
int a, b, c;
✅ Good
void CalculatePlayerScore();
int32 KillCount;
float CurrentMana;
❌ Bad
void ApplyFireEffectToPlayer()
{
Player->bBurning = true;
Player->BurnDamagePerSecond = 10.f;
Player->StartBurning();
}
void ApplyFireEffectToEnemy()
{
Enemy->bBurning = true;
Enemy->BurnDamagePerSecond = 10.f;
Enemy->StartBurning();
}
✅ Good
void UBurnEffectComponent::ApplyBurning(AActor* Target)
{
if (IBurnableInterface* Burnable = Cast<IBurnableInterface>(Target))
{
Burnable->ApplyBurn(10.f);
}
}
❌ Bad
void ABattleSystem::Tick(float DeltaSeconds)
{
UpdateTimer();
CheckStatusEffects();
ValidateEnemyState();
HandleRespawn();
ProcessLoot();
UpdateUI();
// ... 수십 개의 기능
}
✅ Good
void ABattleSystem::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
UpdateBattleState(DeltaSeconds);
}
void ABattleSystem::UpdateBattleState(float DeltaSeconds)
{
ProcessEnemyBehavior();
RefreshCooldowns();
UpdateHUD();
}
❌ Bad
void SetupLevel(FString Name, int32 EnemyCount, float TimeLimit, FVector SpawnLocation, FRotator Rotation);
✅ Good
USTRUCT()
struct FLevelConfig
{
FString Name;
int32 EnemyCount;
float TimeLimit;
FVector SpawnLocation;
FRotator Rotation;
};
void SetupLevel(const FLevelConfig& Config);
❌ Bad
int32 GScore = 0;
void AddScore(int32 Amount)
{
GScore += Amount;
}
✅ Good
UCLASS()
class UScoreSubsystem : public UGameInstanceSubsystem
{
GENERATED_BODY()
private:
int32 TotalScore = 0;
public:
void AddScore(int32 Amount) { TotalScore += Amount; }
int32 GetScore() const { return TotalScore; }
};