News for hackers. Stuff that matters.
[dead]
Re:Python is the new BASIC by protomyth on Friday July 31, 2015 @10:00AM (#9981780)
This is the one lesson of PHP that seems to be ignored by a lot (most?) new languages. If you want your language to be popular with beginning web programmers, then provide system administrators with a dead simple way to install it. Add package, done. Then make sure it doesn't cause too much trouble or at least upgrades easily.

If it takes almost no effort to install your language and any modules that users might need, then the system administrator will just add it to the list of things to install. PHP is everywhere because its very easy.

Re:Python is the new BASIC by tacone on Friday July 31, 2015 @10:15AM (#9981859)
Actually is not just about easiness, rather than safeness.

PHP historically did not come with a disposable webserver, and writing one was hard. All the focus was on stateless applications. So while the smart guys were dealing with the memory leaks of their wonderful engineered systems, PHP monkeys were able to get things done with almost no fear to bring down the server.

I remember reading that Aaron Swartz used to go to bed with his laptop in order to be able to quickly restore Reddit in the case it crashed during the night. [Citation needed]

For hosting companies of the time, the choice of the language was pretty obvious. Most of them have policies of automatically killing long-running processes even nowadays.

Re:Python is the new BASIC by mtberatwork on Friday July 31, 2015 @10:15AM (#9981855)
It's really only "easy" if you are using mod_php. If you are using PHP-FPM, FastCGI, etc, as most people do who run production PHP, then things get about as complicated as using uWSGI, mod_wsgi, etc with Python.

On that note though, getting mod_wsgi up and running with Apache is really quite simple.

Re:Python is the new BASIC by bite_victim on Friday July 31, 2015 @10:38AM (#9982019)
You are absolutely right, strictly speaking it is the same thing. Getting a simple 'Hello World!' from the server though is a different thing but it is by no fault of Apache, Python is just not PHP when it comes to web development in the sense that you need this:

  def wsgi_app(environ, start_response):
      output = 'Hello World!'
      status = '200 OK'
      headers = [('Content-type', 'text/plain'),
                ('Content-Length', str(len(output)))]
      start_response(status, headers)
      yield output

  # mod_wsgi need the *application* variable to serve our small app
  application = wsgi_app
Instead of this:

  <?php

  echo 'Hello World!';
Re:Python is the new BASIC by codygman on Friday July 31, 2015 @11:23AM (#9982314)
Using a framework built on top of wsgi such as flask you do get that though.
Re:Python is the new BASIC by marcosdumay on Friday July 31, 2015 @10:57AM (#9982136)
Getting mod_wsgi to run is really easy.

Adapting your wsgi script for "what? is it in a virtual env? Where? What version of Python is running on this server?" and other similar problems is not so easy.

But yes, it's a matter of an hour or two for a complete newby to complete it. It completely disappears when compared to the time it takes to develop the site, but lots and lots of people consider it the most important aspect of a platform, because it comes first.

Re:Python is the new BASIC by lectrick on Friday July 31, 2015 @10:02AM (#9981789)
The fact that PHP is hated by anyone who learned PHP and moved onto other, ostensibly better things is the reason why all the hate exists.

Given any programming task, you're just going to end up with better code in pretty much any other language, especially a functional one.

Re:Python is the new BASIC by imakesnowflakes on Friday July 31, 2015 @01:23PM (#9982961)
As someone who has worked with php over 9 years, I can confirm this. I think beginners should not be, under any circumstances, suggested to start with PHP.

I shudder when thinking about the damage that showing == vs === stuff (PHP's type coercion rules, in general) to someone new to programming! It is such a waste to force someone new to learn a bunch of edge cases and weird behaviors and an endless list of php lol's that literally have zero value outside the context of PHP.

Re:Python is the new BASIC by bite_victim on Friday July 31, 2015 @10:13AM (#9981840)
> Given any programming task, you're just going to end up with better code in pretty much any other language, especially a functional one.

This is the exact bull* that good hearted Haskell and Lisp guys have to face and fix because of arrogant people like you.

First of all, a good PHP programmer is a good programmer. End of story. You can write crystal clear code in PHP that anyone who started with C (how many I wonder?) or a C inspired language can read. Spreading information and knowledge IS FAR MORE IMPORTANT than debating the language.

Let me ask you a question, did you just happen to read that post that was recently on the front page of HN? The one that showed how much awesome is Lisp comparing to Python? How Python's creator seems to hate Lisp (functional programming)? Did you read it and got to the conclusion that since (perhaps) you are using a functional language then you are entitled to spew crap like that since you are the holder of truth?

Congratulation! PHP is worse than a functional language (you can write functional code in Python and PHP btw) and you are the winning lord of programming languages debates!

Re:Python is the new BASIC by dang on Friday July 31, 2015 @03:47PM (#9983937)
> because of arrogant people like you

> you are entitled to spew crap like that since you are the holder of truth?

We ban users who address other users repeatedly like this, so please don't do it again on HN. Comments here must be civil and substantive.

https://news.ycombinator.com/newsguidelines.html

Re:Python is the new BASIC by bite_victim on Friday July 31, 2015 @04:03PM (#9984066)
Of course HN will always be biased towards followers of the hive. Don't worry, I won't be coming back. ;)
Re:Python is the new BASIC by imakesnowflakes on Friday July 31, 2015 @01:49PM (#9983152)
> This is the exact bull* that good hearted Haskell and Lisp guys have to face and fix because of arrogant people like you.

No. It is not. It takes a lot more effort to produce the code of same quality in php. For one thin, you have to consider that one has to keep and endless list of gotchas and edge cases (yes, all languages have these, but the list is nowhere near as long as it is in php) in mind when writing any amount of php code.

>You can write crystal clear code in PHP that anyone who started with C..

tell me, what does this code do, in php?

$a = array('1' => 'one');

What is the value of $a after this statement?

Answer: It appears that it is creating a dictionary with a string key that maps to another string value, but instead it creates a numerically indexed array with value 'one' stored at numeric index 1.

Do you call this 'Crystal clear'?

PHP is a language that breaks the principle of least surprise at every turn. Please don't say you can write crystal clear code in it, if you are actually interested in spreading information and knowledge, as you put it.

Re:Python is the new BASIC by bite_victim on Friday July 31, 2015 @03:59PM (#9984030)
Isn't the word 'array' quite obvious that it will create an array? Since PHP 5.4 you actually have the shorthand "[]" version available but it is still obvious to anyone who is using PHP or JavaScript (though JS arrays aren't hash maps like PHP's -- you need an object for that).

But I agree, it's crystal clear for anyone with a minor PHP knowledge. For the rest it's just "clear". (It will still work calling $a['1'] with the quotes so what exactly is the issue? If you mean the drawbacks of type coercion not sure if this example is the best one.)

Re:Python is the new BASIC by imakesnowflakes on Friday July 31, 2015 @05:11PM (#9984521)
>It will still work calling $a['1'] with the quotes so what exactly is the issue?

Oh yea. Try this.

    $a = array ('1' => 'one');

    foreach ($a as $k=>$v) {

    if ($a === '1') {

      echo "found one";

    }

    }
Surprise! Never prints "found one".

THAT is the issue! I used '===' so I should be safe from type coercion issues, right? Well, a hidden rule in php says no.

See this bug..oops feature, when it bit even experienced php programmers here

https://www.reddit.com/r/PHP/comments/2zhg6z/how_true_is_thi...

See that post and the comment from the user e-tron. Both of them who are experienced php programmers

Re:Python is the new BASIC by codygman on Friday July 31, 2015 @07:11PM (#9985054)
from that post:

> Bad idea? Sure. But once you know the enemy you can deal with it

Why surround yourself with more enemies than those that inherently exist in your business logic/problem domain? The problem with PHP is all of those "no big deal tiny issues" add up to something reminiscent of death by 1000 papercuts.

Re:Python is the new BASIC by imakesnowflakes on Friday July 31, 2015 @07:38PM (#9985141)
A correction. it is

    if ($k === '1') instead of if ($a === '1')..
Re:Python is the new BASIC by lectrick on Sunday August 02, 2015 @09:27AM (#9990649)
> arrogant people like you

I spent 5 years working with ASP (very similar to PHP especially in the ability to create spaghetti code). In PHP's defense, I wrote an eBay-like site in one night using it. I also know Lisp, some Haskell, BASIC, Pascal, spent 10 years (!) on Ruby, know Clojure, Erlang, JS...

I think I know my shit, I'm 43 and have been basically coding since I was 12 on a Commodore PET... And although PHP lets you get something up quick... It will always be a challenge to create a team-maintainable codebase with it.

PHP doesn't even pass its own test suite. And they do not realize why this is bad? This is the hallmark of hubris.

It's not "arrogance" you're seeing, man. It is the cold hard weight of experience building and maintaining large codebases for years in various languages.

Re:Python is the new BASIC by sigzero on Friday July 31, 2015 @09:55AM (#9981756)
PHP and CLI? Sure it has it. PHP isn't installed by default even in many of the places that Python is. I have never met a Sys Admin that uses PHP as his CLI scripting language and I would shake my head and walk away if one did.
Re:Python is the new BASIC by debaserab2 on Friday July 31, 2015 @09:59AM (#9981773)
But you find plenty who would choose bash or perl. Or do you shake your head them too?