[フレーム]
Uploaded byPeterMartini
PPTX, PDF806 views

Sub Signatures: Next Steps

This document discusses Perl subroutine signatures, which were introduced in version 5.20. It provides an overview of the new signature features, what was contentious about the 5.20 implementation, and potential enhancements for future versions. The author outlines goals for improving signatures in 5.22 such as making them faster, preserving the original signature, and tweaking error handling. Long term enhancements suggested include support for readonly arguments, native types, package types, calling parameters by name, and implicit self parameters to enable multi methods on CPAN.

Embed presentation

Download to read offline
Sub Signatures Next Steps Peter Martini github.com/PeterMartini PeterCMartini@GMail.com @PeterCMartini
We did it!
use feature 'signatures' now available in 5.20 Thanks @rjbs and Zefram
1) Review last year's talk 2) What's in 5.20 3) What's contentious in 5.20 4) Potential enhancements for 5.22 5) Long term enhancements
Goals from last year's talk: Add API for get/fetch – X Add API for parsing – X Add a new module – ✓ Update CPAN signatures – X Performance boost – X
What's in 5.20?
All of the following assumes: use feature 'signatures'; no warnings 'experimental';
Named Parameters sub foo($bar, $baz)
Anonymous Parameters sub foo(,ドル $baz)
Default Values my $n = 1; sub update($rec, $id = $n++)
Default Values (but only for scalars) sub nope(@arr = (1,2)); # syntax error
Strict Checking sub twoargs($one, $two) {} twoargs(1); # dies
Strict Checking sub usedef($one, $two=2) {} usedef(1); # lives!
With Attributes: sub foo :prototype($) ($bar) {}
How it works:
Perl, while parsing, rewrites signatures into equivalent opcodes
perl -MO=Deparse -Mfeature=signatures -e 'sub foo($bar){}' The signatures feature is experimental at -e line 1. sub foo { use feature 'signatures'; die 'Too many arguments for subroutine' unless @_ <= 1; die 'Too few arguments for subroutine' unless @_ >= 1; my $bar = $_[0]; (); }
After parsing, there is no trace left of what the signature was
What's contentious in 5.20?
In 5.18 and before: sub CONSTANT(){ 5 } Replaced by a constant at runtime
In 5.20, it becomes: sub CONSTANT { use feature 'signatures'; die 'Too many arguments for subroutine' unless @_ <= 0; (); 5; }
sub foo : lvalue ($bar) {} # Legal sub foo : lvalue($bar) {} # Syntax error
sub foo($bar); # Syntax error
No path to making use feature 'signatures'; a default
This is why it's still experimental
Goals for 5.22:
Get past experimental!
Revisit signature placement
Right now we have: sub <name> <proto> <attr> And: sub <name> <attr> <sig>
Having the signature after the attributes can cause subtle bugs
Having the signature after the attributes makes coexistence of prototypes and signatures much harder
Especially problematic for sub CONSTANT() {}
Make signatures faster
signatures right now do no more than rewrite your code
Which means it is exactly as fast as doing it by hand
This does not have to be the case
Preserve the signature
Not just for aesthetics; preserving the signature allows sub CONSTANT(){} to work again
Among other optimizations
Tweak error handling
signatures right now injects a 'die' into the sub if the arguments don't match
Which means the error is reported in the sub, not the caller
This is fixable for 5.22
Possible enhancements for 5.22
A separate feature to have signatures imply prototypes
Having a compatibility mode for signatures would allow safely* turning it on by default
safely* - code that warned about illegal prototypes would now probably die; CPAN modules that hijack prototypes would have to be modified to turn off signatures
Allow signatures in sub declarations
Aside: signatures v. initialization block
Defaults in declarations is a sticky subject
# This is bad our $bar; sub foo($baz = $bar); ... { my $bar = 5; sub foo($baz = $bar) {} }
# This isn't any better! sub foo($baz); ... { my $bar = 5; sub foo($baz = $bar) {} }
# This one's sticky ... sub foo($); ... { my $bar = 5; sub foo($baz = $bar) {} }
# Maybe this? sub foo($baz = ...); ... { my $bar = 5; sub foo($baz = $bar) {} }
Fatalize redefinition
Not necessary, but enables optimizations
(sub redefinition already breaks prototypes)
Long term enhancements
Particularly things that can benefit from core
Readonly args sub foo($bar : ro)
Native types sub foo(int $a, num $b, str $c)
Package types sub foo(Some::Class $bar)
Calling parameters by name
sub foo (-bar, -baz = 2) {} foo(-bar => 1); This could be made as fast as simple assignment
Aliasing
sub foo($bar : alias) { $bar = "New"; } my $var = "Old"; foo($var); # $var is now "New"
Implicit $self (method keyword? There's a method attribute already)
Custom handler for sub redefinition
Which would allow multi methods on CPAN
Retrieve signature as a core function
API to override signature parsing
The goal is to let you make promises to Perl, which Perl can enforce for your sanity and its speed
Questions?
Thank you for coming

More Related Content

Try the monad!
PDF
Try the monad!
Cis 170 c ilab 5 of 7 arrays and strings
DOC
Cis 170 c ilab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
PDF
Devry cis 170 c i lab 5 of 7 arrays and strings
The new way to extend VSTS Build and Release
PPSX
The new way to extend VSTS Build and Release
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
PPT
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Preprocessor
PPT
Preprocessor
Karate - MoT Dallas 26-Oct-2017
PPTX
Karate - MoT Dallas 26-Oct-2017
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
PDF
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Try the monad!
Try the monad!
Cis 170 c ilab 5 of 7 arrays and strings
Cis 170 c ilab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
The new way to extend VSTS Build and Release
The new way to extend VSTS Build and Release
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Preprocessor
Preprocessor
Karate - MoT Dallas 26-Oct-2017
Karate - MoT Dallas 26-Oct-2017
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide

Similar to Sub Signatures: Next Steps

Perl6 signatures, types and multicall
PDF
Perl6 signatures, types and multicall
Method::Signatures
PDF
Method::Signatures
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
PDF
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Good Evils In Perl (Yapc Asia)
KEY
Good Evils In Perl (Yapc Asia)
Perl6 signatures
PDF
Perl6 signatures
Lecture 3 Perl & FreeBSD administration
PPTX
Lecture 3 Perl & FreeBSD administration
What's new in Perl 5.10?
ODP
What's new in Perl 5.10?
byacme
Good Evils In Perl
PDF
Good Evils In Perl
Introduction to Perl - Day 2
ODP
Introduction to Perl - Day 2
Software Bertillonage: Finding the Provenance of an Entity
PPTX
Software Bertillonage: Finding the Provenance of an Entity
Intermediate Perl
ODP
Intermediate Perl
Perl 5.16 new features
PDF
Perl 5.16 new features
Short Introduction To "perl -d"
PDF
Short Introduction To "perl -d"
C to perl binding
PPTX
C to perl binding
Perl 6 by example
PDF
Perl 6 by example
Introduction to Modern Perl
ODP
Introduction to Modern Perl
Perl-C/C++ Integration with Swig
PDF
Perl-C/C++ Integration with Swig
Perl6 signatures, types and multicall
Perl6 signatures, types and multicall
Method::Signatures
Method::Signatures
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Perl6 signatures
Perl6 signatures
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
What's new in Perl 5.10?
What's new in Perl 5.10?
byacme
Good Evils In Perl
Good Evils In Perl
Introduction to Perl - Day 2
Introduction to Perl - Day 2
Software Bertillonage: Finding the Provenance of an Entity
Software Bertillonage: Finding the Provenance of an Entity
Intermediate Perl
Intermediate Perl
Perl 5.16 new features
Perl 5.16 new features
Short Introduction To "perl -d"
Short Introduction To "perl -d"
C to perl binding
C to perl binding
Perl 6 by example
Perl 6 by example
Introduction to Modern Perl
Introduction to Modern Perl
Perl-C/C++ Integration with Swig
Perl-C/C++ Integration with Swig

Recently uploaded

6 Hotel Booking Trends You Can’t Ignore in 2025.pdf
PDF
6 Hotel Booking Trends You Can’t Ignore in 2025.pdf
Building production-ready AI Agents with Spring AI and Amazon Bedrock AgentCo...
PDF
Building production-ready AI Agents with Spring AI and Amazon Bedrock AgentCo...
Transform Your Operations with Stackerbee’s Smart Warehouse Management Software
PDF
Transform Your Operations with Stackerbee’s Smart Warehouse Management Software
Patterns of Patterns and why we need them
PDF
Patterns of Patterns and why we need them
Python_Lecture12_SearchingandSorting.pptx
PPTX
Python_Lecture12_SearchingandSorting.pptx
Top 10 Ways AI Can Improve SEO Strategies in 2025.pdf
PDF
Top 10 Ways AI Can Improve SEO Strategies in 2025.pdf
Innovative Software Solutions for Tomorrow’s Challenges | Enterprise-Ready Apps
PPTX
Innovative Software Solutions for Tomorrow’s Challenges | Enterprise-Ready Apps
SiyanoAV: The Best Antivirus Software for Complete Digital Protection
PDF
SiyanoAV: The Best Antivirus Software for Complete Digital Protection
The future Android App Development in 2025
PDF
The future Android App Development in 2025
How to Make Your AI Reliable: Comprehensive Guide to Testing AI Applications ...
PDF
How to Make Your AI Reliable: Comprehensive Guide to Testing AI Applications ...
School-Hall-Pass-System-Modernizing-Student-Movement-Management.pptx
PPTX
School-Hall-Pass-System-Modernizing-Student-Movement-Management.pptx
Python_Lecture13_Introduction to PyQt.pptx
PPTX
Python_Lecture13_Introduction to PyQt.pptx
Build Vs. Buy: Cloud Cost Management and FinOps
PDF
Build Vs. Buy: Cloud Cost Management and FinOps
WhaleSwap Token – Smart Contract Security Audit Report by EtherAuthority
PDF
WhaleSwap Token – Smart Contract Security Audit Report by EtherAuthority
EMR software | Best EMR software | EasyClinic
PPTX
EMR software | Best EMR software | EasyClinic
Scrape Grocery App Data from BigBasket, Zepto, and Blinkit.pptx
PPTX
Scrape Grocery App Data from BigBasket, Zepto, and Blinkit.pptx
Streamline Your Production Process with ERP Solutions
PPTX
Streamline Your Production Process with ERP Solutions
Real-Time AI Voice Agents over WebRTC - A Practical Playbook
PPTX
Real-Time AI Voice Agents over WebRTC - A Practical Playbook
Effortless MBOX Conversion — Fast, Secure, and Compatible with SysInfo MBOX C...
PDF
Effortless MBOX Conversion — Fast, Secure, and Compatible with SysInfo MBOX C...
Wired_AnalyticsTraineeship_13112025_clean.pptx
PPTX
Wired_AnalyticsTraineeship_13112025_clean.pptx
6 Hotel Booking Trends You Can’t Ignore in 2025.pdf
6 Hotel Booking Trends You Can’t Ignore in 2025.pdf
Building production-ready AI Agents with Spring AI and Amazon Bedrock AgentCo...
Building production-ready AI Agents with Spring AI and Amazon Bedrock AgentCo...
Transform Your Operations with Stackerbee’s Smart Warehouse Management Software
Transform Your Operations with Stackerbee’s Smart Warehouse Management Software
Patterns of Patterns and why we need them
Patterns of Patterns and why we need them
Python_Lecture12_SearchingandSorting.pptx
Python_Lecture12_SearchingandSorting.pptx
Top 10 Ways AI Can Improve SEO Strategies in 2025.pdf
Top 10 Ways AI Can Improve SEO Strategies in 2025.pdf
Innovative Software Solutions for Tomorrow’s Challenges | Enterprise-Ready Apps
Innovative Software Solutions for Tomorrow’s Challenges | Enterprise-Ready Apps
SiyanoAV: The Best Antivirus Software for Complete Digital Protection
SiyanoAV: The Best Antivirus Software for Complete Digital Protection
The future Android App Development in 2025
The future Android App Development in 2025
How to Make Your AI Reliable: Comprehensive Guide to Testing AI Applications ...
How to Make Your AI Reliable: Comprehensive Guide to Testing AI Applications ...
School-Hall-Pass-System-Modernizing-Student-Movement-Management.pptx
School-Hall-Pass-System-Modernizing-Student-Movement-Management.pptx
Python_Lecture13_Introduction to PyQt.pptx
Python_Lecture13_Introduction to PyQt.pptx
Build Vs. Buy: Cloud Cost Management and FinOps
Build Vs. Buy: Cloud Cost Management and FinOps
WhaleSwap Token – Smart Contract Security Audit Report by EtherAuthority
WhaleSwap Token – Smart Contract Security Audit Report by EtherAuthority
EMR software | Best EMR software | EasyClinic
EMR software | Best EMR software | EasyClinic
Scrape Grocery App Data from BigBasket, Zepto, and Blinkit.pptx
Scrape Grocery App Data from BigBasket, Zepto, and Blinkit.pptx
Streamline Your Production Process with ERP Solutions
Streamline Your Production Process with ERP Solutions
Real-Time AI Voice Agents over WebRTC - A Practical Playbook
Real-Time AI Voice Agents over WebRTC - A Practical Playbook
Effortless MBOX Conversion — Fast, Secure, and Compatible with SysInfo MBOX C...
Effortless MBOX Conversion — Fast, Secure, and Compatible with SysInfo MBOX C...
Wired_AnalyticsTraineeship_13112025_clean.pptx
Wired_AnalyticsTraineeship_13112025_clean.pptx

Sub Signatures: Next Steps

AltStyle によって変換されたページ (->オリジナル) /