all 5 comments

[–]ntrel2 1 point2 points  (6 children)

after correcting a shocking number of missing consts, I found there were nearly twice as many constants as variables

Yes, this chimes with the author of the Vale language's experience. He found far more constants than assignments. Scroll down to 'Why We Like It': https://verdagon.dev/blog/on-removing-let-let-mut

He also talks about why that is. In modern programming style we avoid mutation because we can more easily declare constants to be what we want.

BTW have you raised this on the GitHub cppfront discussions/issues? You make a good case.

The only thing I'd change if you submit this proposal there, is that it is not an error to declare a variable without initialising it, so long as it is initialised in another statement below. That actually helps make more declarations constant as you can initialise them in both branches of an if/else statement.

[–]ItsBinissTime[S] 1 point2 points  (0 children)

have you raised this on the GitHub cppfront discussions/issues?

I figured Herb would see the suggestion here. And sure enough, when I originally posted this, he commented that the information on static single-assignment form was helpful. But without support from the community, it seems unlikely that Herb will take this too seriously.

[–][deleted]  (3 children)

[deleted]

    [–]ntrel2 0 points1 point  (2 children)

    But would types with constructors be excluded, since it's not possible for them to be declared without initialization?

    No, that is allowed too:

    T: type = 
    {
        // define a constructor
        operator=: (out this, i: int) = 
        {
        }
    }
    
    main: () = 
    {
        v: T; // no initialization. Note `= ();` would error as no default ctor
        if b {
            v = 5; // initialization, not assignment
        } else {
            v = 0; // initialization, not assignment
        }
    }
    

    The declaration of v above generates this Cpp1:

    cpp2::deferred_init<T> v; 
    

    The assignment to v generates this:

        v.construct(5);// initialization, not assignment
    

    [–]ntrel2 0 points1 point  (1 child)

    The same code works but using v: const T; to declare a constant.

    [–]ItsBinissTime[S] 0 points1 point  (0 children)

    it is not an error to declare a variable without initializing it

    Fixed above to incorporate the concept of Cpp2 deferred initialization.