Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Yeah Windows rand() is loving worthless. Found that out when trying to reimplement the deals in FreeCell. It's got some ridiculously low period.

Adbot
ADBOT LOVES YOU

Captain Capacitor
Jan 21, 2008

The code you say?

McGlockenshire posted:

Perl, Ruby and Python all expose the same flawed rand by default, as does, say, C. This has been a known problem for decades.

Don't use rand for anything other than trivial matters.

Doesn't Python use Mersenne? Or am I misinterpreting the flaw in that one too.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Since PHP doesn't already get enough hate, eevee has published the ultimate anti-PHP rant. Look at that thing go.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Captain Capacitor posted:

Doesn't Python use Mersenne? Or am I misinterpreting the flaw in that one too.

Honestly, I last checked over seven years ago when I wrote my last rant about rand.

Everyone has Mersenne implementations available regardless, no excuse to use anything other for non-crypto randomness.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
bahahahahahaha

quote:

Unlike (literally!) every other language with a similar operator, ?: is left associative [in PHP]. So this:
code:
$arg = 'T';
$vehicle = ( ( $arg == 'B' ) ? 'bus' :
             ( $arg == 'A' ) ? 'airplane' :
             ( $arg == 'T' ) ? 'train' :
             ( $arg == 'C' ) ? 'car' :
             ( $arg == 'H' ) ? 'horse' :
             'feet' );
echo $vehicle;
prints horse.

edit:

quote:

function foo() { return new __stdClass(); } leaks memory. The garbage collector can only collect garbage that has a name.

edit:

quote:

php_uname tells you about the current OS. Unless PHP can’t tell what it’s running on; then it tells you about the OS it was built on. It doesn’t tell you if this has happened.

edit:

quote:

PHP’s parser fails if there’s a NUL in a file anywhere

quote:

Declaring a function named __lambda_func will break create_function—the actual implementation is to eval-create the function named __lambda_func, then internally rename it to the broken name. If __lambda_func already exists, the first part will throw a fatal error.

pokeyman fucked around with this message at 06:28 on Apr 10, 2012

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Suspicious Dish posted:

Since PHP doesn't already get enough hate, eevee has published the ultimate anti-PHP rant. Look at that thing go.

That is a magnum opus.

Captain Capacitor
Jan 21, 2008

The code you say?

McGlockenshire posted:

Honestly, I last checked over seven years ago when I wrote my last rant about rand.

Everyone has Mersenne implementations available regardless, no excuse to use anything other for non-crypto randomness.

I gave a quick read through that rand article and Python (and Perl, I think) use Mersenne Twister, and PHP has one using the mt_rand function.

Look Around You
Jan 19, 2009

Suspicious Dish posted:

Since PHP doesn't already get enough hate, eevee has published the ultimate anti-PHP rant. Look at that thing go.

This is the best thing ever.

raminasi
Jan 25, 2005

a last drink with no ice

Suspicious Dish posted:

Since PHP doesn't already get enough hate, eevee has published the ultimate anti-PHP rant. Look at that thing go.

quote:

function foo() { return new __stdClass(); } leaks memory. The garbage collector can only collect garbage that has a name.

:stare:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
That huge list had me laughing out loud. Some of it, like not collecting "unnamed" garbage, is just nonsensical. It's self-parody.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

pokeyman posted:

That huge list had me laughing out loud. Some of it, like not collecting "unnamed" garbage, is just nonsensical. It's self-parody.

quote:

=== compares values and type… except with objects, where === is only true if both operands are actually the same object! For objects, == compares both value (of every attribute) and type, which is what === does for every other type.

hahahaha gently caress you for posting this, I need to sleep!

Opinion Haver
Apr 9, 2007

I'm not noticing that stdClass leak; I'm running it in a tight loop in constant memory. Maybe it got fixed?

pigdog
Apr 23, 2004

by Smythe

the ultimate PHP rant posted:

I have heard a great many stories about the PHP interpreter and its developers from a great many places. These are from people who have worked on the PHP core, debugged PHP core, interacted with core developers. Not a single tale has been a compliment.
:drat:

raminasi
Jan 25, 2005

a last drink with no ice
Oh wait, no, I have a new favorite:

quote:

Array functions often have confusing or inconsistent behavior because they have to operate on lists, hashes, or maybe a combination of the two. Consider array_diff, which “computers the difference of arrays”.
code:
  $first  = array("foo" => 123, "bar" => 456);
  $second = array("foo" => 456, "bar" => 123);
  echo var_dump(array_diff($first, $second));
What will this code do? If array_diff treats its arguments as hashes, then obviously these are different; the same keys have different values. If it treats them as lists, then they’re still different; the values are in the wrong order.

In fact array_diff considers these equal, because it treats them like sets: it compares only values, and ignores order.

Look Around You
Jan 19, 2009

quote:

Functions are not data. Closures are actually objects, but regular functions are not. You can’t even refer to them with their bare names; var_dump(strstr) issues a warning and assumes you mean the literal string, "strstr". There is no way to discern between an arbitrary string and a function “reference”.

create_function is basically a wrapper around eval. It creates a function with a regular name and installs it globally (so it will never be garbage collected—don’t use in a loop!). It doesn’t actually know anything about the current scope, so it’s not a closure. The name contains a NUL byte so it can never conflict with a regular function (because PHP’s parser fails if there’s a NUL in a file anywhere).

Declaring a function named __lambda_func will break create_function—the actual implementation is to eval-create the function named __lambda_func, then internally rename it to the broken name. If __lambda_func already exists, the first part will throw a fatal error.

quote:

Incrementing (++) a NULL produces 1. Decrementing (--) a NULL produces NULL. Decrementing a string likewise leaves it unchanged.

This is the best. PHP is the best.

edit:

quote:

PHP basically runs as CGI. Every time a page is hit, PHP recompiles the whole thing before executing it. Even dev servers for Python toy frameworks don’t act like this.

This has led to a whole market of “PHP accelerators” that just compile once, accelerating PHP all the way to any other language. Zend, the company behind PHP, has made this part of their business model.

Check the prices on that Zend page too :stare:

Look Around You fucked around with this message at 07:17 on Apr 10, 2012

that awful man
Feb 18, 2007

YOSPOS, bitch

tef posted:

assuming no integer overflow :confused:

OddObserver posted:

Well, the compiler probably can (repeat after me: signed integer overflow in C is undefined...)

:ughh:

Let's try this again:

tef posted:

assuming the pointer isn't null :confused:

OddObserver posted:

Well, the compiler probably can (repeat after me: dereferencing a null pointer in C is undefined...)

Do you see the problem with this sort of reasoning?

CGameProgrammer
Nov 5, 2008

Otto Skorzeny posted:

Since it's come up twice now, I'll disagree

Doing

foo = malloc(n * sizeof(*foo))

or

foo = calloc(n, sizeof(*foo))

always makes more sense than

foo = malloc(n * sizeof(whatever_type_*foo_is))
That does not work if foo is declared as void*.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

CGameProgrammer posted:

That does not work if foo is declared as void*.

Well yeah, but

malloc(n * sizeof(void))

isn't standard C either, so that's kind of beside the point.

Vanadium
Jan 8, 2005

Suspicious Dish posted:

Since PHP doesn't already get enough hate, eevee has published the ultimate anti-PHP rant. Look at that thing go.

Look at the hate this writeup is getting on hackernews: http://news.ycombinator.com/item?id=3820431

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Vanadium posted:

Look at the hate this writeup is getting on hackernews: http://news.ycombinator.com/item?id=3820431

To be fair, there are a lot of comments saying "actually the writeup is pretty much spot on and people like you are the reason things like this need to be said".

The fact that those are tucked way down the discussion lists basically proves that vote-moderated discussions are still really lovely even (or perhaps "especially") on niche communities.

edit: While we're here I'd just make the point that even more than Minecraft, PHP more or less proves that code quality is completely orthogonal to something actually being "successful".

Jabor fucked around with this message at 09:36 on Apr 10, 2012

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Vanadium posted:

Look at the hate this writeup is getting on hackernews: http://news.ycombinator.com/item?id=3820431

I only skimmed the comments but it seems like most people defending PHP from criticism like this tend to say things like "yes well it's easy to hack something together in 10 minutes" or "yes well it's easy for newbies to learn" and the part they miss is that yes, those are things that are good about PHP but (the great majority of) the bad things don't have to be present in order to have the good things. You don't have to have a massive standard library with inconsistently named functions in order to be easy for new programmers to learn your language, for example. If anything those redeeming qualities are in spite of the flaws of the language.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Jabor posted:

The fact that those are tucked way down the discussion lists basically proves that vote-moderated discussions are still really lovely even (or perhaps "especially") on niche communities.

I would say that even in my (relatively) short tenure there, the quality of discussions on HN has declined precipitously. The articles posted are still often good, but a combination of the bikeshed problem, influxes of new users from variegated sources and a few other things has really wrecked the comments.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Not sure about 'hate'. That HN thread seems on pretty even keel with a lot of people saying good and bad things about PHP. And overall I don't really see much comments about how the article sucked unless you imply that people who comment defending PHP hated the article.

tef
May 30, 2004

-> some l-system crap ->

pokeyman posted:

That huge list had me laughing out loud. Some of it, like not collecting "unnamed" garbage, is just nonsensical. It's self-parody.

I think my favourite new bit of information is http://www.php.net/~derick/meeting-notes.html#named-parameters

quote:

'Discussion: We don't see the real need for named parameters, as they seem to violate PHP's KISS principle. It also makes for messier code.'

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
"Keep it stupid, stupid"

tef
May 30, 2004

-> some l-system crap ->

Hammerite posted:

If anything those redeeming qualities are in spite of the flaws of the language.

When you learn another language, you'll find those 'qualities' start to look like flaws in their own right. PHP is so broken that the minor bugs look like features.

You can knock up anything quickly in a language you know, meanwhile php is the one that will let you write easily exploitable code off the bat in a number of contexts. If php was a way to build a house, it would be the quickest way to build a house that's on fire. If php was a way to cook food, it would be the quickest way to burn food and poison people.


It isn't easy for newbies to learn. Most of them are using it because they don't want to learn or understand what they are doing. It's the quickest, fastest way to make terrible decisions that will haunt you for life. No-one learns php, they cut and paste and google around the error messages until the issue goes away for them.

The people who defend php, haven't learned any other programming language, let alone the one they champion.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Nippashish posted:

PHP's rand() function seems to have some pretty obvious patterns.

As much as I love a good 'PHP Sucks' rant (and oh god do I), this has been fixed in the intervening four years. It looks like rand() defaults to using Mersenne Twister in at least 5.3.6 on Windows.

ToxicFrog
Apr 26, 2008


Suspicious Dish posted:

Since PHP doesn't already get enough hate, eevee has published the ultimate anti-PHP rant. Look at that thing go.

:drat:

The comments are gold(?) too. I've already seen at least half a dozen "it's open source, if you don't like it fix it rather than whining about it" (by people who I'm guessing have neither read the article, nor attempted to report a bug against PHP).

I've also seen nearly as many "gently caress the haters, PHP pays the bills and that's the only thing that matters. Good luck getting a job with one of your toy languages like ruby, or python, or java. :smug:" posts.

evensevenone
May 12, 2001
Glass is a solid.

McGlockenshire posted:

Perl, Ruby and Python all expose the same flawed rand by default, as does, say, C. This has been a known problem for decades.

Don't use rand for anything other than trivial matters.

Is this really a bad thing, besides rand() being flawed? That way if you have a system with some sort of fancy RNG that can be used without the languages really needing to know. And if a security hole is found in an RNG then fixing it is just a matter of updating the OS as opposed to updating all of your binaries?

ToxicFrog
Apr 26, 2008


evensevenone posted:

Is this really a bad thing, besides rand() being flawed? That way if you have a system with some sort of fancy RNG that can be used without the languages really needing to know. And if a security hole is found in an RNG then fixing it is just a matter of updating the OS as opposed to updating all of your binaries?

Well, the underlying horror is really:
- the only C standard PRNG is rand(); random() is POSIX, so anything that wants to be portable to windows (or weird-but-standards-conformant embedded systems or the like) can't use it
- windows is still using the old lovely rand() and probably will be forever

Using the system PRNG rather than rolling your own is nice for the reasons you stated, except on windows, where the system PRNG is poo poo and will never be fixed.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Is there a reason that rand can't be fixed on windows? I mean what kind of applications depends on the non randomness of the Rand function?

ToxicFrog
Apr 26, 2008


MEAT TREAT posted:

Is there a reason that rand can't be fixed on windows? I mean what kind of applications depends on the non randomness of the Rand function?

I have no idea. As far as I know there's no technical reason except maybe "backwards compatibility with legacy programs that might depend on the brokenness of rand()" and they can always roll that into compatibility mode if people actually need it.

To clarify, my "will never be fixed" statement stems not from any technical reasoning but from the fact that rand() has been known to be poo poo for years if not decades and yet has not, to my knowledge, been fixed in any release of windows or msvcrt.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

MEAT TREAT posted:

Is there a reason that rand can't be fixed on windows? I mean what kind of applications depends on the non randomness of the Rand function?

FreeCell!

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I'm still laughing at ?: being left-associative. That's the best joke I've ever seen.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

ToxicFrog posted:

Well, the underlying horror is really:
- the only C standard PRNG is rand(); random() is POSIX, so anything that wants to be portable to windows (or weird-but-standards-conformant embedded systems or the like) can't use it
- windows is still using the old lovely rand() and probably will be forever

Using the system PRNG rather than rolling your own is nice for the reasons you stated, except on windows, where the system PRNG is poo poo and will never be fixed.

Most systems have a cryptographically secure PRNG:
http://msdn.microsoft.com/en-us/library/aa379942.aspx https://en.wikipedia.org/wiki//dev/random

That it's not the same function in all of them is a poo poo excuse to use rand().

dis astranagant
Dec 14, 2006

pokeyman posted:

I'm still laughing at ?: being left-associative. That's the best joke I've ever seen.

I'm still having trouble wrapping my head around how that's even supposed to work. The words all parse but I just can't make the logic happen.

dis astranagant fucked around with this message at 19:59 on Apr 10, 2012

Optimus Prime Ribs
Jul 25, 2007

As much as I hate having to work with PHP, I love learning about the dumb poo poo that it does.
It's the gift that keeps on giving. :3:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
code:
$arg = 'T';

// whatever PHP does
$vehicle = ( ( $arg == 'B' ) ? 'bus' :
             ( $arg == 'T' ) ? 'train' :
             ( $arg == 'H' ) ? 'horse' :
             'feet' );
echo $vehicle;

// right-associative
$vehicle2 = ( ( $arg == 'B' ) ? 'bus' :
              (( $arg == 'T' ) ? 'train' :
              (( $arg == 'H' ) ? 'horse' :
              'feet' )));
echo $vehicle2;

// left-associative
$vehicle3 = ( ((( $arg == 'B' ) ? 'bus' :
              ( $arg == 'T' )) ? 'train' :
              ( $arg == 'H' )) ? 'horse' :
              'feet' );
echo $vehicle3;

mjau
Aug 8, 2008

ToxicFrog posted:

I have no idea. As far as I know there's no technical reason except maybe "backwards compatibility with legacy programs that might depend on the brokenness of rand()" and they can always roll that into compatibility mode if people actually need it.
Well, if you want repeatability across different systems (e.g. for procedural generation), you'll want the RNG to come up with the same sequence every time it's given the same seed, but the same seed on two different RNGs will result in different sequences. ('course, if you care about repeatability like that you really should use a better defined RNG in the first place)

Adbot
ADBOT LOVES YOU

Maxxim
Mar 10, 2007

You're overcome by an indescribably odd sensation...!

dis astranagant posted:

I'm still having trouble wrapping my head around how that's even supposed to work. The words all parse but I just can't make the logic happen.

code:
( $ arg == 'B' ) ? 'bus' : ( $arg == 'A' ) => false

false ? 'airplane' : ( $arg == 'T' ) => true

true ? 'train' : ( $arg == 'C' ) => 'train'

'train' ? 'car' : ( $arg == 'H' ) => 'car'

'car' ? 'horse' : 'feet' => 'horse'

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply