7 ms·
I think you need to qualify that a bit - what are "way more goodies" exactly? Can you name something that Python can do that PHP can't?
by debaserab2 12y ago
I think you need to qualify that a bit - what are "way more goodies" exactly?
Can you name something that Python can do that PHP can't?
- meowface 12y agoNo, but I can name a lot of things that are way easier and cleaner to do in Python than in PHP.
- debaserab2 12y ago> No, but I can name a lot of things that are way easier and cleaner to do in Python than in PHP. Please do.
- chipotle_coyote 12y agoI can name two. First, list comprehensions. In PHP, what you might write as this: $image_urls = []; foreach ($images as $image) { $image_urls[] = 'illos/' . $image['url']; } can just be this in Python: image_urls = ['illos/' + x['url'] for x in images] And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to use PHP's strange "use ($a, $b, $c)" construct. Yes, that's a small thing, but PHP's way is a little bonkers.
- porker 12y ago> can just be this in Python: In PHP 5.3+ you can write: $image_urls = array_map(function($image) {return 'illos/'. $image['url'];}, $images); Not as concise, but I'd postulate easier to read for people not familiar with list comprehensions. In PHP 5.5+ there may be another way, but we're stuck with 5.3 in production for most clients, so I'm not up to speed. > And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to use PHP's strange "use ($a, $b, $c)" construct. Mmm, the debate of explicit or implicit scope? Explicit at least gets round those strange errors (hello Javascript) where you think you're referencing one thing... and actually referencing something else.
- deleted 12y ago[deleted]
- josai 12y agoimage_urls = images.map { |img| "illos/#{img}" } Even better :)
- chriswarbo 12y agoI'd prefer something like this: $image_urls = array_map(compose(papply('concat', 'illos/'), papply('lookup', 'url')), $images); This builds a function via composition: first lookup 'url' then prepend with 'illos/'. This function is then mapped over the array. Unfortunately relies on a bunch of functions which PHP doesn't include. Unfortunately PHP's stdlib concentrates on incredibly-single-purpose functions for, eg. string manipulation, while ignoring general programming constructs. Also, most of the really useful parts of the language aren't available as functions, for no real reason. In any case, we can define these things ourself like this: // Function composition function compose($f, $g) { return function() use ($f, $g) { return $f(call_user_func_array($g, func_get_args())); }; } // String concatenation. Unfortunately we can't write "concat = papply('implode', '')" function concat() { return implode('', func_get_args()); } // Array subscript. I'd prefer to do this the other way around and write an // argument-flipping function, but that's unnecessary for this example function lookup($x, $y) { return $y[$x]; } // Partial application function papply() { $args = func_get_args(); return function() use ($args) { return call_user_func_array('call_user_func', array_merge($args, func_get_args())); }; } Regarding lexical scope, Python has ridiculous gotchas too http://stackoverflow.com/questions/5218895/python-nested-functions-variable-scoping http://stackoverflow.com/questions/5218895/python-nested-fun... PS: I still much prefer Python to PHP, but straw men aren't going to help ;)
- deleted 12y ago[deleted]
- camus2 12y agoReal production ready servers ,complex scientific calculations, 2d, 3d games , to name a few things. PHP is not general purpose. Python is. PHP has type hinting and interfaces that makes it "java" like(it's a strength). Python doesnt have interfaces but allows type hinting through decorators. @typecheck def gimmeFloat(a:int, b:list, c:tuple=(1,2,3)) -> float: return 3.14
- jbeja 12y agoAnd who is talking here about a general purpose lenguage in this context, i only care about the web stuff i don't need things that ain't gonna use.
- ulisesrmzroche 12y agoIt's also a far more readable language, which matters more than anything in large-scale projects On the other hand, <? ?>.
- jbeja 12y agoLarge scale projects doesn't need "more redeable" languages, it needs good engeneering and type checks.
- zaraflan 12y agoThe single biggest everyday-use thing I miss with PHP is keyword arguments. With PHP the only real equivalent is passing an array of arguments and then checking if each possible key exists, and that's just way clunkier.