LWN.net Logo

PHP: a fractal of bad design (fuzzy notepad)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 17:26 UTC (Fri) by apoelstra (subscriber, #75205)
In reply to: PHP: a fractal of bad design (fuzzy notepad) by rev
Parent article: PHP: a fractal of bad design (fuzzy notepad)

If you did

char *str = malloc (LEN * sizeof *str);

You would not need to change anything if you changed the type of str in the future. Explicitly writing a type, is a maintenance hassle, and writing sizeof(char) is pointless. So doing both is doubly bad, and suggests that the
author of the code is not very comfortable with the language. (Which again, increases the mental load on the maintainer.)


(Log in to post comments)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 21, 2012 13:56 UTC (Sat) by rev (guest, #15082) [Link]

Yep. That would be even better idiom.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 21, 2012 14:19 UTC (Sat) by rev (guest, #15082) [Link]

A few side notes. Somewhat tongue in cheek, somewhat provocative, and on the other hand, quite serious.

There's only one programming language that's worse than PHP, and that is C. Make that two languages worse than PHP: Perl and C.

Whenever there's a need in a programming language community to take pride in knowing every quirk and detail of a language, as your remark alludes to, the merits of said language are up for debate.

Whenever programmers feel the urge to impress their peers with their knowledge of a programming language, the quality of these programmers is up for debate.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 21, 2012 16:38 UTC (Sat) by apoelstra (subscriber, #75205) [Link]

The use of the 'sizeof' operator is hardly a detail or quirk of the language -- it is absolutely crucial to any C program that uses dynamically allocated memory.

PHP: a fractal of bad design (fuzzy notepad)

Posted May 7, 2012 15:04 UTC (Mon) by rev (guest, #15082) [Link]

Agreed. One of the reasons C should be avoided like the plague.

PHP: a fractal of bad design (fuzzy notepad)

Posted May 8, 2012 8:49 UTC (Tue) by nix (subscriber, #2304) [Link]

It's when you find yourself using addition, subtraction, or (size_t)pow() on the result of sizeof() that you really know you're playing with the big boys.

(I've done the first two, but so far have restrained myself from the insanity required for the third, preferring to multiply by hand. How plebeian.)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds