Moving from Perl to Python

Created 2021-04-27. Latest update 2024-02-19.

The programming languages that I've previously used include Java, JavaScript, PL/SQL, Ruby, Perl, C, C++, PHP, Pascal, Visual Basic, Lisp and Fortran (at least).

The most used general purpose programming language for me has been Perl. As it is 2020's now, the activity of the Perl community and the activity on maintaning Perl modules is decreasing. I think it is time to change my primary general purpose language to something new, or old.

I was looking for a flexible and well-established interpreted programming language. My main candidates were Go, Python, Ruby, Rust.

Since I was looking for a somewhat smooth transition from Perl I felt that Go and Rust were not for me. So finally I had only two real candidates: Python and Ruby.

I've already been programming with Ruby but Python was a new language for me. I decided to go with Python which seems to be widely used and not close to the end of its practical life.

These are the key benefits of Python:

  • As a general-purpose interpreted language it offers a smooth enough transition from Perl.
  • The code very easy to read and to understand.
  • Very likely to be alive at least ten years, so at least to 2030's.
  • Based on my initial testing works well on both Windows and Linux.
  • Has excellent libraries.
  • Seems that anything I ask about Python programming I get Google search results and an answer from Copilot AI.

As I'm making a transition from Perl to Python as an avid Perl programmer here are some key things I've noticed.

Indentations are important part of the language. This goes so far that a tab indentation is different from indentation done with spaces and mixing them leads to an error inconsistent use of tabs and spaces in indentation.

At first I found it strange not to use { } and instead use : and indentation. But after first two hours of programming I feel that I never like to go back to those { }'s.

Perl variables indicated with $, @ and % are a mess. A serious mess for a new programmer. No so much for me but I don't miss them at all. Python is much clearer.

Function definitions and calls always ends with () which I find very logical.

There is no direct equivalents of Perl's

__DATA__

and

__END__

in Python.

My Perl modules tend to start with lot of meta lines like

use 5.14.2;
use strict;
use warnings;
no warnings 'experimental';
use utf8;
binmode(STDOUT, ":encoding(UTF-8)");

I think this because of the long history of Perl and the decision to retain backwards compatibility. All the modern things I like to use I must list at the beginning of the module or script. As I converted some Perl programs to Python it seems that the Python versions don't require any of these lines.

2024-02-19: To be continued.