Hacker News new | ask | show | jobs
by mrsteveman1 4163 days ago
I've seen quite a few people describe Python 3 as a new language relative to Python 2. Having used both now, I don't agree at all, but I have no experience whatsoever with Perl so I'm not in the same position to compare the different versions of it.

Are there really more differences than things they share in common, to the extent that "new language" is an accurate description?

1 comments

I think it is correct to view them as related, but definitely not the same language.

A short example from the recent Perl6 calendar[1]:

Perl5:

    package Timer;
    
    use Time::HiRes qw(gettimeofday tv_interval);
    use Mojo::Base -base;
    use experimental 'signatures', 'postderef';
    
    has _event_log  => sub { [] };
    has _start_time => sub { [ gettimeofday ] };
    
    sub record ($self, $event_description) {
        # record the event and timestamp
        my $event = {
            timestamp   => sprintf('%.3f', tv_interval($self->_start_time)),
            description => $event_description,
        };
        push($self->_event_log->@*, $event);
    }
    
    sub report ($self) {
        # render a full report
        my $report = '';
        foreach my $event ($self->_event_log->@*) {
            $report .= sprintf "[%s] %s\n", $event->{timestamp}, $event->{description};
        }
        return $report;
    }
    1;
Perl6:

    class Timer {
        has $!start-time;
        has @!event-log;
    
        method record ($event_description) {
            # initialise the start-time if this is the first time through
            $!start-time //= now;
            @!event-log.push({
                timestamp   => now - $!start-time,
                description => $event_description
            });
        }
        method report {
            my @report_lines;
            for @!event-log -> %event {
                 @report_lines.push("[%event<timestamp>.fmt("%.3f")] %event<description>");
            }
            return @report_lines.join("\n");
        }
    }
[1] https://perl6advent.wordpress.com/2014/12/13/day-14-a-perl-6...