-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Longer question marks RFC #1737
Conversation
I don't know why we must be restricted to postfix operator ^ {}
postfix func ^<T>(opt: T?) throws -> T { ... }
...
let address = try IPAddress(string: addresses[id]^)^.withPort(12345) |
Seems pointless. If we were to add "method macros" then |
@durka how should method macros work together with the |
Going to join in the bikeshedding. Why not get rid of the operator and make it The biggest problem with I feel like alternative syntaxes were probably already bikeshedded on the original RFC, though. Has anyone checked that thread? Method macros are interesting and, while off topic, please, yes, let's do that. I think the big problem with macros generally (at least, why I don't just use them) is that you can't namespace them, and it's going to be a long, long time before that's fixed. The current system makes it too expensive to use the convenient names; you can effectively only use it once per project or, if the crate is popular, once for the entire ecosystem. Being able to make custom operators in Rust would also be a nice feature in limited circumstances, but probably you need to combine that with method macros to extend error handling. |
@est31 actually something like @camlorn one of the big arguments in favor of Also I think Rust has explicitly rejected custom operators as a design decision, we don't want to be Swift or Haskell. |
Longer question marks, eh? How about ? FULLWIDTH QUESTION MARK? There's also the emoji version,❓. Nice and red! |
@durka That said, it may not matter. I think, if you're willing to use words, you can have any custom operator you want inside something like a And, with that scary thought, I'll avoid taking this further off topic. |
@camlorn
That's wrong. Macros are always namespaced to the block they are defined. If you define a macro in mod.rs and want to use it in lib.rs that includes mod.rs, you will get an error. If you define a macro inside a crate, users of that crate won't get it unless you add What you think about is C/C++ preprocessor macros, which do act on a global scope and leak through headers per default until they are undefined, but which destroys any macros with the same name that were used before. Yes, you can't rename Rust makros (unlike with use ... as notation that works for all other language items), and if you use a crate's macros, you need to use all of them, but generally the situation is much much better than on say C/C++. But your dislike against macros is symptomatic, and the unpopularity is listed as one of the drawbacks of a macro based solution to the problem in the RFC, although I personally would even prefer to use macros over custom operators in my code. |
@durka if you make an RFC for adding method macros and removing the @camlorn
I've skimmed over it before doing the RFC, but most of the discussion was about entirely different approaches, like one can observe in this thread already. Almost none was about which notation exactly should be used. To get discussion on topic again: What criticism is there to this proposal other than "I think RFC 243 was wrong, and this is basically RFC 243, lets use [...] instead, I'm against this RFC"? Why do you think the |
Everything starts at -100 points. The
(Also a note that some people consider (1) a positive, because often when reading code you want to focus on the main flow and worry about error handling later.) This RFC would solve (1) (sort of -- two characters really isn't much more than one) but doesn't touch (2) at all. That's why I don't see it as a major gain.
I'm not even sure they are a good idea, so I probably won't be the one to write that RFC. We'll see what happens when Macros 2.0 shakes out, maybe. |
@est31 I could say more, but this is off topic. Suffice it to say that the lack of namespacing support for macros frustrates me greatly, especially since we don't have default and keyword parameters and you have to use macros to emulate them. |
@camlorn It is off topic, but allowing macros to be namespaced and imported like other items is planned for macros 2.0. |
How about renaming it to ‽ ? We could also have a right-associative version, ⸘. |
@durka, is there a "methode macro" RFC?? I think such a think wouldn't be to bad e.g. |
I haven't seen any full proposal on implementing method macros, just a vague idea being thrown around. There has been some other discussion about it in rust-lang/rust#31436. |
@dathinab There is an issue #676, no pre-RFCs yet. Making |
From the linked issue discussion on method macros:
And a similar note from withoutboats. |
Overall, I'm pretty happy with That said: |
No, the "WTF" connotation is not intentional. My main concern is that Any other ideas how a longer version of |
I think that a good reason for why "?" is significant enough is that I expect editors to change syntax highlighting to highlight it specially, and from what I can tell that should be good enough. @durka seems to share this belief. As it relates to the RFC, |
I really like the current |
Note that it wouldn't be the first time to rename something during or close to stabilisation: rust-lang/rust#27719 (comment) |
I think this would be better served by discussion on the tracking issue for FWIW, I also think it's very unlikely that this change will be accepted, since it cuts against much of the spirit of the I'm going to close this RFC for the time being, in favor of tracking issue discussion. |
Wait, wasn't the main argument for Still doesn't change my opinion that |
@est31 Eh, |
@ticki yes, I know that it is not With chaining I mean the use case outlined in this comment #243 (comment) , aka builder pattern. |
Rendered.