News for hackers. Stuff that matters.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by metadat on Saturday September 17, 2022 @11:31AM (#32878315)
Looking forward to finding out what kind of feedback and discussion this generates. Some of the changes seem to make the syntax pointlessly different.

    /* Proposed "new" c++ syntax */
    main: () -> int = {
      cout << "hello world\n"; 
    }

    // vs.

    /* Classix c++ syntax */
    int main() {
        cout << "hello world\n";
    }
The "new" way looks a lot like a copy of the newer Java syntax for closures.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by onedognight on Saturday September 17, 2022 @11:59AM (#32878558)
It’s actually close to the new C++ syntax for functions. Take a look at the output C++ in the regression-tests/test-results folder:

    auto main() -> int {
        cout << "hello world\n";
    }
The difference between the two is mostly the : and the =. The colon is for declarations being written:

    i : int = 0;
Instead of

    int i = 0;
main is the variable/function above and its type is ()->int and it’s being assigned, i.e. defined, hence the =. This syntax removes a ton of parsing complexity and makes the language more regular. Functions are defined and assigned similarly to variables.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by philippejara on Saturday September 17, 2022 @02:40PM (#32880087)
been a bit since I've touched c++, but is there any reason to use trailing return types in that manner aside from solving scope issue with decltype on templates? I assumed this was a way to write functions to deal with that case and not for "regular" functions.

On another note, anything with "->" is just painful to write, same thing with the (in his proposal) ":_" instead of "=" for function arguments. Just annoying.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by Jtsummers on Saturday September 17, 2022 @02:55PM (#32880267)
:_ appears to mark it as a generic type parameter, the `hello` function in the example ought to be equivalent to this straight C++:

  template<typename T>
  void hello(T msg) {
    std::cout << "Hello " << msg << "\n";
  }

  hello: (msg: _) = {
    std::cout << "Hello " << msg << "\n";
  }
I kind of like this, actually, because so many people I've worked with are afraid of templates in C++, but they seem to have no trouble with essentially equivalent code using generics (in other statically typed languages) or dynamically typed languages where it "just works" (until it doesn't). Not that we'll be adopting this any time soon, but I suspect they'd be more amenable to this form when `template` seems to make them quake in their boots.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by gpderetta on Saturday September 17, 2022 @05:39PM (#32881854)
The syntax:

   void hello(auto msg){
      ...
   }
Is legal today (since C++20 IIRC) and it is equivalent to your first example.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by philippejara on Saturday September 17, 2022 @03:46PM (#32880831)
Ah actually missed that, good catch, it does seem to be a step forward in regards to dealing with the syntactical clunkyness of templates. Now if we could have keyword arguments in functions calls without having to deal with some kludge...
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by int_19h on Sunday September 18, 2022 @06:50PM (#32892230)
I actually prefer trailing return type for the simple reason that they often get very verbose with templates, and then it can be difficult to find the function name in the declaration. With the -> syntax, the function name is always in the same spot visually.

As for -> being painful to write - that's obviously subjective, but more importantly, given that it's the operator you use to access members via pointer-like things (including smart pointers and iterators), it's already pervasive in C++.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by mgraczyk on Saturday September 17, 2022 @04:32PM (#32881300)
You have to use it for lambdas, so using it everywhere makes some code more consistent and readable
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by metadat on Saturday September 17, 2022 @04:14PM (#32881144)
Why does it need both the keywords "auto" and "int" when declaring main()? Just seems extra confusing..
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by mgraczyk on Saturday September 17, 2022 @04:29PM (#32881276)
This is cruft. Without auto it wouldn't be parsed as a function declaration
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by alcover on Saturday September 17, 2022 @05:15PM (#32881653)
Allow me to hijack a little. I'm working on a new language.

Would you people object to ':' for assign and single '=' for equality ?

  int i:42
  if i=42 print "ok"
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by mkl on Saturday September 17, 2022 @06:58PM (#32882451)
Maxima does something like this. It's weird to use. I think := for assignment makes more sense if you want = for equality (i.e. like Pascal etc.).
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by bhawks on Saturday September 17, 2022 @06:45PM (#32882353)
Golang uses : to assign in struct initialization and := for new variable assignments so there is some prior art.

Practically speaking I find : to be challenging to quickly scan out of source visually. In golang this objection is muted slightly because struct initialization usually ends up being clearly indented by the formatter.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by uwagar on Saturday September 17, 2022 @04:03PM (#32881029)
ouch is it just me that feels

int i = 0; // pretty

i : int = 0; // ugly

i will stick to c++03 thank u very much.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by kagakuninja on Saturday September 17, 2022 @04:39PM (#32881362)
I have been using C and related languages since 1980. Switched to C++, later Java. Then about 7 years ago, I went all in on Scala, and have never looked back.

Something like "i: int" is superior (at least in Scala), because the type annotation is optional. You can drop it, and just say "val i = 42". I believe it simplifies the parser as well.

There is a reason many modern languages are adopting the style.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by mgraczyk on Saturday September 17, 2022 @04:31PM (#32881290)
Most new languages use postfix types. I grew up using C and C++, but now that I've learned and use Python with types and Typescript, I'm used to and prefer postfix syntax
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by uwagar on Saturday September 17, 2022 @04:39PM (#32881355)
shouldnt it then be?

i: int 0 = ;

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by mgraczyk on Saturday September 17, 2022 @04:48PM (#32881435)
No, it should read grammatically as English.

int x = 0 "There is an integer x with value 0"

x: int = 0 "x is an integer with value 0"

x: int 0 = "x is an integer that is zero valued"

The last one is awkward, the first one is harder to read.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by tsimionescu on Sunday September 18, 2022 @02:16AM (#32884911)
They said postfix types, not postfix syntax.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by int_19h on Sunday September 18, 2022 @07:06PM (#32892329)
Now consider how this works out in C++:

   int i;     // i is a local int
   int i();   // i is a global function returning an int
   int i(0);  // i is a local int initialized to 0.
Yes, there's uniform initialization now. But this whole thing was a problem in the first place because of poorly designed declarator syntax that doesn't extend well and is difficult to parse unambiguously.

It can actually get worse, to the point where it's impossible to tell whether a given line of code is a declaration or not. E.g. "a<b>c" can be a declaration "a<b> c", or it can be an expression "((a < b) > c)", depending on what "a" is, exactly. This can be taken to 11 with templates:

   template<size_t N = sizeof(void*)> struct a {
       template<int> struct b {};
   };

   template<> struct a<sizeof(int)> {
       enum { b };
   };

   enum { c, d };

   a::b<c>d;
The meaning of this code now depends on whether sizeof(int)==sizeof(void*) for a given implementation on which it runs. Now, granted, this isn't the kind of thing you'd find in real world code outside of IOCCC and the likes; but it's legal, so the tooling has to be able to process it anyway. And by "tooling" I mean anything that has to parse C++ at some point - not just the compilers, but also debuggers, IDEs etc.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by tricky777 on Saturday September 17, 2022 @04:26PM (#32881254)
the ugly way is easier for the parser on some edge cases. https://en.m.wikipedia.org/wiki/Most_vexing_parse

syntax "beauty" is just a matter of how used to it you are (excl brainfuck ofcourse). Admitting this, is quite a big present one can give to him/her self.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by dataflow on Saturday September 17, 2022 @12:49PM (#32878958)
That colon is going to be quite burdensome to type, due to the need to hold the Shift key on a line where you otherwise might not need to. It might sound silly but I do think little things like this can really hinder adoption without people necessarily realizing it.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by kagakuninja on Saturday September 17, 2022 @04:43PM (#32881387)
No more burdensome than using capitol letters (camel case), underscore (snake case), curly braces or quote marks.

Been using Scala for 7 years, and it has never even occurred to me this was a "burden".

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by Merad on Saturday September 17, 2022 @05:49PM (#32881933)
Meaning no offense but if you aren't exaggerating you might want to invest some time in typing lessons. I'm not even remotely close to being an expert typist and I spend most of the day going back and forth between a C style language (C#) and modern style that uses the colon (Typescript). The difference needed to type a colon doesn't even register.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by dataflow on Saturday September 17, 2022 @06:00PM (#32882027)
I write both C++ and Python all the time and I type enough underscores and caps all day just fine, thank you. The colon doesn't register for me when I'm writing those either. When it did register for me was precisely when I started designing my own language, attempted to design declarations with this exact syntax, played around with it, and realized this is a burden I'd never noticed before, and that this was one thing that made languages more pleasant to write in.

Think of it like font kerning. Some people notice it, some don't, but most people prefer good kerning even if they never think about it.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by KerrAvon on Saturday September 17, 2022 @02:40PM (#32880094)
You must not have used Python or classes in C++, where the colon is ubiquitous?

Does `{` not require shift on your keyboard?

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by dataflow on Saturday September 17, 2022 @02:46PM (#32880163)
> You must not have used Python or classes in C++, where the colon is ubiquitous?

You misread my comment. I'm talking about cases where existing prevalent syntax for that construct does NOT already require holding Shift. Python is better in this respect since ":" requires fewer presses of Shift than "{" or "}". This is not the case when you go from "int x = 1;" to "x: int = 1;".

Moreover, the inconvenience of going from 1 Shift to 2 is not the same as the burden of going from 0 to 1. Especially because you can often combine the 2 into 1 without releasing the modifier key in between.

And furthermore, variable declarations are far more common than class or function declarations, so you can't weight them equally.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by hiccuphippo on Saturday September 17, 2022 @05:26PM (#32881734)
You could just change your keymap if you really need to. I used to remap / in my Spanish keyboards because normally it is shift+7.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by wyan on Saturday September 17, 2022 @03:32PM (#32880671)
In many non-US keyboard layouts typing the ";" requires holding shift as well, so not sure how bad this issue is in actuality.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by Oreb on Sunday September 18, 2022 @04:55AM (#32885730)
Most non-US keyboards are terrible for programming in general. I only use my native Norwegian keyboard layout when I need to type a significant amount of text in Norwegian. Whenever I need to type some code, I switch back to US layout. I believe most other programmers do the same.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by qsort on Sunday September 18, 2022 @11:25AM (#32888306)
Yes, programming with anything other than the US layout is simply unbearable. I simply switched to the US layout for everything. Although to be fair my native language is Italian, which doesn't need many special characters.

Most programmers I know use native+US layouts (like you), a minority always uses US (like me), almost nobody uses a native layout to code.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by TheFlyingFish on Monday September 19, 2022 @11:36AM (#32899792)
I'm an English speaker, so I'm curious: Italian technically requires some accent marks, right? Do you have a quick way to do those from a US layout, or do you just ignore them in casual conversation the way people tend to ignore capitals and (some) punctuation?
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by qsort on Monday September 19, 2022 @02:13PM (#32901853)
Yeah, technically it requires diacritical marks, but unlike French they are only written explicitly when they fall on the final letter of a word. Italian only has seven vowels, so these are the only common ones: è é ì ó ò ù à.

What I would do is this:

- Replace them with a single quote -> E' instead of È or É and so on.

- Ignore all uncommon marks.

In most contexts, it is perfectly acceptable to do that. A native speaker would understand without giving it a second thought or considering it impolite. I write emails to my boss like that.

If I had to make something meant for the public (say a UI, or a document), then I'd switch to the Italian layout for that purpose only and then go back to the US one.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by account42 on Tuesday September 20, 2022 @06:43AM (#32910020)
Not for Italian, but I use a US keyboard layout with the addition of German umlauts behind right alt + letters (as well as right alt + ' and right alt + ` being dead keys to put accents on letters for foreign words). I find this much better than the standard German layout which puts all of @{[]}\~ behind right alt - and most of them on the right side of the keyboard too so you have to akwardly hit the right alt + combo with a single hand.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by coliveira on Saturday September 17, 2022 @02:35PM (#32880020)
Tell this to people using Python. Every function, if, and loop has a colon at the end.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by dataflow on Saturday September 17, 2022 @02:47PM (#32880176)
You misread my comment. I'm not saying "colons are bad", I'm saying "excessive holding of keys is bad".

if (cond) { } requires 4 presses of Shift (or 2, if you combine them).

if cond: foo requires 1 press of Shift.

I'm not sure what part of my comment makes you believe that I think the latter comes out worse than the former. If anything, the fewer keypresses probably strongly helped Python's success without people necessarily realizing it. Moreover, this might very well be one thing hindering more widespread adoption of Python's type annotations.

You also need to consider how common each construct is. A class declaration requiring 20 excessive keystrokes is not necessarily worse than a variable declaration requiring 1 excessive keystroke.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by dureuill on Sunday September 18, 2022 @06:51AM (#32886380)
The number of excessive keystrokes is largely irrelevant (as long as it isn't an order of magnitude too much), because typing the code on keyboard is generally far from the limiting factor for the speed of writing code.

Most of the time you spend thinking about what you should be typing.

So optimizing for the number of keystrokes is optimizing for the wrong metrics

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by the_af on Saturday September 17, 2022 @07:59PM (#32882899)
But Scala and lots of other programming languages use ":" with no hindrance to adoption.

Also consider this: lots of hugely frequent characters and symbols that don't require SHIFT in EN-US keyboards do in other keyboards layouts, for example Spanish. So this cannot be a consideration, at least not a major one.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by dataflow on Sunday September 18, 2022 @02:18AM (#32884922)
> But Scala and lots of other programming languages use ":" with no hindrance to adoption.

It's kind of weird to see you assert that with no attempt to establish its truth when Scala is something like... the ~20th most popular language? Whereas Python, C, C++, Java, VB, C#, etc. are right at the top. So either this is one of the (obviously many) factors hindering wider adoption of Scala, in which case the relative popularity is entirely consistent with this, or it isn't a factor, in which case the it would make sense to present at least some evidence to the contrary given that your assertion goes against the popularity rankings.

> Also consider this: lots of hugely frequent characters and symbols that don't require SHIFT in EN-US keyboards do in other keyboards layouts, for example Spanish. So this cannot be a consideration, at least not a major one.

I'm pretty sure the popularity of {most software technologies} outside the US and inside the US are very far from being independent variables.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by the_af on Sunday September 18, 2022 @11:14AM (#32888205)
> It's kind of weird to see you assert that with no attempt to establish its truth when Scala is something like... the ~20th most popular language? Whereas Python, C, C++, Java, VB, C#, etc. are right at the top

The barrier to adoption of Scala has to do its functional programming side, as well as its complex libraries and types.

Kotlin also uses ": type" syntax, by the way. As does Python!

> I'm pretty sure the popularity of {most software technologies} outside the US and inside the US are very far from being independent variables.

It's hard to understand your point. Are you arguing that programming languages are less popular outside the US? Or "most software technologies"?

So let's sum it up: SHIFT concerns are very minor in comparison to other programming language ergonomics (in which need I remind you, C++ never fared very well), and the ": type" syntax is very common and mainstream in programming languages, with no hindrance to adoption.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by gumby on Saturday September 17, 2022 @03:26PM (#32880598)
No emacs user would even notice.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by metadat on Saturday September 17, 2022 @04:14PM (#32881150)
Or Vim and Python users. They type ":" a lot.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by xigoi on Sunday September 18, 2022 @01:55AM (#32884800)
I actually have <space> mapped to : in Vim precisely because it's easier to press.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by humanrebar on Saturday September 17, 2022 @11:36AM (#32878354)
Some of the syntax changes are to support simple LR parsing. Ideally cpp2 would have boring grammar descriptions available for popular off-the-shelf parser generators. No need to link libclang into everything.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by Sharlin on Saturday September 17, 2022 @02:44PM (#32880142)
The "type first" declaration syntax is a source of much wailing and gnashing of teeth when it comes to trying to parse C++. See the "most vexing parse" [1].

[1] https://en.wikipedia.org/wiki/Most_vexing_parse

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by tsimionescu on Sunday September 18, 2022 @02:46AM (#32885074)
The most vexxing parse was a huge problem in C++ and a very niche problem in C not because of "type first" declaration syntax, but because C++ constructor calls in variable initialization are essentially identical to function declarations. This is a big reason why Java or C#, also type-first syntax languages, have no such ambiguity.

The two examples on Wikipedia are both caused by this, even though it's not explicitly spelled out:

  int i(int(my_dbl)); // two calls to int's constructor

  // in Java/C# style syntax:

  int i = new int(new int(my_dbl)); //no ambiguity

  TimeKeeper time_keeper(Timer());

  // in Java/C# style syntax:

  TimeKeeper time_keeper = new TimeKeeper(new Timer());
C++ could have also chosen to reserve a keyword for initialization even for in-place values, just like they did with `new`, but they chose to re-use function call syntax instead.

I would also say that just moving the type after the variable name doesn't fully solve the issue - it's the : syntax for initialization that does this. Here is a hypothetical C++ where the syntax remained the same as today, but (return) type was moved at the end of a declaration:

  typedef double my_dbl;
  typedef int i;
  foo (my_dbl double ) void {
    i int (int(my_dbl));
    //unambigous: i is an int initialized with an int constructed from my_dbl

    f (double) int; //unambigous: f is a function from double to int
    g int (my_dbl); //unambigous: g is an int constructed from my_dbl

    bar((my_dbl)i); 
    //ambigous: calling bar with i cast to double, or calling it with a function from my_dbl to i (double to int)?
  }
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by DerekL on Sunday September 18, 2022 @05:03PM (#32891480)
Similar problems happen even in C. Suppose you have this line inside a function:

    X *y;
Are you declaring a pointer, or are you performing multiplication? It depends on what “X” is.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by tsimionescu on Sunday September 18, 2022 @05:43PM (#32891771)
True, though in this case as well, just replacing type first to type last would presumably lead to `y *X` which doesn't help so much in resolving ambiguity.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by hackingthenews on Saturday September 17, 2022 @11:36AM (#32878355)
This is explained in the talk he gave. One of the benefits is that with new syntax the semantics can change without breaking backward compatibility, e.g. [[nodiscard]] can become default for all functions written in the new style.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by snvsn on Saturday September 17, 2022 @10:53PM (#32883979)
I had the same reaction initially but then realized that this makes the variable declaration / initialization syntax very consistent.

  variable: Type [= initial_value];

  // initializes foo to an int with an initial value of 43 
  foo: int = 43;

  // initializes main to a (presumably, as I haven't read the
  // spec yet, const)pointer to a function that takes no 
  // arguments and returns an int.
  main: () -> int = {
     ...
  }
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by nickhalfasleep on Saturday September 17, 2022 @11:34AM (#32878346)
The idea is to have a consistent way across many items, functions, lambdas, etc…
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by oblio on Saturday September 17, 2022 @05:09PM (#32881595)
The "new" way is basically updated Pascal, which was the right way to do it, from back in the 80's.

Similar story with C strings vs Pascal strings, another can of worms.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by int_19h on Sunday September 18, 2022 @07:09PM (#32892345)
And the "old" way is basically Algol-60, which was what Pascal improved on.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by oblio on Sunday September 18, 2022 @07:41PM (#32892517)
True, but C missed the memo, unfortunately.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by williamvds on Saturday September 17, 2022 @11:37AM (#32878362)
From a C/C++ programmer's POV those may look like GOTO labels, I agree. The proposed syntax is probably a consequence of a modern trend in using := for declaration and assignment.

    x := 5
Where you can optionally insert the type between the colon and equals, otherwise it is deduced

    x : int = 5
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by cvoss on Saturday September 17, 2022 @02:07PM (#32879748)
It's not modern at all. Type system notation has been using x : T to say "x has type T" for at least 50 years. It's the standard in academia, and has existed in real-world programming languages since 1971. [0]

[0] https://cstheory.stackexchange.com/questions/43971/why-colon...

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by forrestthewoods on Saturday September 17, 2022 @03:37PM (#32880729)
It is an old idea and also a modern trend. Trends come and go. It is currently trendy.

90s fashion is also trendy right now. Which is great because a few years ago it was 80. The cycle continues!

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by the_af on Saturday September 17, 2022 @08:03PM (#32882924)
"Currently trendy" how? Scala and Kotlin, to name just a few established programming languages, use the ": type" suffix style. They are neither "recent" nor from the original Algol era.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by int_19h on Sunday September 18, 2022 @07:09PM (#32892351)
It depends on how you define "current", I suppose, but personally I'd consider Kotlin to be fairly recent.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by the_af on Sunday September 18, 2022 @11:16PM (#32893907)
Well, Kotlin is from 2011 and Scala from 2004! 11 and 18 years ago, respectively. I'd say neither is recent by any reasonable sense of the word that would imply their syntax or conventions are "a current trend".
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by int_19h on Monday September 19, 2022 @08:16PM (#32905955)
11 years is not all that much for a PL, especially if you count from the date it was first announced, rather than from the first stable release (which for Kotlin was in 2016). For example, Rust started in 2006, and Rust 1.0 was in 2014, so it's actually older the Kotlin - but I think it still qualifies as "new", and many still consider it not fully battle-tested.

For another example, Python goes all the way back to 1991, with v1.0 in 1994. But it didn't really start to trend until early 00s.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by the_af on Tuesday September 20, 2022 @04:52PM (#32917649)
> "11 years is not all that much for a PL"

Sure, if we redefine "recent" or "current" we can twist words to reach whatever conclusion. In reality, this ": type" syntax is neither new nor recent, nor is it "a current trend". Kotlin is also not recent. A decade is a lot.

You conveniently left Scala out, I suppose because it didn't fit your argument.

> "For another example, Python goes all the way back to 1991"

Well, since we are discussing Python, the syntax for its type hints looks like what exactly? And it was discussed as far back as 2014. Is that "recent"?

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by int_19h on Tuesday September 20, 2022 @04:59PM (#32917718)
If you look at the thread, I'm not the same person who originally made the claim.

Nevertheless, it is definitely the case that the "name: type" syntax is noticeably more trendy now than it was, say, 15 years ago. Sure, there were plenty of languages that had it already back then, including Scala (and ML, and Delphi, and ...). But how many of them were mainstream? Whereas now, this syntax is embraced by Python and TypeScript.

And not even OP claimed that the syntax itself is new or recent; I mean, everybody who knows about Pascal knows how old it really is! They literally said "it's an old idea" that is "currently trendy".

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by thechao on Saturday September 17, 2022 @12:15PM (#32878681)
I used to code for a language called "Spad" — originally shipped in 1972(?). The syntax:

    x : t = e
Was called "headform" and was the only syntactic form for the whole language. (Expressions used a shunting yard algorithm to desugar into a sequence of headform.)

The language included modules, classes, parameterics, functions, constraints, ..., whatever.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by naruhodo on Saturday September 17, 2022 @09:31PM (#32883489)
Well, everything looks like a pile of dirt when the only tool you have is a Spad.

ducks

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by SaddledBounding on Saturday September 17, 2022 @01:42PM (#32879487)
> The proposed syntax is probably a consequence of a modern trend...

ML uses `name: type = value`. It came out over a decade before C++ and just one year after C.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by teo_zero on Saturday September 17, 2022 @01:38PM (#32879436)
In English, the colon is used to separate a term to its definition, so it looks perfectly apt to mark declarations.

Besides, it makes it trivial for text editors to implement "go to definition", and many other niceties without a real semantic parser.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by dvratil on Saturday September 17, 2022 @01:18PM (#32879244)
I don't think this has anything to do with modern trends - := is a formal way of writing assignment (the widely used = is actually an equality sign), and has already been present in Pascal for decades (and other languages as well).
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by Jtsummers on Saturday September 17, 2022 @01:33PM (#32879401)
https://en.wikipedia.org/wiki/ALGOL_58

ALGOL, the := in programming languages used for assignment comes from IAL which became ALGOL 58. It's definitely not a modern development. Go reintroduced it to popular mainstream languages, sort of. Except they still use = for assignment and := is used when it's also declaring a new variable.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by int_19h on Sunday September 18, 2022 @07:13PM (#32892365)
:= for assignment ultimately comes from math, as do most operators in early Algol: https://www.masswerk.at/algol60/report.htm#2_3
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by noobermin on Saturday September 17, 2022 @02:45PM (#32880158)
All the replies are missing something, does cpp2 have goto labels? What happened to them.

Unless you now have named loops in modern C++ now this removing goto is problematic.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by rafram on Saturday September 17, 2022 @01:23PM (#32879284)
I’m not sure I’d := is a “modern trend.” Smalltalk had it circa 1972, but none of the modern-day hip languages I can think of do. Your latter example is a common syntax, but the colon is omitted with the type in most languages (TypeScript, Rust, etc.).
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by charcircuit on Saturday September 17, 2022 @02:45PM (#32880159)
X being a modern trend does not mean it was not done in the past. It doesn't mean that it hasn't trended in the past either.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by the_af on Saturday September 17, 2022 @08:04PM (#32882937)
So what does it mean then?

It was done in the very distant past. It was done in the intervening time. And it's done now. "Modern" trend?

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by criddell on Saturday September 17, 2022 @12:03PM (#32878608)
Both versions are supposed to return an int but neither has a return statement. Is that not an error?
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by e4m2 on Saturday September 17, 2022 @12:14PM (#32878675)
The main function returns zero implicitly if control flow reaches the end without encountering a return statement.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by LeSaucy on Saturday September 17, 2022 @12:32PM (#32878807)
It wouldn't be C++ without undefined behaviour.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by hota_mazi on Saturday September 17, 2022 @02:12PM (#32879797)
It's disappointing they would keep that odd << syntax, which has always looked weird to me.

Why not take this opportunity to streamline the calling syntax? Streams are no different than regular function calls, e.g.

cout.output("hello").output("world\n")

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by layer8 on Saturday September 17, 2022 @02:28PM (#32879951)
You are talking about library API design, not language design. A new C++ syntax will not change how functions in the standard library are named (e.g. operator<<).
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by CyberDildonics on Saturday September 17, 2022 @02:30PM (#32879965)
That is an operator overload of a library and not built in language syntax.

Even so there is now std::format

https://en.cppreference.com/w/cpp/utility/format/format

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by hota_mazi on Saturday September 17, 2022 @04:28PM (#32881267)
Doh, you're absolutely correct.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by hardlianotion on Saturday September 17, 2022 @11:59AM (#32878562)
In that particular case, it looks like he declared and assigned a thunk called main. It looks different to me than the original-style main.
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by zozbot234 on Saturday September 17, 2022 @12:01PM (#32878582)
> main: () -> int = {

Y U NO fn??!? So close, and yet so obviously wrong.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by duped on Saturday September 17, 2022 @12:05PM (#32878625)
Why add a keyword when you don't need it?
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by teo_zero on Sunday September 18, 2022 @02:16AM (#32884915)
One answer would be: So that when you hit the ( you know it's a list of parameters and not an expression, even before you spot the ->

I still haven't read enough about syntax 2 to understand if it allows any other use of ( after a : but if yes, a keyword like fn or fun would make the parser much more regular.

Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by bogdanoff_2 on Saturday September 17, 2022 @12:53PM (#32878999)
For easier grepping
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by duped on Saturday September 17, 2022 @04:13PM (#32881135)
Use an IDE
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by chlorion on Saturday September 17, 2022 @09:17PM (#32883414)
I'm not sure that any IDEs support cppfront yet!
Re:Cppfront, Herb Sutter's proposal for a new C++ syntax by Koshkin on Saturday September 17, 2022 @02:04PM (#32879727)
fn is no fun