|
seems on shaky ground philosophically though
|
# ? Sep 21, 2016 15:44 |
|
|
# ? May 29, 2024 11:14 |
|
The Curious Case of the Switch Statement
|
# ? Sep 21, 2016 15:57 |
|
quote:It’s not even useful as an optimization any more; I’m pretty sure our compilers are plenty smart enough by now to recognize an if tree and turn it into a jump table or binary search or whatever. It’s one of those things that feels like it’ll make a program faster, but almost certainly won’t make any difference whatsoever.
|
# ? Sep 21, 2016 16:57 |
|
hating on duff's device???
|
# ? Sep 21, 2016 16:57 |
|
quote:None of those are intended as huge complaints, and I’m not proposing we start a petition to remove switch from the next version of C or anything. I merely object… aesthetically. (And if we were really going to change C to match my aesthetic preferences, we’d start with something much more important, such as ditching the braces.) Oh, so that's what matters
|
# ? Sep 21, 2016 17:17 |
|
Switch statements that refuse to compile when you don't cover all the cases are good, though.
|
# ? Sep 21, 2016 18:08 |
|
switch in swift is cool fallthrough must be explicitly specified must be exhaustive intervals tuples & pattern matching https://developer.apple.com/library...14097-CH9-ID127
|
# ? Sep 21, 2016 18:24 |
|
raminasi posted:hating on duff's device??? it's a disgrace that duff's device even compiles
|
# ? Sep 22, 2016 00:19 |
|
triggered by control flow
|
# ? Sep 22, 2016 18:29 |
|
switch statements are super fun in verilog. you can switch on a constant and match against variables: case(4'b0101) begin foo[3:0]: begin ... end {bar[2:0], baz}: begin ... end endcase also wildcard-matching is its own thing in two different forms and when to use which seems to be an open subject of debate: casex and casez, which can do nice things like: casez(hello[3:0]) begin 4'b1???: begin... end // matches all hello where hello[4] == 1 4'b0101: begin ... end // matches one concrete case {butts[1:0], 2'b??}: begin .. end // matches on hello[3:2] == butts[1:0] and ignores hello[1:0] endcase and because its verilog, you can (probably? i honestly dont know) match multiple cases at the same time and that (might?) be totally okay it's probably definitely fine if the two cases don't conflict internally, for example: 1: a <= 5; 2: b <= 6; 1 only touches a, 2 only touches b. those statements can happen at the same time, nbd but: 1: a <= 5; 2: a <= 6; both touch a. if they happen at the same time, your behavior is probably synthesizer-dependent. a might be 5, might be 6, might catch on fire, might fail synthesis (in detectable cases)... in simulation, you'll at least get a warning that it has two drivers i actually have no idea how much of this is right or synthesizable and i use this language a lot. i love languages where 90% of the spec is a landmine the only patterns i ever use are switches on variables with entirely concrete matches or non-overlapping matches if wildcards are used Bloody fucked around with this message at 18:53 on Sep 22, 2016 |
# ? Sep 22, 2016 18:50 |
|
quote:ALGOL W was a big step towards something recognizable as a modern language. It brought us such revolutionary innovations as null, a value that crashes your program.
|
# ? Sep 22, 2016 18:59 |
|
Gazpacho posted:triggered by control flow
|
# ? Sep 22, 2016 19:04 |
|
This article has some good quotesquote:Perl 5, historically, did not have a switch statement. Perl 6, in its quest to include literally every single language feature ever conceived, sought to remedy this.
|
# ? Sep 22, 2016 19:14 |
|
eevee is very good
|
# ? Sep 22, 2016 19:27 |
|
Symbolic Butt posted:they use the character for REALITY to represent True, that's badass No, it means true. it's most frequently used as an adjective a la really/truly. saying it means reality is like saying "truth" means philosophical truth rather than "something that is true".
|
# ? Sep 22, 2016 19:49 |
|
FamDav posted:No, it means true. it's most frequently used as an adjective a la really/truly. saying it means reality is like saying "truth" means philosophical truth rather than "something that is true". oh. whatever source I used to look this up gave an embellished meaning I guess
|
# ? Sep 22, 2016 20:06 |
|
typescript 2 out, with some work towards abolishing nulls, seems promising https://blogs.msdn.microsoft.com/typescript/2016/09/22/announcing-typescript-2-0/
|
# ? Sep 22, 2016 22:16 |
|
Bloody posted:switch statements are super fun in verilog. you can switch on a constant and match against variables: verilog is cheating
|
# ? Sep 22, 2016 22:49 |
|
especially since anything remotely clever is going to be synthesized straight to ground
|
# ? Sep 22, 2016 23:00 |
|
hifi posted:Oh, so that's what matters
|
# ? Sep 23, 2016 00:13 |
|
Bloody posted:and because its verilog, you can (probably? i honestly dont know) match multiple cases at the same time and that (might?) be totally okay no, priority is inferred from the ordering and only one matches at a time. there are priority & unique keywords, but i forget what they do casex is the more liberal, it'll stand in for casez but not vice versa i liked verilog case statements
|
# ? Sep 23, 2016 01:41 |
|
Captain Foo posted:eevee is very good
|
# ? Sep 23, 2016 02:50 |
|
Captain Foo posted:eevee is very good i had the opportunity to work with them hacking on something years ago and yes, they are
|
# ? Sep 23, 2016 03:29 |
|
Captain Foo posted:eevee is very good
|
# ? Sep 23, 2016 03:57 |
|
on the off chance someone here hasn't read php a fractal of bad design, it is very enjoyable and also written by the aforelauded eevee
|
# ? Sep 23, 2016 03:58 |
|
i mean they're wrong about switch statements being redundant, most compilers are way less smart than they're assuming and exhaustiveness checking on enums (like in java) is really useful. but they're right about most of the rest and the history bit is interesting
|
# ? Sep 24, 2016 11:15 |
|
Soricidus posted:i mean they're wrong about switch statements being redundant, most compilers are way less smart than they're assuming and exhaustiveness checking on enums (like in java) is really useful. but they're right about most of the rest and the history bit is interesting case/match statements are good, switch statements are bad.
|
# ? Sep 24, 2016 11:47 |
|
case/match is great but switch is better than chained if/else
|
# ? Sep 24, 2016 11:55 |
|
swiftswitch owns stfu
|
# ? Sep 24, 2016 12:08 |
|
so i started doing a swift for a dumb project and its cool i like it much more than obj c, and the methods got rid of all the NSFoo bullcrap which is nice too but peppering your code with "?" and "!" seems a bit of a weird way to deal with nullable types/arguments e.g.: code:
|
# ? Sep 24, 2016 22:01 |
|
why not wrap the uploadRequest init in an if-let block tho
|
# ? Sep 24, 2016 22:14 |
|
becuase a) this is a halfass project and b) i have no idea what i'm doing its my first time writing swift so i'm sure all my code is terrible. and the last time i did obj-c was like 3 years ago
|
# ? Sep 24, 2016 22:17 |
|
i kind of like elvis operators as a way to deal with the world of null
|
# ? Sep 24, 2016 23:51 |
|
you're trying to deal with null at every place you use the thing that's cool, you can do that, but it's usually better to figure out at some useful point whether you have a value or not like if you're positive something can't fail, go ahead and assert that with ! and if it might, just check and bail out, maybe with guard
|
# ? Sep 25, 2016 00:02 |
|
yeah you still want to make an effort to avoid null, but in the cases where you can't you have an ok option for dealing with it
|
# ? Sep 25, 2016 00:06 |
|
I'm beginning to think this whole null idea was a mistake from the beginning
|
# ? Sep 25, 2016 00:34 |
|
after using some Haskell I never want to go back from Maybe and Either.
|
# ? Sep 25, 2016 01:09 |
|
hoare is wrong, null is good
|
# ? Sep 25, 2016 09:43 |
|
i prefer the pythonic way of dealing with None but thats probably because i like + am used to python
|
# ? Sep 25, 2016 11:55 |
|
|
# ? May 29, 2024 11:14 |
|
i am glad most languages seem to have started adding option types / actual ways of dealing with acknowledging nullability of values, rather than the "let's just sprinkle (if x == null) everywhere", or, even worse, "let's pretend this code is correct even though there's no way to guarantee a null can't just get in and break the whole drat thing".
|
# ? Sep 25, 2016 15:32 |