Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

masak (6289)

masak
  (email not shown publicly)
http://masak.org/carl

Been programming Perl since 2001. Found Perl 6 somewhere around 2004, and fell in love. Now developing November (a Perl 6 wiki), Druid (a Perl 6 board game), pls (a Perl 6 project installer), GGE (a regex engine), and Yapsi (a Perl 6 implementation). Heavy user of and irregular committer to Rakudo.

Journal of masak (6289)

Wednesday July 22, 2009
04:22 PM

Three things in Perl 6 that aren't so great

[ #39334 ]

I keep repeating how great Perl 6 is, because it is. But there are things I wish were different, and that I feel are accidents of history. Maybe they will change before Christmas rolls around, maybe not. But at least to my mind, they stand out as emergent mistakes, good features that combine to make something pretty bad.

Here they are:

  • Methods and Pod
  • Form syntax and string interpolation
  • Comments in the beginning of lines

Below, I'll go through each problem in detail.

Methods and Pod

Perl 6 has two ways of declaring package-like entities such as classes, roles and modules. One way is familiar from Perl 5, and looks like a single statement:

class Austria;

# code here

The other is familiar from some other languages, and looks like a block:

class Austria {
   # code here
}

For the purposes of this blog post, let's call these the statement form and block form, respectively.

The block form is supposed to be the general one, and you can tell from the spec because that's the one that doesn't have any restrictions to it. The statement form is restricted so that it may only occur once in a file, preferably (one might assume) somewhere at the top. In practice, this means that if you have one file with several classes in it, you'll have to use the block form. That's OK, because people like the block form anyway; that's the one they tend to use when no-one tells them not to.

Now, enter Pod. Just like in Perl 5, the Pod directives are written on the leftmost column of the file, no exceptions. This has to do with parsing and stuff; it should be really easy to tell what's a Pod comment and what isn't. But look what happens: people will tend to use the block form for their classes, they will want to document them with Pod, and the result — indented methods and non-indented Pod — will be too hideously ugly for the poor Perl 6 programmer to bear. So they will have to use the more restricted statement form. They will cry a little, because they like the block form. But in the end, they will switch back to the statement form, because the alternative will be too ugly to think about.

There hasn't been much of an uproar about this, because people haven't started Pod-documenting their methods in earnest yet. I did it with the Druid classes, and went through all the above stages: shocked realization, sadness, and then switching to the statement form on a massive scale, at least if they decide to keep their method Pod.

We never had this problem in Perl 5, because Perl 5 doesn't have the block form. We haven't started having the problem in Perl 6, because Pod is in a state of limbo, and people don't really know how to use it to document their methods anyway. But Pod and the block form for declaring classes (and stuff) don't mix well.

Form syntax and string interpolation

E07 was written long ago, in Internet years. Some time after that, the string interpolation changed, and {...} was appropriated to mean "this part of the string isn't part of the string".

So people will be bitten every time they use an interpolating string with the form function. This error will be caught as a syntax error at compile time, so it's not a critical flaw, just bloody annoying.

Matt-W++ is still building Form.pm for Perl 6, so this also hasn't become a real annoyance for people yet. But there's a corresponding thing with eval and interpolating strings that bites people all the time.

It's kinda double-edged: we all like {...} in interpolated strings, but it keeps coming back and biting us too, because we forget it's special syntax.

Comments in the beginning of lines

There was a long bikeshedding discussion about this some years ago. Perl 6 introduces embedded comments, comments which start with a # and then a bracketing character, with all the Unicode smorgasboard to choose from.

However, it was soon realized that people who commented things out by putting #s at the absolute beginning of lines might accidentally create embedded comments by placing their # next to a curly brace or a parenthesis or a bracket. So anything that looks like an embedded comment at the beginning of a line is now treated as a syntax error.

At this point I would like to add that this does not bother me very much. I have come to terms with this particular oddity of the language. But it took me a while, and I can still feel a lingering sense of dissatisfaction with Perl 6 causing me to (*gasp*) change a habit, and one I don't think is a particularly bad one to begin with. Perl is supposed to accomodate a large range of common programming styles, and quickly commenting out some lines by prefixing them with #s is pretty common.

I've now learned to put ## at the beginning of lines I want to comment out instead of just #. This takes care of any unintended embedded comments. So things are fine over here; I'm just worried that a lot of people will feel significant pain when they go through the same process of realization.

I'm not sure embedded comments are all that useful. I seem to find a use for them sometimes in one-liners, but very seldom in other circumstances. Are they really worth the special-casing of a common development technique?

In conclusion

Perl 6 (the spec) is lovely, except in spots. It also isn't finished yet. I like the fact that I can complain like this in a blog post, and smart people will pick my arguments apart, or mull over them and propose improvements for the synopses. All the above three misfeatures are hard to solve because they arise as consequences of features we want, and so fixing the emergent problems would mean going back and changing the features somehow. That's hard.

As usual, feel free to comment. I'm the only one I know who has been severely bitten by the first and the last things, but I'd love to hear if others have too, and how they felt about it.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • There isn't actually a problem in the interaction of methods and pod, when you consider that the "problem" is based on false assumptions.

    One false assumption is that methods have to be indented when you have a block class in order to be pretty; I disagree, and methods can be flush left just like their pod, so all pretty so far.

    Another false assumption is that you can't have block classes in Perl 5, and so what worked for Perl 5 can't work for Perl 6; in fact you *can* have block classes in Perl 5, and I hav

    • There isn't actually a problem in the interaction of methods and pod, when you consider that the "problem" is based on false assumptions.

      One false assumption is that methods have to be indented when you have a block class in order to be pretty; I disagree, and methods can be flush left just like their pod, so all pretty so far.

      I had this discussion with Tene yesterday after writing the blog post. He said the same thing [perlgeek.de].

      I think I started to value indenting everything many years ago, when I wrote my first medium-sized application (in BASIC) without indentation, and got into a situation when I had to find a missing 'END' somewhere. Everything I've been doing since then has reinforced the idea that consistently indenting things is a really, really good thing.

      But you're right: making an exception in this case would solve the whole thi

    • One false assumption is that methods have to be indented when you have a block class in order to be pretty; I disagree, and methods can be flush left just like their pod, so all pretty so far.

      This is an interesting issue in Perl because now TIMTOWTDI makes a real mess of things. Frankly, I don't want my methods to be flush left because if I scan down the code, I like my indentation to instantly give me a hint of scope. If the method is indented, that gives me information that left justification won't. So let's say I have two classes in one package. The structure can look like this:

      class
          method
          method
          method
      end
      class
          method
          metho

      • Thank you, Ovid. You put words to what was only an indistinct feeling for me. I agree fully, I also don't want to sacrifice indentation within classes.

        But I also want my Pod. Maybe I'll end up putting the Pod at the end of each file, and then writing some tests to make sure the Pod doesn't drift away from the methods themselves.

      • I agree that indenting methods relative to classes does look better, and I even do that myself some times.

        Mainly I find that the indenting works best when individual classes are fairly small in the amount of code department, and similarly in those cases I generally don't use the dividing lines I mention.

        Where I don't find indenting necessary is when classes are large or there are a number of large methods (ones that fill a screen or more), so that say you've got hundreds to thousands or more of code lines i

  • MooseX::Declare adds a block style class to Perl 5 and I have been running into the same POD problem.

    • Ah! I actually suspected as much when writing the post, but I didn't want to complicate the point further by mentioning MooseX::Declare. Thanks for confirming my suspicion.

  • people who commented things out by putting #s at the absolute beginning of lines might accidentally create embedded comments by placing their # next to a curly brace or a parenthesis or a bracket. [...] I've now learned to put ## at the beginning of lines I want to comment out instead of just #.

    Is it too late to spec this in S02 the other way around? Let single # be used for commenting out, no matter what follows. Let ## (perhaps also ### and so on) switch on the special behaviour of brackets etc.

    The rati

    • I kinda like that way of thinking. And no, it's not too late to spec things differently.

      However, if you want your proposal to be noticed and possibly acted upon, you really should send an email off to perl6-language [perl.org]. That's where language features and spec changes are discussed.

    • Hmm, a row of hashes, optionally followed by other text, is often used for a separator, so there is still some potential for getting "special" meaning where none was intended if multi-hash is changed to mean "special" handling.

      How about making the special codes a bit harder to get by accident?  Something like #{#  ... #}# - with no whitespace permitted between the braces and the enclosing hashes - for a block delimited comment, perhaps.  That would only be an accidental hazard for people who
  • I have to say, I find the whole idea of POD interspersed with code quite loathsome. It appreciate all the reasons why it's a Good Thing (which boils down to keeping the docs as close to the code as possible), but it has so many drawbacks.

    Most notably, it makes it hard to skim through the code when there's big globs of POD getting in the way. If I'm reading the source then it's code I want to concentrate on. If it's the end-user documentation that I want then I'll use perldoc or look at an HTML version

    • Another problem is that it forces you to write your POD to match the structure of your code or vice versa. This is wrong.

      This is the most salient criticism of interspersed POD, in my mind. I spend a lot of time thinking about how to organize prose -- especially technical prose -- and the only case where interspersed POD reads naturally is solely API documentation.

    • When I actually wrote a Perl 6 module with POD I found that I actually duplicated the signatures in the POD, because they are just so expressive.

      So I nagged p6l over this duplication (and triggered a huge flame war :/ ), and as a result Damian Conway came up with a way to include parts of the code from within the POD.

      Why am I telling you this here? Because that mechanism will encourage interleaved POD, because it's easier to reference something close by. So the Problem won't go away anytime soon.
      • Interesting, considering in PBP Damian suggests (In Documentation, under 'Contiguity') not to intersperse POD throughout code, for similar reasons already stated here.
    • I think you've touched upon something that leads to the root of the issue - the fact that there are several different types of documentation that is produced, each with different display needs and different audiences, and possibly different authors.

      Like you said, comments are written by the programmer, for other programmers (including oneself) and are intended to communicate knowledge about the nearby code.

      On the other hand, POD's purpose is a little more loosely defined. POD is usually written by the p
      • Exactly! POD is indeed used for multiple purposes; some people have even authored books written in POD.

        However, I find the debate between "POD interspersers" and "POD separatists" boils down to only two usages of POD. The first is to document the API, which is a low-level documentation from one programmer to another. The second is to document the program, which is a high-level documentation from the programmer to the user. Incidentally these two use cases follow closely the preferences of "POD interspers