News for hackers. Stuff that matters.
Re:White space does matter in C23 by jll29 on Thursday January 18, 2024 @02:36PM (#39046513)
White space in variable names is a bad idea.

And not everything that is possible is worth doing; e.g. I once designed a language ("Leazy") where keywords don't have to be declared, and can be used as variable names, just to show I could still write an LL(1) recursive descent parser for it. You don't want that in anything for daily use, as it introduces confusion.

Re:White space does matter in C23 by rogerbinns on Thursday January 18, 2024 @04:39PM (#39048144)
Even more fun is zero length names. In SQLite they didn't require table and column names to be at least one character, so you can do this:

    CREATE TABLE []([] []);
Which will create a table with zero length name containing one column with a zero length name and zero length type. And yes you can do all the regular SQL against them providing you quote the zero length name.
Re:White space does matter in C23 by Someone on Thursday January 18, 2024 @04:48PM (#39048273)
> where keywords […] can be used as variable names

PL/I has that, too, because the designers thought you couldn’t expect programmers to know all keywords. For PL/I, that’s a correct assumption. Implementations can have hundreds of keywords, and some of them are single-letter (http://bitsavers.trailing-edge.com/pdf/ibm/series1/GC34-0084... pages 19-25 mentions A, B, E, F, P, R, S, V and X)

Re:White space does matter in C23 by nerdponx on Thursday January 18, 2024 @02:44PM (#39046600)
Meanwhile both SQL (and more recently Python) have tokens that are keywords in certain contexts and regular identifiers in others.
Re:White space does matter in C23 by Findecanor on Thursday January 18, 2024 @03:03PM (#39046875)
PL/I was infamous for it being possible to express valid code that read "IF IF THEN THEN ELSE ELSE".
Re:White space does matter in C23 by colejohnson66 on Thursday January 18, 2024 @03:16PM (#39047026)
Yep. One of the goals was that there would be no reserved words. Not sure why.

    IF IF = THEN THEN THEN = ELSE ELSE = END END
Re:White space does matter in C23 by layer8 on Thursday January 18, 2024 @05:54PM (#39049089)
C++ has some contextual keywords as well:

  final (C++11)
  override (C++11)
  import (C++20)
  module (C++20)
Re:White space does matter in C23 by wyldfire on Thursday January 18, 2024 @07:39PM (#39050119)
But did they make those contextual in order to avoid conflicts with code that had existing identifiers before the new keyword was specified?
Re:White space does matter in C23 by layer8 on Friday January 19, 2024 @07:16AM (#39054564)
Yes.
Re:White space does matter in C23 by tsimionescu on Friday January 19, 2024 @01:36AM (#39052237)
C# is probably the king of contextual keywords, they have tens of them. They started I believe with `yield return` and `yield break` and then added all of the LINQ ones (select, from, where etc), and kept adding others (notnull, record, required, etc).
Re:White space does matter in C23 by twic on Thursday January 18, 2024 @06:20PM (#39049363)
Java too:

> A further ten character sequences are restricted keywords: open, module, requires, transitive, exports, opens, to, uses, provides, and with. These character sequences are tokenized as keywords solely where they appear as terminals in the ModuleDeclaration, ModuleDirective, and RequiresModifier productions (§7.7).

https://docs.oracle.com/javase/specs/jls/se12/html/jls-3.htm...

Re:White space does matter in C23 by avgcorrection on Thursday January 18, 2024 @03:38PM (#39047335)
> White space in variable names is a bad idea.

Pff. You can have your cake and eat it too: disallow whitespace in variable names except no-break space. ;)

Re:White space does matter in C23 by enriquto on Thursday January 18, 2024 @04:25PM (#39047977)
And the same thing for filenames!

Writing shell script under the assumption that filenames do not contain spaces is a liberating experience. I want more of that! And it is nearly possible, by tr ' ' 0x00A0'ing every call to fopen, (probably as an option for mount).

Re:White space does matter in C23 by layer8 on Thursday January 18, 2024 @05:56PM (#39049105)
We’d have long debates about spaces vs. tabs in identifiers. ;)
Re:White space does matter in C23 by ketralnis on Thursday January 18, 2024 @09:55PM (#39051064)
> White space in variable names is a bad idea.

In many contexts yes but as a blanket statement no. Calca allows whitespace in names and it is a delight to write as a result

Re:White space does matter in C23 by julesnp on Friday January 19, 2024 @01:37AM (#39052250)
I think the way F# implemented it is pretty good: if you want to use a keyword or whitespace in a variable or function name, it has to be enclosed in double backticks.

e.g:

  [<Property>]
  let ``Reverse of reverse of a list is the original list`` (xs:list<int>) =
      List.rev(List.rev xs) = xs
Re:White space does matter in C23 by lifthrasiir on Friday January 19, 2024 @03:15AM (#39052913)
I'm not sure if F#'s implementation is good enough. The specification [1] suggests that it doesn't do any additional normalization to the resulting identifier, so otherewise identical identifiers with a single space, a single tab and two spaces would be different. I would expect them to collapse into a single space character.

[1] https://fsharp.org/specs/language-spec/4.1/FSharpSpec-4.1-la...

Re:White space does matter in C23 by chrismorgan on Friday January 19, 2024 @05:07AM (#39053680)
Why would you expect that? I would explicitly expect not that. Unicode normalisation (typically to NFC) maybe, but nothing more.
Re:White space does matter in C23 by lifthrasiir on Friday January 19, 2024 @05:59AM (#39054040)
Mostly because it's rare to see identifiers with whitespace allowed after all. So this has to fulfill some specific needs.

The main use case here seems like self-describing properties that will be hardly referenced elsewhere. In principle this doesn't really need any new syntax, as you can put the description into the attribute (`[<Property>]` here) and the name itself can remain arbitrary or even be made anonymous. But we've got textual identifiers instead. So I guess that some code does refer to those textual identifiers, and if that's the case, being able to ignore invisible differences when comparing textual identifiers looks like a good idea as well.