LoginSignup
12
5

More than 5 years have passed since last update.

Gotanda.pm #17 での発表を記事化しました.
Perl を学ぶ際の参考になればうれしいです.

Perlとは何か

  • 汎用プログラミング言語
    • 当初は, テキスト処理のため
    • 現在は, システム管理, Web開発, ネットワークプログラミングなど様々な用途

経緯

  • 1987年、Larry Wall によって公開
  • sed, awk よりも強力なテキスト処理ができ、C言語よりも簡単に開発できるような言語として開発された

SEE: perldoc perlhist

哲学

  • "There's more than one way to do it"
  • "Easy things should be easy and hard things should be possible"
  • "practical rather than beautiful"
  • "The three principal virtues of a programmer are Laziness, Impatience, and Hubris"

SEE: perldoc perlintro, perldoc perl, Camel Book

"There's more than one way to do it"

  • 「やり方はひとつじゃない」
  • 略して TIMTOWDY
  • 発音は Tim Toady

"Easy things should be easy and hard things should be possible"

  • 簡単なことは簡単に、難しいことも可能に

"practical rather than beautiful"

  • "practical" (実用性)
    • "easy to use, efficient, complete" (使い易さ、効率、完全性)
  • "beautiful" (綺麗さ)
    • "tiny,elegant, minimal" (小規模、エレガント、最少)

"The three principal virtues of a programmer are Laziness, Impatience, and Hubris"

  • プログラマの3大美徳
    • 怠惰, 短気, 傲慢

ポリシー

  • メンテナンスとサポート
  • 後方互換性

SEE: perldoc perlpolicy

メンテナンスとサポート

  • 前提
    • Perl5 の開発をしているのは コミュニティ
    • (期待しすぎるのはよくない)
  • Perl5 の公式サポート
    • 最新の安定版とそのひとつ前の安定版のみ
    • 2018/04/16 なら 5.26 と 5.24
    • メジャーバージョンの更新頻度は定められていないが, 大体 1年に1回で5月頃

後方互換性

コミュニティ

Webサイト

余談

Chrome を利用していれば検索エンジンに、metacpan, perldoc, perldocjp などを登録しておくと便利

SEE: http://post.tetsuji.jp/2014/01/perldoc-jp-shortcut-to-search/

書籍

  • 初めてのPerl 第7版
    • 通称, リャマ本
    • 2018年1月に第7版が出版された
  • Programming Perl
    • 通称, ラクダ本
    • 上述の3大美徳などの理由などが書かれている
  • Perl Best Practice
    • 通称, PBP
    • Test::Perl::Critic などを利用していると, "PBPの何ページのプラクティスだ" と指摘される
  • Modern Perl by chromatic
    • ebook であれば無料で利用できてしまう

perldoc

  • ドキュメントが手元で見れる
  • 最高に便利!

perldoc perl

  • Perl をどこから学ぶと良いか、perldoc のどこを見れば良いかなどが書いてある
Overview
      perl                Perl overview (this section)
      perlintro           Perl introduction for beginners
      perlrun             Perl execution and options
      perltoc             Perl documentation table of contents

Tutorials
      perlreftut          Perl references short introduction
      perldsc             Perl data structures intro
      perllol             Perl data structures: arrays of arrays

      perlrequick         Perl regular expressions quick start
      perlretut           Perl regular expressions tutorial

      perlootut           Perl OO tutorial for beginners

      perlperf            Perl Performance and Optimization Techniques

      perlstyle           Perl style guide

      perlcheat           Perl cheat sheet
      perltrap            Perl traps for the unwary
      perldebtut          Perl debugging tutorial

perldoc perlintro

  • Perl の概要が掴める
  • まず最初に読むのにおすすめのドキュメント
  • 上述したような哲学などもここからだいたい引用した

perldoc perldoc

  • perldoc の使い方などが閲覧できる
  • perldoc は単純なドキュメントの閲覧だけでなく、ドキュメントの検索機能も備えている
    • $_, @_ などの特殊変数も調べられる!
  • 例えば, 次のような使い方ができる
% perldoc -f rand # rand 関数のドキュメント
    rand EXPR
    rand    Returns a random fractional number greater than or equal to 0 and
            less than the value of EXPR.
% perldoc -v $_ # `$_` のドキュメント
    $ARG
    $_      The default input and pattern-searching space.

% perldoc Data::Dumper # Data::Dumper モジュールのドキュメント

NAME
    Data::Dumper - stringified perl data structures, suitable for both
    printing and "eval"

SYNOPSIS
        use Data::Dumper;

        # simple procedural interface
        print Dumper($foo, $bar);
% perldoc -l DateTime # DateTime モジュールのパス
/path/to/DateTiem.pm
% perldoc -l SQL::Maker | xargs -o view # SQL::Maker モジュールのパスを, view に食わせて開く
% perldoc -m Aniki # Aniki モジュールのソースコード閲覧
package Aniki;
use 5.014002;

use namespace::autoclean;
use Mouse v2.4.5;

TOOL

  • plenv
    • Perl binary manager
    • 類例: perlbrew(Perl), rbenv(Ruby)
  • cpanm
    • モジュールインストーラー
    • 類例: cpm(Perl), gem(Ruby)
  • Carton
    • 依存管理
    • 類例: Camel(Perl), Bundler(Ruby), dep(golang)

おまけ

Perl の名前

  • Perl と書いたら、言語を指し
  • perl と書いたら、インタプリンタを指し
  • PERL とは基本書かない
    • 環境変数名(e.g. PERL5LIB) など大文字が慣用ルールの時

TIMTOWTDI

There’s more than one way to do it のモットーをたどるため、 Larry Wall のインタビューを読んでみました.

https://srad.jp/story/03/03/06/1041206/
http://gihyo.jp/dev/serial/01/alpha-geek/0000

宇宙には、押し付けるべきスタイルのガイドラインなどないのだ

ということが書いてありました. 1つに絞るのは難しいというニュアンスだと思います.

インタビュー以外の記事を読んでいて、こういう言葉を見つけました.

There’s more than one way to do it, but sometimes consistency is not a bad thing either (TIMTOWTDIBSCINABTE, pronounced Tim Toady Bicarbonate)

意味は「やり方は一つじゃない、けれど、一貫性は悪いことじゃない」という感じでしょうか.

どうやら rjbs 曰く #moose の irc で話されたことらしい のですが、ログを探せなかったです.

DateTime などの作者で知られる DROLSKY
Perl Best Practice の書評 の冒頭にて, 次のように述べられていました.

Perl Best Practices (PBP) was released in 2004, about 7 years ago. Perl is a great language, but its culture of TIMTOWTDI can be a problem. These days, we often hear that “there’s more than one way to do it, but sometimes consistency is not a bad thing either” (TIMTOWTDIBSCINABTE). PBP deserves a lot of credit for encouraging discussion about the downsides of TIMTOWTDI.

要約すると, Perl でこれが一番というやり方が提示されることで, TIMTOWTDI の弱さについて話すきっかけになった という感じでしょうか.

個人的には, 今までプロジェクト開発の経験に当てはめると, 一貫性を保てた方がコミュニケーションしやすかったので違和感がない考えに思えました.
また, プロジェクトの年月が経過すると, 一貫性が変化するということも自然なことと感じました.
そして, Perl のように後方互換性を保つポリシー があると,
改善のために新たなやり方を模索し, やり方が1つにならない のは必然に感じました.

perldoc perl するとNOTE に, 次のように書かれていました.

The Perl motto is "There's more than one way to do it." Divining how many more is left as an exercise to the reader.

どんなやり方があるか(あると良いか)は, 考える必要がありそうです.

以上〜

12
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
5