Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's just a bad argument. Simple code that suddenly breaks because of the contents of a directory shouldn't be possible, whether or not said simple code is unnecessary because of a standard library function. The example stands, weak typing is a horrible vector for difficult-to-catch bugs.


> That's just a bad argument

It's not my only argument. Here's what I wrote on the blog's own comments:

> I agree with your points, but picking this line as an example of the language’s problems

> is a bit of a straw man:

>

> “while ( ($filename = readdir($dh)) == true) $files[] = $filename;”

>

> Code like this smells terribly.

>

> First of all it uses “==”. That operator should trigger a deprecated warning, since it’s

> never appropriate. Even if you want the coercion, it’s better to write it explicitly with

> things like (int) or intval().

>

> Next, it’s using “== true”, which is completely redundant since the “while” will interpret

> the value as a boolean anyway.

>

> Next, it’s performing assignment inside a condition, which is generally frowned upon.

> There’s potential to confuse “=” with “==” or “===”, it’s using a statement in the place of

> an expression and it performs side-effects (setting the $filename value).

>

> After all that, it’s just duplicating existing functionality anyway: you could just say

> $files = scandir($dh).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: