Hacker News new | ask | show | jobs
by umbrai_nation 3180 days ago
I use them with functions that have too many arguments. It's not always feasible to fix the problem at the source.

damageDealt = calcDamage(weaponType, monsterType, DamageType.FIRE, null /* specialEffectFlags /, false / hasMagicTargeting */ );

It's definitely a code smell, but it's much better than nothing and I'm always glad to see these comments when I come back to the code.

1 comments

Yeah, that was the closest I could think of. But in Python you’d use keyword arguments, and in JavaScript you’d use objects with named fields in lieu of that, and in Rust you’d commonly try to use struct fields or custom enums for such things (I still want named arguments there).

The extreme in your case would be `hasMagicTargeting = false` and then pass `hasMagicTargeting` instead of `false`.