News for hackers. Stuff that matters.
Re:Can C++ be 10x Simpler and Safer? by torrent on Saturday November 12, 2022 @05:21PM (#33577749)
Syntax is mostly a matter of taste. Preference of taste and style changes with time and trends. Why should "name : type" ee preferred to "type name"? Just because others do it? Why and this unnecessary, additional ':'?

> C++ has this issue of every few years looking entirely different So what. The style you have been using does the job then just keep it. There is no obligation switch to use new stuff. You should stick with that what proved to be successful.

Re:Can C++ be 10x Simpler and Safer? by Kranar on Saturday November 12, 2022 @07:06PM (#33578556)
The reason some languages use "let name: type" instead of "type name" is to eliminate various ambiguities, for example C++'s most vexing parse, or the classic C typedef ambiguity where a statement like "X * Y" is ambiguous because it could be the declaration of a variable Y whose type is "X*" where "X" is a typedef, or it could be the multiplication of a variable "X" with a variable "Y". There are many languages where the "type" can be a fairly complex composition that can introduce ambiguities.

Modern languages use a type of syntax where all declarations start with an introducer, something along the lines of "let", "fn", "class", etc... in order to eliminate ambiguities as well as avoid the need for the parser to have potentially unbounded look-ahead.

Re:Can C++ be 10x Simpler and Safer? by steveklabnik on Saturday November 12, 2022 @07:25PM (#33578671)
Additionally, for let specifically, it’s much nicer of a diff to explicitly annotate types vs having them inferred.

  int x = 5;
  auto x = 5;
vs

  let x: i32 = 5;
  let x = 5;
(This is one part the practical impact of a lot of your comment is about, of course, just also adding this little bit to make it concrete.)