5 ms·
I hear this argument time and time again and it's simply FUD. Bad Perl is no different to bad C++ or any other language with a flexible syntax. But it's also th
by anom9999 12y ago
I hear this argument time and time again and it's simply FUD. Bad Perl is no different to bad C++ or any other language with a flexible syntax. But it's also the same visa versa.
The problem with Perl is most times people are exposed to it, it's either from code golfing sessions were code is deliberately obfuscated; or when it's basically been used as a shell scripting language and thus often written by aging Perl hackers who don't care much for code cleanliness. And sometimes people just run away screaming because they simply don't understand all the regular expressions (but to approach Perl without an understanding of Regex is a little like trying to code Java without understanding classes then moaning about the weird surplus boilerplate code)
I'm not trying to say that Perl doesn't have it's faults. It has a great many problems. But to state that Perls syntax makes it impossible to write clean code, is just a daft flamewar argument.
- crucini 12y agoHmm. In python you have: dog.head.ears[0].hairs[123] In perl5 you have: $dog->{head}{ears}[0]{hairs}[123] I can see why some folks prefer the former.
- viraptor 12y agoIsn't that a hash? Shouldn't python version be: dog['head']['ears'][0]['hairs'][123] ?
- maratc 12y agoIn both Perl and Python, "object" is a glorified hash, and its attributes are entries in that hash. Python just allows for a deeper level of syntactic sugar.
- deleted 12y ago[deleted]
- pwr22 12y agoIn Perl a hash is any scalar value blessed into a class In modern Perl the attibutes would be accessed through accessors so the original example needs tr/{}/()/
- esaym 12y agoI can't stand the '.' syntax. Someone that doesn't know python would have no idea if those are method calls or what. And in both cases, that is terrible code. Use a class or something...goodness.
- coldtea 12y ago>I can't stand the '.' syntax. Someone that doesn't know python would have no idea if those are method calls or what. How is what someone who DOESN'T know Python would think relevant? That said, after even the smallest familiarity with the language, he sees that it's obviously not method calls unless it ends in (). Someone who doesn't know Lisp also doesn't know what (foo 4 2) or (quote foo 4 2) is.
- FreezerburnV 12y agoI'm going to disagree with you: as someone who has worked in an extensive Python codebase, based on the snippet above, I have zero clue what is actually going on. Those could just be attributes in the object, or they could be properties with arbitrarily complex code to calculate the resulting object. It could be the same object, or a freshly-allocated object, or an object that exists already. The index operator could be on a list, dictionary, or custom class with, again, arbitrarily complex code. All of that code could even be written in pure C for all I know! That single line of code could be a rats nest of a thousand lines of Python, or C, or both. And that's not even getting started with the possibility of metaprogramming or creating new classes by wrapping an existing class at runtime. Saying that the snippet is obviously not using method calls is naive. Python is too flexible and allows programmers to do too many clever things for that, all hidden under "nice" syntax. EDIT: Forgot a case for what that code could be doing: it could be accessing a module with globals.
- esaym 12y ago>How is what someone who DOESN'T know Python would think relevant? Because most of the people that complain about Perl don't know it either. I have no problem reading perl code of any kind (because I know it). Perl is a beautiful language IMHO.
- anom9999 12y agoPerl's pseudo-objects are, in my opinion, one of the weakest aspects of Perl. So I'm not going to disagree with you that many other languages do that one thing better. But it's not always appropriate to nest your objects that deeply anyway (in any language, that can quickly become a mess). In my personal opinion, I prefer C-style braces over whitespace formatted blocks. Which means I find reading function and iteration blocks much easier to read in Perl than I do in Python. I'm not saying one is "better" than the other, but just offering a counter argument for how subjective language aesthetics really is.
- collyw 12y agoJust to counter your points, having done many years of Perl, and now a Python. Perls OOP does feel like a bit of a hack. But it does make it transparent how everything works. I learned Java at University, and everything OOP was a black box and I had no real understanding of how it worked. After learning the Perl way, its really obvious what is going on because it is so transparent. Your current object doesn't have a method? Just look along the @ISA array until you find an object that does have it. Pythons whitespace is a pain at first, but having used it for a few years, one problem I do not miss is loosing a brace, when reorganizing blocks of code. You cut a few lines of code and paste it somewhere above or below, and your IDE shows you you are missing a brace somewhere. The indentation looks fine, so you can't see where it is. The whitespace thing is worth it to get rid of that problem alone.
- kbenson 12y agoAren't there just as many problems with cutting and pasting python and getting either slightly off indentation or mixed spaces/tabs? If the IDE fixes the problem, I don't see why it's any different for braces as it is for whitespace. There's easy ways to identify both.
- anom9999 12y agoExactly. Arguing that one is better than the other is like arguing over which colour the best. Which is why I get so utterly sick of Perl being compared with Python - they are all going to have their strengths and weaknesses so at the end of the day, the "better" language / syntax boils down to personal preference.
- draegtun 12y agoWell if Explicit is better than implicit then this is one example of where Perl should be the preferred!
- rtpg 12y agono snark, do you have a snippet you enjoy looking at in perl?