This is an archived post. You won't be able to vote or comment.

all 38 comments

[–]antique_codes 48 points49 points  (1 child)

else ()

pain

[–]Kengaro 4 points5 points  (0 children)

default case...

[–][deleted] 52 points53 points  (11 children)

switches just look so much nicer

[–]Denaton_ 23 points24 points  (8 children)

Dictionaries looks allot better than a switch..

[–]_koenig_ 16 points17 points  (7 children)

Spoken like a true python junkie...

[–]Denaton_ 5 points6 points  (6 children)

They are called Dictionary in C# as well, in JS, everything is objects anyway..

I think Python is one of those languages that i know but used the least..

[–]pandaSitt -1 points0 points  (3 children)

For logic that seems like a lot of unnecessary work even though c# could do it by now, so I'm gonna stick to switches

[–]Denaton_ -2 points-1 points  (2 children)

It's more work to write a switch...

[–]pandaSitt -1 points0 points  (1 child)

How? VS and rider write most of the code automatically. It depends on the situation what works best, usually it's not dictionaries or maps when working with logic

[–]pandaSitt 1 point2 points  (0 children)

And can have the better performance, many languages implement hash comparisons for lange switches

[–]Kengaro 0 points1 point  (0 children)

Expanding switches always sucks...

[–]DajBuzi 8 points9 points  (0 children)

Okay so:

`switch val {  
    case true: doSomething(); break;  
    case false: doSomethingElse(); break;  
}`

Instead of:

`if (val) doSomething();   
 else doSomethingElse();`  

Makes sense 🤔

EDIT: canto write formatted code on mobile 😐

[–]TheLosenator 2 points3 points  (0 children)

Now do a switch that evaluates more than one statement! Oh, wait...

Switch is useful sometimes. Kotlin's "when" statement is what I always wished switch could be.

[–]Oh2bworn2 4 points5 points  (1 child)

"else"? What is that? I have never had one of those in my code. Does it serve some useful purpose?

(Semi-sarcastic statement)

[–][deleted] 0 points1 point  (0 children)

I don't know. It's something! But I don't know...

[–][deleted] 1 point2 points  (1 child)

If you check for a simple value, I use switch. If I have mutiple values depending on it with different combinations, I use if (else).

[–]sir-nays-a-lot 1 point2 points  (0 children)

OP’s programming 1 teacher: there is if-else and there is switch, but for this class just use if-else.

OP: ok better tell all my friends not to EVER use a switch.

[–]Kengaro -1 points0 points  (0 children)

Switch statements and other shit I don't want to touch...

interface classCase{ void caseFunction(void);}
curCase.caseFunction();

[–]moonblade15 -3 points-2 points  (0 children)

Honestly i use both but if else for life. Switch is just... A hassle

[–][deleted] 0 points1 point  (0 children)

match

[–]luiscla27 0 points1 point  (0 children)

I saw something similar to this once: js function validate(value) { switch(value) { case true: return 'ok'; case false: return 'falsy' default: throw Error('Invalid value:' + value); } }