in reply to Slow evolution of Perl = Perl is a closed Word

Today a good IDE is capable to parse the code, navigate the code, show documentation texts over the code and point code errors and warnings without run the code.
That kind of thing is usually called "static analysis" and support for it is language-dependent. Java is an extremely simple language, semantically speaking, so static analysis of Java source code is quite easy.

The perl module PPI can parse perl quite well, so there's no good reason for an IDE to miss out.

Existing perl5 IDE's (such as Komodo) or tag systems can navigate perl code very well so that's a non-issue.

In Visual Studio, the VB.Net team chose to employ more static analysis (before compile-time) than the C# team because that was an expectation of incoming VB programmers... in that case the decision was not related to the difficulty in statically analyzing the source code.

IDE's that show errors as you type are simply compiling the source code all the time as you type. Some exceptions to this include type/arity errors which can be determined by simple lookup. Re-compiling all the time slows down the IDE (and is the reason that Visual Studio does not do the same for C#).

perl5 does not have type or arity signatures for its methods so that kind of lookup or analysis is quite meaningless.

As for documentation, there's no reason why an IDE for perl cannot parse structured POD for a method to have it provided (in a tool-tip) in other contexts.

Some errors are not easily detectable until run-time due to a concept known (in non-perl circles) as "late binding". Languages like Java and C#(<3.0) have no inbuilt late binding so one doesn't notice that class of error in practice, however both provide introspection/reflection API's and the same sorts of errors apply there... the IDE is no help in those cases.

Dynamic languages in general benefit more from unit testing than from static analysis, and so IDE's with good support for unit-testing suffice in practice.

To have a good IDE for Perl 5 is difficult, since Perl 5 has a very complex syntax, especially because Perl 5 depends of runtime states to be really parsed.
I do not believe the later statement to be true. Can you cite credible sources for this assertion?

To do this on Perl 5 to me is near to impossible. I was waiting for Perl 6 to resolve these syntax problems, but Perl 6 today is just a dream.
These "problems" are not about syntax. The perl language must be parsed by a sufficiently context-aware parser. (A discussion of classes of parser is out of scope here.)

The language features which make perl different/difficult to parse relate to expressiveness and semantics.

There's been a conscious effort in the perl6 design team (over the last year) to reduce parser ambiguity in the perl6 grammar, solely to make parsing perl6 faster (not easier... it was easy before ;).

At the risk of being down-voted, I think your whole rant is simplistic and ill-informed.

-David

  • Comment on Re: Slow evolution of Perl = Perl is a closed Word

Replies are listed 'Best First'.
Re^2: Slow evolution of Perl = Perl is a closed Word (use)
by tye (Sage) on Sep 01, 2007 at 05:42 UTC
    To have a good IDE for Perl 5 is difficult, since Perl 5 has a very complex syntax, especially because Perl 5 depends of runtime states to be really parsed.
    I do not believe the later statement to be true. Can you cite credible sources for this assertion?

    Of course it is true. The whole reason BEGIN blocks were created was so that useing a module could force the module's run time to happen before the remainder of the useing code's compile time so that the run-time states could impact how the remaining Perl code is parsed.

    In the general case, reliably parsing Perl code that uses a module requires one to run the Perl code (and perhaps even XS code) of the used module. This is also true for BEGIN blocks not implied by use statements.

    And the PPI documentation covers quite a bit of this. So if you use PPI for implementing your IDE, then your IDE will simply not be able to handle some Perl code. For many people, the Perl code that they deal with is rarely such that PPI actually fails on it (how fully and correctly PPI parses it is surely more variable, though I haven't seen good data on this). In fact, the author of PPI reports that almost everything on CPAN (excluding some things) can be parsed as well as PPI tries to.

    But trying to pretend that the parsing problem doesn't in fact exist is just silly, IMHO.

    - tye        

      Of course it is true. The whole reason BEGIN blocks were created was so that useing a module could force the module's run time to happen before the remainder of the useing code's compile time so that the run-time states could impact how the remaining Perl code is parsed.

      In the general case, reliably parsing Perl code that uses a module requires one to run the Perl code (and perhaps even XS code) of the used module. This is also true for BEGIN blocks not implied by use statements.

      Ok, that's a reasonable explanation. Do you know whether there are any examples of this that aren't Source-Filter related issues ?

      I believe that modules which change code semantics aren't really relevant to this issue, only those which change how code is parsed for the purposes of simple static analysis.

      And the PPI documentation covers quite a bit of this. So if you use PPI for implementing your IDE, then your IDE will simply not be able to handle some Perl code. For many people, the Perl code that they deal with is rarely such that PPI actually fails on it (how fully and correctly PPI parses it is surely more variable, though I haven't seen good data on this). In fact, the author of PPI reports that almost everything on CPAN (excluding some things) can be parsed as well as PPI tries to.
      Well that's good. With the size of CPAN, that's a pretty good indicator that a PPI-based approach would be very effective for use in an IDE.

      But trying to pretend that the parsing problem doesn't in fact exist is just silly, IMHO.
      You're right, of course.

      I wonder if anything can be done (perhaps in the area of machine-readable POD) to make it easier for IDE implementors to deal with such issues.

      -David

        Do you know whether there are any examples of this that aren't Source-Filter related issues ?
        Of course there are.
        use constant FOO => 1234;
        Whether or not this line is parsed/run first will change how the next line is interpreted:
        print FOO;

        This will either be treated as printing a constant, or printing $_ to a filehandle FOO.

        And functions with prototypes:

        foo +3
        will be parsed differently if foo is declared first as
        sub foo ();
        or with
        sub foo;

        It means foo()+3 in the former and foo(3) in the latter case.

        (It'll do the same if the sub with body is placed in the source code before the call, without the separate declarations, or in a module you use.)

        And no source filter in sight.

        Of course there are other issues besides source filters. If you read the PPI documentation (really, go ahead, do it now, just the first part, not the really gory details; I'll wait right here in front of the comma until you come back), it covers this fairly well though briefly, even linking to "our own" On Parsing Perl.

        Yes, even the non-source-filter issues can impact correctly parsing to the point of doing static analysis correctly.

        With the size of CPAN, that's a pretty good indicator that a PPI-based approach would be very effective for use in an IDE.

        Um. Maybe. PPI doesn't fail when trying to parse most of CPAN (that is, it doesn't notice that it has parsed something incorrectly to the point that it throws up its hands and declares that it can't go on). I have yet to see any claims as to how accurately or even completely PPI's parsing of all of CPAN actually is.

        I wouldn't be surprised to find that many people only rarely run into problems with PPI's parsing of the code that they usually deal with. In fact, if someone is burdened1 by the use of syntax highlighting when editting their Perl code, then their coding style will be somewhat skewed such that they avoid even reasonable constructs if they happen to confuse their syntax highlighter. So I wouldn't be surprised if they also avoid some things that would trip up PPI. If their syntax highlighter actually uses PPI (such as if they were to use a PPI-based IDE for editting their Perl code), then surely their style will be skewed toward things that PPI gets right.

        1 Is that the right word? I can't find my thesaurus.

        My impression is that PPI, in practice, is good enough often enough that a PPI-based IDE could be successful if used on a new project (due to the feedback loop I noted above). The effectiveness of a PPI-based IDE when applied to an existing code base is certainly less certain, IMHO.

        - tye        

Re^2: Slow evolution of Perl = Perl is a closed Word
by ikegami (Patriarch) on Sep 04, 2007 at 14:20 UTC

    To have a good IDE for Perl 5 is difficult, since Perl 5 has a very complex syntax, especially because Perl 5 depends of runtime states to be really parsed.

    I do not believe the later statement to be true. Can you cite credible sources for this assertion?

    Better yet, I can give an example.

    $x = foo / bar / - 1;

    Is bar a function call, or part of a regexp? It depends on foo's prototype. If foo is an imported symbol, then running code (the exporting module's import function) is required to determine foo's prototype and therefore whether bar is part of a literal or not.

    sub foo() { ... }$x = foo() / bar() / -1;
    sub foo { ... }$x = foo(m/ bar / - 1);