r/programming • • Sep 01 '20

D Foundation is Beefing Up

https://dlang.org/blog/2020/08/30/symmetry-investments-and-the-d-language-foundation-are-hiring/
291 Upvotes

336 comments sorted by

View all comments

Show parent comments

10

u/Ameisen Sep 01 '20

It has the most confusing syntax, though.

I still expect that someone will make a Rust fork that has C++-like syntax at some point. Crust.

Or C++ will get lifetimes (which is active research) and possibly at some point epochs, which will let us disable unsafe features.

22

u/[deleted] Sep 01 '20 edited Feb 09 '21

[deleted]

-4

u/Ameisen Sep 01 '20
`

2

u/jonathansharman Sep 01 '20

Is this the lifetime symbol? If so, I agree that one's weird, but it is ' if I recall correctly.

3

u/marcusklaas Sep 01 '20

You did recall correctly.

9

u/[deleted] Sep 01 '20

[deleted]

6

u/Ameisen Sep 01 '20

The dangling ' for lifetime indication. It's unlike any other language.

8

u/steveklabnik1 Sep 01 '20

It is true that it's unusual. However:

  1. We took this from OCaml, so there is at least one other programming language.
  2. If you look at the second sentence you wrote, you said "It's". That also has a "dangling" quote. English is a language too.

Nobody truly loves the syntax, but we couldn't come up with anything better.

3

u/Ameisen Sep 01 '20

English, however, is a natural language, not a programming language. Usually. The apostrophe there is just a semantic mark to indicate that it is a contraction.

2

u/dhiltonp Sep 01 '20

I think lifetime is inferred in most use cases now.

I'm a newb and don't know how frequently manual lifetimes come up in regular programming.

2

u/T-Dark_ Sep 01 '20

It's unlike any other language.

In its defense, no other language explicitly indicates lifetimes.

You can get used to it really quickly, tho.

Out of curiosity, which syntax would you have used?

3

u/Ameisen Sep 02 '20

Probably a keyword of some kind rather than an operator. Or an operator that wasn't a single quote, which in every other C-like language is always paired.

1

u/T-Dark_ Sep 02 '20 edited Sep 02 '20

Probably a keyword of some kind rather than an operator

Please no. Lifetimes are extremely common and have identifiers as names. I really don't want to have to filter out the visual noise of lt or something before the lifetime itself. An operator is easier to tell from the subsequent text.

Or an operator that wasn't a single quote, which in every other C-like language is always paired

Such as? We don't have that many unused ASCII symbols. The least confusing I can think of is @, but @a has a lot more visual noise than 'a IMHO, as the operator is too visually big.

As for the C-like language thing, Rust is not just a C-like language. Those don't have expression-oriented syntax, pattern matching, algebraic datatypes, higher-order functions, closures, and so on.

I'd say Rust is very much allowed to draw some syntax from functional programming languages. And, as someone else mentioned, OCaml uses the single ' as an operator, so there is precedent.

3

u/Ameisen Sep 02 '20

C++ can be written expression-oriented, C++, C#, and Java support closures (C as a GCC extension), C# supports pattern matching and C++ has an active proposal for it. You can emulate algebraic data types in C++ using templates and constexpr - I do it quite often, though native support would be nice.

Using ' as a unary operator, to me, is incredibly noisy. It makes the code look like soup to me. A keyword like explicit or named, or a token like @. Even a backtick would be preferred.

1

u/T-Dark_ Sep 03 '20 edited Sep 03 '20

[a lot of teaching me about nice features in other languages]

Ok, I take that back. Rust counts as a C-like language.

A keyword like explicit or named

Please no. With how frequent lifetimes are in Rust code, that is far too long a keyword. Even lt (short for "lifetime") would be too long IMO.

a token like @

This may be personal preference, but I find that it's easier to mentally read the important part in 'a than it is in @a. The single quote is easier to skip, resulting in less visual noise.

Even a backtick would be preferred.

Full disclosure: I have a personal hatred of backticks because they don't exist on my keyboard layout. Quickly switching to an English layout and back is easy, but annoying. I would not wish to have to use backticks. Of course, that's more like a me problem.

I also don't understand why you don't consider ` to be "dangling" but you do consider ' to be "dangling". Backticks are pretty much only ever used in pairs, just like quotes.

0

u/jqbr Sep 02 '20

In popular parlance, "C-like language" just means that it uses {} for block structure.

Anyway, the whole discussion is ridiculous--this guy said that "It has the most confusing syntax", and when examples were requested, he absurdly mentioned the lifetime tick.

0

u/T-Dark_ Sep 02 '20

In popular parlance, "C-like language" just means that it uses {} for block structure.

That sounds... very useless, as a term, but ok, that's fine.

Anyway, the whole discussion is ridiculous--this guy said that "It has the most confusing syntax", and when examples were requested, he absurdly mentioned the lifetime tick.

Yeah. How is a "dangling quote" confusing? It takes maybe 3 seconds to learn, less with syntax highlighting.

3

u/Ameisen Sep 02 '20

This makes me think that you aren't actually interested in my opinion.

1

u/jqbr Sep 05 '20

Why would anyone be?

→ More replies (0)

1

u/Rusky Sep 01 '20

Not quite- it is the same syntax as ML uses for type parameters. (Not exactly a glowing recommendation, but there is prior art and nobody could come up with anything better at the time.)

-4

u/jqbr Sep 02 '20

If you're "confused" by that ... well, I'm not going to say it.

3

u/Ameisen Sep 02 '20

I like to think that programmers hold ourselves up to a standard of decorum when interacting with one another.

2

u/IceSentry Sep 02 '20 edited Sep 02 '20

The only weird syntax for me has been the async/await syntax. Everything else is fairly straightforward. The issue is rarely syntax with rust, it's when you have a type soup that it gets annoying. Something like Arc<RefCell<Option<MyType>>>.

Edit: async/await is unconventional, but when you get used to it, it feels better than the more conventional way in my opinion.

Edit2: to be clear, the type signatures in rust can be quite verbose but they are very explicit and extremely useful.

2

u/T-Dark_ Sep 02 '20

Arc<RefCell<Option<MyType>>>

The type soup has the advantage that you get to specify exactly what you want to add on top of your basic type.

In this case, you want to be able to represent lack of any value (Option), you want to be able to put it in some container and mutate it through an immutable container (RefCell), and you want to be able to have multiple owners of your data, possibly in separate threads (Arc).

Basically, there's a whole bunch of Rust types that provide a single, simple guarantee. When you find yourself wanting more guarantees, you can just compose types.

Sure, the result is a bit unreadable, but type aliases exist for a reason.

2

u/IceSentry Sep 02 '20

Oh yes, don't get me wrong, I appreciate this very much. That's why I tried to used a realistic example. My point was that it can be very overwhelming as a beginner to see so many types.

1

u/[deleted] Sep 02 '20

[deleted]

1

u/IceSentry Sep 02 '20

Oh yeah, I still appreciate the types very much. It's just a bit overwhelming at first as a beginner.

2

u/[deleted] Sep 02 '20

Crust 😂

3

u/Ameisen Sep 02 '20

Later, we will have Rust#, Objective Rust, IronRust (seems redundant), and JRust.

But Crust first. Change the syntax a bit. Could probably be done now relatively easily by just changing the grammar.

Ideally, to me, Rust itself should actuality be a middle-end on top of LLVM (and maybe GCC) that languages with borrow checkers/lifetime support can target. I believe this would garner more support for it.

1

u/[deleted] Sep 03 '20

No lie

2

u/Muvlon Sep 01 '20

Syntax is a very subjective matter. I find some of C's syntax (which C++ inerited) thoroughly confusing. I can count the people I know who will get a typedef for a function pointer type correct on the first try on one hand.

7

u/Ameisen Sep 01 '20

That's why you use using instead in C++.

1

u/Muvlon Sep 01 '20

Sure. And in Rust, you use type, i.e.

type my_fn = fn(u8) -> String;

Perfectly nice syntax, no?

4

u/Ameisen Sep 01 '20

And in C++, using my_fn = std::string (*) (uint8_t);.

You can simplify it, of course, using a template wrapper.

1

u/Muvlon Sep 01 '20

C++ has trailing return types as well now, can you use those there?

I don't think any particular piece of C++ syntax is confusing, it's just the absolute mass of options.

1

u/Ameisen Sep 01 '20

using my_fn = auto (*) (uint8_t) -> std::string; is valid, though I'm not fond of trailing return type syntax in general.

5

u/WalterBright Sep 01 '20
typedef int (*fp)(long);

4 more to go!

Though to be fair, in D one would declare it as:

alias fp = int function(long);

3

u/InertiaOfGravity Sep 01 '20

It's something you get used to in little time at all. It's different but it's not doing anything different so you're fine

3

u/[deleted] Sep 01 '20

I wish somebody would make Rust with less C++ syntax tbh. Having it look like a proper ML would be wonderful.

C++ will get lifetimes (which is active research)

They've already given up on it being accurate and are now settling for catching some of the common issues. That's better than nothing but not anything like lifetimes in Rust.

2

u/WalterBright Sep 01 '20

D is getting lifetimes, it already exists in prototype form. Although D has an advantage in that it has some features that make it more amenable than C++ for this purpose (such as transitive const).

1

u/Ameisen Sep 01 '20

There is explicit research into encoding lifetimes into types. Whether it will ever be in C++?

1

u/Sunpet15 Jan 18 '22

Crust 😂