6 ms·
In terms of expressiveness I think Python falls closer to Java than Perl. People make fun of Perl's sigils but I think Python's magic underscores and 'self' eve
by guelo 13y ago
In terms of expressiveness I think Python falls closer to Java than Perl. People make fun of Perl's sigils but I think Python's magic underscores and 'self' everywhere are much uglier in a verbose way. And no one will ever convince me that significant-white-space and not having block enders are good ideas, it makes refactoring and copy-pasting code hazardous. And I don't understand why every language hasn't added Perl's native regex syntactical sugar, it's a huge win for many problems.
But yea, Python won.
- thirsteh 13y agoTo your last point about regexes: I think the general idea is to discourage their use, at least as a default. It is so easy to use them in Perl that they are used way too much, e.g. when you could do a regular (and faster) string search.
- DougWebb 13y agoThat's a lousy reason to not include them. Cars are used to much and people really should walk and bike and take the bus more, but we're not about to make cars more difficult to use because of that. Perl's embedding of regexes into the language syntax is a fantastic feature, as is the way captured groups can be assigned to a list. No other language comes close to making regexes usable. Javascript, which at least has a literal syntax for regex, is still awkward. And the other language I use the most, C#, has such a bad interface for getting captures that I get it wrong and have to look up the documentation EVERY SINGLE TIME I USE IT. I would compare regex as an add-on library in most languages to be as awkward as OOP as an add-on to Perl 5 was. At least Perl has corrected that; besides Javascript, have any other languages taken steps to make regexes easier to use?
- pyre 13y ago> At least Perl has corrected that Perl hasn't really corrected that. Moose is an external library (with downsides, such as load-time last I checked). When it becomes part of the core Perl language, I'll consider Perl to have corrected it.
- Renaud 13y agoBut isn't that a crime of premature optimisation? Perl's integration of Regex makes them easy to use and they fit naturally in the language, a lot more than in most implementations. Being able to use Regex easily is a plus in my book. Yes they are lower than some dedicated string search or some state machine ad-hoc implementation, but you can document Regexes and they pack a lot of punch. If a Regex is causing a concern in term of performance, then it may be time to review that code and optimise it, otherwise why even bother? When people talk about Regex being bad and they say you can often use string manipulation instead they only talk about the most trivial uses of Regex. As soon as you go beyond that, using a Regex is almost always going to be cleaner than spewing lines of codes and building state machines to achieve the same functionality.
- maxerickson 13y agoIt's more a matter of different design taste than it is an optimization. (I don't think it is controversial that Python has a relatively simple language definition/grammar/etc; regex as language syntax would expand all of that quite a bit)
- pyre 13y agoIIRC, they were not included because Guido's opinion is that Regex should be a library, not a core feature of a language.
- einhverfr 13y ago> And I don't understand why every language hasn't added Perl's native regex syntactical sugar, it's a huge win for many problems. The one language which didn't for a very good reason was Rebol. The reason is that Rebol has different syntactic sugar for recursive descent parsing.
- pyre 13y ago> People make fun of Perl [...] but I think Python's [...] are much uglier Do you really expect this to end well? There are endless flamewars raging across the Internet about the 'correct' way to place braces with both sides claiming that the other side's solution is 'uglier.' > And no one will ever convince me that significant-white-space and not having block enders are good ideas Insightful discussion doesn't usually stem from the phrase 'no one will ever convince me.' > it makes refactoring and copy-pasting code hazardous I see this bandied about a lot, but I'm curious if people actually run into this issue. I certainly haven't run into this issue, nor have I come across anyone who has had this issue. A couple of points: 1) This comes across to me sort of like the arguments against git due to the user's ability to rewrite commits (e.g. "I can't use git because you can rewrite commits; therefore when someone fixes a bug they will rewrite the commit that introduced the bug rather than patch the current state of the repo"). Arguments that are theoretical, rather than practical. Similar to the other top-level poster claiming that significant whitespace will run into issues with all of the Unicode whitespace characters. 2) When you copy-paste Perl (or C, or Java, etc) code, do you not reformat that code anyways? I shudder to think of the code base where refactoring efforts rely on copy-pasting code without any sort of a consistent style since "it's between the braces, so we're all good." 3) This seems to be an argument that runs along the lines of static-vs-dynamic typing. One side argues that static-typing is "better" because you don't have to worry about type errors cropping up at runtime, since they are resolved at compile time. You're arguing that it's 'hazardous' to copy-paste or refactor code because you could mess up the indentation, but you don't have to worry about these things 'for free' when you have more concrete start- and end-block semantics.
- chromatic 13y agoWhen you copy-paste Perl (or C, or Java, etc) code, do you not reformat that code anyways? Sure, but you don't have to worry about reformatting making code that was correct suddenly and subtly incorrect.
- pyre 13y agoWhen I use C, I don't have to worry about subtle type errors cropping up at runtime. Should we all ditch dynamic-typing for Haskell?
- mixmastamyk 13y ago> significant-white-space In my experience it's been a problem about five times in the last 10-15 years, but the conciseness pays dividends every single day.
- collyw 13y agoPerl to Python convert here. At first I hated the whitespace, but when I went back to Perl, I moved some code about and "lost" a brace. You never get the unmatched brace problem in Python.
- thetrb 13y agoGetting that message is not a bad thing as it tells you there's a problem as opposed to just silently doing something you didn't want it to do.
- collyw 13y agoYes, but its just as likely you pasted in the wrong place. Python makes you a little more disciplined when cut-pasting bits of code around.