Exclamation ! mark ! for ! macros ! feels ! kinda wrong?

I love coding in Rust so far, but did they really have to use this for macros?
This is not a thread about criticizing the current syntax, but what would have been better for you?

Post your alternatives you would have used in your own Rust version!

  • @println()
  • println|()
  • :println():
  • #vec()
  • (((vec)))
  • #vec[ ]
  • println!()

0 voters

3 Likes

I'm quite happy with !, but if I had to pick some other symbol I'd probably go with @vec[].

6 Likes

yeah that's quite handy and very clear.
I still got this boolean inversion in mind using "!". !false !true

@println() is also pretty quick to write. Like that

1 Like

Ah, well, most of the alternatives you posted already mean something in Rust :slight_smile:.

In fact, my own @ syntax has ambiguous cases.

! is unambiguous because it's always preceded by an identifier and proceeded by some kind of bracket.

7 Likes
  • 𝔳𝔢𝔠[]
  • 𝓿𝓮𝓬[]
  • 𝕧𝕖𝕔[]
  • []ɔɘv

Regrettably, I think these all would be breaking changes, except maybe the last one.
Which letter-like characters aren't valid as the start of an identifier?

9 Likes

ȩ̸̸̷̶̷̶̷̡̡̢̛̛̂ͤ͛́͐̎ͫͫͪ̆ͥ͆̒̑͒̋ͯ̈̒̄̄̄͊ͦ̍̃ͦ̋͐ͫͫͬͣ̎̐́̅͌̔̈̇͗ͣ͑̈ͤͩ͐͊̍ͭ̽ͤͣ̄̄ͭ͒͋̿ͧ̔͛͊̅̆̐̉̐̈ͮ͋̌͑ͮͫͣͭ̎̇̐͐̾͐ͯ̔̃̀́́̚̚̕͜͝͝͏̛̟̠̼̗̻̱̪̭̦̖̟̰̭͍̜̝̦͖̣͇̬͙͕͍̟͉̻̰̩̣̥͇̫͕̟͚̩͚̟͈̩̲͓͚̖͔̦̖̘̤̰͖̯̠̻͍̻̱͖̪͇̼̮̗͍̤̰͕̼̳̰̲̬̫̩̥͖̩̗̺͖͓͓̫͠ͅͅͅͅͅc̛ͥ̓ͬ̃ͣͫ̆ͪ̄̓ͪͦͧ̔ͨ̃͒̂ͤ̓̎͐͑͐̉́̅̈ͦͭ̃̅͊̃̅̋̓́͊̈́ͬ͂̃ͥ̂̒̅ͦ̀̿̒̅ͣͪ̽̃͂̈́ͮ̉̍̽̍ͩ̈ͥͬ͛̆̾̽̾ͧͧͩ̉͛̈́̂͂̀͋̍̓̊̈́̚̚̚͠͏̷̨̧͞͞͏̶̴̧̢̛̤̝͍͚̯̤̬͕̪̺̣̩͚̲͙͈̥͖̟͖̰̼̘̘̮͖̪͖̭̰̗̙̝͔͈̠̼̘̠͔͖̠̥̹̲̱͉͓͔̭̞̻͎̞̬̦̘͎̬̞̪͎̥̗̪͍͔̖̫̳͎͔̬̗̝̪̠͍̙̳̜̳̬̰̙̰́́̕̕͢͞͞͠͝ͅͅͅ[̸̑̏̽ͪͤ͊͊̿ͮ̋͂̓͋͊̀̾͊̓̿͌́ͣ̅̈̍ͧ̿͛ͦ̎͗̒ͬ̄̽̄̽̔̔̋̄ͨ͋̓̊̊̉ͫ̏͆ͭͨͦ̏̾ͧ̍̌̇ͤ͐̃̔ͣ̈́ͨͤ͛ͬ͆̀̔͌͗ͮ͑̋͊̌ͧͨͨ͛ͩ͑ͩͧ̆̚͢͏̴̶̶̵́͘͢͏̸̴̨̨̨̞̫̗̱̰̹̥̰̥̖̤̗̟̼̻͍̣̞̘̙͕̙͇̰͉͕͉̝̠̦̯̲̩̲̯̫̭͓̟̱̖͔̭͚̮̱͓̱̻͉̺͈̞̜̯͈̭̜̟̘͎̩̪̱͍̺͈̟̭̼̣͖̲͍̘̳̪̞͈̙̩̳̙̯̀̕͜͢͜͡͠ͅͅͅͅͅ]̸̷̨̀̅̂̌̓̏͐ͧ͛ͯ̀̓ͧ͊ͭ̔̒͐̐ͦ͛̅̋̈͂͛̐̿̓ͯ̌ͫͫ̓̈́̓̎̄ͤͯ͆ͥ̇̈́ͤ̋̓̔̈͐͊̏̐ͥ̽̂͗̋ͩ͆ͨ͂̐́͌ͬ̇̆̿ͫ̓͒̋̽̄͊̃͊͌ͪͧͦ̒̋͛ͤͩ́́̚̚͢͠͞͝҉̸̨̡̨̀͜҉̡͘͜͏̨̲̰̱̭̱̤͉̣͉̥̳͚͕̹̲̣̰̗͕̳̦̻͚͕͕̰̞̠̦̙̯͕͍̹͚̰̞̙͎̤̗̟̰̘̺̠̼̦̦̖̥͇̣̬̫̭͕̲̫͚̰̙̺͍̤̹̺̟̱͓̟̺͓̳̺̖̺̣̯̣͖̦͇͕̠̺͔̗̱͜

7 Likes

A pair of characters I don't think I've ever seen used in rust code are % and ~.

1 Like

As a historical note, macros (known as "syntax extensions") were written as #vec() until August 2011, then as #vec[] until July 2012.

13 Likes

@v1yd0r67gk30, can you add an option for println!()?

Your poll suffers from a logical fallacy called "begging the question" - basically, it assumes that people don't like the println!() syntax so it only contains options that support that assumption.

Therefore, anyone reading the results will come to the conclusion that "the majority of Rust programmers would prefer @println() for macros"[1], when actually the vast majority of Rust programmers might think all proposed alternatives are worse than the status quo... but we don't know that because those people never get the option.


  1. or println|() or :println(): or whatever other syntax wins. ↩︎

29 Likes

yes but I was kinda drunk when creating this thread.
Will add these options now.

5 Likes

omg this is the best.

1 Like

We have the remainder operator a % b! But ~ isn't used indeed. AFAIK it used to be some pointer type ~T in old pre-1.0 versions. I'm not certain whether that was the Box-like or the Arc-like one.

6 Likes

Technically there's the unstable ~const bounds too...

2 Likes

I definitely agree with this guy over here.

1 Like
#[vec]
1 Like

In Ruby, an exclamation mark at the end of a method name indicates a dangerous method, see documentation on method names in Ruby. Often, this means that a method modifies its receiver.

In Rust we always know when something can get modified because it requires a mutable reference (except for inner mutability).

Nonetheless, anything with an exclamation mark might be considered "dangerous" in Rust because it (i.e. macros) can change syntax unexpectedly or do things which normal calls couldn't do (e.g. return from a function).

7 Likes

no!

:slight_smile:

What I want to know is why programming languages chose & for reference like things when & when represents the conjunction "and". How daft is that? It's always niggled me.

Then. we have the misuse of @in programming languages. Also a niggle.

I'm sort of happy with ! for macros. As in i_am_not_a_function!().

1 Like

You think & for reference is bad? Behold:

int square(int and num) {
    return num * num;
}

That's perfectly valid C++ function (and all modern compilers agree). And yes, num here is reference to int.

Thankfully Rust haven't picked up that particular peculiarity of C++ (and all senior developers I personally know had no idea that it's valid C++ till I showed that to them and explained how it works).

7 Likes

Well, * meant multiply long before & meant reference, and here we are. :slight_smile:

2 Likes

I'm fine with ! for macros but I wish Rust used Python's not, and, and or to avoid having !matches!(a, A) and similar overload with references/AND and closures/OR.

4 Likes