a place to explore and practice the perl programming language, with an eye towards becoming familiar enough with it to use it for quick personal calculations (in place of python).
Personal experiences with python have led me to search for a more beautiful alternative. This is likely an unpopular take, but if you're interested, you can view a private video explaining it here, though it does have a couple of imperfections. A summary of points is given below.
Reasons why I prefer perl to python:
- whitespace is not required, nor does it affect the logical flow of the program. Instead, it is left to the aesthetic whims of the developer.
- improved conventions: no one looks at you weird for putting
;
at the end of a line. - variables actually have scope (if a variable is defined inside a scope, you can't call it outside that scope).
- all the simplest words, like
sum
andmin
, are predefined functions in python, making it a bad practice to use them as variable names. - python 2.7 has the following uncanny behavior about dynamic typing:
2 >= 3
returnsFalse
;str(2) >= 3
returnsFalse
;2 >= str(3)
returnsFalse
;2 >= "3"
returnsFalse
;"2" >= 3
returnsTrue
!
- error messages in python are far more ambiguous. For example, consider the following error in python3:
This message is infuriatingly vague. It uses one and only one line to describe the error, and the description uses no more than six words. It does not state which expression corresponds to the
File "/home/chozorho/ctf/advent/2021/11/./solve.py", line 77, in <module> if (newBoardState[size-1][width-1] > 9): TypeError: 'int' object is not subscriptable
'int' object
(e.g., is itnewBoardState
, or is itnewBoardState[size-1]
? etc.). It also does not give any column index, so this information cannot be easily inferred. In fact, because python is dynamically typed, it is difficult enough to track down the error: whereas a compiler would have checked this ahead of time before blindly running the program, with errors like these, the programmer must waste time re-checking the code manually. In this case, the error was caused on an earlier line of code, so as it turns out, the line being printed isn't even that helpful.
More relevantly to this repo, while perl is also dynamically typed, the fact that the variable prefixes force us to mind the data types means that this error is less likely to occur in the first place. If oneuse
swarnings
, then they'll see a message like:which is clear, specific, and helpful: it even points to a code change that might solve it.Global symbol "@test" requires explicit package name (did you forget to declare "my @test"?)
- perl has references.
- TODO explore: Can you easily convert from array to set in perl? In python, this requires an extra cast to a tuple in order for it to be immutable.
GPLv3
chocorho -- [email protected]