I don't think "say 1.WHAT" is reasonable syntax in the slightest.
But Perl 6 is designed to put code smells in capital letters. EVAL, for example. WHAT shouldn't be used in normal code, but it's useful as a teaching tool or for debugging. If you want to test if something is an integer, you'll want "1 ~~ Int" instead.
By the way guys, string concatenation isn't . or + or a comma or something. It's a tilde: ~
'a' ~ 'b' to get 'ab'.
Because it looks like a "piece of string" ... that ties ... strings together, apparently.
If you read a little farther you might have seen this: Note: .VAR and .WHAT are code smells. They’re useful to understand the language and debug, but testing against what they return is nearly always the wrong approach.
> Because it looks like a "piece of string" ... that ties ... strings together, apparently.
You're mistaking a mnemonic for the reasoning. The reasoning is most likely because using a period for string concatenation is likely to cause problems when it's also used for method calls and strings can have methods, and when methods can be quotes. E.g. "foo"."chars"(), which might be useful with string interpolation.
As for why it's not +, that's covered as well. Perl takes the stance that operators should be different for different operation types. What does foo + bar mean in python? You need to know the types of foo and bar to know that. In Perl 5 and Perl 6, you know whether you are adding numeric types or concatenating (not adding) strings.
It's easy to assume no thought went into the development[1], but it's been very well thought out and been baking for a very long time. They spent that time actually testing their ideas, and making changes when reality didn't match expectations.
1: for that matter, a lot of people think that about Perl 5, which is untrue, it just has different design goals than many languages
1. Python helps you think more like the computer does. Perl helps the computer think more like you.
2. Modern Perl is C# for hippies.
JavaScript overloading + to mean addition and string concatenation was the worst decision ever given the use case of JS. 1 + '1' * 1 is not the same as '1' + 1 * 1 good job. That definitely wont be evil once the values are in a more complex equation with variables coming from some server side JSON string... at all. Definitely wont lead to any unusual bugs when something like the following happens 1 + '000001'. You might not notice 2 being 12 for a while but your customer will likely notice 2 suddenly becoming 1000001.
At least '~' joins two different string together when writing. Makes a lot more sense than '+' to me ~ Ulti 2015
I guarantee you, most people new to the language would be much more put-off by keeping perl5's -> for method calls. Perl lost that battle, it's over. They're making the best of it.
Also, any language with a self-reflective object system is going to show that off to beginners to help them explore, even if it wouldn't be used in production code much. That's like complaining about a language tutorial showing off the REPL to start out, even though you don't use it in production code.
To quote the conclusion of the article you linked:
> Why should you care? Because, I argue, that a fully expressive language is one that supports the delicate interplay between static and dynamic techniques. Languages that force only one perspective on you ... hobble you; languages that admit both modes of reasoning enable you and liberate you from the tyranny of a single type.
It would seem he ought to love Perl 6.
"Getting beyond static vs dynamic" may be of interest:
* HN discussion https://news.ycombinator.com/item?id=9089259
* Youtube: https://www.youtube.com/watch?v=id4pDstMu1s
The syntax is basically the same as Ruby or Python:
# Ruby:
puts 1.class
# Python:
print 1L.__type__
The names of the methods are different, and Python needs the L suffix, or wrap the integer around parens `(1).__type__` to avoid it confusing the dot with a float literal. But, besides that, the syntax is the same.In Perl 6, special meta method built-ins are always all caps, specifically because it's not a very reasonable name to choose in most cases, similarly to how python surrounds a name with double underscores. They are special and different, and should appear as such.
> But "object1.WHAT == object2.WHAT" is something that wouldn't occur to me in a million years
Well, that's good,because you aren't really supposed to be doing that. Rather than getting upset at how Perl 6 looks weird when you map operations directly to how you would do them in another language, it might be better to see if that case actually comes up at all. Maybe the language has other features that support different, possibly better, idioms (or at least better for that language)?
Just because Perl 6 and Python are both dynamic languages and have some features doesn't mean you should assume it functions or should be programmed in the same way. I doubt you would make that mistake for something that looked obviously different, like racket, so why jump to those conclusions here just because they look similar in certain aspects.
I was just pointing out that what you considered unreasonable syntax was actually pretty common syntax. That the function/method names could be better, I agree. But that's an entirely different matter.
Are you referring to python's choices, ruby's, Perl 6's, or all of them? If you think .WHAT could be better, is it the all caps you dislike or is it use of the word 'what' or both? What would you suggest instead?
raiph: we're talking about perl 6's two choices for the things you've brought up, that it's in all-caps and that it consists of the contextually nonsense word 'what'.
The word "what" is one of the most common English words - so the opposite of a better, explicit choice, like type, class, classtype, etc - and doesn't even mean "what-is" if you read it out loud. 3.WHAT doesn't sound like "What 3 is" - it sounds like "3 - I didn't hear you" or if you're being very generous it means "What is 3?" (asking for its value).
You asked what I would suggest? If you want to be really cute and grammatical while sounding like a natural language, here is a suggestion. Instead of WHAT my suggestion is the word STYPE, and read it as though the preceding word had an apostrophe at the end: 3.STYPE, thiswindow.STYPE and so forth. (3's type, thiswindow's type, etc). anyway you asked for a suggesiton, there you have it. I woudn't use it myself though.
I don't buy that it's contextually nonsense. I suspect you had a bad reaction to it and have gotten caught up in that initial reaction. I could be wrong about that but your stated perspective is noticeably extreme and unique about a relatively tiny point.
> if you're being very generous it means "What is 3?" (asking for its value).
I don't think that's being especially generous. But yes, please be generous. :)
I don't think it's asking for its value.
What is Belgium? (Country) What is HN? (Time Sink) What is `4 -3i` ? (Complex Number). What is $age? (Int)
If you want a value you just write something like:
say 3; # 3
say $age; # 55
> You asked what I would suggest?Well I intended my comment for epidemian, but OK. :)
> If you want to be really cute
Perl 6 explicitly incorporates fun but also explicitly avoids "you think that's cute today" mistakes.
I like the choice of names for the pseudo method mop macros: what, which, where, who, why, how, etc. But that's partly because: I find them easy to remember as a group; I found them easy to understand once I'd encountered them once; and I've not seen anyone react negatively to any of them the way you have.
----
Anyhoo, I hope you won't let your dislike for the rarely used .WHAT et al to unduly color your view of Perl 6. I don't expect the tutorial that's the topic of this HN to impress anyone but that's because it deliberately sticks to absolute basics. Instead, I urge you to wait until next year, and then take another look; I think you'll see there's a lot to like.
# perl6 -e 'class Person { has $!initials }; my $p = Person.new( :initials<KAB> ); say $p.WHAT' (Person)
As for why all capitals, you can just as easily ask Python why double underscores. In the end, it's all language convention (explained here[1]). Denigrating something just because it's different is not a position I think has merit. If down the line we discover that these were bad choices, at least then there will hopefully be some evidence to point to.
> The word "what" is one of the most common English words - so the opposite of a better, explicit choice, like type, class, classtype, etc - and doesn't even mean "what-is" if you read it out loud. 3.WHAT doesn't sound like "What 3 is" - it sounds like "3 - I didn't hear you" or if you're being very generous it means "What is 3?" (asking for its value).
If you think WHAT in a programming language is likely to be interpreted as "What? I didn't hear you." then I submit that you are using libraries with very poorly named cutesy methods that the author should have really known better than to use if it ends up in in production. Given the context of a programming language, when would you ever need to call a built in metamethod (because it's all caps...) that meant "I didn't hear you" ?
Even when "what" is used in the context of "I didn't hear you" it actually is asking for information (to be repeated), and the "I didn't hear you" is the implicit part (otherwise why would you ask for the same thing be said again?).
I personally prefer Ruby's stance of making built-in methods look like normal user-defined ones (no special double underscore or all caps convention or anything like that). But this is a small quibble; i wouldn't ditch an entire language for such a minor thing (i've used Perl and regularly use Python and have found both to be quite pleasant languages to use :)
1 is an integer. In Perl 6 integers are objects and have methods. The method calls are distinguished by periods, as has become the most common way to call methods in programming languages.
Is your main complaint that it just looks weird? Is there something you would expect it to be other than a method on an integer or numeric type? Personally, while yes, it does look somewhat weird, the uniformity of knowing you can call .WHAT on anything is nice.
You get one guess as to what 1.23.WHAT does.