GSoC, contextuals, and intolerance (three posts in one)

masak on 2010-04-29T15:01:41

This is three thirds of a post. The three parts will simply have to combine into one big mechbot in order to pass as a whole post.

I'm a GSoC 2010 student

I sent in a proposal, and it got accepted. Yay!

Use contextuals for "process data", not attributes

Sometimes you both want do subdivide methods into small manageable parts, all the while keeping some sort of data between them. Most people reach for the instance attributes to do this, since these shared between all the methods of one object.

But this can also be done with contextuals, as is now done in Yapsi. This keeps the lifetime of the variables as short as possible, and keeps the objects light-weight. And it still works with inheritance.

I like how Perl 6 allows me to mix OO and contextuals this way. And I really like that it works in Rakudo already.

The mechanics of intolerance

I've blogged before about how #perl6 is a small, friendly community which turns even flame wars into interesting discussions and which works on being kind and open. We've had a bit of troll activity since I wrote those posts, as well as a few borderline trolls.

The other day I treated someone with undue impatience. The whole episode ended well, and I've apologised. In short, what looked like nagging questioning may simply have been someone's slightly different means of communicating.

Mean and evil acts are often committed by people convinced that they're actually doing good. mst++ writes about the reasons for being harsh, and I thought this was one of those times when that was called for. It wasn't.

It taught me to look out for situations when I might be mistaking variations in personality and communication skills for truly annoying behaviour. In many ways, that's a refreshing reminder: a really open community requires that we recognize that everyone doesn't operate exactly the same as we do. That sounds terribly clichéd, I know; but forgetting it is also far too easy.


Off-topic (Perl 6 syntax)

nilsonsfj on 2010-04-29T18:11:47

I don't mean to be a troll or anything like that and I haven't really looked at the how the Perl 6 syntax has evolved over the years.

So, out of curiosity I decided to take a look at the commit and I was bewildered by code such as:


%*pads{$*current-block} = {};
for $ -> $statement {
    self.find-vars($statement, 'statement');
}

I mean, I can see the point in Perl 5 sigils. They're not pretty, but they're acceptable and they didn't bother me in these almost 10 years I've been programming in Perl.

But (and I'll definitely be tagged as a troll for this) this almost looks like line noise to me.

I mean, assuming we use shorter variable names, the following code would be valid:

%*foo{$*bar} = {};

This means more sigils the alphabetic characters in an assignment.

Granted, I don't know what the "*" stands for, neither the "!" which it replaced (seems to be attribute declaration). But if this is something which would be used regularly throughout the code... Perl 6 programmers will likely require specialized keyboards. Thankfully I don't see any Unicode operator madness as was the case some years ago (are they still around?).

I guess this just reinforces my feeling that Perl6 should be renamed Perl++ or PerlNG.

(sorry if I seem trollish, that really isn't my intention)

Re:Off-topic (Perl 6 syntax)

masak on 2010-04-29T21:26:37

Thank you for writing your comment. You're fears of being a troll are quite unfounded. You're quite frank, and your intention is clearly not to cause ire but to air your own distress. Let me try to help allay it.

It's nice to be the one putting some Perl 6 code in the way of a Perl 5 programmer with ten years of experience. I'm not surprised that your first reaction to twigils is one of slight... unease. Perl 6 syntax is different, and not just in minor details.

Things look like line noise when you don't know their semantics. I can assure you they look quite meaningful to me, and I say that as a normal guy, without unusual intelligence or memory. Just as the sigils, twigils indicate the kind of variable you're dealing with, in a way that quickly grows to become more informative than bothersome.

People not used to Perl 5 could use your very argument about line noise to code they don't understand. I'd venture to say that Perl 6 is less line-noisy than Perl 5 on average, because most 'special variables' have been removed, and some uncommon constructs have been de-huffmanized to have longer names. That being said, both Perl 5 and Perl 6 are heavy in operators and sigils compared to other languages.

I don't understand your comment about specialized keyboards. Maybe you're worried that there are hundreds of different twigils. In fact there are eight, by my count, and most of them are quite uncommon. What the twigils do is indicate 'unusual scoping', which is why they (as you correctly guessed) figure in dynamic lookup and OO. They form immediate visual cues to the programmer, shouting "I'm an attribute" or "I'm a contextual", just like sigils shout about being arrays or hashes.

This is typical of changes from Perl 5 to Perl 6. The basic systems are still the same, but there are fully-formed subsystems for dealing with things like OO and contextuals, and the subsystems all mesh well. Most of the changes have been "inward", so to speak, in deepening the language while keeping the original Perl core fairly constant, or adding saner defaults where boilerplate tended to be the norm.

The Unicode madness has indeed abated a little. There used to be a 'Yen' operator; it's now a 'Z'. All Perl 6 is (and has always been, I believe) writeable with ASCII characters, but some constructs have Latin-1 synonyms.

A renaming of Perl 6 to something else is, and should be, completely up to Larry Wall. I don't see any merit in discussing it, except to note that many outsiders seem quite vocal in changing the name, while most insiders (who have studied the language and gotten to know the culture) don't. Of course, everyone's entitled to an opinion.

There, you rascal. You caught me by posting a comment which even predicts being tagged as trollish, as a response to a post partly about radical understanding and tolerance. I hope you feel you got what you deserve. :)

Re:Off-topic (Perl 6 syntax)

nilsonsfj on 2010-04-29T22:30:51

I think I understand the motivation behind the twigils. In other programming languages you can't immediately tell if a variable name is a local variable or an object attribute, for instance.

And while I can't think of a better solution, twigils just don't seem to be the best solution to me. Maybe always requiring the object to be explicit is a better solution (e.g. $self.attribute). But then you'll hit me with a TIMTOWTDI hammer since that probably also works. :)

I don't agree that "line-noise appearance" comes from not knowing the semantics. There are some cases in Perl 5 land where I'm perfectly aware of the semantics but the end result still looks like line noise (e.g. manual symbol table manipulations).

But these are very specific situations and you can even argue that it's a feature - these constructs should only be used by those who know what they're doing.

Having all this everywhere is the issue I'm worried about.

I joked about "specialized keyboards" because I was thinking of something like second row of keys above the numbers, as the shift key would be used a lot.

Of course that it's possible to get used to it (specially considering I'm already a Perl 5 programmer). But I can assure that if Perl 5 people thinks the syntax is a little awkward... well, the rest of the world will find it, at least, *very* awkward.

I'm saying all this because I just didn't bother following up on Perl 6 anymore after the Unicode ops and the whole "periodic table of operators" thing.

All new developments in the Perl 5 world seem to try to "clean up" the syntax, i.e., less non-alphanumeric characters whenever possible. These initiative were supposedly influenced by Perl 6 features, so it came as a shock when I read some real Perl 6 code and it looks a lot "dirtier" than current Perl 5 code.

Anyway, I thank you for your very detailed reply to my comment.

Re:Off-topic (Perl 6 syntax)

chromatic on 2010-04-30T21:17:23

I can assure that if Perl 5 people thinks the syntax is a little awkward... well, the rest of the world will find it, at least, *very* awkward.

I can imagine that idiomatic Perl 6 is difficult for people to understand if they've never learned any Perl 6. I care more about how easy a language is to learn and to use once you've learned it than how difficult it is to guess at meanings if you don't know how to lex it. I don't mean to sound harsh, but the metric of "intuitive to the uninitiated" is irrelevant to me.

All new developments in the Perl 5 world seem to try to "clean up" the syntax, i.e., less non-alphanumeric characters whenever possible.

I disagree in principle and in theory. You can and should remove or reduce irrelevant, inconsistent, misleading, and redundant syntax. Few people disagree. Yet syntax is not a bad thing. Syntax is good. Punctuation clarifies "LETSEATGRANDPA", for example.

Isn't the goal of programming language design to communicate intention effectively to other programmers?

Re:Off-topic (Perl 6 syntax)

nilsonsfj on 2010-05-02T04:40:59

I agree that the "intuitive to the uninitiated" metric shouldn't be considered a major thing (although, I think it is desirable if it doesn't get into the way of other features).

To be honest, I'm just worried that typing all these "shift characters" everywhere will make programming in Perl 6 actually a tiring experience which results in a bad aesthetic result. I mean, pre-"syntax sugar revolution" Perl 5 was already at the limit for me.

Re:Off-topic (Perl 6 syntax)

chromatic on 2010-05-02T07:21:20

I understand that concern, especially for people with keyboard layouts where typing symbols is more difficult than shift-eight, for example. I don't have a good solution for that. Certainly I'll never argue in favor of Perl 5 reference syntax.

Re:Off-topic (Perl 6 syntax)

masak on 2010-04-30T23:31:20

And while I can't think of a better solution, twigils just don't seem to be the best solution to me. Maybe always requiring the object to be explicit is a better solution (e.g. $self.attribute). But then you'll hit me with a TIMTOWTDI hammer since that probably also works. :)

Sorta, kinda, yes and no. :) Even considering what you say in your self-counterattack, many people will use the twigils anyway. Especially if they're the recommended default. Which they are.

But these are very specific situations and you can even argue that it's a feature - these constructs should only be used by those who know what they're doing.

Hm. Twigils as a shibboleth for tricky features. ("You have unlocked the '*' twigil and can now use... contextuals!") Yes, I guess so. But I still maintain that they're not as spooky as you imply, especially not the OO ones. The twigils make them fittingly stand out as "almost, but not quite, ordinary variables".

Trying to understand your original argument better, I realize that it's the sigil-twigil combination that bothers you. But people have been chugging together non-alphanumerics at least since the day someone created the += operator. It's nothing new.

I'm saying all this because I just didn't bother following up on Perl 6 anymore after the Unicode ops and the whole "periodic table of operators" thing.

You should take a look at the new table from last year, if you haven't yet. It's gorgeous. Also -- and I bet you know this -- neither Perl 5 or Perl 6 is meant to be taken in all at once, and the periodic table sort of goes against that and says "Boo! Operators!" and scares everyone giddy with all the horrible richness. Perl isn't a first language, it's more of a last language. :)

Also, after you've recovered from the Unicode thing, you'll be pleased to know that all of the ops in that table are all quite ASCII-friendly. Wreaking havoc with Unicode operators is left as an exercise for module authors. :)

Again, thank you for taking the time to express your doubts and concerns. It would be thrilling to see you at #perl6 sometime, to discuss these things more in real time.

Re:Off-topic (Perl 6 syntax)

nilsonsfj on 2010-05-02T04:51:35

Well, I just looked at the new periodic table and if by "gorgeous" you meant "scary", I agree with you. :)

If you think about it, I guess this discussion wouldn't even exist if Perl 6 wasn't called Perl 6. This implies it's a successor of Perl 5 and thus, eventually, Perl 5 will be obsoleted by Perl 6.

Being completely honest, what goes through my mind when I read about Perl 6 these days is something like: "Oh shit, I will need to go through all this madness sometime in the future when Perl 6 is completed".

I would just ignore Perl 6 if it was called something else and move on happily with my Perl 5 (with added sugar) life.

Since I can't do this, I get a bit worried because I like Perl and think people in the Perl community have the best development philosophy I've seen. But if Perl 5 is ever obsoleted by Perl 6 I just feel that I'll just move on to another more attractive language such as Groovy (and try not to stab people from the Java community in the process).

Maybe I'll try joining #perl6 some time. Currently behind a stupidly restrictive firewall at $work, so no IRC, so this makes life a bit more difficult.

Re:Off-topic (Perl 6 syntax)

masak on 2010-05-02T13:28:21

In the interests of mutual understanding, I tried to look at the periodic table (which is here, by the way), and tried to instill a measure of fear in myself. The closest I got was "huh, that's quite a lot of them, isn't it?".

I think one of the big dividing points between the Perl languages on the one hand and other programming languages on the other, is that Perl embraces complexity -- often quite fearlessly. Language designers are known to talk about minimalism and orthogonality. Perl, in contrast, seems to take as a starting point that the world, including the programming world, is complex and messy and non-orthogonal and full of redundancy and can be seen in different ways by different people.

Perl 5 has quite a lot of operators. I haven't counted them, and wouldn't really know where to start if I were to try. I'm sure Perl 6 has more, maybe even twice as many. (Again, by some half-defined measure.) I think I don't think "scary" when I look at the table because most of these operators are familiar to me now, and I see the rationale for them. (Yes, duh.) Also, many of them I don't normally consider operators, either because they're too infrastructural (like the comma or the different dotty method calls) or too abstract (like 'does' or most of the alphabetic list operators) to be real operators.

With the rest of them, they're either new (which one would expect from a new language or even an upgrade), or they're instances of one Perl 5 operator that has exploded into a couple of Perl 6 operators because Perl 6 often takes a more strict view to keeping different things distinct and relies less on value context than does Perl 5. The shift/and/or/negate operators prefixed by plus or tilde or question mark are an example of this; I briefly give the rationale for why I like this change in blog post from a while back. I should add that I don't use those particular operators on a day-to-day basis, because of their quite specific and close-to-the-metal nature. (That's also a dimension not visible in the Table; some operators are uncommon in practice.)

Much of the complexity is actually hidden and folded in by the presence of the metaoperators. Of course, the mere concept of a metaoperator and the sudden ability to create a fitting operator on the spot (along with the parser technology required to make that work) are, by rights, scary in an objective sense. But it's one of the things that grows on you. And I haven't seen people abuse it either; just because there are metaoperators available, people don't suddenly go crazy and produce unmaintainable code. Rather, it helps turn a for loop here and there into a one-liner.

I came in at around 2004, and I've seen many of these operators mature and take shape. So I guess I'm biased by having seen the rationale for most changes, from Perl 5 through the Apocalypses and Synopses up until today. I agree with most of them. I still don't quite understand how we ended up with eight flip-flop operators, but I haven't really used them yet, so I'll reserve judgment on that point. Maybe they'll be handy in a perl6 -ne context or something.

As for the "Perl 6 by dint of being called 'Perl 6' places itself as the ultimate successor of Perl 5" discussion, it's not an issue that only you are facing, but probably the sore point between the Perl 5 and Perl 6 communities. Patrick Michaud addresses the naming thing here. I address the topic at length in this blog post (which goes together with this blog post by mst++), and I don't feel I have to add much to what is said there. Relations are, by and large, much better since then, but still not ideal.

It's possible that freenode's webchat still works from behind your firewall. I've known some people to reach #perl6 that way.

Re:Off-topic (Perl 6 syntax)

nilsonsfj on 2010-05-02T16:13:53

I've actually read all these these references before posting here. I don't usually actively participate in discussions, though.

"Scary" was the least offensive adjective I could think of to express my general disapproval of it. "Batshit fucking insane" sounds more like my thoughts. :)

Anyway, the whole periodic table of operators sounded novel when I first looked at it a few years ago. These days, I just feel like such things could be the last nail in the coffin for Perl in general.

I'm a bit more optimistic lately as the downward trend for Perl 5 seems to be history (or least it's now stable). But I still think Perl 6 has a large potential of doing some serious damage.

Perl 6 is probably a nice and revolutionary language and I remember being excited about its ideas in the past. However, my feeling is that in the middle of turning those ideas into reality, people got lost somehow (or just chose a very awkward and longer path).

I'm guess I'm just too much into "Perl Survival Mode" in the past couple of years. Being a Perl supporter has been largely an "us vs. them" thing everywhere and Perl 6 just seems to get into the way sometimes. It wouldn't be an issue if everyone else was reasonable, but it's common to try to push Perl as a solution only to have some moron reply something along those lines: "Come on, we're not really going to choose a language with a periodic table of operators, are we?"

This isn't an issue in pure-Perl shops, but these are rare in most places in the world and *extremely* rare where I live.

Re:Off-topic (Perl 6 syntax)

Aristotle on 2010-05-02T16:35:37

Ask these people if they have a periodic table of standard libraries. Have you ever tried even skimming the full reference of all the Java classes?

Just because the complexity isn’t in the operators doesn’t mean it’s not there anywhere.

Of course, these people will immediately respond that they don’t use all of that every day, and what they don’t know they can look up. Which of course is just how it is with the operator table too.

Re:Off-topic (Perl 6 syntax)

masak on 2010-05-02T16:40:20

I can relate to what you're saying about "Perl Survival Mode" and about Perl 6 getting in the way and creating negative PR for Perl 5 users in the business.

I wish I could do more to help counteract such negative effects. None of us can change the past, which does contain its fair share of failed dreams and dead ends for Perl 6. With a bit of luck, we can learn a bit from it, and find ways of working which do produce results, and not just important lessons.

From my perspective, Perl 6 is bringing important (if still reasonably modest) results lately, and it's the newfound confidence from those advances in the Perl 6 community, combined with the mostly independent revival of the Perl 5 community, that has led to debates like this one flaring up. I think they're a good sign, because we have to have them sooner or later.

Here's hoping for a future where Perl 5 stays strong, vital and vibrant, where Perl 6 makes up for the mishaps of the past to emerge as an interesting technology of its own, and where the members of those two communities manage to engage in fruitful exchanges and friendly competitions, all the while uniting against the petty criticism of outside detractors in a larger meta-community wherein it's recognized that deep similarities outweigh surface differences. :)

Re:Off-topic (Perl 6 syntax)

ank on 2010-06-06T13:13:24

Masak and his homies won't acknowledge it, but having few and well-defined operators is a GOOD thing for a language. Operators are akin to prepositions and should be kept to a minimum, in my very humble opinion. I'm pretty sure chromatic/masak/lwall/etc don't think so, though.

Re:Off-topic (Perl 6 syntax)

chromatic on 2010-06-07T19:50:33

I'm pretty sure chromatic/masak/lwall/etc don't think so, though.

Very true, because operators are verbs. Prepositions in programming languages are rare. Perhaps regex modifiers count.

As for the larger question, parsimony of primitives leads directly towards dialectization, in the case of Forth-like languages; top-down standardization of APIs, in the case of Java; or oscillating periods of expansion and contraction towards contentious compromises, in the case of CLOS or Scheme. Each has disadvantages. None reduces the essential complexity of general purpose programs in any measurable way.

Re:Off-topic (Perl 6 syntax)

ank on 2010-06-08T05:26:19

Again, I'm pretty sure you think that - after all, you guys see no downside in crap like "twigils" :D

Oh, Mr. Christopher, what are we going to do with you? How you love writing! So, your name is Chromatic (one word!) sort of like Cher? What's wrong with your real name?

Re:Off-topic (Perl 6 syntax)

ank on 2010-06-08T05:49:54

"parsimony of primitives leads directly towards dialectization"

You are missing the point entirely. Firstly, minimising the number of operators, especially in perl 6's case, would be positive. Secondly, what you are saying, in plain English (I have my pretentiousness filter on) is "if we have very little primitives, we will get into a mess like lisp" and that's simply false - there are many programming languages in the middle of the spectrum that have not been (as you say) "dialectised" (which, according to Dictionary.app is not really a word - but that's what happens when you turn your pretentiousness to overdrive)

Re:Off-topic (Perl 6 syntax)

chromatic on 2010-06-08T10:26:55

Firstly, minimising the number of operators, especially in perl 6's case, would be positive.

Why?

No, seriously. Why?

It's obvious you have a target number in mind. Quantify it. If there are facts, discoverable facts, for the design of an ideal programming language, let's be engineers about it. Be specific. "Too many" is not specific. "Fewer" is not helpful. "I know it when I see it" is opinion, not science. Be bold; back up your assertions.

I cheerfully ignore the reductio ad lambda calculus argument. Tell me the ideal number of operators for a given programming language and buttress it with studies or papers or interaction design tempered with the practical experiences of multiple developers on multiple successful projects. Ideally, these people have each implemented a Scheme with no more than six special forms in the compiler.

"if we have very little primitives, we will get into a mess like lisp"

Let's talk about complexity in simpler terms then. Perl 5's default object system is simple. You get method dispatch and bless. You can build anything you want out of that. The Class:: namespace on the CPAN demonstrates that many people do (and I can only imagine the DarkPAN). Now try integrating multiple object systems with different ideas about representation and access and initialization and encapsulation and lament the lack of coherence of the end product (especially if you have multiple applications of the Adapter pattern). It happened to Tcl and it happened to Lisp. It will happen to Lua with more code reuse. It even happens to JavaScript. Shells... well, sometimes I don't pick on the easiest targets.

The good news, if any, is that you save making class and method reserved keywords, even though you give up reliable reflection and take on complexities such as inherited AUTOLOAD and multiple, oft-conflicting, ways to assign to @ISA.

Complexity occurs somewhere. All the adults in the room know that we're merely pushing broccoli around on our dinner plates--but it's still all there.

Re:Off-topic (Perl 6 syntax)

ank on 2010-06-08T11:12:20

Because the operators are not obvious. Not even for Perl 5 programmers. They should be as obvious as +, or -. I'm not against introducing a couple of operators, if they make sense. In this day and age, the engineering goal of a programming language should be to make multithreading and object plurality as easy as possible. I think it's right to make operators smarter so they can operate on arrays or sole elements, but it seems to have gone to a confusing extreme in perl 6.

One small case, just looking at the periodic table of perl 6 operators. I see a whole bunch of string comparison operators (leg, lt, lg, eq, ge, gt, ne) and a whole bunch of numeric comparison operators (<=>, >, <, etc etc) plus cmp plus eqv. Now, I haven't had time to look at perl 6 deeply in years, but at first glance, that's even worse than common lisp's 5 different notions of equality.

And in the end, that's not really enough either, because for some concepts (is this playing card the same as this other? do I care if they are the same physical object?) even those are not enough. Not to mention that string comparison can get very nasty very quickly if you compare a byte[] to unicode string. No, this calls for two separate concepts: referential equality as a basic comparison operation, and user-defined operations, with polymorphic behaviour. You will notice that this is similar to java, except that there's no operator overloading there. If you think a bit further, all these modifications (defining how the comparison should be done, and defining what i'm comparing, so I know how to compare loose strings or lists of strings) are really just modifications of some basic behaviour - which are also generalities that can be directly applied to operators, to reduce their numbers.

Pushing the complexity into a sensible set of open default classes is a good compromise imho - much better than having trouble trying to understand what's written in the page.

I am not necessarily against more reseved keywords, because those tend to make the language clearer.

As for this reply, it's more of a brain dump at the moment. I remember reading a paper about how many operators people find more comfortable with in the 1st edition of the Gruner/Jacobs parsing book - if someone knows it please post - trying to find it atm.

Re:Off-topic (Perl 6 syntax)

Aristotle on 2010-06-10T14:08:33

One small case, just looking at the periodic table of perl 6 operators. I see a whole bunch of string comparison operators (leg, lt, lg, eq, ge, gt, ne) and a whole bunch of numeric comparison operators (<=>, >, <, etc etc) plus cmp plus eqv. Now, I haven’t had time to look at perl 6 deeply in years, but at first glance, that’s even worse than common lisp’s 5 different notions of equality.

You are aware that Perl 5 has almost all of these already, right?

Re:Off-topic (Perl 6 syntax)

ank on 2010-06-10T14:25:09

You are aware that Perl 5 has almost all of these already, right?

Yes.

Re:Off-topic (Perl 6 syntax)

ank on 2010-06-12T16:52:30

So, are you not going to post my comments on your blog, Mr. Christopher (aka chromatic)?

Since you and your friend Ovid seem to be only interested in what you two have to say to each other, I've started posting my comments in my own blog, http://fixingsoftware.blogspot.com/.

Granted, I didn't expect such unwarranted censorship. I guess it's only okay to talk about whatever you decide, huh? -- ank

Re:Off-topic (Perl 6 syntax)

chromatic on 2010-06-13T07:04:38

I'd rather discuss the Dick Grune research to which you alluded months ago. Did you ever find it? (I'm not Mr. Grune, nor Mr. Pierce, nor Mr. Carlyle, nor Mr. Romata either. What bizarre assertions.)

Re:Off-topic (Perl 6 syntax)

ank on 2010-06-14T07:44:21

No, your name is Shane Warden, and you've published a couple of books as S. Christopher. As for the rest - my Pierce books are laughing at you. I'm sure you want to be them, but it's obvious to everyone you fail (as for Romata, I think you should have said Tomita - he has nice parsers that are porbably the only ones that can parse your perl 6 monstrosity.) Also, I'm tired of you editing my comments, so I am still cross-posting this to my blog http://fixingsoftware.blogspot.com/

Oh, and it becomes thread-safer

masak on 2010-05-08T09:48:11

Either I didn't think of it at the time of blogging, or I forgot about it, but another nice thing about using contextuals rather than instance attributes is that the class becomes thread-safe. In other words, you can suddenly use the same instance of Yapsi::Compiler to compile two different sources simultaneously. The contextuals will be local to each thread and not interact; instance attributes would have been shared and cause a bit of trouble.

Yapsi::Compiler currently only has one instance attribute: @.warnings -- this is so that one can query the object for warnings after compilation. Maybe we should factor this one out into a result object of some sort, returned from the .compile method. But, meh; YAGNI.