Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: David Brown Newsgroups: comp.compilers Subject: Re: for or against equality, was Why are ambiguous grammars usually a bad idea? Date: Thu, 6 Jan 2022 09:11:29 +0100 Organization: A noiseless patient Spider Lines: 50 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-01-018@comp.compilers> References: <17d70d74-1cf1-cc41-6b38-c0b307aeb35a@gkc.org.uk> <22-01-016@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="22569"; mail-complaints-to="abuse@iecc.com" Keywords: design Posted-Date: 06 Jan 2022 10:49:10 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <22-01-016@comp.compilers> Content-Language: en-GB Xref: csiph.com comp.compilers:2796 On 05/01/2022 11:25, Martin Ward wrote: > Using a language that you don't know in its entirety might seem > dangerous, but everybody seems to do it these days: > how many C programmers have read the entire 500+ pages of > the latest C standard and memorised the 200+ varieties > of "undefined behaviour" so that they can avoid all of them > in every line of code that they write? I think it is normal not to know everything about the language you use. And if you include the language's standard library, then there are very few currently used languages where it would even be possible to learn it all. By the time you learned all of the language and default libraries of C++, Java, Python, etc., there would be a new version out and you'd have more to learn. The important things for writing code are to know enough to be able to write the kind of code you are doing, and to avoid accidentally doing things you didn't intend. Static warning tools are vital here - from syntax-highlighting and check-as-you-type editors and IDE's, through compiler warning flags, to stand-alone checkers. Your tools should tell you if you are accidentally using a reserved word as an identifier. There is no need to memorize undefined behaviours for a language - indeed, such a thing is impossible since everything not defined by a language standard is, by definition, undefined behaviour. (C and C++ are not special here - the unusual thing is just that their standards say this explicitly.) The trick is to memorize the /defined/ behaviours, and stick to them. You generally don't need to know if a language leaves (1 / 0) as undefined, or gives a specific value, or prints an error message - usually it is sufficient to know the values for which (x / y) /is/ defined, and stick to those values. Basically, trying to execute undefined behaviour is no more and no less than a bug in the program - whether it is "undefined" in terms of the language, the library, the code you wrote yourself, the customer's specification, or anything else. People program primarily by trying to write correct code - not by trying to think of all the ways they could write incorrect code! The real challenge from big languages and big standard libraries is not /writing/ code, it is /reading/ it. It doesn't really matter if a C programmer, when writing some code, does not know what the syntax "void foo(int a[static 10]);" means. (Most C programmers don't know it, and never miss it.) But it can be a problem if they have to read and understand code that uses something they don't know.