4 ms·
Is Russian the hardest language to read for someone that doesn't know Russian? C type brackets and semicolons are second nature to a lot of people. Perl has a
by vgy7ujm 10y ago
Is Russian the hardest language to read for someone that doesn't know Russian?
C type brackets and semicolons are second nature to a lot of people.
Perl has a lot of built-in stuff that makes a lot of sense when you have learned it.
Your example in Perl 5:
print qw/A B C/[-1];
I instantly know that qw has to do with a list of words, and the qw// can be replaced with qw(), qw[], qw##, etc to make the code the most readable to you.
Can be written like this if you like the commas and quotation marks:
print qw/'A', 'B', 'C'/[-1]; #Will warn
print(('A', 'B', 'C')[-1]);
'say' instead of 'print' adds a newline:
say qw/A B C/[-1];
Print the three first elements:
print qw/A B C D/[0..2];
Assign elements to variables:
my ($a, $b, $c) = qw/A B C/;
Print the number of elements and assign it to a variable at the same time:
print my $num =()= qw/A B C/;
You CAN very easily write "boring" readable Perl if you want to. But the power is there when needed. One letter variables, insane uncommented regexes, removing all whitespace etc is generally not how modern Perl programmers code.
Take a look at some code in Python that is done by someone less disciplined (or intentionally obfuscated). It is as unreadable (or worse) as the obfuscated C and Perl from the late 90s.
- sametmax 10y agoOf course you can get used to anything. But even if you get use to run, walking is always easier. Using so much context to convey meaning implying a lot of processing even if you are train for it, so you have an additional load. Using so many symbols to convey meaning as well. By design, Perl is harder to read if you write it the way it's intended to be used. Just like Russian is harder to read than english because the language has some concept like letter effecting other letters than implies you brain need to backtrack. Eventually, if you become a master at it, you won't feel it. But you can only master so many things in life. Most of the stuff, at best, we become very good at it. But very good means you still use your brain CPU. There is no way around it. That's why language design is important, and to me, Perl failed this big time. It's not just about habit either. Take Erlang for example. It is a very different language. It's hard to reason about. But it's not very hard to parse in your head because it's quite consistent and regular in the way it unfolds. Erlang has other issues of course and I wouldn't recommand it over Perl for non highly // related tasks. But yes, Perl has been written to be clever. This is not a quality in language design. Handy yes. Intelligent yes. Clever, not so much.
- vgy7ujm 10y ago"Using so many symbols to convey meaning as well." Actually as a visually oriented person I find it very helpful. And logical: $ - a single thing @ - a list of things % - a hash (associative array, key-value pair list) \ - a reference to any of the above my @fruits = qw/Apple Pear/; my $company = $fruits[0]; # A reference can be declared directly, this is a \% # with a nested \@. Encodes nicely to JSON as an example. my $hash_ref = { fruits => [ 'Apple', 'Pear' ] }; my $apple = $hash_ref->{fruits}[0]; "By design, Perl is harder to read if you write it the way it's intended to be used." What way is it intended to be used? Perl 4 style mixing Perl and shell script? Perl 5 has had (roughly) yearly releases since 1994 and is now at 5.24. Quite a bit has changed in that time and the language has evolved and improved. There are modern non blocking web frameworks, great database support, several modern OO systems etc. And Perl still works great shell script style (you can choose to code in a clean style) and for the most parts there is great backwards compatibility. Perl is definitively about getting the job done. Hence the slogans "make easy things easy and hard things possible" and "there is more than one way to do it". For someone well versed in Perl something like idiomatic Python becomes a prison where it is hard to get the job done because you can't freely express yourself. I think it's not just philosophy or language design but people are wired differently. And Perl is a lot of fun for creative individuals. Lastly, I am looking forward to the next years when the Python community has to clean up because of its current popularity with novice programmers. That's what Perl has been through and that old novice code is also where most of the undeserved reputation come from.