More consistent definition of functions / methods + some suggestions #2026
Replies: 1 comment 9 replies
-
Hi, you might want to chime in on issues that cover some of these. When we are talking usability then I weight rank legibility/readability/scanning over consistency, within reason. So for function signatures I would want this priority:
So priority 1 means the name should be to the left. Priority 2 means that the return type should be given weight, which can be done with a unique marker such as Note that the
Carbon has chosen a conservative syntax approach with introducer-keywords in the tradition of ML (or Algol). I personally don't think this redundancy is necessary now that people use IDEs that highlight syntax mistakes. The argument is that it makes tooling easier, but then again, maybe it would be better to provide ready-made parser-libs? Regarding your point 3: I saw somewhere that @chandlerc is open for doing user testing with other syntax alternatives. If the compiler AST is clean, then it should quite easy to play with multiple syntaxes during initial testing (as long as macro-like rewrites are avoided). Syntax is easy to change, semantics are not so easy to change, so it is more important that the focus is on the latter at this point, IMO. Regarding your point 4: I have a preference for "and", "or", "not" (C++ also has these) as I think they are less noisy than sigils, so I think Carbon made a good move there. The biggest syntax issue for me personally is that Carbon has chosen to depart from the all-lowercase naming scheme for language constructs and core standard library constructs (array etc), this leads to a more noisy screen-display and is clashing with various existing C++ code base style practices. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I have been thinking for a while on ideas similar to what @chandlerc talked about. Even I was thinking on creating a simple language using LLVM for my own needs (number crunching), without all the complexities of C++, but hey, we all know how long it takes...
After watching the intro video, I had some strange feelings about the syntax, and I think many others have that too. I know that you are trying to simplifying things (especially parsing), but I think it has gone a bit too far and became a little too weird for a successor language. Here is my views, with the hope that they help:
I think there is some inconsistency in defining the argument and return types for a function / method; the return type uses
->
while every other place is:
is used (see suggestions below). Good to see that it is like C++ in some sense, but it doesn't match the other parts well.While I completely understand some decisions taken for simplicity of parsing, I think we could do things so that C++ developers feel better; for example, instead of using
fn
keyword, we could elaborate something like C++ way of defining lambdas for functions:For methods / generics, you can still put deduced parameters there. This way you do not need to mimic Rust, and still I think parsing is easy enough.
If this is accepted, I believe you can even revert to C / C++ way of defining types of parameters, return type and variable declaration, without the vexing parse problem:
The next thing I want to complain about is
var
andlet
keywords. These remind me of JavaScript, except that they have completely different meanings here and there we haveconst
as well. A suggestion might be using one of them (var
? at least it is C#-like!) and use theconst
(for non-mutable) keyword whenever needed. It is much more readable, I think. Even you can usemutable
keyword for the purpose.The syntax for generics / concepts is too weird... consider using something other than
!
for it. C++ uses!
for 'not' operator, which seems counterintuitive here.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions