On Wednesday, 23 November 2022 at 15:21:07 UTC, ryuukk_ wrote:
> On Wednesday, 23 November 2022 at 14:21:23 UTC, deadalnix wrote:
> On Wednesday, 23 November 2022 at 13:41:12 UTC, ryuukk_ wrote:
> // verbose API, readable
struct SuperLongStruct
{
struct SuperLongInnerStruct
{
enum SuperLongEnum
{
VALUE_A, VALUE_B
}
SuperLongEnum super_long_flags;
}
SuperLongInnerStruct some_data;
}
// oh shoot
SuperLongStruct super_long_struct = {
some_data: {
super_long_flags: SuperLongStruct.SuperLongInnerStruct.SuperLongEnum.VALUE_A | SuperLongStruct.SuperLongInnerStruct.SuperLongEnum.VALUE_A
}
};
// oh nice!
SuperLongStruct super_long_struct = {
some_data: {
super_long_flags: .VALUE_A | .VALUE_A
}
};
Try alias E = SuperLongStruct.SuperLongInnerStruct.SuperLongEnum;
> AttackType attack_type = .MELEE;
(..)
switch (attack_type)
{
case .MELEE:
break;
}
now your variable name carry more and proper information about what it is,
auto attack_type = AttackType.MELEE;
switch (attack_type) with(AttackType) {
case MELEE:
break;
}
struct Action
{
AttackType attack_type;
}
// no auto here
in your switch, did you read it?
switch attack_type with AttackType
this is not appealing and is the noise and repetition that needs to be suppressed
i was verbose when i declared my variable name, that's enough
and you didn't read my other comment
why should i declare an alias? it leaks the symbol to the scope, it is another symbol that i need to remember when i refactor, and it adds cognitive load when i read my whole module, too much gymnastic and scope bloat
now this example:
switch (action.attack_type) with(AttackType) {
case MELEE:
if (action.weapon_type == SuperLongType.InnerType.SWORD)
(...)
break;
}
switch (action.attack_type) with(AttackType) with(SuperLongType.InnerType) with(SuperLongType.AnotherInnerType) {
case MELEE:
if (action.weapon_type == SWORD)
(...)
if (action.buff_type == STR_UP)
(...)
break;
}
Yeah no thanks..
There it's miles better, you don't need no alias to workaround anything that bloats scope and adds superfluous and unnecessary cognitive load, you read the variable name and you know what you deal with
switch (action.attack_type) {
case MELEE:
if (action.weapon_type == .SWORD)
(...)
if (action.buff_type == .STR_UP)
(...)
break;
}