I think if we try to omit named arguments, then at least we should have some thing to denote that you are intentionally omitting thing, not some careless mistake.
personally I’d like to just use h = {x::, y::}, because typing two colons is easier, but too bad that :: is already used for namespace resolution.
I like the underscore! In other languages and in Crystal’s own typechecker _ is used as “infer here what it should go”. Here, the only sane inference is the thing with the same name. Voilá, easy to explain and visually clear. To me the best option so far.
And it “felt” visually “not good” at a glance. Like a chained inverse attribution.
So I tried Whatever(a_huge_name_of_something: ==, another_crazy_stuff: ==, a: 3)
And that “bad feeling at a glance” disappeared. The operator in such context says “the same” (value). Its a fast and easy 2 keystrokes of the same key.
I still keep my original suggestion over others until now.
in some languages, _ is used as placeholder in pipe operator, like "1" |> String.parse_int(_, 10). so it’s actually easier to understand if you come from those languages.
Well…, it exits in Crystal, and means a “matches anything” for such purpose of being discarded.
It’s also already used in Crystal methods definitions, in a diverse way, that will cause confusion, when thinking in definition, and invocation.
An underscore is used in type restrictions. It means “matches anything”:
# Same as not specifying a restriction, not very useful
def foo(x : _)
end
# A bit more useful: any two-parameter Proc that returns an Int32:
def foo(x : _, _ -> Int32)
end
FWIW, i find that first context helpful when i want to differentiate between a parameter without a type restriction, versus one that is allowed to accept any type. Makes it clearer to the reader what the intent is.
Not in such context of method arguments, and underscore in Crystal already have a meaning in such context making its use confuse adding “sub-contexts” like:
_ in the context of parameters, WHEN defining it means matches anything, BUT when invoking it would mean “the value of the previous symbol”.
I would avoid such thing if possible.
Well, this part is just for people curious about other languages
In Go, it’s called “blank” and is used to discard things. Very useful, because Go does not accept unused variables so a
func main() {
a, b := get_2_vals()
fmt.Println("val a = ", a)
}
will raise an error because “b” is never used. So the author fix that expliciting “discard and ignore b” as
func main() {
a, _ := get_2_vals()
fmt.Println("val a = ", a)
}
In Rust, it means basically the same as Crystal depending on the context; in place of a variable it means “discard/ignore”; in places where we need to match “patterns” in such context, it is called “wildcard” and matches anything.
The _ is a decent option. Isn’t that also the “default” variable in Pearl?
Still, this is 2022 and we have the whole vastness of Unicode codepoints to choose from. lets pick something fun. like ≡ or ≈ or the musical repeat sign : 𝄇 :D
A good language still need what’s on most keyboards worldwide without needing juggling to generate a char. We should stick with the ASCII universe, and less keystrokes and modifiers (control-shift-alt-key) == more productivity and less complexity.
Yep. Implicit or direct, if possible; and not complex. Not tied to unusual “hardwares” to be written, accessible in most standard keyboards seeing the symbols, and not having to remember a combination of keys to generate it. The math symbol ≍ means “equivalent to”, would be interesting as an option for f( x: ≍) but it does not exists in standard keyboards, so it is impractical.
After thinking a bit on it, I will not miss it anytime if it will not be implemented but, at the same time, it would not be so harmful in the case it will.
For the later, I’m in favor of the original spec:
h = {x:, y:}
p(x:, y:)
or the underscore one
h = {x: _, y: _}
p(x: _, y: _)
Both of those aren’t strange (for me), and are clear and concise.
I also dislike this “thing:” syntax because I’m expecting something else following it on method calls.
In Spanish, and I think other languages too, there is the concept of using quotation marks
to repeat something already written:
If anything, I would use ^ which is something that points up, almost with the meaning “what’s above”:
x = 1
y = 2
call(x: ^, y: ^)
The only problem is that this isn’t always true: in Ruby (and eventually maybe in Crystal) omitting the value could also mean a call to a method named like that, like: