[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

break statements in a switch case is horrible syntax. By using

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 3

File: download.jpg (3KB, 121x144px) Image search: [Google]
download.jpg
3KB, 121x144px
break statements in a switch case is horrible syntax. By using the switch, it's implied you want each case separately.
>>
File: 1460913391674.gif (1MB, 268x274px) Image search: [Google]
1460913391674.gif
1MB, 268x274px
>>57826881
Wouldn't the program just display every case below it without the break, though?
>>
>>57826908
That's my point. Get rid of the fucking break and have the default be you only execute that case, and have a different statement if you want it to fall through
>>
>>57826881
What you are looking for OP is called 'pattern matching': https://doc.rust-lang.org/book/patterns.html
>>
File: 1451623136518.jpg (61KB, 1000x800px) Image search: [Google]
1451623136518.jpg
61KB, 1000x800px
>>57826937
pls explain am retard
>>
>>57826881
you're trying to argue logical semantics OP. settle down you fucking faggot
>>
>>57826881
>it's implied you want each case separately.

No it isn't.

Very often you want the same behavior for several cases.

switch(weekday) {
case 'saturday':
case 'sunday':
return 'It\'s weekend, time to shitpost!'
break;
default:
return 'More work :('
break.
}
>>
>>57827558
IMHO the syntax isn't very thought out. In 90% of the cases you want to check only a single case and not many. The multiple case syntax could also have been using a separator for different cases e.g. a comma. This would allow matching multiple cases and would not make the single match case verbose with the need of multiple break statements.
>>
If this thread is supposed to be bait, you're not doing a very good job of it, OP, that opinion is hardly controversial.

We're just stuck with the thing we're stuck with in the languages we're using. Some languages do it opt-in, some do it opt-out. No big deal either way.
>>
Google performed a mass code study and found that break was used in ~95%+ of switch cases.

So, Go does break by default.
To fallthrough, you can either explicitly use the "fallthrough" keyword, or supply multiple values in case (e.g. `case "Saturday", "Sunday": ...`)
>>
I love it when new programmers try to act like they know shit.
>>
>>57826881
Why not use break statements?
>it's horrible syntax
How does your second sentence support this claim? Oh right, it doesn't. You are just mashing shit on your stupid keyboard and hoping that someone will agree.
>>
>>57829660
He read it in a book and now he thinks he knows shit.
Thread posts: 13
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

If you need a post removed click on it's [Report] button and follow the instruction.
If you like this website please support us by donating with Bitcoin at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties. Posts and uploaded images are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that website. If you need information about a Poster - contact 4chan. This project is not affiliated in any way with 4chan.