why are undergrads in compsci so obsessed with switch statements

@wallhackio not an undergrad but purrsonally i just despise how if-elseif chains look

@aescling but switch statements add a bunch of indentation so for me it's picking your poison

@wallhackio @aescling Do they?

switch (some_enum) {
case VALUE1:
do_something();
break;
case VALUE2:
do_something_else();
break;
}

vs.

if (some-enum == VALUE1) {
do_something();
} else if (some_enum == VALUE2) {
do_something_else();
}

That's the same amount of indentation...

@vaporeon_ @aescling I would always do it like

switch(gorp) {
case 'norp':
console.log('norp');
break;
case 'sorp':
console.log('sorp');
break;
default:
console.log(' what the gorp???');
break;
}

@wallhackio @vaporeon_ @aescling you should instead do

switch (gorp) {
case 'norp': {
console.log('norp')
break
}
// etc
}

@vaporeon_ @Lady @aescling JavaScript will auto insert semicolons if you don't add them

There are camps on whether or not you should manually add them

I think ignoring them makes more sense but it was a style convention at my old job to use them and the Deno autoformatter inserts semicolons so I just write them now out of habit

@wallhackio @Lady @aescling Just when I thought you couldn't make me hate JavaScripts even more :psyduck:
Cursed language

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.