Live data from Hacker News

Language Design: Use 'ident: Type' not 'Type ident'

soc.me

81–90 of 192 posts

Re: Language Design: Use 'ident: Type' not 'Type ident'

#81
post #48

Earlier quoted context omitted.

>there are no demonstrable differences worth arguing about. That is a big claim. Is very easy to believe (I do it before, when my knowledge of programming languages was about just 3 or 4. Now is more than 12). : But is clearly false, and is easy to prove: async/await go chan fn sort (of:list ...) try/catch match All the above are just small things that have a HUGE impact in how develop programs. Also, in matter of "s…

I also know many languages (which is hardly some grand accomplishment) and it’s my firm opinion that syntax MATTERS LEAST. You spend some time getting used to it and it never really bothers you again. Semantics matter most - syntax is just an interface to the important stuff. The difference between Python, C++, Haskell, Common Lisp, Prolog, and SQL isn’t syntax. If it was, everyone would pick their favorite syntax an…

> The difference between Python, C++, Haskell, Common Lisp, Prolog, and SQL isn’t syntax

Ok, let's try: Do SQL without the SQL syntax.

P.D: I don't think we are that in disagreement ("The syntax just needs to be a decent enough interface to the semantics"), is that the claim of "syntax don't matter" make it look is just an irrelevant aspect of the language. Can be argued how much relevant, but after years on this trade, go to the C++ community (for example) and tell them to change the syntax to lisp syntax and see how much it will succeed.

Syntax is 100% tied to paradigms, idioms, and such. Is intrinsic to the language we use.

Re: Language Design: Use 'ident: Type' not 'Type ident'

#82

It is presented here that name before type is easier to read as a matter of fact. I’m not so sure. In math or languages where type info is optional, we often write “x = 5”. When type info is required, it is natural to evolve to “int x = 5”. Readers would naturally focus on the latter part. When we write “x: int = 5”, the type info is in the middle. We cannot skip it even when we just want to focus on the name and val…

If you have local type inference, an alternative would be "x = 5: int".

In Rust, you can write:

    let x = 5i32;
Sadly it's nowhere near as elegant for string literals.

Re: Language Design: Use 'ident: Type' not 'Type ident'

#83

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 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…

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'

#84
I think the author misses the single biggest advantage of `identifier: Type`.

The moment `Type identifier` syntax encounters higher order functions and types, you end up with messes of parenthesis. Figuring out what a type means then involves bouncing back and forth across the type definition.

With `identifier: Type` complex higher order types still parse linearly left to right.

It's enough of a UI issue that people will end up avoiding higher order functions in `Type identifier` languages simply because they're a mess to express.

Re: Language Design: Use 'ident: Type' not 'Type ident'

#85
post #58

Earlier quoted context omitted.

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 m…

The checks are not the most expensive part of compiling Rust.

What is it then?

Re: Language Design: Use 'ident: Type' not 'Type ident'

#86
post #40

Strong disagreement here. "type ident" flows with the data during assignment, doesn't confuse the infix operators, and doesn't misuse ":" from a human-language standpoint. For example: val x: String = "hello" The type interrupts the flow of data from "hello" to x, so one thing that pops into mind is that this is typecasting the value to a string before storing it. Nope. Another possibility I instinctively see this as…

If you're using immediate initialization, leave the type off entirely and let the compiler infer it.

Re: Language Design: Use 'ident: Type' not 'Type ident'

#87
post #36

Earlier quoted context omitted.

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.

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.

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'

#88
post #40

Strong disagreement here. "type ident" flows with the data during assignment, doesn't confuse the infix operators, and doesn't misuse ":" from a human-language standpoint. For example: val x: String = "hello" The type interrupts the flow of data from "hello" to x, so one thing that pops into mind is that this is typecasting the value to a string before storing it. Nope. Another possibility I instinctively see this as…

But a colon is also often used to indicate a mapping of names or categories to value. For instance:

  Breakfast: eggs and bacon
  Lunch: falafel sandwich
  Dinner: BBQ pork and slaw
The type of the variable is the "explanation" here.

  val x: String
"x, which is a String"

  val x: String = "hello"
"x, which is a String, is initialized with 'hello'"

Re: Language Design: Use 'ident: Type' not 'Type ident'

#89
post #81

Earlier quoted context omitted.

I also know many languages (which is hardly some grand accomplishment) and it’s my firm opinion that syntax MATTERS LEAST. You spend some time getting used to it and it never really bothers you again. Semantics matter most - syntax is just an interface to the important stuff. The difference between Python, C++, Haskell, Common Lisp, Prolog, and SQL isn’t syntax. If it was, everyone would pick their favorite syntax an…

> The difference between Python, C++, Haskell, Common Lisp, Prolog, and SQL isn’t syntax Ok, let's try: Do SQL without the SQL syntax. P.D: I don't think we are that in disagreement ("The syntax just needs to be a decent enough interface to the semantics"), is that the claim of "syntax don't matter" make it look is just an irrelevant aspect of the language. Can be argued how much relevant, but after years on this tra…

It's worth reiterating the point of my initial comment (which I admit I may not have conveyed well). I never said "syntax doesn't matter", because that's not my point. My point is that it's almost never worth arguing about. Just pick something (or accept what already exists) and move on. Language designers (and you) have more worthwhile things to do.

My issue is with unproductive, endless debates about syntax minutiae like the original post. Syntax doesn't matter enough to be worth it, and such debates devolve into everyone shouting about their personal preferences anyway (see: many of these comments).

> Do SQL without the SQL syntax

I'm not sure what you're saying here. The syntax of SQL is completely arbitrary - I'm sure you could think of a completely different syntax that works just fine. Let me know if I'm missing something, but it seems extremely obvious to me that the biggest difference between C++ and SQL programs isn't how they look - it's how they behave. One wouldn't dream of replacing one with the other and that has nothing to do with their syntaxes.

> go to the C++ community (for example) and tell them to change the syntax to lisp syntax and see how much it will succeed

Obviously it'll fail - good. Even if lisp syntax was way better, they've gotten used to C++ syntax and have much more important things to spend their time on.

Re: Language Design: Use 'ident: Type' not 'Type ident'

#90
post #40

Strong disagreement here. "type ident" flows with the data during assignment, doesn't confuse the infix operators, and doesn't misuse ":" from a human-language standpoint. For example: val x: String = "hello" The type interrupts the flow of data from "hello" to x, so one thing that pops into mind is that this is typecasting the value to a string before storing it. Nope. Another possibility I instinctively see this as…

I agree, though I could see the merit for a standalone declaration: val x: String x = "hello" The type at this point is almost like a comment. For declaration and assignment though, I agree that reading "ident: Type" is harder for me. Perhaps an interesting idea would be to have the type at the end of the expression . Like so: val x = "hello": String Essentially, you're making a type assertion on an expression. Since…

Most statically typed languages don't even need the type assertion in a case like this, though. A literal has a definite type (hopefully), so the type of x can be inferred.

  val x = "hello"
Standalone declarations are the most important problem to solve here.
Post reply on HN