🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #6

Re: Taming The Switch-Statement

#6
From: Kaz Kylheku
Date: Wed, 07 Oct 2026 00:42
118 lines
6426 bytes
On 2026-10-05, bart <bc@freeuk.com> wrote:
> On 05/10/2026 22:48, Kaz Kylheku wrote:
>> On 2026-10-05, bart <bc@freeuk.com> wrote:
>>> A lot of what big compilers do is what used to be called 'linting'.
>> 
>> I don't suspect you can get rid of that in any language.
>> 
>> The reason is that as experience with the given language grows, it is
>> found that programmers make certain mistakes, where making formal
>> syntactic and semantic rules against those mistakes, and sticking
>> them into the language, would be a poor idea.
>> 
>> At some point, you are trying to design a pencil that cannot be
>> used to draw an optical illusion.
>> 
>>> I don't consider that to be their job, which should be to verify my
>>> program and turn it into runnable code, and not give opinions.
>> 
>> That's a waste of potential; why would you refuse a machine that
>> can apply hundreds of deterministic pattern matching rules against
>> possible trouble situations in hundreds of thousands of lines of code,
>> in seconds.
>
> I simply don't care about it. I don't have seconds to waste either.

Your implementation of the same thing would take milliseconds, of
course.

> Here are some common C-compiling scenarios:
>
> * You want to build a finished, working, debugged program from source.
>    This does need the compiler spending time double-guessing the author's
>    intentions, and in any case the person building it is not going to
>    mess with the source
>
> * You are building a program which is machine-transpiled C code. It
>    should be valid C with no errors. (If there are, that is the
>    responsibility of the transpiler author.) But again you don't care
>    about style, or the fact that there are lots of unused labels for
>    example (common in such code)

Then

* you still want linting in the source language.

* even if you are generating C you could do something wrong
that can be flagged by a C linter --- and you are in the best possible
position to do something about it. THin about it: suppose you transpile
500,000 lines of code to about as many lines of C, and the C linter
identifies 50,000 instances of the same error.  You may be able to fix
all of them with a one line change in your translator!!!
(By contrast, if you have 50,000 individually hand-written instances of
a lint violation, good luck ...)
If you're in a great position to take advantage of linting, do it.

>
> * You've made a one-line change and just quickly want to run it again.
>    You don't want a style analysis on the same few thousand lines that
>    has already been recently done.
>
> Linting is something you might do every so often - not for routine builds.

If you are in a closed loop already in which you have addressed 
all linting errors or else turned off specific diagnostics you're
not interested in fixing, in fact you do follow up to all new lint
issues caused by a change. It becomes like any other diagnostic.

> However, with C compilers it is common for warnings to be generated 
> rather than hard errors.
>
> This is blurring the line between compiling and linting:

No diagnosable situation in C according to ISO C is required to
terminate translation immediately, or mark it unsuccessful.

All diagnostic requirements are linting. :)

> * Is the transgression serious? Is so then report an error and fail to
>    compile

For instance, converting among incompatible pointer types without a cast
is a required diagnostic by ISO C; it is "serious" in that it defeats
the type system and can be the root cause of a crash.

But it's just a formality in that you can insert the cast to request
it and then the conversion doesn't require a diagnostic.
(If the lack of the cast formality was the only thing stopping it from
being correct, then it is correct; otherwise it stays incorrect.)

The bottom line is that a program which converts among incompatible
pointer types is not necessarily incorrect. It can be translated
and it can work.

There has been historically a "loosey goosey" attitude across the C
landscape whereby the expectation is that compilers try to accept code
and at worst grumble about it.

A lot of the time this would actually just work by dumb luck; weird code
that worked on one system on its compiler worked on another system with
its compiler, and so the /apparent/ work of porting something to a new
platform was reduced, even if it was by fluke.

You are right in that this does not fly in all necks of the woods.

Can you imagine Haskell people saying, oh, type checks are just gonna be
warnings now ... :)

Postel's Law, being "liberal in what you accept [etc]", isn't such a
great idea. Hypothesis: was Postel inspired to that by exposure to C?

History has brought us to a kind of reckoning. Attitudes of new people
are different, the compilers have marched on, yet things are saddled
with the historic baggage at the same time.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID: <20261006171259.512@kylheku.com>
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
References: <119qf6l$2rmg3$1@dont-email.me> <119r8u3$34nce$1@dont-email.me> <119rau4$35ugq$1@dont-email.me> <119uo2c$3kc0t$1@paganini.bofh.team> <119uqnv$d6j2$1@dont-email.me> <20261005143559.157@kylheku.com> <11a1arj$1e8ks$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: Kaz Kylheku <046-301-5902@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Wed, 7 Oct 2026 00:42:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 118
Message-ID: <20261006171259.512@kylheku.com>
References: <119qf6l$2rmg3$1@dont-email.me> <119r8u3$34nce$1@dont-email.me>
 <119rau4$35ugq$1@dont-email.me> <119uo2c$3kc0t$1@paganini.bofh.team>
 <119uqnv$d6j2$1@dont-email.me> <20261005143559.157@kylheku.com>
 <11a1arj$1e8ks$1@dont-email.me>
Injection-Date: Wed, 07 Oct 2026 00:42:07 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2522813"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18wuB7qTVOOfz1O9bSzl2HQja/2ku2/L7k="; posting-host="d356fd15bdef34ae3066964338315ff0"
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:XQJCVVaID6eakyLt1C5V6a7DfhA= sha256:qqQqV0QD5seJyqvK4sc/tb8gDnYybZIZrNZ7xGBqXBg=
	sha1:qWpZ9RV9+4y6WvXQAQBlq+Ekgzo= sha256:/3awHdd6T4HPxX0kvG4NL395OHSdjdBgpgfVPPyOUa4=