3 ms·
>>Perl's syntax is a bit off-putting. Not sure which parts of Perl syntax you find off putting, but I could guess. 1. Sigils: Why is this bad? Perl has symbol
by kamaal 4y ago
>>Perl's syntax is a bit off-putting.
Not sure which parts of Perl syntax you find off putting, but I could guess.
1. Sigils: Why is this bad? Perl has symbols do represent lists(@), associative arrays(%), scalars($). This is actually more readable than Python's approach where there is no symbol to indicate things. The only place where symbol pollution gets out of hand is where you need nested structures. But even there having explicit indication of what's what is better than leaving programmer guessing. Note how this is a program design problem, than a problem with the language itself. To me the only time I deal with this when I'm parsing XMLs and JSONs. Nothing much can be done there because XMLs and JSONs themselves are nested structures.
2. Regular expressions: How else would you represent regular expressions? Do you want Java style
string.matchAtStart('x')
.matchAtEnd('.')
.dontMatchImmediatelyStart(...)
.noAlphaNumericChars(...)
.exceptChars(...)
...
...
See how verbose this gets and very hard to read, it's really the equivalent attempting to do math in words than symbols.
3. References: There are places where you are better of passing a reference to some data, than passing the data itself, for obvious performance and efficiency reasons.
4. Quote words, expressions: Very useful for rapid scripting, and adding data without having it to massage it to a program's syntax.
5. Text utilities: Like chomp, tr, grep. Make it very easy for Unixy work. Why are these even issues?
Perl also contains your regular list manipulation utilities, and OO features. Overall very useful. Not sure where this 'hard to read syntax' thing comes from.
>>However, learning simpler Unix tools - i.e. grep, sed and awk - is worth the trouble, as those are very useful tools for command line tasks, and work with pipes.
There are lots of limitation with those tools, you can't do work with several files. You don't get error handling. You are stuck with a paradigm of working on line/block at a time. You can't do other stuff like make Rest API calls. You can't do XML/JSON stuff, the list goes endless because they are not by definition regular programming languages. In fact Perl exists to address these limitations.
>>However, using Python's re module for regular expression matching results in far more readable code than any of the predecessors, particularly as expressions get more complex.
No Python got famous, because its users never worked with messy early internet work. Like having to deal with multiple data formats, log files, API responses, database work with no standard data exchange formats. Perl lost a lot of its utility when JSON and XMLs became ubiquitous.
And yeah Python was never big in Unix world either. Its main use was for developing web apps(Django, Twisted Matrix etc).
For that even today Python is bad at anything which has non trivial data work.
- apple4ever 4y ago> See how verbose this gets and very hard to read No I think its easier to read. But I prefer verbosity over cleverness.
- darrenf 4y agoI'm a Perl coder of almost 30 years standing and I find the defence of its readability a bit of a stretch, tbh. Even though I don't personally struggle with it, I've worked with enough very good software engineers who have been able to eloquently describe the problems they have grasping the sigils that I can't discard their opinions, and in good conscience support the argument it's objectively more readable. It might suit the way some people's brains work - mine included! - but that doesn't extend to everyone. And that's OK. I don't feel compelled to defend it. I'm happy doing Perl, they're happy doing their stuff. Whatever :)
- kamaal 4y agoIt could entirely in someone's mind. People use brackets like {{{ }}} in C based languages all the time, when they have to deal with ((( ))) in Lisp suddenly they become unreadable. The thing is people want to spend little effort to learn something new, even if it can help them. Programming in the modern context is reduced to familiarity of syntax, and a small set of easily learnable and usable patterns. Problems related to bad programming, programming practices, bad program design, syntax bloat etc etc. Today exist with Python too. Python 3.x series is really how we do Perl stuff the Python way.
- apple4ever 4y agoBrackets are different than a bunch of different operators.
- photochemsyn 4y agoJust in terms of readability, not functionality, sometimes "attempting to do math in words than symbols" is not such a bad idea. Also, explicit comments within regular expressions are nice (I notice Perl has this capability too, but perhaps not used as much as it could be)? Such as: a = re.compile(r"""\d + # the integral part \. # the decimal point \d \* # some fractional digits""", re.VERBOSE) Also, the Python re basic functions - match, search, fullmatch, finditer - return match objects which are not so bad to process, and the other functions - findall, split, sub, subn - are well-documented and easy to interpret. The pattern being used is also clearly separate from the functions that use it, making it easier to understand. In contrast, Perl regex tutorials are a bit more complex... such as: https://perldoc.perl.org/perlre https://perldoc.perl.org/perlre Basically, it seems you can get the same functionality with Python but with a less steep learning curve, and it's easier to read and maintain than Perl.