Quote:
Code:
>>> '{var}'.format(var='value') |
Quote:
Code:
foo="bar"; echo "foo=$foo" Simple. The goal of Perl was to attract users of 'sed', 'awk', 'sh', and the goal of Python apparently was to be different from Perl. |
This is all nonsense. :)
The languages are different, as are their respective designers. Perl shows its original influences as an extension of Awk, designed to excel at solving file- and text-manipulation problems. Python, despite its odd indentation-driven syntax, is much more LISP-like. These are both: tools for a job. Your job. Therefore, it would behoove you to learn a great deal about both languages (as well as others). Each programming language or tool has a certain mind-set that it champions: a certain class of problems that it solves well, and a certain methodology for solving such problems. Today, each language also is accompanied by a large and rich tool-set of contributed software, which in many pragmatic ways are more-important than the core language itself. So, the middle word in the question should not be "Or." It should be, "And." A carpenter never chooses between a hammer "or" a chisel, but selects the most-appropriate tool for the task at hand, and allocates a certain amount of his professional-development time learning about more tools. |
Quote:
|
[QUOTE=sundialsvcs;4898709]... Python, despite its odd indentation-driven syntax, is much more LISP-like. .../QUOTE]
I'd say it's quite the opposite, especially for the earlier Python versions. But both Perl and Python are influenced by LISP. |
Quote:
|
Quote:
|
Quote:
Your argument is silly, since both languages have similar set of features and they can do similar things. They have different syntax for various things but on functional level they do the same. And some of the differences are a matter of taste. Like I've said for instance, I don't like having to typo $, @ and % since I have to reach my fingers far away from home row. I also don't like Perl object model, and I'm sorry, but if you tell my that it's better then Python's than you are crazy. And string formatting thing? "string: $s, number: $n, float: $f" is very hard to internationalize whereas "string: %(string)s, number: %(number)d, float: %(float)f" is very easy to internationalize. |
Quote:
Quote:
Quote:
By the way, I suggest to read the whole article - quite an interesting review of a number of programming languages. So, since you dislike Perl object model which in fact is the one of Python, your defending Python looks silly :). Quote:
If you want a practical example, translate this: Code:
sergei@amdam2:~/junk/closures_demo> cat -n main.pl Pay attention that you can not by mistake or intentionally change variables (e.g. $_lame_replacement_of_warn ) at top level of 'car_creator.prl' from 'main.pl'. |
philosophy of Perl == write less code
philosophy of Python == write readable code |
Personally, I use Perl and Python (and... and...) pretty much interchangeably in my line of work, so I honestly don't think too much about them and certainly don't try to debate philosophies or to suggest that one is "better than" another. It also simply isn't the point of "what can one do that the other cannot."
There are various articles such as http://www.norvig.com/python-lisp.html and http://openbookproject.net/py4fun/lisp/lisp.html which are much better than I am at discussing the etymology of the various programming languages (and, mind you, they definitely do each have one). In my view, you can definitely see a Lisp influence in Python, with its use of tail-recursion, S-expressions and a bunch of other funky ideas. Not so much in Perl, which was inspired by Awk. There are always multiple "levels of :jawa:" in every programming language. There's a friendly, approachable front-room that you can spend a lot of time in, perhaps an entire career in. But, over there in the corner, not drawing attention to itself in any particular way, there is a little Door. If you choose to open that door, a strange and intoxicating odor will waft out. You can follow it, exploring the first Hall of Mysteries. At the far end of that room, also not drawing attention to itself, is another little Door ... You will generally not find the differences between various languages in that friendly, approachable front room. Every programming language, without exception, started in the mind of some person (or, eecch! committee) who had a problem to solve and who envisioned an "–er" tool to solve that problem and others like it. Then, a whole bunch of other people whacked on it over the years, and wrote a lot of code in it which paid for their research-grants and salaries. And, so it goes. |
Quote:
"philosophy of Python == write readable code" - OK, write a regular expression in Perl and Python, and let's compare readability. |
Quote:
- it can't start catching up with Python - because Python finally started catching up with Perl since Python 3. If you want a practical example, translate this: Quote:
I can also agree that it would be nice if Python had full-blown lambda where you can put any amount of code, but I really don't see the argument of not polluting namespaces here. And frankly, I find equivalent Python code more readable (mostly because Python has sane syntax for objects): Code:
$ cat main.py Quote:
UPDATE: In case you'll try to pursue your namespace pollution argument: Code:
$ cat main.py |
Quote:
"Yes, I agree that Python's lack of variable declaration (which can be enforced in Perl by using warnings) is a big flaw." - I think you are missing the point. I said that from 'main.pl you can not change variables in 'car_creator.prl' - by construction of the language. I.e. the variables in question are invisible. In your translation you completely missed the point. My 'main.pl' imports (using Perl 'require' statement) another file: 'car_creator.prl'. Even though I myself wrote both file the point is that in real life such files are written by different developers, and protection from unauthorized use of resources is important - you know, all that private/protected stuff ? So, if you want to understand what Python can't do while Perl can, try to translate my code preserving separation into two files, and preserving functionality of the files. By the way, pay attention that I have not used Perl OO model at all. And closures which I'm using exist for a reason - closures are a classical mecahnism to implement state. Also, I export only methods through $self, while you, if I understand correctly, in stuff like self._color export data. I.e. if my understanding is correct, you do not have data encapsulation while I have it. If you can't adequately (i.e. using equivalent mechanisms) translate what I've written, you have a vivid example of what can be done in Perl, but not in Python. Not polluting namespaces means less mess when several developers work on a project - they do not have to agree on names. Perl is a production language. |
Quote:
Quote:
Quote:
Quote:
|
All times are GMT -5. The time now is 02:44 PM. |