Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by saurik on Thursday February 02, 2017 @02:37PM
(#13553778)
Ok, I don't mean "stop writing C", but "stop reading C": people too often look at not-even-difficult things and say "I happen to not have bothered to learn that, so you shouldn't use it in writing, as I couldn't read it", which to me sounds exactly like someone saying "I happen to have a first grade reading level, so you shouldn't use big words or long sentences or prepositions, because I didn't understand them". There are times and places where that is appropriate, but those are not all times and places, not I would argue the majority of times and places.
Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by GFK_of_xmaspast on Friday February 03, 2017 @07:57AM
(#13559451)
I've been doing c for almost 25 years now, and for many of those years it was my primary language, and not only would I refuse to write that kind of crazy switch construct I would refuse to allow it to pass code review.
Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by digler999 on Thursday February 02, 2017 @03:19PM
(#13554240)
> The idea that one has to know all the hidden edges of a language
switch is hardly a hidden edge, it's an important control structure in the language. You want a "hidden edge", look at designated initializers [1] which I just heard of yesterday (thanks to HN), despite having 17 years experience using C. Or bitfields, or function pointers.
[1] http://www.drdobbs.com/the-new-c-declarations-initialization...
Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by AnimalMuppet on Thursday February 02, 2017 @04:34PM
(#13554885)
Switch is hardly a hidden edge, but using it like that is.
Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by tomjakubowski on Friday February 03, 2017 @08:16AM
(#13559562)
Huh, I wouldn't think of function pointers as a hidden edge in the language, and I've only been seriously using C for about 4 years.
Is there some crazy consequence of using function pointers that I've been missing? Callbacks are pretty ubiquitous in C code bases, and the "hand coded vtable" pattern isn't too uncommon.
Maybe the lesson is that what language feature are the "hidden edges" depend on one's domain.
Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by digler999 on Friday February 03, 2017 @09:57AM
(#13560154)
I was being figurative. nothing's hidden in an ANSI standardized language. My point was you can go along way in C without ever needing function ptrs. Their syntax isn't exactly welcoming, either. Compared to switch, which OP had compared to a hidden corner, need switch a lot more frequently than you need function pointers.
Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by minitech on Thursday February 02, 2017 @07:23PM
(#13556454)
Designated initializers aren’t “hidden” at all, just new (and not that new).
Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by ConceptJunkie on Thursday February 02, 2017 @05:28PM
(#13555472)
I've always understood switch statements just fine.
However, after this article, I now understand them a little better.
Re:‘Abusing’ the C switch statement – beauty is in the eye o...
by sh_tinh_hair on Thursday February 02, 2017 @11:48PM
(#13557761)
Exactly.
Oh please. C is perfectly usable without knowing switch is actually a bunch of gotos. The idea that one has to know all the hidden edges of a language to use it is pointless, because every language has something like that. Even Python can be a minefield if one tries hard abusing metaclasses, and I'm pretty sure 95% of the Python users don't know how to use them.
If you pursue the idea of knowing every deep place to the extreme, the only language left for general developers to use is Go. A language so concerned at removing hidden features that almost no features are left.