Article View: comp.lang.c
Article #519Re: Taming The Switch-Statement
From: David Brown
Date: Sun, 18 Oct 2026 19:09
Date: Sun, 18 Oct 2026 19:09
149 lines
7198 bytes
7198 bytes
On 18/10/2026 18:09, bart wrote: > On 18/10/2026 15:27, David Brown wrote: >> On 18/10/2026 15:33, bart wrote: >>> On 18/10/2026 12:22, David Brown wrote: > >>>> To me, that is just as much gibberish as the original C. >>> >>> That doesn't matter - the problem is not even knowing what it >>> represents. >> >> That is, shall we say, a strange attitude. Gibberish (since that >> seems to be the preferred term here) is gibberish, no matter the >> language or representation, and is equally meaningless and useless. > > 'Gibberish' here refers to the representation, whether the type being > described is made-up nonsense or real. > Maybe that's what /you/ mean by it, but to me the type itself there is gibberish - no matter what representation you use. > You may want to know what some complex type is for many reasons, you > don't necessarily need to understand what it means or why it was used. > > (For example I might come across a type in a C API that I want to > convert to another language.) You are just making stuff up. C API's use different named types just like any other C code, so that people can understand what they are. > >>> In practice there will be actual types that start to look like >>> gibberish, full of *, () and [] that must be in exactly the right place. >> >> Not in my code, or the code I work with - types are clear to me. >> Again, experiences can vary. > > What are you saying here, that your types never involve * () or []? That > is hard to believe. I'll cross off "false dichotomy" on my "Bart's logical fallacies" bingo card for the day. I don't write types that look like gibberish, full of *, () and []. That does not mean I do not write types that contain *, () or []. > >> (Of course the syntactical elements must be in the right place!) > > Isn't that the problem? C makes it tricky. Here are two very > straightforward declarations from my projects: > > ref []ichar stringtable # ichar is ref char > [N]ref proc(T) handlertable Are you suggesting that in your language, "stringtable" could also be declared as : ref ichar [stringtable] or ][ stringtable ichar ref ? I suspect that your language also requires the syntactical elements to be in the right place. > > These are the C versions: > > char *(*stringtable)[]; > void (*handlertable[N)(T); > > They involve * () and [] that must all be in the right place, in the > right nesting order. In C, parentheses are used to alter precedences as > well as for parameter lists. This not a thing in LTR forms. I assume that : [N] ref proc(T) handlertable and ref [N] proc(T) handlertable are different? You need to give things in the right order, or use parentheses, to get the right "type expression". It's just like any other kind of expression. The intention of the declaration syntax in C is that the declaration order follows usage. If you would not write code that /uses/ a declaration in a particular way - like so many *, () and [] sets that it is hard to comprehend - then do not write /declarations/ in that way. I don't think there is anything inherently better about C's declaration syntax than your declaration syntax, or others that are more right-to-left or more left-to-right. There's a lot of good things to say about left-to-right ordering, since that is the order for reading (in English, anyway). But it also means the declaration order and usage order are different unless your array subscript, pointer dereference and call operators are also all left-to-right. My point is not that C's syntax is wonderful (I disagree with Kenny here), but that it works fine in practice, you don't have to write incomprehensible declarations, and that if you /do/ want to write incomprehensible declarations, you can do it in any language just as easily. > > Additionally, in C, you can sometimes mix up the order of * and [], but > since a T* value can be indexed, and a T[] value can be dereferenced, > those errors might still compile. > > So it's a problem. You're saying it isn't one if you do X, Y and Z. I'm > that you shouldn't need to do X, Y and Z; if you do then it's a > language problem. > I know you say that - you are wrong to say that. If you want good, clear, correct C code, you need to write good, clear, correct C code. That's the X, Y and Z. And that applies to all languages, including yours. The details may differ, but the principles do not. You can well hold the opinion that you personally find it easier to write good, clear, correct code in your own language than you do in C. It would indeed be extraordinary if that were not the case. But your opinion there does not make it fact, or mean it applies to others. > >> Use a typedef. Or since C23, use type inference - that can save >> naming and identifying types when things get complex, > > OK, that's a fifth kind of workaround! Although it is more of an > unrelated feature. >>> This should be simple enough to do in a language without needing to >>> follow some back-and-forth algorithm, or use an external tool, or >>> need to decompose them into multiple levels using 'typedef', or need >>> to disambiguate with parentheses. >> >> You just /have/ to whine, don't you? Whenever you complain - usually > > I thought it was, for a change, a civil exchange up to now. It was - I really am trying, but you wrote one knee-jerk comment too many. I will try to reset.
Technical Details
Message-ID:
<11b35gt$1cn63$2@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11arjmc$2qid7$1@dont-email.me> <11at5vi$5vu$1@reader2.panix.com> <11auad0$3no1k$1@dont-email.me> <11aupfl$3ul$1@reader2.panix.com> <11avmfb$55rt$1@dont-email.me> <11b2a6d$131h6$1@dont-email.me> <11b2hr6$15thq$1@dont-email.me> <11b2l06$16mof$1@dont-email.me> <11b2qv0$19h68$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Sun, 18 Oct 2026 21:09:17 +0200 Organization: A noiseless patient Spider Lines: 149 Message-ID: <11b35gt$1cn63$2@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <11arjmc$2qid7$1@dont-email.me> <11at5vi$5vu$1@reader2.panix.com> <11auad0$3no1k$1@dont-email.me> <11aupfl$3ul$1@reader2.panix.com> <11avmfb$55rt$1@dont-email.me> <11b2a6d$131h6$1@dont-email.me> <11b2hr6$15thq$1@dont-email.me> <11b2l06$16mof$1@dont-email.me> <11b2qv0$19h68$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 18 Oct 2026 19:09:18 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1465539"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GSCqXD1/Spdf8m9+XbuCvd/tQm6l5HSQ="; posting-host="a272f2752d0a4376a695806f42b83d2a" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:K0wTIOpWMPRUnOMyrMoJj+qYU7g= sha256:QwNXz6sL5mxeg+mCmWwQc6q/0mERecFbgr8TxUXaN80= sha1:Cj3L4xAa/jLjQgEDI3olmKJXUnc= sha256:nXtH3Qgjc1nThmnJBf/zfLiQUCTeH4wzFgwMQ4cKTPk= Content-Language: en-GB In-Reply-To: <11b2qv0$19h68$1@dont-email.me>