-
-
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
Remove "of" syntax #3399
Comments
If an alternative could be figured out for Arrays too, then the proposal would be better than the status quo. |
Here's a thought: In Dart, you can create a typed array via |
Before we continue discussing this, it would be nice to point out at least one problem with the current syntax, or how changing it would enhance something. As far as I remember, we changed |
@RX14 - I meant to add support for that with that "operator". |
It's not that the reading of "of" is bad. In that respect it is pretty good. But it is a special keyword in the language and those always add more "cognitive load" to the language (for lack of a better term). Granted its not a huge one in this case, but I think it makes sense to ask if we really need it. Does it really improve the language significantly enough to justify the extra "load"? Does,
Significantly improve matters over,
And, if we feel it does improve matters, it is also reasonable to ask if their might be a way to achieve essentially the same (and perhaps even improve upon it) but in a way that fits into the language better, i.e. without the extra word. So, for that reason, I think it is at least worth careful exploration of the options. |
@ozra My point was that adding support is the wrong thing to do because it's overloading one operator with two semantics, one ofwhich only appears when used on a literal. My opinion is basically that of @trans. I don't have a good syntax worked out but it somehow feels out-of-place to me, and I tend to use |
Could someone point me to where in the api docs it defines |
@samueleaton It's not a method, it's syntax. Same as |
@RX14, yes it might lead to confusion. |
See also thread on the google group. |
The difference between
And if we just don't want to use this syntax sugar, we can just use btw, I think we made |
I don't think anyone would disagree that |
I don't think we'll be removing or changing the We did spoke with @waj today about |
Wow. No one said one word about the |
@trans well my mother always taught me if you have nothing nice to say, say nothing at all. |
@RX14 I don't understand. Are you inclined to personally insult me b/c of it? I welcome professional critique of the idea. I thought it was a really good idea. I realize it seems odd at first, but I think it makes sense when you work through it. If I've made some error in thinking I'd like to know. It's one thing to be ignored when you make a minor or even silly suggestion, that happens. But when you make a sincere suggestion that you think has a lot of merit, it really sucks to be summarily ignored. |
@trans maybe bring it up on the mailing list... |
@trans Woah, I'm pretty sure that was an attempt at humor, not an insult. |
@trans I didn't mean it as a personal insult, I'm sorry. I simply meant that I didn't like the idea, but didn't have much to say about it at the time. Making a variable which hasn't been set have some value or be operable on seems like an idea which only exists to add the Is |
I appreciate that, and I appreciate the assessment of my idea. And I think it is a very good assessment actually. Although, in part I think any rationale can be made to sound a little like "only exist to..." since you have to somehow connect the current language as is to the additional syntax, as opposed to just tacking on something new. But my idea does (or did) have the pretty serious flaw in it of "making a variable which hasn't been set have some value or be operable on". You're right about that. Thankfully last night I realized I was over thinking it and was able to simplify things, so that part isn't a problem any more. You can read about it here. To summarize, I realized we were already using
Personally if you asked me to choose between one or the other based solely on looks I would choose the more concise forms. No question in my mind. It's only that we understand that the long forms are technically simpler (to the compiler) that we even ask, "is it really better?" At least for me. And I think on the whole it must be so, b/c why else would even have I really think my simplified rationale will appease most of the concerns you expressed. But I can understand if you still feel why bother, just use the |
@trans I agree that If anything, special forms such as |
How about untyped array/hash literals? Make this work:
And, coincidentally, |
one other aspect about arr : Array(Int32) = [1]
def foo(a : Array(Int32))
end
# reads really nice arr = [1] of Int32
def foo(a : Array(Int32)
end
# reads not nice cause once its Array(bla) and once just bla |
Any update on the decision? There are three ways to create Arrays and Hashes, too much IMHO. Examples: This is the same array: p [0, "a"]
p Array(String | Int32){0, "a"}
p [0, "a"] of String | Int32 This is the same hash: p {"a" => 0}
p Hash(String, Int32){"a" => 0}
# Requires parentheses
p ({"a" => 0} of String => Int32) Ok the In fact the main problem of the |
I'm also in favor of removing this, it makes new programmers mix styles and need to learn one more way to do the same thing. |
I’m in favour of removing it when I have to spent sometime deciding which is my preference would be a time wasting. |
@proyb6 just choose which you like, IMO I still vote for reading the code easily and naturally while keeping "of" |
That's the problem @david50407 , we are losing time deciding about which syntax has to be used. Multiply this by each newcomer. |
@j8r I think I agree with the point of multiply way may cause newcomer confuses, but I like the |
I propose we remove the
{} of Foo => Bar
syntax from Crystal. We've already removed thefoo as Bar
syntax, so this syntax specifically sticks out.The current syntax is useful in two situations: creating empty hashes of a specific type, and specifying hash types when the compiler is too specific.
For example:
Fortunately, the alternative syntax already exists in the language:
For empty hashes, simply use
Hash(Foo, Bar).new
. Empty arrays are much the same.Unfortunately, a good syntax for specifying array types without
of
currently doesn't exist, because the "array-like object" syntax uses{}
instead of[]
.The text was updated successfully, but these errors were encountered: