Why PHP programmers aren't considered real programmers

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

User avatar
Ariphaos
Jedi Council Member
Posts: 1739
Joined: 2005-10-21 02:48am
Location: Twin Cities, MN, USA
Contact:

Why PHP programmers aren't considered real programmers

Post by Ariphaos »

Code: Select all

<?php

  $arr = array ();

  for ($i = 0; $i < 100000; $i++)
    {
      $c = mt_rand (0,1);
      if (!isset ($arr[$c])) $arr[$c] = 1;
      else $arr[$c]++;
    }

  ksort ($arr);

  foreach ($arr as $key => $value)
    {
      echo '<b>'.$key.':</b> '.$value.'<br />';
    }
0: 24969
1: 75031

Half of my development time with PHP is basically rewriting things I can't trust the php team to have done properly. I think this epitomizes it.
Give fire to a man, and he will be warm for a day.
Set him on fire, and he will be warm for life.
User avatar
General Zod
Never Shuts Up
Posts: 29211
Joined: 2003-11-18 03:08pm
Location: The Clearance Rack
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by General Zod »

Can someone translate this into English?
"It's you Americans. There's something about nipples you hate. If this were Germany, we'd be romping around naked on the stage here."
User avatar
Ariphaos
Jedi Council Member
Posts: 1739
Joined: 2005-10-21 02:48am
Location: Twin Cities, MN, USA
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Ariphaos »

It's a php (the same programming language this forum software was written in) script that attempts to generate 100,000 numbers, chosen between zero and one. Or heads and tails.

It's supposed to be rather evenly distributed between them, so 0 should come up half the time, and 1 the other half. Instead, 1 is showing up three quarters of the time.

Ie, you flip a coin 100,000 times, you expect heads about half the time. Instead, php's rand() and mt_rand() functions are returning heads 75% of the time.
Give fire to a man, and he will be warm for a day.
Set him on fire, and he will be warm for life.
User avatar
Ryan Thunder
Village Idiot
Posts: 4139
Joined: 2007-09-16 07:53pm
Location: Canada

Re: Why PHP programmers aren't considered real programmers

Post by Ryan Thunder »

What exactly did they do wrong? It looks like they're using a standard method to generate the random numbers, if I've read it correctly. Then again, I'm not familiar with php, just curious.
SDN Worlds 5: Sanctum
User avatar
Ace Pace
Hardware Lover
Posts: 8456
Joined: 2002-07-07 03:04am
Location: Wasting time instead of money
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Ace Pace »

Or it could be the total lack of proper coding among large PHP code bases. Globals, lack of documentation, ugly ways of writing extensions to their programs. I hate the major PHP code bases like MediaWiki and PHPbb.
Brotherhood of the Bear | HAB | Mess | SDnet archivist |
User avatar
Ariphaos
Jedi Council Member
Posts: 1739
Joined: 2005-10-21 02:48am
Location: Twin Cities, MN, USA
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Ariphaos »

Ryan Thunder wrote:What exactly did they do wrong? It looks like they're using a standard method to generate the random numbers, if I've read it correctly. Then again, I'm not familiar with php, just curious.
There should be nothing wrong with my script above, and in most languages, there wouldn't be. PHP implements rand () and mt_rand () incorrectly, however.

PHP is littered with all sorts of these bugs, and it's quite a problem. Worse, they actively refuse to fix it. I'm sorely tempted to switch to Python, but that would mean rewriting flup. C is an option but I'd have to write my own fastcgi handler. Rather frustrating.
Give fire to a man, and he will be warm for a day.
Set him on fire, and he will be warm for life.
User avatar
Ace Pace
Hardware Lover
Posts: 8456
Joined: 2002-07-07 03:04am
Location: Wasting time instead of money
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Ace Pace »

I think Destructionator here wrote a library to deal with C/CGI issues, check it out with him.
Brotherhood of the Bear | HAB | Mess | SDnet archivist |
User avatar
Drooling Iguana
Sith Marauder
Posts: 4975
Joined: 2003-05-13 01:07am
Location: Sector ZZ9 Plural Z Alpha

Re: Why PHP programmers aren't considered real programmers

Post by Drooling Iguana »

Which version of PHP are you using? I ran that code on my system and the results are coming out fairly even. I'm running PHP version 5.2.10.
Image
"Stop! No one can survive these deadly rays!"
"These deadly rays will be your death!"
- Thor and Akton, Starcrash

"Before man reaches the moon your mail will be delivered within hours from New York to California, to England, to India or to Australia by guided missiles.... We stand on the threshold of rocket mail."
- Arthur Summerfield, US Postmaster General 1953 - 1961
User avatar
Ariphaos
Jedi Council Member
Posts: 1739
Joined: 2005-10-21 02:48am
Location: Twin Cities, MN, USA
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Ariphaos »

Drooling Iguana wrote:Which version of PHP are you using? I ran that code on my system and the results are coming out fairly even. I'm running PHP version 5.2.10.
5.2.11 (CentOS 5.3 32 bit) and 5.2.12 (Debian Squeeze 64 bit).

I would have to imagine that this isn't occurring on all platforms/configurations else it would have been caught.

I created my own RNG suite anyway that pipes from /dev/(u|f|e)random.
Give fire to a man, and he will be warm for a day.
Set him on fire, and he will be warm for life.
User avatar
Bedlam
Jedi Council Member
Posts: 1509
Joined: 2006-09-23 11:12am
Location: Edinburgh, UK

Re: Why PHP programmers aren't considered real programmers

Post by Bedlam »

Now I'm not a programer and I assume from the previous posts that there is something wrong with the underlying code, however, if this is just a single run of the 100,000 repeats there the chance of 1 and 0 could still be the same and still give a 25/75 split, its just unlikely (someone might be able to do the calculations). You would expect it to tend towards 50/50 but it could be 100/0 and still be random its just very very unlikely. I assume that multiple runs all end up with the approximatly the sam split?
User avatar
fuzzymillipede
Youngling
Posts: 96
Joined: 2005-03-17 03:05pm

Re: Why PHP programmers aren't considered real programmers

Post by fuzzymillipede »

Bedlam wrote:if this is just a single run of the 100,000 repeats there the chance of 1 and 0 could still be the same and still give a 25/75 split, its just unlikely (someone might be able to do the calculations). You would expect it to tend towards 50/50 but it could be 100/0 and still be random its just very very unlikely.
Maybe if the sample size was 10, something like that could happen. But with a sample size of 100,000, the chance of any significant deviation from a 50/50 split is practically zero. At that sample size even a 60/40 split would mean there was a problem with the RNG.
User avatar
Ariphaos
Jedi Council Member
Posts: 1739
Joined: 2005-10-21 02:48am
Location: Twin Cities, MN, USA
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Ariphaos »

Destructionator XIII wrote: Eh, not really. When I do cgi in C, I just recreate the little pieces I need as I need them. I do have some CGI stuff in the D language, but I keep hacking it up and breaking it, so that's not redistributable either. Though, FastCGI and CGI aren't the same thing anyway...
The issue is I would actually need to write it and be competitive with -and more stable than- php+APC-stat. Flup is neither stable enough nor fast enough to handle thousands of connections per second on my server.

PHP, actually, is.

There's fastcgipp, but that was designed for integration with mod_fcgid. PHP's raw fastcgi overhead is actually significantly less than the difference between Apache and nginx.
For PHP, what I find most hilarious are the people who layer shit on top of it. Ever used the Smarty template system? why God?! WHY?!
I tried to. It's ostensibly to allow end users to do semi-code level things with some level of security.

I think I'll just whitelist allowable css elements and unicode points, myself.
I've been dealing with this php shit for a client for months now. The client paid like $2000 for a license to this fucking thing - for that kind of money, you'd expect it to be decent, right? Wrong, it's PHP!
There is a vBulletin plugin to Sphinx search that costs $2k. It is only marginally more impressive than the one built for SMF. The one the phpBB team built is a joke, and who does the phpBB dev blame?

Sphinx's author.

Insane.
On the top level, the code is spaghetti, of course. Things are repeated all over the place - every single file in it has about 80 lines of the same boilerplate, only slightly different each time. (Functions? What are they for?) Every function it does have starts with a long list of globals - about 15 of them. Among them is a database class... that just wraps the built in mysql library, obfuscating the myriad sql injection holes.
What's really annoying is that mysql(i)_real_escape_string still has a major security hole, as no widely used cms's database wrapper uses prepared statements and all of the major forum softwares encourage utf8 conversion.

Which means the database's default character set may be latin1, but if the forum/cms owner got convinced to use utf8 tables, every single one of those forums is vulnerable to SQL injection via unicode code points. Because none of them know about prepared statements.

The Internet functions because smart people are not in general evil.

Seriously.
Then, there is this retarted, utterly worthless Smarty thing. All it does is duplicate the one thing PHP itself does reasonably well, but with more slowness. You add a pile of boilerplate to the PHP to use it... then the template just has more embedded PHP! And of course, repeated instances of nested tables all over.

How the fuck did something this messed up pass review? Easy - it didn't have review!

In the time I've wasted trying to work around the shit and deal with the repeated bloat, I could have just rewritten the thing from scratch myself. But noooo, we must reuse existing code!
It's faster to write code than to read it. A very important distinction that I like to remind clients of.

Fortunately, for my current major project, the only person I answer to is me.
Give fire to a man, and he will be warm for a day.
Set him on fire, and he will be warm for life.
User avatar
Zixinus
Emperor's Hand
Posts: 6663
Joined: 2007-06-19 12:48pm
Location: In Seth the Blitzspear
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Zixinus »

If I get the posts correctly, is PHP fundamentally flawed? Because that is the point that I feel gets across. How did that happen?
Credo!
Chat with me on Skype if you want to talk about writing, ideas or if you want a test-reader! PM for address.
User avatar
Chris OFarrell
Durandal's Bitch
Posts: 5724
Joined: 2002-08-02 07:57pm
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Chris OFarrell »

Its free, and it has been the mantra of a lot of geeks that Apache + PHP = Liberation...or something.
Image
User avatar
Xon
Sith Acolyte
Posts: 6206
Joined: 2002-07-16 06:12am
Location: Western Australia

Re: Why PHP programmers aren't considered real programmers

Post by Xon »

Mysql and secure? Don't make me laugh.

mysql_real_escape_string doesn't protect against against SQL injection properly with dynamic sql even ignoring unicode! Linky.

I'm not sure if I trust php & mysql todo prepared statements properly, but it is much safer than relying on known buggy sql escaping encoding in php (which they still haven't gotten right).
"Okay, I'll have the truth with a side order of clarity." ~ Dr. Daniel Jackson.
"Reality has a well-known liberal bias." ~ Stephen Colbert
"One Drive, One Partition, the One True Path" ~ ars technica forums - warrens - on hhd partitioning schemes.
User avatar
Starglider
Miles Dyson
Posts: 8709
Joined: 2007-04-05 09:44pm
Location: Isle of Dogs
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Starglider »

Zixinus wrote:If I get the posts correctly, is PHP fundamentally flawed? Because that is the point that I feel gets across. How did that happen?
Quite a lot of programming languages are someone's personal crappy scripting language that somehow escaped and gained popularity. These are kludged together with no real understanding of language, compiler or library design, and they universally suck. Perl is in this category despite massive efforts put in for over a decade to try and make it into a real language (why anyone would want to, I don't know).

These languages are attractive only because they seem simple and easy to pick up. In actual fact, all the 'counterintuitive' and complex features in other languages are generally there for a reason. Furthermore there are now plenty of properly designed languages that target simplicity and beginners, so really there is no excuse for using junk like PHP except having to maintain legacy code.
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Re: Why PHP programmers aren't considered real programmers

Post by phongn »

Destructionator XIII wrote:PHP was (and is) created by morons for morons. Fundamental technical flaws are the least of its problems. Greater is that the idiots around it don't see them as flaws.
Perhaps one of the few good things about PHP is that it does scale very well (as mentioned earlier) - but that is in spite of its many problems.
Chris OFarrell wrote:Its free, and it has been the mantra of a lot of geeks that Apache + PHP = Liberation...or something.
PHP was early, free, cross-platform and relatively easy to understand. There were not many alternatives when it was created (CGI scripts and Perl come to mind). Nowadays there are many alternatives - but PHP lets you get your feet wet early and is deceptively simple.
Xon wrote:Mysql and secure? Don't make me laugh.

mysql_real_escape_string doesn't protect against against SQL injection properly with dynamic sql even ignoring unicode! Linky.
IIRC, most security sites specifically advice users not to use *escape_string for sanitizing. Also, MySQL is terrible - too bad Postgres made some bad decisions back in the day and let MySQL take the market.
Starglider wrote:Quite a lot of programming languages are someone's personal crappy scripting language that somehow escaped and gained popularity. These are kludged together with no real understanding of language, compiler or library design, and they universally suck. Perl is in this category despite massive efforts put in for over a decade to try and make it into a real language (why anyone would want to, I don't know).
Perl came early with the right features and the right price at the right time. Plus, there was strong demand for something to do string parsing and munging. Of course, now there's so much legacy code and so many Perl gurus they want "sane" Perl.
These languages are attractive only because they seem simple and easy to pick up. In actual fact, all the 'counterintuitive' and complex features in other languages are generally there for a reason. Furthermore there are now plenty of properly designed languages that target simplicity and beginners, so really there is no excuse for using junk like PHP except having to maintain legacy code.
Yeah, but it's popular, free and cross-platform so new people see it and dive right in.
User avatar
Terralthra
Requiescat in Pace
Posts: 4741
Joined: 2007-10-05 09:55pm
Location: San Francisco, California, United States

Re: Why PHP programmers aren't considered real programmers

Post by Terralthra »

Xeriar wrote:Half of my development time with PHP is basically rewriting things I can't trust the php team to have done properly. I think this epitomizes it.
Incidentally, when you write things like

Code: Select all

 $arr = array ();

  for ($i = 0; $i < 100000; $i++)
    {
      $c = mt_rand (0,1);
      if (!isset ($arr[$c])) $arr[$c] = 1;
      else $arr[$c]++;
    }

  ksort ($arr);

  foreach ($arr as $key => $value)
    {
      echo '<b>'.$key.':</b> '.$value.'<br />';
    }
when you could write

Code: Select all

  $arr = array (0,0);
  for($i = 0 ; $i < 100000 ; $i++) {
    $arr[mt_rand(0, 1)]++;
  }
  foreach($arr as $k => $v) {
    echo '<b>'.$k.':</b> '.$v.'<br />';  
  }  
you lose the right to complain about poorly-written code.
User avatar
Ariphaos
Jedi Council Member
Posts: 1739
Joined: 2005-10-21 02:48am
Location: Twin Cities, MN, USA
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Ariphaos »

I can only have so much respect for people who equate poor optimization (especially for a pruned test case) with an actual failure of implementation.

Anyway.
Starglider wrote:Quite a lot of programming languages are someone's personal crappy scripting language that somehow escaped and gained popularity. These are kludged together with no real understanding of language, compiler or library design, and they universally suck. Perl is in this category despite massive efforts put in for over a decade to try and make it into a real language (why anyone would want to, I don't know).

These languages are attractive only because they seem simple and easy to pick up. In actual fact, all the 'counterintuitive' and complex features in other languages are generally there for a reason. Furthermore there are now plenty of properly designed languages that target simplicity and beginners, so really there is no excuse for using junk like PHP except having to maintain legacy code.
PHP gets out of the way. Far too early, but it has an installed base of pretty much Everywhere, and is getting slowly whipped into shape. It might take a fork to get a proper implementation, however.
phongn wrote:Perhaps one of the few good things about PHP is that it does scale very well (as mentioned earlier) - but that is in spite of its many problems.
I suspect the concept is actually related. Because so much php code is hacked together, quite a lot of the most important parts (getting information from the database to the server) gets tweaked for speed. And occasionally they notice about security.
Yeah, but it's popular, free and cross-platform so new people see it and dive right in.
php.net's documentation is currently king. Pretty much the sole reason. Problem with anything? Look it up.
Give fire to a man, and he will be warm for a day.
Set him on fire, and he will be warm for life.
User avatar
Terralthra
Requiescat in Pace
Posts: 4741
Joined: 2007-10-05 09:55pm
Location: San Francisco, California, United States

Re: Why PHP programmers aren't considered real programmers

Post by Terralthra »

Xeriar wrote:I can only have so much respect for people who equate poor optimization (especially for a pruned test case) with an actual failure of implementation.
It's not "poorly optimized," it's "badly written." It has extra control structures for no conceivable reason, which make it hard to read and understand, pointlessly. If you really, for some reason, didn't want to initialize the array when you declared it (I am guessing you started with a much larger array, due to the pointless ksort, and pruned it down to 0/1? Filling with 0 manually in that case would be tedious), $arr.fill(0) works just fine.
Xeriar wrote:
Yeah, but it's popular, free and cross-platform so new people see it and dive right in.
php.net's documentation is currently king. Pretty much the sole reason. Problem with anything? Look it up.
The fact that you have to read through the comments section with various posts of questionable expertise and veracity to answer most questions and read about known issues somewhat negates this.
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Re: Why PHP programmers aren't considered real programmers

Post by phongn »

Xeriar wrote:
Yeah, but it's popular, free and cross-platform so new people see it and dive right in.
php.net's documentation is currently king. Pretty much the sole reason. Problem with anything? Look it up.
PHP.net's documentation is not "good".
User avatar
Terralthra
Requiescat in Pace
Posts: 4741
Joined: 2007-10-05 09:55pm
Location: San Francisco, California, United States

Re: Why PHP programmers aren't considered real programmers

Post by Terralthra »

Destructionator XIII wrote:FUCK MY KEYBOARD WITH A BACK BUTTON NEXT TO THE SHIFT KEY

FUCK FUCK FUCK
Terralthra wrote:It's not "poorly optimized," it's "badly written." It has extra control structures for no conceivable reason, which make it hard to read and understand, pointlessly. If you really, for some reason, didn't want to initialize the array when you declared it (I am guessing you started with a much larger array, due to the pointless ksort, and pruned it down to 0/1? Filling with 0 manually in that case would be tedious),
Think for a minute. His code is easily altered. If he wants to change the range of the random numbers generated, it is a one line change - the mt_rand arguments. He can punch in any values and it will just work.

Not so with any of your suggestions. Changing it from 0-5, for example, requires two lines changed: the mt_rand and the array constructor.

Moreover, your suggestion is needlessly wasteful of memory and performance, initializing an (associative) array that is never used.

Consider 10-20. In his code, change mt_rand and boom. On your code, what will you do? Construct a 20 element array and waste half the memory? Make it 10 elements and subtract 10 from the returned value? Lol.

Or, the most likely case: mt_rand() with no arguments, goes between 0 and RAND_MAX which is something like 2^31. Do you suggest that he allocate 2 GB * sizeof(php arr element) of memory up front?

Fucking lol, especially with only 100,000 iterations. Less than 1/1000 of that memory will ever even be used - it is sparsely and randomly populated. The very definition of where a lazy AA is meant to be used.


For the simple 0 and 1 case, your code is a bit nicer (saves two lines! woooo!) but for almost any other conceivable case, his code is vastly superior.


The real incompetence here is you throwing out the initial ad hominem (yeah, dismissing someone's points because of a "failing" in personal style is really logical. oh wait, it's a textbook fallacy) and then having your own defense of it lead the way to knocking you right on your ass, but you fail to see it! And you make the sweeping "inconceivable" claim.

Christ.

Finally, does php even have an arr.fill() function? I didn't think it did.
Not only does it have a fill function, it completely obviates your complaint, since the fill function can take as additional arguments the range of values you wish to fill. Want to do 10 - 20? $arr.fill(10, 20, 0). So, not only did the function you didn't think existed exist, it also does what you didn't think it could do.

If you think you could adequately test an RNG across a spread orders of magnitude greater than the number of iterations, I don't know where you learned statistics. A sparsely populated RNG test array would be meaningless. If mt_rand were between 0 and 2^31, he would doubtless have incredibly more iterations in order to have any meaningful results. And yes, said program would be a memory hog, either way.

His code is also harder to read. That is not a trivial complaint. That it has "more lines" is not the key point. It has extra control structures; moreover, these control structures do not actually reflect the logic of the code. This is bad on two levels. If he really wanted to be sure that "he only had to change it in one place" in order to run a different test case, he could put in defined constants and use them in both places. Note that this would be more lines, but more easily read yet.
User avatar
Ariphaos
Jedi Council Member
Posts: 1739
Joined: 2005-10-21 02:48am
Location: Twin Cities, MN, USA
Contact:

Re: Why PHP programmers aren't considered real programmers

Post by Ariphaos »

Terralthra wrote: It's not "poorly optimized," it's "badly written." It has extra control structures for no conceivable reason, which make it hard to read and understand, pointlessly. If you really, for some reason, didn't want to initialize the array when you declared it (I am guessing you started with a much larger array, due to the pointless ksort, and pruned it down to 0/1? Filling with 0 manually in that case would be tedious), $arr.fill(0) works just fine.
The original code was testing a function that generated random strings of various lengths and levels of randomness, where certain characters are forbidden (cookie storage), and I was doing various tests on that. I didn't rethink it after adjusting the test case, it being a test case.

After I posted the code I realized it sucked and was wondering how long it would take for someone to bitch about it. It seems most people here are perfectly fine with assuming something completely different is going on from what is presented.
Terralthra wrote:The fact that you have to read through the comments section with various posts of questionable expertise and veracity to answer most questions and read about known issues somewhat negates this.
It makes it of disputable quality, yes, but I was referring to its accessibility.
Give fire to a man, and he will be warm for a day.
Set him on fire, and he will be warm for life.
User avatar
Jeremy
Jedi Master
Posts: 1132
Joined: 2003-04-30 06:47pm
Location: Hyrule

Re: Why PHP programmers aren't considered real programmers

Post by Jeremy »

Approximately, how long would it take for me to read enough and have enough hands on experience to know how to do any of this?

The most advanced "code" I knew was how to set the background color in HTML and I don't really remember that right now. To the point, I have to take a COP 2220 course in the summer, what do I need to learn before putting my ignorant butt into it?
• Only the dead have seen the end of war.
• "The only really bright side to come out of all this has to be Dino-rides in Hell." ~ Ilya Muromets
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Re: Why PHP programmers aren't considered real programmers

Post by phongn »

Jeremy wrote:Approximately, how long would it take for me to read enough and have enough hands on experience to know how to do any of this?
Why not try it?
The most advanced "code" I knew was how to set the background color in HTML and I don't really remember that right now. To the point, I have to take a COP 2220 course in the summer, what do I need to learn before putting my ignorant butt into it?
COP 2220 looks like a basic introductory course: you should know how to use a computer.
Post Reply