News for hackers. Stuff that matters.
Re:Language Design: Use 'ident: Type' not 'Type ident' by TazeTSchnitzel on Friday May 01, 2020 @05:00PM (#23046434)
A more practical reason as a language designer is that C and C++-style type-before-name syntax is a nightmare to lex and parse, as you can't tell whether

  A * B;
is a multiplication or a variable declaration, or whether

  A<B, C> D;
is a two comparisons with a comma operator or a templated variable declaration, without first knowing the names of all declared types.

This means in practice that you have to declare types before they are used in a file, which means forward-declarations if they are defined later, that you can't separate lexing and parsing because the parser has to provide constant feedback to the lexer, and that misspelling a type name can lead to a syntax error! C++, not content with merely inheriting C's problems, throws in the “most vexing parse” as a bonus.

Re:Language Design: Use 'ident: Type' not 'Type ident' by Animats on Friday May 01, 2020 @05:11PM (#23046538)
It's a historical problem in C. Originally, C had only built-in types. Structs were declared with

    struct foo { int x; int y; };
which is easy to parse. Then came typedef. With user-defined types,

    foo*bar;
isn't parseable with a LALR(1) parser until you've seen the definition of "foo". Even the ordinary case

    foo bar;
needs more than one lookahead to parse. This is a headache for compilers, and a huge headache for anything that wants to work on single source files without seeing the included files.

It's a big win if files are parseable without their dependencies. The Pascal/Modula/Ada family all are. I think Go is. Not sure about Rust, but it probably is. C and C++, no.

(The hacks for template syntax in C++ are painful to think about.)

Re:Language Design: Use 'ident: Type' not 'Type ident' by barrkel on Friday May 01, 2020 @08:22PM (#23047866)
Yeah, the easiest way to do it is return a different token type from the lexer for type names, which means the lexer looks up the symbol table when it sees identifiers.

Amusingly, the Delphi dialect of Pascal has an ambiguity in its grammar from how it made function pointers work:

    function g: Integer;
    // ...
    f(g);
Depending on the definition of f, this could be passing the function f by reference (as a function pointer), or passing the result of calling f.

Delphi looks at the argument type to resolve the ambiguity, but it stays awkward in overload scenarios, when there's a choice between Integer or function pointer arguments.

At some point around about 2009, I added the ability to specify explicitly that you want the call, to eliminate the ambiguity:

    f(g());
Re:Language Design: Use 'ident: Type' not 'Type ident' by lmkg on Friday May 01, 2020 @05:54PM (#23046932)
> Not sure about Rust

Rust has made a point of being parser-friendly, to support tooling. The entire reason the turbofish ::<> exists is to avoid ambiguous grammar. (This operator seems to vex people, I don't get the hate.)

Re:Language Design: Use 'ident: Type' not 'Type ident' by WalterBright on Friday May 01, 2020 @08:18PM (#23047838)
Being parser-friendly is not at all the same thing as being user-friendly. The difficulty of writing parsers is way overblown.

One thing to avoid is depending on the existence of the symbol table to parse correctly. (C++ has this problem.) Needing a symbol table makes it hard for parsers like source code formatting and syntax highlighting.

Another is to avoid raw string literals that reach back and try to unwind the results of previous "phases of translation".

Re:Language Design: Use 'ident: Type' not 'Type ident' by barrkel on Friday May 01, 2020 @08:24PM (#23047881)
Agree with a caveat; if the syntax has many ambiguities, with resolution solved by a clever parser, it'll be confusing for users, especially newbies, because they'll tend to get errors unrelated to what they were trying to achive.

Redundancy in syntax can be a bonus.

Re:Language Design: Use 'ident: Type' not 'Type ident' by WalterBright on Friday May 01, 2020 @08:32PM (#23047946)
> Redundancy in syntax can be a bonus.

I agree. I even wrote an article about that:

https://www.digitalmars.com/articles/b05.html

Re:Language Design: Use 'ident: Type' not 'Type ident' by seanmcdirmid on Saturday May 02, 2020 @01:42AM (#23049575)
Both humans and computers parse code. Humans can handle ambiguity mode easily than computers, but that doesn’t make the ambiguity more user friendly somehow.
Re:Language Design: Use 'ident: Type' not 'Type ident' by estebank on Friday May 01, 2020 @08:13PM (#23047813)
Do note that Rust the language is regular and easy to parse, but rustc the compiler actually performs bounded lookahead and contextual parsing on parse errors to detect common typos and invalid syntax that would otherwise be vexing to users. The nightly only type ascription : syntax is a good example because it crops up in several different contexts as a 1-substitution typo and used to be terrible (may it burn in a fire). The turbofish is another case where we now suggest the correct syntax, but there are many, many more.
Re:Language Design: Use 'ident: Type' not 'Type ident' by usrusr on Saturday May 02, 2020 @06:00AM (#23050673)
Surely that's an example of how parser-friendly syntax empowers tooling? I imagine that it would be much harder to guess intention and fixes from lookahead and context if those were already necessary to make sense of correct code?
Re:Language Design: Use 'ident: Type' not 'Type ident' by thrtythreeforty on Friday May 01, 2020 @10:37PM (#23048638)
I love the turbofish so much, not because it looks nice in code or anything, but because the name is a bit of harmless fun that makes the language feel inviting.
Re:Language Design: Use 'ident: Type' not 'Type ident' by TazeTSchnitzel on Friday May 01, 2020 @05:16PM (#23046587)
Ah, C not originally having typedefs explains why the syntax wasn't thrown out as too annoying to begin with. Syntax creep I guess.

An easy solution to the problem would be to do what e.g. Haskell does where case-sensitivity determines a type name. For better or worse, C didn't do that.

Re:Language Design: Use 'ident: Type' not 'Type ident' by lisper on Friday May 01, 2020 @05:23PM (#23046659)
In Dylan all types were delimited with <angle_brackets>. Personally I always found that very aesthetically pleasing.
Re:Language Design: Use 'ident: Type' not 'Type ident' by Riverheart on Friday May 01, 2020 @11:47PM (#23048975)
Same in Powershell except they use square brackets

[string] $foo = "foo"

Re:Language Design: Use 'ident: Type' not 'Type ident' by zelphirkalt on Saturday May 02, 2020 @05:02AM (#23050446)
In my brain the instantly translates to "list of strings". Not sure square brackets are such a good choice.
Re:Language Design: Use 'ident: Type' not 'Type ident' by yaktubi on Friday May 01, 2020 @09:50PM (#23048381)
On the other hand doesn’t forward declaration make sense? The code is declaring it depends on the forward declaration defined “somewhere else”. In a sense it is documenting the the classes/structs better.
Re:Language Design: Use 'ident: Type' not 'Type ident' by BruceEel on Saturday May 02, 2020 @12:54AM (#23049343)
Years ago, I stumbled upon a Visual C++ 6.0 bug (if memory serves me right), just by playing around trying to understand C/C++ decls. It would crash on a stray:

   *c;
at the beginning of a translation unit.

Didn't K&R have a tiny, tiny C declarations parser (printing out 'human readable' equivalents) example in their book? I think the caveat was that it needs to assume it's dealing with a declaration...

Re:Language Design: Use 'ident: Type' not 'Type ident' by mariodiana on Friday May 01, 2020 @06:02PM (#23046996)
I was just thinking about pointer syntax today, and if you ask me, there are a lot of problems that could be avoided if language designers took a page out of Guido van Rossum's book and extend his idea of forced spacing.

Take the first example you've given, and let's just talk about variable declaration:

    int* a;
    int * a;
    int *a;
That's all the same. That's wrong. Obviously, you can write a lexer and parser that doesn't give a crap, but the human mind does. If you think it doesn't, that's only because you've internalized the various cases.

It should be this:

    int* a;
The type we're talking about is a pointer to a variable of type int: in other words, "a" is an int-pointer. If you were to create a macro, you'd do something like this:

    #define int_ptr int*
Do you see what I'm getting at? The star in this case is a suffix, equivalent (in our minds) to "_ptr". Conceptually, it doesn't belong anywhere else than attached to the type. It's a compound type, conceptually.

Now, take the star being used in a different context:

    int b = 10;
    int* a = &b;
    printf("%d\n", *a);
There, though we see the same character, it's a completely different thing. It's a dereference operator. Conceptually, it belongs attached to the pointer variable it is dereferencing; and since the star is already used in one context as a suffix, here it should be used as a prefix.

This is no good:

    printf("%d\n", * a);
It doesn't matter that "this compiles." That's not what this is about.

Many C programmers (and programmers in other languages, even Python) are used to writing things like this:

    int c = x*y;
That's wrong. Sure, the lexer and parser don't care. But that makes the language worse, for the human operator. "But it saves space!" Spare me.

The thing with this one example, using the star, is that what we have is the equivalent of a homonym. We have one sign that is actually three different words. Mandating spacing removes the ambiguity you're complaining about.

C is what it is, but if we imagine someone were going to write it today, they should incorporate the above and mandate spacing. For the sake of the humans. "ident type" is not the only solution.

Re:Language Design: Use 'ident: Type' not 'Type ident' by dllthomas on Friday May 01, 2020 @10:39PM (#23048661)
There's a perspective that doesn't seem to be noted yet, which is that

   int *f
is declaring that

   *f
will be an int.

This perspective addresses why the star belongs with the name, why it's star instead of ampersand, why you need to repeat the star for multiple variables, why the brackets goes after the name for arrays, and it will sort of get you where you need to go with function pointers (although there's an automatic promotion which means things will work at the call site that won't work for the type).

This isn't to say alternative constructions mightn't be a better choice in a new language, but it's much more parsimonious when considering C than memorizing a bunch of special cases.

Re:Language Design: Use 'ident: Type' not 'Type ident' by kevin_thibedeau on Saturday May 02, 2020 @01:54AM (#23049636)
Then someone comes along and typedefs a pointer to hide the "scary" double pointer syntax.
Re:Language Design: Use 'ident: Type' not 'Type ident' by dllthomas on Saturday May 02, 2020 @04:24PM (#23054634)
I don't think that actually breaks things. A typedef isn't purely syntactic substitution like a macro.

If we have

    typedef float *floatp;
then the following compiles:

    float x, y;
    floatp xp = &x, yp = &y;
while the following does not:

    float x, y;
    float* xp = &x, yp = &y;

You have defined a new type (which happens to be equivalent to an old type - note that we don't get nominal type-checking from typedefs); the above logic still holds.
Re:Language Design: Use 'ident: Type' not 'Type ident' by cyphar on Friday May 01, 2020 @10:27PM (#23048591)
People have been arguing about where the asterisk should be for a very long time. The main counter-argument to the construction you used is that multiple variable declaration immediately looks ugly given the current rules of C variable declaration:

    int* a,* b; // ??
And that's usually why most C style guidelines use

    int *a, *b;
Now, if we treated "int<asterisk>" as the full type name in the syntax then you get a much nicer result:

    int* a, b; // much nicer!
Though that does have its own tradeoffs. But that would require actually changing the C syntax, at which point you might as well make it the postfix syntax:

    var a, b int*;
Re:Language Design: Use 'ident: Type' not 'Type ident' by klyrs on Friday May 01, 2020 @07:14PM (#23047471)
> It should be this:

> int* a;

I must disagree... the following sends the wrong message the reader:

  int* a, b;
Though I also agree that dereferencing is best without a space. Perhaps the correct suggestion is to not declare pointers and instances on the same line, but that's a convenience that many seem to enjoy
Re:Language Design: Use 'ident: Type' not 'Type ident' by tomjupiter on Friday May 01, 2020 @07:49PM (#23047690)
I think mariodiana is describing a hypothetical language where a and b would both be int-pointers in this case.
Re:Language Design: Use 'ident: Type' not 'Type ident' by WalterBright on Friday May 01, 2020 @08:22PM (#23047871)
To declare two pointers to int in C:

    int *a, *b;
In D:

    int* a, b;
The use of whitespace makes the distinction clear, although the parser doesn't care.
Re:Language Design: Use 'ident: Type' not 'Type ident' by klyrs on Friday May 01, 2020 @08:40PM (#23048007)
C is just riddled with mistakes and this one finally gelled with me. Python taught me that whitespace is great for syntax and, in this case, I'm quite convinced that it should be used more firmly in most languages.
Re:Language Design: Use 'ident: Type' not 'Type ident' by andreareina on Saturday May 02, 2020 @01:10AM (#23049417)
Python's syntax precludes works against a lot of things, like first-class lambdas, case (yes it can be emulated with if/elif, but it's not the same, even without fallthrough), pattern-matching in general, or assigning the result of a method-chaining pipeline to a variable.

I use python at $dayjob, and I run into the limitations of whitespace as syntax all the time.

Re:Language Design: Use 'ident: Type' not 'Type ident' by klyrs on Saturday May 02, 2020 @12:39PM (#23052899)
Yeah, the switch thing is a mindboggle, but the associated pep makes it very clear that/why the problem is quite unsolvable.

https://www.python.org/dev/peps/pep-3103/

It's quite frustrating as there are a lot of situations where a simple switch would be so nice...

Re:Language Design: Use 'ident: Type' not 'Type ident' by dirtydroog on Friday May 01, 2020 @09:53PM (#23048396)
I find the opposite, I can't stand it. Give me curly braces over arbitrary indentation any day.
Re:Language Design: Use 'ident: Type' not 'Type ident' by mhh__ on Friday May 01, 2020 @10:33PM (#23048622)
I think a better (subjective of course) lesson might be to enforce a style.

I have been thinking about making a toy compiler (I wanted to write a borrow checker) that treats bad code as an error, solely aimed at numerical code - I have recently had "Scientific Programming in Python for physics etc." inflicted on me.

Slight tangent, but I think if Haskell enforced some kind of whitespace a la Python it would be much more approachable in real codebases (Haskell is usually quite readable if you are just translating mathematics into code but it - to me at least - feels dreadful as a productive language because of the way a lot of functions seem to be dumped onto into the text editor in a lot of the code I have read)

Re:Language Design: Use 'ident: Type' not 'Type ident' by iso-8859-1 on Saturday May 02, 2020 @12:24AM (#23049181)
What do you mean? Whitespace does mean something in Haskell, see http://echo.rsmw.net/n00bfaq.html .
Re:Language Design: Use 'ident: Type' not 'Type ident' by dllthomas on Saturday May 02, 2020 @04:33PM (#23054690)
Not really relevant to the broader discussion, but Haskell's whitespace sensitivity is defined in terms of automatic insertion of braces and semicolons, and you can write it that way instead if you want. A few people do write Haskell that way (SPJ maybe?) but the community is mostly united around using whitespace. That said, it's useful to know about the braces and semicolons if you're generating Haskell code, because that's often easier. Also occasionally at the GHCI prompt, where it will let you keep things on one line.
Re:Language Design: Use 'ident: Type' not 'Type ident' by todd8 on Saturday May 02, 2020 @06:27AM (#23050829)
As in Python, whitespace in the form of indentation matters in Haskell.
Re:Language Design: Use 'ident: Type' not 'Type ident' by mariodiana on Saturday May 02, 2020 @05:18PM (#23055002)
If I'm describing a hypothetical language, then I'm actually describing a hypothetical language where you wouldn't declare more than one variable per line.

It's been a long, long time since C required a programmer to declare his variables at the top, and best practice argues that you declare a variable as close to its use as possible. So, there really isn't the same case for multiple variables on one line, whereas it may have been a little more forgivable, once upon a time.

Moreover, when I was first learning C, I learned from an O'Reilly book by Steve Oualline. I remember him saying, when it came to operator precedence, that coding style that relied on the rules was a really bad idea. I think he said something like, "Multiplication and division come before addition and subtraction, and use parentheses for everything else."

My bottom line is C has a little too much "convenience" to it. (Granted, to my taste.) It goes back to my van Rossum comment. I'm against special cases and loosey-goosey stuff.

Re:Language Design: Use 'ident: Type' not 'Type ident' by ufo on Friday May 01, 2020 @08:54PM (#23048087)
The problem in C is more than just the `*`. Consider arrays, where C uses `int xs[];` instead of `int[] xs;`. There is no way to use define to declare an int_array type like you did with int_ptr. (Function types also exibit a similar problem)
Re:Language Design: Use 'ident: Type' not 'Type ident' by a1369209993 on Saturday May 02, 2020 @01:45AM (#23049590)
There are four possible spacings to consider:

  foo*bar; // multiplies foo and bar
  foo* bar; // declares bar as pointer-to-foo
  foo *bar; // declares *bar as foo (so bar is still a foo*)
  foo * bar; // multiplies foo and bar
These are all unambigous and there are only two semantics between them. You also have:

  foo* bar,baz; // baz is a pointer
  foo *bar,baz; // baz is a foo
  foo *bar,*baz; // baz is pointer again
  foo* bar,*baz; // baz is now a pointer *to* a pointer
This is all obvious - or at worst unambigous - to a person reading the actual code (without trying to correct for the idiosyncracies of a parser), so the language should either match that or spit out a warning about unsupported spacing.

> [`int c = x*y;` is] wrong.

No, that's unambigously multiplication.

Re:Language Design: Use 'ident: Type' not 'Type ident' by earthboundkid on Friday May 01, 2020 @09:58PM (#23048422)

    A pointer to an int "should" be &int, not int*. That we use *, the 
    dereference operator, to indicate pointers is wrong. * in a type means it's an 
    address, but * in a value means it's not an address. That's nuts! Make it 
    consistent and use & both places. If you need to have a distinction between 
    refs and pointers, it should be that pointers are nullable refs: &int? or some 
    such.

    Edit: How to escape asterisks in HN?
Re:Language Design: Use 'ident: Type' not 'Type ident' by mariodiana on Friday May 01, 2020 @10:18PM (#23048530)
I think you may be right, &int would be better than int*.

I did not want to stray too far from what C does now, for the sake of argument. I just wanted to say that the ambiguity in C is often because it's so loosey-goosey with whitespace.

Re:Language Design: Use 'ident: Type' not 'Type ident' by saagarjha on Friday May 01, 2020 @10:06PM (#23048473)
I’ve had luck with not putting something directly after the asterisk.
Re:Language Design: Use 'ident: Type' not 'Type ident' by earthboundkid on Saturday May 02, 2020 @12:58PM (#23053079)
Apparently HN does not have an escape character which seems like a real oversight. :-/
Re:Language Design: Use 'ident: Type' not 'Type ident' by stormbrew on Friday May 01, 2020 @05:22PM (#23046642)
It's possible to argue here that the problem is not so much the order of type-then-name but the overloaded meanings of * and < at the grammar level.
Re:Language Design: Use 'ident: Type' not 'Type ident' by lilott8 on Friday May 01, 2020 @05:42PM (#23046828)
More generally this falls into a discussion of context-specific vs context-free grammars. Of which C++ falls into the former, Java falls into the latter.
Re:Language Design: Use 'ident: Type' not 'Type ident' by MaxBarraclough on Friday May 01, 2020 @06:14PM (#23047088)
The grammar of C++ is not a context-sensitive grammar. It's Turing-complete, on account of its template metaprogramming capabilities.

I'd be very surprised if Java's grammar were context-free. Do you have a source for this? I wasn't able to find one with a quick search.

Re:Language Design: Use 'ident: Type' not 'Type ident' by tom_mellior on Saturday May 02, 2020 @02:28AM (#23049790)
Pretty much every programming language has a nicely parseable context-free "rough syntax" (my term I just invented) that can be written down formally for the language documentation and a parsing tool. And then every language also has a notion of "well-formed programs", which introduces a whole bunch of additional constraints on what programs should actually be accepted by compiler frontend.

Well-formedness includes type checking. But even without full type checking that can be done later, it also includes things like being aware, in C, of whether a given identifier is declared as a typedef in the current scope. So while C has a nice context-free "rough syntax" formally specified in the standard, its actual input language is context sensitive.

As for Java, the first example that comes to mind is that constructors must have the same name as the class they belong to. This "choose whatever identifier you like, but at some later point repeat that exact same identifier" is a very typical example of something that is not context-free.

You might disagree whether this constraint is part of what you consider Java's "grammar". So the answer to your question depends on what language level you are thinking of. But whichever level you apply to Java, you should apply the same to C++. C++ also has a context-free "rough syntax" in its standard.

Re:Language Design: Use 'ident: Type' not 'Type ident' by battery_cowboy on Friday May 01, 2020 @09:31PM (#23048290)
It's Turing complete because it could simulate a Turing machine, not because of metaprogramming. The language brainfuck is Turing complete, for example.
Re:Language Design: Use 'ident: Type' not 'Type ident' by saagarjha on Friday May 01, 2020 @10:10PM (#23048493)
Checking if a Brainfuck program is well formed (i.e. can be run) is a linear time operation. In C++ this can take forever. They have different complexities.
Re:Language Design: Use 'ident: Type' not 'Type ident' by battery_cowboy on Friday May 01, 2020 @11:59PM (#23049042)
The original comment was about Turing completeness, and it was defined incorrectly. I was giving an example of a dead-simple language that was Turing complete, because the claim was that metaprogramming made C++ Turing complete.
Re:Language Design: Use 'ident: Type' not 'Type ident' by wtetzner on Saturday May 02, 2020 @07:31AM (#23051116)
The claim wasn’t that C++ is Turing complete, that’s trivially true. The claim was that C++’s grammar is Turing complete. I don’t know if that’s exactly the right way to phrase it, but C++’s template expansion stuff is Turing complete.
Re:Language Design: Use 'ident: Type' not 'Type ident' by battery_cowboy on Saturday May 02, 2020 @01:52PM (#23053552)
It was a weird phrasing to me, but i get what you were all saying now.
Re:Language Design: Use 'ident: Type' not 'Type ident' by tom_mellior on Saturday May 02, 2020 @02:13AM (#23049719)
No, the claim was that metaprogramming made the grammar of C++ Turing complete.
Re:Language Design: Use 'ident: Type' not 'Type ident' by battery_cowboy on Saturday May 02, 2020 @04:03AM (#23050207)
Metaprogramming in C++ is TC, but it's not what makes C++ TC by itself.
Re:Language Design: Use 'ident: Type' not 'Type ident' by tom_mellior on Saturday May 02, 2020 @06:21AM (#23050791)
Yes, but it is the difference to other programming languages.

In C you cannot encode a Turing machine that is executed by the compiler at compile time. In Brainfuck you cannot encode a Turing machine that is executed by the compiler at compile time. In C++ you can encode a Turing machine that is executed by the compiler at compile time.

That is the difference we are discussing here.

Re:Language Design: Use 'ident: Type' not 'Type ident' by battery_cowboy on Saturday May 02, 2020 @01:52PM (#23053544)
Yes i now realize that, thanks for explaining further. The original comment was worded in a way that i misunderstood the claim.
Re:Language Design: Use 'ident: Type' not 'Type ident' by benibela on Saturday May 02, 2020 @08:01AM (#23051240)
>In C you cannot encode a Turing machine that is executed by the compiler at compile time.

But you can get quite close with macros

Re:Language Design: Use 'ident: Type' not 'Type ident' by tom_mellior on Saturday May 02, 2020 @08:44AM (#23051429)
No. You would need the ability to write unbounded loops or unbounded recursion. You don't have that with the C preprocessor.

Yes, you can do a lot with the C preprocessor. You can also do a lot in languages that only have bounded loops and are therefore not Turing complete. You can either express nonterminating computations (Turing completeness), or you can't (still powerful, but dramatically less poweful). This question is binary. There is no fuzziness, there is no approximation, there is no "quite close".

Re:Language Design: Use 'ident: Type' not 'Type ident' by MaxBarraclough on Saturday May 02, 2020 @06:19AM (#23050777)
You misunderstand. C++ is Turing-complete at compile time, due to template metaprogramming. This demonstrates that it isn't a context-free grammar.

This isn't true of all programming languages.

Re:Language Design: Use 'ident: Type' not 'Type ident' by battery_cowboy on Saturday May 02, 2020 @01:50PM (#23053529)
Thanks, i see what you were saying now, i misunderstood your original comment.
Re:Language Design: Use 'ident: Type' not 'Type ident' by battery_cowboy on Friday May 01, 2020 @08:33PM (#23047956)
https://stackoverflow.com/questions/14589346/is-c-context-fr...

Context free means something different to what you're saying here. This is a good discussion of this topic, I never knew C++ was so irregular and informal.

Re:Language Design: Use 'ident: Type' not 'Type ident' by downerending on Friday May 01, 2020 @05:50PM (#23046909)
Arguably a programming language is ultimately a user interface, and the more intuitive the interface, the better.

In 2020, not sure we should care that much about how hard compilers have to work to achieve this. Computers and software are here to support us--we're not here to support them.

Re:Language Design: Use 'ident: Type' not 'Type ident' by lmm on Friday May 01, 2020 @11:57PM (#23049033)
A parser tends to get confused in the same places where a less experienced human would get confused. Making a language that's easy to parse dovetails with making one that's easy to read.
Re:Language Design: Use 'ident: Type' not 'Type ident' by downerending on Saturday May 02, 2020 @09:55PM (#23056293)
That's a reasonable point. As long as it's the "good for humans" that driving things, this makes total sense. It's "good for computers" but "bad for humans" that needs to go away these days.
Re:Language Design: Use 'ident: Type' not 'Type ident' by MaxBarraclough on Friday May 01, 2020 @06:08PM (#23047041)
> In 2020, not sure we should care that much about how hard compilers have to work to achieve this.

That's not right. Long compile times are a real issue for some programming languages even today (Rust and C++).

> Computers and software are here to support us--we're not here to support them.

A false dichotomy, and not a perspective that offers any insight. Sometimes a low-level language is appropriate, and sometimes it is not.

Re:Language Design: Use 'ident: Type' not 'Type ident' by Gibbon1 on Friday May 01, 2020 @07:17PM (#23047494)
C++ is stuck in this trap where because it's slow to compile, the compiler maintainers increase the amount of optimizations the compiler does to make it faster. Which of course makes the compiler even slower. Which motivates them to increase the amount of optimizations. Which makes the compiler yet slower.

I feel part of the problem with rust is it doesn't have quick and dirty mode thats fast and a production ready mode that is slow but does all the checks. I do this with my C programs, using various formal analysis tools which are slow to vet the code before releasing it.

Re:Language Design: Use 'ident: Type' not 'Type ident' by TsiCClawOfLight on Saturday May 02, 2020 @04:14AM (#23050253)
Checks in rust are fast. In fact, you can 'cargo check' to run checks without actually compiling, and that will finish in less than half a second.

Most editors did this on save before LSP came along. For logic, this is fast enough because the type system catches enough mistakes and I don't need to run tests all the time. For UI though, a faster iteration cycle would be nice...

Re:Language Design: Use 'ident: Type' not 'Type ident' by MauranKilom on Friday May 01, 2020 @10:47PM (#23048693)
C++ debug builds (i.e. without optimizations) are not that much faster in my experience. So it's not optimizations that are the culprit.
Re:Language Design: Use 'ident: Type' not 'Type ident' by steveklabnik on Friday May 01, 2020 @08:24PM (#23047880)
The checks are not the most expensive part of compiling Rust.
Re:Language Design: Use 'ident: Type' not 'Type ident' by Gibbon1 on Friday May 01, 2020 @09:25PM (#23048253)
What is it then?
Re:Language Design: Use 'ident: Type' not 'Type ident' by Ar-Curunir on Friday May 01, 2020 @10:49PM (#23048704)
The codegen is. This is partially because the IR passed to LLVM is not the best, but it’s also not terrible.
Re:Language Design: Use 'ident: Type' not 'Type ident' by MaxBarraclough on Saturday May 02, 2020 @06:20AM (#23050788)
Does Rust allow for fast unoptimised builds then? Perhaps I'd missed that.
Re:Language Design: Use 'ident: Type' not 'Type ident' by steveklabnik on Saturday May 02, 2020 @08:01AM (#23051243)
Faster, yes. Still lots to do.
Re:Language Design: Use 'ident: Type' not 'Type ident' by MaxBarraclough on Saturday May 02, 2020 @08:12AM (#23051280)
You're saying LLVM is slow even when generating code without optimisations?
Re:Language Design: Use 'ident: Type' not 'Type ident' by steveklabnik on Saturday May 02, 2020 @08:37AM (#23051392)
Yes.

The thing that will massively speed up rustc is the current re-architecting of it. We’re at the point of “few percent here, few percent there” with the current design. These add up over time, of course, but batch compilers are inherently slower than the newer style ones (after an initial compile).

Re:Language Design: Use 'ident: Type' not 'Type ident' by Ar-Curunir on Sunday May 03, 2020 @07:31PM (#23062768)
To add to Steve’s point, Rust adds more checks during debug (non-release) more, which can makes the IR larger. So it’s not always the case that debug mode is faster to compile (though it generally is)
Re:Language Design: Use 'ident: Type' not 'Type ident' by downerending on Friday May 01, 2020 @07:28PM (#23047570)
I'd consider compile time as part of the UI, so in that sense I think we agree. (If the compile is long because the implementation is poor, that needs to be fixed.)

Not sure what you mean on the dichotomy. If someone says that a language needs to have X because that will make things simpler for the computer, I say that they are wrong. The goal, the only reasonable goal, is to make things better for humans.

Re:Language Design: Use 'ident: Type' not 'Type ident' by ncallaway on Friday May 01, 2020 @08:20PM (#23047853)
> If the compile is long because the implementation is poor, that needs to be fixed

The compile time could be long because the implementation is poor. But it's also possible that the specific requirements do not allow for a significantly faster compile time.

That's why the requirements matter. They determine the space of possible implementations. If the requirements eliminate all "fast" implementations, then the resulting user experience will be poor because of slow compile times.

Re:Language Design: Use 'ident: Type' not 'Type ident' by MaxBarraclough on Saturday May 02, 2020 @06:30AM (#23050837)
The best example of this problem is probably SPARK, a variant of Ada which permits formal verification.

Its verifiers are awfully finicky, and tuning the parameters (including selecting the most appropriate verifier) can mean the difference between successful completion in a few seconds, and outright non-termination/timeout-with-failure.

It's true that the answer is to have better verifiers, but that's not just a matter of tweaking the verifier code, it's a serious research challenge. One of the most serious problems with formal methods is the ability to scale.

https://en.wikipedia.org/wiki/SPARK_(programming_language)

Re:Language Design: Use 'ident: Type' not 'Type ident' by pierrebai on Friday May 01, 2020 @09:11PM (#23048170)
This has nothing to do with order and everything to do with the chosen grammar of C and C++.

You can have an ambiguous grammar in a language that puts the type after. A * B could be ambiguous even if A is the identifier name and B the type.

All arguments in the "Language Design" notes are of the same nature.

Re:Language Design: Use 'ident: Type' not 'Type ident' by MaxBarraclough on Friday May 01, 2020 @05:51PM (#23046919)
I missed your mention of the 'most vexing parse' before writing this up, but for those not in the know, here's another fun quirk of C++ syntax:

Declare a local named neko of type Kitten, passing a value to its constructor:

    Kitten neko(42);
Declare a local named neko of type Kitten, without passing a value to its constructor:

    Kitten neko;
Declare a function named neko with zero parameters and with return type Kitten:

    Kitten neko();
https://en.wikipedia.org/wiki/Most_vexing_parse , https://stackoverflow.com/a/620149/
Re:Language Design: Use 'ident: Type' not 'Type ident' by a1369209993 on Saturday May 02, 2020 @01:55AM (#23049640)
And Ceiling Cat help you if you try to declare something like:

  Kitten neko(Felis<0xCA7>::catus);
where catus may be either a typename or a variable depending which template instantiation you landed on.

There's probably some way to say:

  Kitten neko(Felis<is_function_type<typeof neko>::value_of>::catus);
Re:Language Design: Use 'ident: Type' not 'Type ident' by MaxBarraclough on Saturday May 02, 2020 @06:25AM (#23050813)
Beautifully terrible!
Re:Language Design: Use 'ident: Type' not 'Type ident' by raverbashing on Saturday May 02, 2020 @02:50AM (#23049890)
I think this C pointer ambiguity would be "easy" to solve with one of those minor changes:

1 - (sorry, formatting is messing this up) mandate the declaration:

   'A*' or '*B'   
without space (depends if you think the pointer is a type of variable or a type of type)

2 - add some keyword like "type"

Though the compilers are able to deal with it, so it's not a big issue

Re:Language Design: Use 'ident: Type' not 'Type ident' by Groxx on Friday May 01, 2020 @05:48PM (#23046891)
`int * A` and `A * int` both seem ambiguous unless a) you require "int-pointer" naming instead of "pointer-int", and/or b) you have a separator (like the title uses) so this becomes `A * B` vs `A: * B` which is indeed unambiguous but in a very different way.

i.e. without extra rules you can't tell either way, so it comes down to the extra rules. `A * B` is unambiguous for type-before-name if you require "pointer-int" since it would need to be `* A B` for A to be a type.

(quite possibly there are counter-examples when you get into weirder corners, but my point is that it's not as simple as presented)

Re:Language Design: Use 'ident: Type' not 'Type ident' by WalterBright on Friday May 01, 2020 @08:28PM (#23047909)
D resolves the:

    A * B; // declaration or multiplication?
in an unusual way. If it was a multiplication, the result would be thrown away and be pointless. Hence, it is a declaration.

But what if A overloads the * operator and the side effects are desired rather than the result? D has a philosophy that arithmetic overloads should be for arithmetic-like operations, not I/O, template metaprogramming, or other nonsense. Hence if you try it like that, too bad, so sad, it'll be treated as a declaration.

Re:Language Design: Use 'ident: Type' not 'Type ident' by Ididntdothis on Friday May 01, 2020 @08:34PM (#23047965)
I wouldn’t mind if such a statement in isolation would be a compiler error and if languages in general were much stricter. So far all languages I have seen that are very forgiving in terms of syntax (PHP comes to mind) seem to breed sloppy programmers and software written in these often have stupid little bugs caused by typos.
Re:Language Design: Use 'ident: Type' not 'Type ident' by WalterBright on Friday May 01, 2020 @08:47PM (#23048055)
This particular issue has not caused any "silly typo disease" problems that I'm aware of in D. In fact, pretty much nobody notices it, it just works the way people expect it to.

(There are some other things in D that are designed to discourage trying to overload arithmetic operators for non-arithmetic purposes. For example, < <= > >= cannot be overloaded individually, only as a group.)

Re:Language Design: Use 'ident: Type' not 'Type ident' by WalterBright on Friday May 01, 2020 @08:10PM (#23047790)
Ironically the article chose the < > syntax:

    class Id<T>() {
Instead of the D syntax:

    class Id(T) {
Not using < > for template parameters eliminates all kinds of parsing problems.
Re:Language Design: Use 'ident: Type' not 'Type ident' by ZoomZoomZoom on Friday May 01, 2020 @08:17PM (#23047830)
I don't see it being ironic. In Rust () is always a tuple, so if you see it that way it makes sense () isn't used for type declaration.
Re:Language Design: Use 'ident: Type' not 'Type ident' by threatofrain on Friday May 01, 2020 @06:29PM (#23047196)
Makes me wonder why Dart went the same way. One thing I don’t like about type first is that what you want is often more specific than the type.