LWN.net Logo

PHP: a fractal of bad design (fuzzy notepad)

It's a bit of a rant, but a blogger known as "Eevee" has put together a detailed criticism of PHP as a language. It covers the flaws Eevee sees in the predictability, consistency, reliability, debug-ability, security, and many other attributes of the web application language. "PHP is the lone exception. Virtually every feature in PHP is broken somehow. The language, the framework, the ecosystem, are all just bad. And I can’t even point out any single damning thing, because the damage is so systemic. Every time I try to compile a list of PHP gripes, I get stuck in this depth-first search discovering more and more appalling trivia. (Hence, fractal.)" (Thanks to Paul Wise.)
(Log in to post comments)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 0:36 UTC (Tue) by roskegg (subscriber, #105) [Link]

This kind of content is why I keep coming back to LWN.net. Very insightful. PHP was the origin of brogramming, not JavaScript. If you squint, you can pretend the JavaScript is a variant of LISP. PHP is like the bad parts of C++, dumbed down so any idiot can misuse them.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 7:42 UTC (Tue) by kmike (guest, #5260) [Link]

It's a bit ironic reading this here at LWN which was powered by PHP in the early 2000's (google for "lwn phtml" or "lwn php3").

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 14:04 UTC (Tue) by maney (subscriber, #12630) [Link]

Our Editor is not the only one who fell for the PHP Hype back in the bad old days. The thing is, it did make simple things pretty easy, and is still arguably a good choice for the sort of simple database query & generate that it was first intended for. And besides, back then Python's support for web page generation was little more than "import cgi". But that changed, and we escaped PHP. Years later I found the perfect concise explanation of what went wrong:

Q: What do you get when programmers design a language while trying to get something else done?
A: PHP -- Jeremy H. Brown

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 10:23 UTC (Thu) by janpla (guest, #11093) [Link]

Well, it is popular, and as they say: 50 million flies can't be wrong.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 16:42 UTC (Thu) by smitty_one_each (subscriber, #28989) [Link]

Dyslexia: I'm all, "50 million flies?" which also makes sense in this context.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 23, 2012 5:01 UTC (Mon) by zlynx (subscriber, #2285) [Link]

No, the saying really is flies.

Just because 5,000 flies like the s**t does not mean it isn't s**t.

Applications and languages

Posted Apr 17, 2012 16:13 UTC (Tue) by gwolf (subscriber, #14632) [Link]

Well, I agree that PHP is an awfully awful language. I have (fortunately) only had to write a small project in it, although I have maintained some largish things... The problem is, there are some good apps done in it. Many people, me included, will happily use a good and well-maintained application (say, I am a very happy Drupal user, and its developer community is very security-conscious and active), even though it's programmed in PHP.

But choosing PHP for a new project? No, no, for the love of all that's holy, no!

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 0:55 UTC (Tue) by apoelstra (subscriber, #75205) [Link]

For people who want to waste time, but for some reason not read through the article (though I highly recommend it), there is a great link in there:

http://phpsadness.com/

Not Again

Posted Apr 17, 2012 2:08 UTC (Tue) by brianomahoney (subscriber, #6206) [Link]

Ever little while I come across some self-important dumbass who explains why XXX is an evil language and should not be used, the worst go on to invent another unusable language that never gets real code written in it, they Range from Nicklaus Wirth [ETH, Zuerich](Alogol-W, Pascal, Modula 1-12345) and come in churches of Functional, Procedural and Object.

Exactly like Climate Alarmists don't know what they are doing, the Theory (Universal Turing Machines), the Practice (writing, debugging and maintaining a large, say 1M line program).

Competent Programmers, most of whom have have very simple simple tastes, we like stuff that is simple (C, Perl); powerful (Perl, Python); predictable (C, Perl); understandable, and suscinct (not Cobol, Java); and do not contain so many syntactic and semantic traps that you need 3+ boots and a 2000 page spec to document the gotchas (C++); and not captured by a Library eco-system that invites patent suites (Java, If ORACLE win at trial Java is DEAD).

Now I don't expect this comment to do anything but attract a fleet of arrogant newbies and pack of stupid religeous experts, but each time I find an idiot proposing Java for rael-time or high frequency systems, or telling people that they can't use PHP or JavaScript because they are not TYPE SAFE I wonder what the Universities are really doing.

Programming and System Design is one of the most Complex and Challenging Tasks there are and no wonder it can't be done by deserving people with room temperature IQ and an indifferent BS or PhD from the University of Nowhere.

Keep this up and all innovation will be done by asians who havnt been taught by progressive idiots that it can't be done.

Not Again

Posted Apr 17, 2012 2:15 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

>Competent Programmers, most of whom have have very simple simple tastes, we like stuff that is simple (C, Perl); powerful (Perl, Python); predictable (C, Perl); understandable, and suscinct (not Cobol, Java); and do not contain so many syntactic and semantic traps that you need 3+ boots and a 2000 page spec to document the gotchas (C++); and not captured by a Library eco-system that invites patent suites (Java, If ORACLE win at trial Java is DEAD).

Wow! You've managed to nail EVERYTHING. In reverse.

Perl and C are hardly 'simple' or predictable. While Python is good, it's not that powerful (still no way to use real multithreading or do system-level programming). Java _wins_ in 'understandable' category (along with COBOL, really) though it's not succinct. Etc.

>Now I don't expect this comment to do anything but attract a fleet of arrogant newbies and pack of stupid religeous experts, but each time I find an idiot proposing Java for rael-time or high frequency systems,
Like http://www.azulsystems.com/ ?

>or telling people that they can't use PHP or JavaScript because they are not TYPE SAFE I wonder what the Universities are really doing.
Duh. They're right.

>Keep this up and all innovation will be done by asians who havnt been taught by progressive idiots that it can't be done.

I work with quite a few Asians and most of good Asian software developers hate PHP with a passion. PHP simply transcends cultures.

Oh, and should we mention Ruby which is made in Japan?

PS: I love the smell of flame-roasted bacon in the morning!

Not Again

Posted Apr 17, 2012 3:14 UTC (Tue) by fest3er (guest, #60379) [Link]

>>or telling people that they can't use PHP or JavaScript because they are not TYPE SAFE I wonder what the Universities are really doing.
> Duh. They're right.

Really? When did it become socially fashionable for anyone to disparage another for her choice of programming language?

To attempt to add a bit of perspective to the issue, consider maintaining a 1700-program suite written in business basic over the past 30 years with one-letter var names, few comments, data packed every which way into ISAM files, and with data stored in the ISAM keys. In comparison, PHP is a fantastic and robust language and ECMA Script is a joy to use.

Competent programmers write efficient and stable software in the languages they are most skilled at using.

Decorum prohibits me from sharing my opinion of folks who tear down rather than build up.

Not Again

Posted Apr 17, 2012 4:02 UTC (Tue) by dvdeug (subscriber, #10998) [Link]

> When did it become socially fashionable for anyone to disparage another for her choice of programming language?

My first instinct was to say 1957, when FORTRAN came out; but there were probably earlier instances after assembly languages came out that people still hacking machine code were disparaged for not switching.

> Competent programmers write efficient and stable software in the languages they are most skilled at using.

I don't think so. Competent programmers know the art of picking a reasonable tool for the job; e.g. unless you really need to use something else, write Android programs in Java. Not only that, competent programmers in real life have to work with other programmers; you may be the best ML or Modula-3 hacker in the world, but if someone else has to work with you or will have to maintain it after you, those probably aren't the best languages to use.

Not Again

Posted May 25, 2012 15:46 UTC (Fri) by dashesy (subscriber, #74652) [Link]

you may be the best ML or Modula-3 hacker in the world, but if someone else has to work with you or will have to maintain it after you, those probably aren't the best languages to use.

Very very true, but same can be said about most other languages as well. C++ is more popular but some boost-like paradigms should be avoided in a not so technical company that does not get many job applicants with high level of skills (not Google so to speak).

If it is in a library that no body is going to see the source then it might be OK. I had to remove so many Functors+for_each statements recently and replace them with simple for loops, because over time they had evolved into ugly monsters passing and changing state. A simple rule of thumb (for work-place I described) is to try to avoid what a language does not provide naturally (not highlighted by IDE is a good sign); no lambdas for C++ even for skilled programmers, please just switch to C++11 if you need them.

A competent programmer who does not work in an elite workplace (Google, RedHat, ...), should think ahead, if working on the next Google, then even inventing a new functional language might be worthwhile let alone using Haskell, otherwise please keep it as simple as possible.

Not Again, Bacon

Posted Apr 17, 2012 4:29 UTC (Tue) by brianomahoney (subscriber, #6206) [Link]

If you don't think C or Perl are predictable you don't understand their semantic model.

As to multi-treading, and micro-kernels, as an OS developer I do not understand the fascination with multithreading in USER SPACE, it simply brings all the cpmplexity of non-sequential programming into the app space for no visable gain:

.. Stop/Start latency can be better managed without threads,

.. Pre staged processes anyone?

.. The kernel, and only the kernel knows it the context switch needs register save/restore, cache flush or page table flush and dosn't need user space to second guess it.

.. Fast locks can be done better in shm.

You are too dumb to see that I was not defending PHP and JavaScript, I was not, and you are right that they are very poorly designed by language designers from Europe and the US. Exactly what I was doing was attacking knee jerk language fascists who are dumb enough that they have discovered the holy grail!

There is a lot of PHP and JavaScript out there doing very useful things that cannot now be replaced.

Bleagh

Posted Apr 17, 2012 6:52 UTC (Tue) by jd (guest, #26381) [Link]

C is not "predictable" for many reasons, not least that no two system C libraries implement identical semantics. Different C libraries implement different malloc strategies, different levels of sanity-checking, and even different levels of detail in errors. That means that the same C program will run differently in different environments.

Sometimes you want that, sometimes you don't. You don't want real-time systems to run programs exactly the same way as high-performance systems, mission-critical systems or highly secure systems. It's good if programs can acquire some of the characteristics of the environment.

In part for the above reason, but also in part because of some really sloppy compilers out there, C is notorious for Heisenbugs, where different compilers will produce different Heisenbugs for the same code.

This is something you definitely Do Not Want.

Ok, what about user-space threading?

Have to disagree here, too. M:N threading in the Linux kernel was abandoned because it wasn't achieving any good results - even though it's not obvious as to why the extra complexity was overwhelming the reduction in bottlenecks.

I am also an ardent supporter of Occam, *THE* language for user-space parallel processing (IMHO, anyway). Completely 100% explicit userspace threading, no room for discretion by compiler or OS, explicit synchronization and explicit affiliation between threads. It's so explicit, even the compiler needs to be over 18 to read it. It is also mindboggingly fast. Nothing, bar assembly, comes close.

On the Transputer, the system Occam was originally written for, Occam was about the same level above Transputer machine operating instructions as C was above the machine operating instructions of the systems it was designed for.

And that makes my final point:

The power of a language will ALWAYS be dictated by the translation needed to convert it into native form. Something will ALWAYS be lost in translation when making paradigm shifts and you will ALWAYS introduce bugs and performance issues. When running a consistent paradigm from start to finish, that might still happen (if the language is merely badly designed, or if either the compiler or processor are defective) but the chances are good that it will not.

C will NOT run well on a Transputer. Occam does NOT run well on an Intel. If anyone actually built a true Object Oriented Processor, neither language would work well on it at all but C++ and Java probably would work just fine.

Bleagh

Posted Apr 17, 2012 7:26 UTC (Tue) by mpr22 (subscriber, #60784) [Link]

How well C++ would work on an "object-oriented" processor would depend very heavily on what style of C++ the programs were written in. (Also: what does the apparent buzzphrase "mission-critical systems" mean that is somehow incompatible with "real-time"? I'd argue that a significant subset of real-time systems are mission-critical, and I'm sure that NASA, General Dynamics, and Boeing would agree with me.)

Bleagh

Posted Apr 18, 2012 0:01 UTC (Wed) by jd (guest, #26381) [Link]

Definitions are close to what are usually used:

"Mission Critical" - seven 9s reliability as being a minimum

"Secure" - B2 or EAL5 as a minimum, can't have known exploits, security kernel must be amenable to being provably correct (whether or not it has actually been proven)

"Real-Time" - I'll accept "fixed number of CPU cycles in a given window, doesn't matter when in that window", -or- "fixed start and end times in which the program will be running, doesn't matter exactly how many CPU cycles were used", soft real-time is not really "Real-Time".

And so on. Real-Time has multiple definitions, so I simply ORed the two usual ones together and excluded the one that should never have existed.

Some of these are orthogonal, some have trade-offs and some are mutually exclusive. Which is what has changed, as new techniques and methods are discovered. "Mission-Critical" is orthogonal to "Real-Time" up to the point where sufficient validation of pre-conditions permits deadline guarantees to be met.

Where it is NOT possible to validate pre-conditions to the extent needed to ensure the probability of an error resulting in a failure condition is below the threshold guaranteed (99.99999% reliability = 0.00001% probability of a catastrophic error) THEN you cannot have something that meets both requirements, you have to trade off.

However, for most practical purposes (and I include NASA's rocketry, Boeing's military aircraft, etc, to be a practical purpose), well-written software, developed using an established and recognized software engineering technique, properly tested, is very unlikely to require validation that is so extensive that real-time guarantees can't be met.

Bleagh

Posted Apr 19, 2012 13:49 UTC (Thu) by nye (guest, #51576) [Link]

>Definitions are close to what are usually used:

> "Mission Critical" - seven 9s reliability as being a minimum

I'd say that's pretty far from 'usually used'. Nearly nothing has seven 9s reliability. That's 30 seconds of downtime per decade - even applications which are literally life-or-death don't generally manage that, and the overwhelming majority of people using the phrase 'mission critical' would mean at least two orders of magnitude less reliable.

'Real-time', as you (sort of) say, has too many definitions to be especially meaningful without qualification. I've always been a little confused by 'soft real-time'. It generally seems to mean vaguely 'low-latency'; which is largely orthogonal to real-time. I guess it's really intended to mean 'general purpose' as opposed to 'batch mode'.

Either way it sounded like your earlier post said that a system can't be both 'real-time' and 'mission-critical', but then later you seemed to say that they can, which is confusing.

Bleagh

Posted Apr 19, 2012 20:32 UTC (Thu) by dlang (✭ supporter ✭, #313) [Link]

"Mission Critical" just means that the organization can't function without it, it says nothing about the required uptime.

for many businesses e-mail is mission critical, but if it's up between 9 and 5 it could be down the rest of the day and not matter. And if it is down during the day and business is crippled, it hurts, but the business doesn't go under.

I can't think of very many companies that electrical power wouldn't be considered "Mission Critical", but very few companies (outside of ones focused on Internet accessible servers) have backup generators and UPS systems, and those don't come anywhere close to 7 9's of availability.

Bleagh

Posted Apr 17, 2012 10:11 UTC (Tue) by dgm (subscriber, #49227) [Link]

> Different C libraries implement different malloc strategies, different levels of sanity-checking, and even different levels of detail in errors.

Come on. The last one is false (errors in libraries?), and none of the three is part of the semantics. C has it's quirks, certainly, but they are not those you listed.

Take for instance the many operations that can trigger undefined or platform specific behavior. *That* can make code unpredictable. One has to take into account, though, that such code is considered buggy, or at least fragile, and they are well documented.

There are also some obscure points in the language that should have been left out. The comma operator, for instance. But all in all, C is very pleasant and predictable. For some reason, more pleasant than more orthogonal languages like Pascal (hey, that's _my_ personal opinion).

> That means that the same C program will run differently in different environments.

That means that _buggy_ C programs _may_ run differently in different environments. Which is not surprising, if you ask me.

Bleagh

Posted Apr 17, 2012 19:58 UTC (Tue) by jzbiciak (✭ supporter ✭, #5246) [Link]

C will NOT run well on a Transputer. Occam does NOT run well on an Intel. If anyone actually built a true Object Oriented Processor, neither language would work well on it at all but C++ and Java probably would work just fine.

Anyone with an iAPX432 box care to try and find out? ;-)

Actually, slightly more seriously, some of the LISP machines of the 80s provided a true object floor. Objects were first-class at the instruction level. LISP apparently ran great on it. I wonder if Java or C++ would work there? I suspect straight C++ wouldn't because it allows too much low-level monkeying about.

Not Again, Bacon

Posted Apr 17, 2012 8:42 UTC (Tue) by renox (subscriber, #23785) [Link]

> If you don't think C or Perl are predictable you don't understand their semantic model.

About C, you should really read this blog: http://blog.regehr.org/ which contains lots of article about software correctness and C.

Do it and then we'll discuss about C's "predictability" which isn't so good..

Not Again, Bacon

Posted Apr 17, 2012 16:03 UTC (Tue) by k8to (subscriber, #15413) [Link]

Did you actually read the article? It wasn't "lol php sucks", but in fact a pretty good dissection of what the problems are.

Based on some of your own criteria, it provides all the evidence that it's a poor choice for nearly any situation, and that's good information for future decision making. Nowhere does it tell you to replace all your php right away. That's your invention.

Not Again

Posted Apr 17, 2012 2:27 UTC (Tue) by szoth (guest, #14825) [Link]

You racism has no place here or anywhere else.

Not Again, Racism

Posted Apr 17, 2012 4:03 UTC (Tue) by brianomahoney (subscriber, #6206) [Link]

What racism, a view that American (Caucasian, unstated, but if the cap fits, wear it) Lefty Progressive shits replay the same nonsense every 10 years is some how racist?

Take your head out your ideology for long enough to see that my post is IDIOTist, not RACist.

Not Again, Racism

Posted Apr 17, 2012 4:17 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

I'm a card carrying member of the Communist Party of Russia I can state that the US 'lefties' are non-existent. The US has a right-wing and an extremely-right-wing party.

PS: yes, I really have a membership card, it makes a great conversation starter :) That's why I got it in the first place.

PPS: What? Politics on LWN?!? Are we turning into Slashdot?!??? Help!

Not Again, Racism, Communism

Posted Apr 17, 2012 4:45 UTC (Tue) by brianomahoney (subscriber, #6206) [Link]

Your membership of the Communist party of the erstwhile CCCP is interesting but I would advise keeping your sins from Putin, but is not germain to the discussion except that you are simply unaable to see a point of view other than your own, which is naive and arrogant in the extreem.

No one is telling you what to write in, ML, Lisp ... C++, that is Libertarian just to STFU about others, but we know, and most of us now simply ignore your nonsene.

Thank you for starting the firestorm of intolerance that I wanted to illustrate!

Not Again, Racism, Communism

Posted Apr 17, 2012 6:06 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

I'm perfectly able to see others' view, if it's reasonable.

We can argue about usefulness of DSLs or about the ways to extend JS. I can see that ML and Haskell people have some great arguments in favor of their language.

However, your arguments in favor of PHP can be summed as: "Basic is worse than PHP, so PHP is good".

That's kinda... weak.

Not Again, Racism, Communism

Posted Apr 17, 2012 20:10 UTC (Tue) by jzbiciak (✭ supporter ✭, #5246) [Link]

Or to phrase it as a political joke I've heard here in the states, "Both parties are bad, so vote Republican." (I don't, BTW.)

Looking through that (lengthy) article, I think Edsger Dijkstra's comment on BASIC may also apply to people who've only coded in PHP:

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.

Granted, this is coming from the same person who said gotos are bad without exception. I think reality is a bit more subtle than such stark pronouncements.

PHP's suckiness, though, appears to be anything but subtle. Glad I stayed away from it.

Mentally mutilated

Posted Apr 18, 2012 15:59 UTC (Wed) by man_ls (subscriber, #15091) [Link]

I am probably tainted by my humble beginnings with Amstrad BASIC, but I have programmed in Pascal, Perl, Python, C, Java, JavaScript, PL/SQL, even Bash; but I kind of like PHP. It lets you do what you want quickly and it is not so full of itself as Python.

That is all. I just wanted to add a Leftist vote for PHP. Please don't flame me.

Mentally mutilated

Posted Apr 18, 2012 18:11 UTC (Wed) by juliank (subscriber, #45896) [Link]

You started with BASIC? You know, "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."

Mentally mutilated

Posted Apr 18, 2012 18:34 UTC (Wed) by man_ls (subscriber, #15091) [Link]

Well, what can you do. At least it was not Visual Basic; and my first programs were really Spectrum Basic. Actually I have very fond memories of GFA basic. When I recoded the 3D graphic application I did for the Atari ST in 68k assembler, for speed gains, I was ultimately unable to debug it, probably due to the massive brain damage inflicted by the various Basic dialects.

That was when I was young and agile, now that I am older I have learned not to do anything too clever in my code.

Not Again, Racism, Communism

Posted Apr 17, 2012 11:19 UTC (Tue) by AndreE (subscriber, #60148) [Link]

I think I know whose nonsense most of us will be ignoring from now on.

Not Again, Racism

Posted Apr 18, 2012 16:13 UTC (Wed) by tjc (subscriber, #137) [Link]

The US has a right-wing and an extremely-right-wing party.

That's an interesting perspective. Placing myself into your view of the U.S. political system leaves me pining for an extra extreme right-wing party. :)

Not Again, Racism

Posted Apr 19, 2012 14:03 UTC (Thu) by nye (guest, #51576) [Link]

>That's an interesting perspective. Placing myself into your view of the U.S. political system leaves me pining for an extra extreme right-wing party. :)

I'm confused - are you saying that you want a party even more right-wing than the US Republican party or have I misunderstood?

(BTW from the UK perspective I believe the US Democrat party would probably be unelectably right-wing.)

Not Again, Racism

Posted Apr 19, 2012 14:51 UTC (Thu) by mpr22 (subscriber, #60784) [Link]

I'm not sure the Democrats are that much to the right of Maggie's incarnation of the Tories.

Not Again, Racism

Posted Apr 21, 2012 15:47 UTC (Sat) by tjc (subscriber, #137) [Link]

> I'm confused -

You said it, not me. ;)

> are you saying that you want a party even more right-wing than the US Republican party or have I misunderstood?

Yes. A party that runs up 4.9 trillion dollars in debt in just 8 years (2000-2008) is not conserving anything.

please cut the politics

Posted Apr 21, 2012 16:24 UTC (Sat) by dlang (✭ supporter ✭, #313) [Link]

this isn't the appropriate place for such things

please cut the politics

Posted Apr 22, 2012 22:12 UTC (Sun) by tjc (subscriber, #137) [Link]

Fear not: I shall not don my hairy breeches and begin preaching, at least not this time. :)

Not Again

Posted Apr 17, 2012 2:36 UTC (Tue) by Doogie (guest, #59626) [Link]

It's an international Communist conspiracy to sap and impurify all of our precious bodily fluids!

Not Again

Posted Apr 17, 2012 3:41 UTC (Tue) by cmccabe (guest, #60281) [Link]

Your comment is a fractal of fail.

Not Again

Posted Apr 17, 2012 16:55 UTC (Tue) by nix (subscriber, #2304) [Link]

It is quite remarkable how well that comment fits with the thesis of the blog post it's responding to. Fractal of fail, indeed. (Perhaps this was intentional... but I kind of doubt it. The inclusion of climate-change denial in there makes me wonder again though: it's so out of place...)

Not Again

Posted Apr 17, 2012 3:47 UTC (Tue) by dvdeug (subscriber, #10998) [Link]

Personally, I tend not to take advice from people who abuse others as being stupid and yet can't write a coherent post. How do you program if you can't get simple things like spelling and capitalization right in English? (The first is why they invented spellcheckers; you just have to learn the rules for the second, but they're not that complex.)

Not Again

Posted Apr 17, 2012 4:52 UTC (Tue) by brianomahoney (subscriber, #6206) [Link]

English, UK US, De, Fr, It, Es, BPT

Oh well, I am so stupid! And you are a Lefty, first all to resort the 'ad homs'.

Not Again

Posted Apr 17, 2012 5:54 UTC (Tue) by edomaur (subscriber, #14520) [Link]

I don't see the link between your answer and his question... Well, color me stupid.

More seriously, if I could erase PHP from my life, I would do. It's a mess as a language, and this has no link whatsover with my political preferences, my skin tone, the things I know as a learned human, and any other non-software related themas.

However, you have the right (and the left) to choose your programming language of preference, and to beeing offended by the negative views some other people will have about it.

But you have to be realist.

Not Again

Posted Apr 17, 2012 16:14 UTC (Tue) by k8to (subscriber, #15413) [Link]

Seriously Brian, attacking everything as 'lefty' when totally irrelevant to this degree is a warning sign of schizophrenia. Please talk to a mental health professional.

Not Again

Posted Apr 19, 2012 14:27 UTC (Thu) by jschrod (subscriber, #1646) [Link]

Thanks for giving the information that you can be ignored for all times on LWN.net.

Not Again

Posted Apr 17, 2012 10:49 UTC (Tue) by mpr22 (subscriber, #60784) [Link]

How do you program if you can't get simple things like spelling and capitalization right in English?

First, English spelling is sufficiently non-simple that a spellchecker can't save you from howlers.

Second, a former (English!) co-worker of mine could design and write sane, coherent software despite being unable to reliably internalize the spelling of "receive".

Not Again

Posted Apr 17, 2012 14:34 UTC (Tue) by pboddie (subscriber, #50784) [Link]

If the compiler keeps telling you that you're wrong, eventually you'll step up and give it something it can work with, and then you'll always have the executable and a debugger. There isn't such a toolchain for English.

Not Again

Posted Apr 17, 2012 16:18 UTC (Tue) by HelloWorld (guest, #56129) [Link]

I guess it depends on what you consider sane.
> Besides a mathematical inclination, an exceptionally good mastery of one's native tongue is the most vital asset of a competent programmer.
(Edsger Dijkstra)

Not Again

Posted Apr 17, 2012 16:38 UTC (Tue) by sorpigal (subscriber, #36106) [Link]

Yeah. Even Ritchie couldn't spell "create" right.

/me ducks

Not Again

Posted Apr 17, 2012 22:34 UTC (Tue) by tjc (subscriber, #137) [Link]

I think that was Thompson, and I *think* he said that if he could change one thing about Unix, that would be it.

Not Again

Posted Apr 18, 2012 12:50 UTC (Wed) by sorpigal (subscriber, #36106) [Link]

I recall it was Ritchie, but I could be wrong. And yes, that's the quote I was thinking of.

Not Again

Posted Apr 19, 2012 11:00 UTC (Thu) by jwakely (subscriber, #60262) [Link]

Although there seem to be several sources on the web attributing it to Ritchie (e.g .http://www.gobolinux.org/?page=doc/articles/clueless) Wikiquote attributes it to Thompson, citing Kernighan & Pike as the source: http://en.wikiquote.org/wiki/Kenneth_Thompson
My copy of TUPE is at home so I can't check it, but I'm inclined to believe Kernighan & Pike would have got it right.

How to get `receive' right

Posted May 12, 2012 1:54 UTC (Sat) by Max.Hyre (subscriber, #1054) [Link]

Back in the day, I was programming a custom multiplexer board for the HP 2100. Obviously I had to have a testbed that would cause it to transfer data in either direction. :-)

Being lazy, most of its commands were single letters: `s' for send, `h' for halt, &c. But to get it to listen for incoming, I had to type in the entire word `receive' correctly. By the end of the week I had no further trouble remembering the spelling.

Not Again

Posted Apr 17, 2012 6:05 UTC (Tue) by juliank (subscriber, #45896) [Link]

> If ORACLE win at trial Java is DEAD

If they win the patent stuff, then maybe. If they win that copyright argument, then Oracle is dead, and almost every programming language.

Not Again

Posted Apr 17, 2012 22:39 UTC (Tue) by tjc (subscriber, #137) [Link]

If it gets to the point where we have to start using non-words for API function names, named constants, etc, all to avoid copyright problems, then pre-processors are going to become essential.

Not Again

Posted Apr 18, 2012 15:43 UTC (Wed) by man_ls (subscriber, #15091) [Link]

Then makers of competing preprocessors would quickly get sued, and so on.

Not Again

Posted Apr 18, 2012 16:18 UTC (Wed) by tjc (subscriber, #137) [Link]

Not if the copyrighted API symbols were part of the input. We would all have to carry around keyword translation lists sewn into the liners of our jackets. This proposition is only slightly more absurd than Oracles actual claim.

Not Again

Posted Apr 18, 2012 16:50 UTC (Wed) by man_ls (subscriber, #15091) [Link]

Ah, back to the golden era of quilt-driven programming. Those were the days.

Not Again

Posted Apr 17, 2012 6:09 UTC (Tue) by juliank (subscriber, #45896) [Link]

> predictable (C, Perl);

C and predictable? If you do f() + g(), the order in which f() and g() are called is undefined. Furthemore, if you were to write a stack machine, and you want to operate on two elements, and you use an expression involving to pops such as: fun(pop(stack), pop(stack)), the same problem arises; you cannot even know which argument to fun() is the top of the stack.

Not Again

Posted Apr 17, 2012 8:49 UTC (Tue) by deepfire (subscriber, #26138) [Link]

Are you sure?

Not Again

Posted Apr 17, 2012 8:50 UTC (Tue) by deepfire (subscriber, #26138) [Link]

> If you do f() + g(), the order in which f() and g() are called is undefined.

Are you sure?

Not Again

Posted Apr 17, 2012 9:02 UTC (Tue) by HelloWorld (guest, #56129) [Link]

Not Again

Posted Apr 17, 2012 9:12 UTC (Tue) by juliank (subscriber, #45896) [Link]

OK, formally it's not undefined but unspecified. But for evaluation order, that basically doesn't make much difference. The draft I have (N1256, which is basically C99 + TC3) specifically says so in section 6.5:

"The grouping of operators and operands is indicated by the syntax.74) Except as specified later (for the function-call (), &&, ||, ?:, and comma operators), the order of evaluation of subexpressions and the order in which side effects take place are both unspecified."

Not Again

Posted Apr 17, 2012 20:24 UTC (Tue) by jzbiciak (✭ supporter ✭, #5246) [Link]

Yep, and that bit me when I ported Doom to one of our DSPs. The code used the idiom P_Rand()-P_Rand() all over the place to get signed random numbers that were roughly normally distributed. GCC evaluated left-to-right, DSP compiler right-to-left.

While it wouldn't really affect the game play much, it was enough of a change that the prerecorded demo loops didn't function properly, because they expected the engine to be 100% deterministic. Once I found and fixed this error, they started working.

C is predictable when your program is bug free and relies on no implementation defined, unspecified or underspecified behavior. Such a program is extremely tedious to write, and next to impossible even for experienced practitioners. That's because implementation defined behavior is pervasive and useful.

I remember coming across a long, tiresome thread in comp.lang.c once where the goal was to bit-reverse a large integer array in 100% portable ANSI C. I don't recall if anyone succeeded, but the thread went far longer than I expected. Everyone made subtle assumptions about the environment, despite the guarantee that unsigned int is at least guaranteed to provide modulo-wraparound 2s complement arithmetic.

Not Again

Posted Apr 19, 2012 14:19 UTC (Thu) by nye (guest, #51576) [Link]

>C is predictable when your program is bug free and relies on no implementation defined, unspecified or underspecified behavior.

Okay, I know what 'undefined' means (nasal demons, etc.); I think I know what 'implementation defined' means; I guess 'underspecified' means that the standard writers didn't consider something quite precisely enough? But what - exactly - does 'unspecified' mean?

The first few Google hits don't distinguish sufficiently clearly for my liking between 'implementation defined' and 'unspecified'.

I'm guessing it's something like "a given compiler implementation can do whatever it likes, including behave non-deterministically, but your program remains valid so all other well-defined constructs remain well-defined", whereas 'implementation defined' is the same but without "behave non-deterministically"?

Not Again

Posted Apr 19, 2012 14:43 UTC (Thu) by anselm (subscriber, #2796) [Link]

»Implementation-defined« means that there are various options out of which the implementation needs to pick one and adhere to it. For example, an implementation can set the size of »short« arbitrarily (as long as it is not smaller than that of »char« and not larger than that of »int«) but the choice, whatever it turns out to be, must be consistently enforced.

With undefined behaviour the implementation can do anything it wants and doesn't have to do the same thing twice even in the same situation.

Not Again

Posted Apr 19, 2012 17:22 UTC (Thu) by nix (subscriber, #2304) [Link]

... and doesn't have to do what the Standard says elsewhere in the program either, as you are clearly no longer using the Standard as reference. (Or that's what it says, though as a QoI issue compilers try not to produce a program that reformats the disk on every little error.)

Not Again

Posted Apr 23, 2012 8:37 UTC (Mon) by ekj (guest, #1524) [Link]

Why are compilers not FORBIDDEN from compiling programs that contain instructions which are "undefined". Given that a valid program can format the hard-disk when containing undefined instructions, what are the odds that the programmer actually intended to say: "at this spot, do whatever random thing" ?

Not Again

Posted Apr 23, 2012 9:48 UTC (Mon) by mpr22 (subscriber, #60784) [Link]

With regard to your first sentence: because people want to be able to compile programs which contain functions that perform arithmetic on signed integers, and the results of signed integer arithmetic overflow may be outside the implementation's reasonable ability to control. (Unsigned integer arithmetic, on the other hand, has strictly-defined overflow behaviour summarized as (UINT_MAX + 1) == 0)

With regard to your second sentence: given a contradiction, everything is true.

Not Again

Posted Apr 23, 2012 9:57 UTC (Mon) by ekj (guest, #1524) [Link]

Wouldn't arithmethic operations on signed integers that overflow be unspecified rather than undefined ? I was thinking mostly of constructs that are by themselves -always- undefined, not subject to "undefined *if* the sum of these two overflow" which the compiler cannot generally know about beforehand.

What is the rationale for letting "void main(void)" compile and produce a program that you can run (if you dare!) despite the fact that it means, according to the C-spec: "Do nothing, or anything whatsoever."

Not Again

Posted Apr 23, 2012 10:40 UTC (Mon) by anselm (subscriber, #2796) [Link]

What is the rationale for letting "void main(void)" compile and produce a program that you can run (if you dare!) despite the fact that it means, according to the C-spec: "Do nothing, or anything whatsoever."

According to the C standard, the prohibition on prototypes for »main« other than »int main(void)« and »int main (int, char **)« applies only to what the standard calls a »hosted environment«, i.e., an operating system like Linux. The standard makes certain stipulations about how such an environment is supposed to call into a C program, and this is where the restrictions on »main()« come from. The output from a C compiler could, however, be useful in what the standard calls a »freestanding environment«, where – among other differences – the implementation defines how a program is actually started. It could force a different prototype for »main()« or call a differently-named function altogether. (An obvious example of a »freestanding environment« would be the Linux kernel, which runs on the bare machine, without the benefit of an underlying operating system, since of course it is supposed to be the operating system that would make up part of a »hosted environment« for ISO C.)

Having said that, it is probably safe to say that 99%+ of programs compiled with, say, GNU C, are intended to be run in the hosted environment, which is why, in the highly recommended »-Wall« mode, gcc emits warnings complaining about non-conforming definitions of »main()« unless the »-ffreestanding« option is specified on the command line. If you're serious you could use the »-Werror=main« option to turn this warning into an error.

Not Again

Posted Apr 23, 2012 10:42 UTC (Mon) by mpr22 (subscriber, #60784) [Link]

The result of void main(void) is only formally undefined if you're targeting a hosted implementation (which, admittedly, application programmers generally are). If you're using a freestanding implementation, then both the type and the name of your program's entry point are implementation-defined, so main might not be magic and even if it is, it might legitimately have a return type of void.

(Note to self: check whether it's defining void main(/*whatever*/) or returning from main having done so, that crosses the undefined-behaviour threshold on hosted implementations.)

Not Again

Posted Apr 20, 2012 5:19 UTC (Fri) by jzbiciak (✭ supporter ✭, #5246) [Link]

Here, go read the doc: www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

Here's my understanding, such that it is:

  • Implementation defined: We expect implementations to pick a behavior, tell the user about it, and stick to it. It's something you can rely on, but only in that implementation. Example: whether unadorned char is signed or unsigned.
  • Undefined: Here lie demons. An implementation is entirely within its rights to call system("nethack") or something else equally capricious when it sees one of these. Example: void main(void).
  • Unspecified: The environment must behave "reasonably", as in, it's not allowed to reformat your hard drive. But, it doesn't have to document its choices, and it can behave differently compile-to-compile. It can do whatever is convenient with best effort. Example: f() + g() Which gets called first?

Make sense?

Not Again

Posted Apr 24, 2012 10:56 UTC (Tue) by nye (guest, #51576) [Link]

>Make sense?

Yes, thank you.

Not Again

Posted Apr 17, 2012 22:42 UTC (Tue) by tjc (subscriber, #137) [Link]

That's a feature -- it gives the compiler more opportunities for optimization. If you're going to write tricky code in C, it's important to understand sequence points.

Not Again

Posted Apr 18, 2012 1:10 UTC (Wed) by jzbiciak (✭ supporter ✭, #5246) [Link]

It does, but it's so easy to forget some of these rules that it can lead to subtle, mind boggling errors -- errors that may not show up until you change compilers or compile flags, and may never evoke a warning from the compiler. The P_Rand() - P_Rand() example I gave elsewhere is a prime example, and I don't think anyone would have called John Carmack (or whoever wrote that idiom at id) an amateur.

So, while it's all well and good to say "Write tricky C only if you understand sequence points," there are plenty of non-tricky sequences that are nonetheless ill defined and subject to implementation defined or undefined behavior.

Throw in modern hardware and multithreading, and it's.... exciting. Sequence points only barely help you there. The Linux "memory barriers" document is an informative read.

Not Again

Posted Apr 19, 2012 22:12 UTC (Thu) by BenHutchings (subscriber, #37955) [Link]

The most important things to understand about sequence points being that they are not points and do not generally define a sequence. :-)

Not Again

Posted Apr 21, 2012 15:50 UTC (Sat) by tjc (subscriber, #137) [Link]

What would you call them then?

Not Again

Posted Apr 21, 2012 16:23 UTC (Sat) by BenHutchings (subscriber, #37955) [Link]

I would refer to a partial ordering of operations. Anyway, this was fixed in the latest standard (though unfortunately multithreading and atomic operations make this a lot more complex).

Not Again

Posted Apr 18, 2012 19:07 UTC (Wed) by jthill (guest, #56558) [Link]

From the standpoint of software maintenance I'll argue that's a good thing: when you're changing code, the single most critical question you can ask is "is this change safe?". In common cases leaving expression-evaluation order unspecified when the math doesn't require it limits the spelunking necessary to answer that question to the code in front of you.

Or, shorter: relying on undocumented API implementation details and unnecessarily specifying implementation details both produce bad, fragile code.

Not Again

Posted Apr 19, 2012 22:10 UTC (Thu) by BenHutchings (subscriber, #37955) [Link]

You're hardly beginning to scrape the surface of unpredictability.

macro expansion, signed overflow, weird operator precedence, complex coercion rules, bitfield layout and signedness, external linkage name limits, char signedness, errno, the whole mess of #include paths and name conflicts, functions you can never safely use (tmpnam(), gets(), atoi(), signal()), ...

Not Again

Posted Apr 20, 2012 17:23 UTC (Fri) by juliank (subscriber, #45896) [Link]

Of course. I just wanted to point out something that most people most likely don't know about.

Not Again

Posted Apr 17, 2012 11:02 UTC (Tue) by dskoll (subscriber, #1630) [Link]

Wow... you are so far off base I have no idea where to begin. Did you even read the article? It pointed out the myriad of ways in which PHP is absolutely horrible. Why don't you argue with the article using technical arguments? Oh, right... because there aren't any technical arguments for PHP...

Not Again

Posted Apr 17, 2012 14:53 UTC (Tue) by davide.del.vento (guest, #59196) [Link]

> Java, If ORACLE win at trial Java is DEAD

You'd better document yourself before spitting non-sense. Most of the crap Oracle was claiming has been already proved invalid, or not applicable. Google in a sense has already won.

http://www.groklaw.net/article.php?story=20120416085550303

Not Again

Posted Apr 17, 2012 18:51 UTC (Tue) by dlang (✭ supporter ✭, #313) [Link]

Yes, but what remains is that Oracle is claiming that they control the library API and anything that closely resembles the API, not just their implementation of it.

If they actually do control any use of the API calls, they own every program ever written in JAVA.

Not Again

Posted Apr 17, 2012 21:10 UTC (Tue) by brianomahoney (subscriber, #6206) [Link]

Spitting nonsense? Just see how long the enterprise puts up with the "Our business plan is to sue our customers" and see how that worked out for SCO and Sonny.

This wont be over, with Ellison's ego till it is heard, en blanc, by the Supreem Court. I know, they should withdraw and slink away but they have also wrecked the JCP and alienated Apache.

Not Again

Posted Apr 18, 2012 19:07 UTC (Wed) by jthill (guest, #56558) [Link]

Thank you for explaining why C++ is an evil language that should not be used.

Not Again

Posted Apr 20, 2012 3:53 UTC (Fri) by IanJ (guest, #84238) [Link]

Right, not again. You start with "Ever little while I come across some self-important dumbass who explains why XXX is an evil language"

Later you accuse someone else of being the first to descend into ad hominem attacks. Well, what do you understand by the phrase "self-important dumbass"?

You seem to have very little idea of reality or history. ALGOL came out being careful to make a real structured language avoiding all the mistakes of FORTRAN and discarding machine dependence of machine language. It really was about making processors that execute our programs, rather than using programs as a mechanism to instruct computers (that thought due to Dijkstra... another dumbass).

C came along and put some structured programming over a machine language, but put back in the faults of FORTRAN (using = for assignment), and machine language. It was a big step backwards but has been successfully defended against better alternatives by launching angry attacks against any and all improvements.

C is not an evil language. But because of its flaws it can be used in an evil way - viruses, worms, etc are all possible because of lack of bounds checking. C is just a bad tool.

Yes programming is hard, we need all the help we can get. It's not just a matter of saying "trust programmers they know what they are doing". The best programmers admit it is difficult and too often there are things we don't spot and can use the help of automatic type checking.

I'll say no more. C and C++ are languages that are really lacking:

http://www.ianjoyner.name/Ian_Joyner/C++.html

It's time to move on and get real programming principles back.

Not Again

Posted Apr 20, 2012 10:42 UTC (Fri) by dgm (subscriber, #49227) [Link]

> C is not an evil language. But because of its flaws it can be used in an evil way - viruses, worms, etc are all possible because of lack of bounds checking. C is just a bad tool.

Absurd. There any _many_ ways a program can be thwarted into running attacked controlled code, improper bounds checking is just one of them.

C is a superb tool, just not for everything. It's a very powerful tool that requires skill and knowledge, but so do most computer languages (even Logo!).

And everything can be used in evil ways. Can you point out any (Turing-complete) language that is not capable of doing bad?

Not Again

Posted Apr 20, 2012 11:17 UTC (Fri) by mpr22 (subscriber, #60784) [Link]

C and C++ continue to thrive partly because their detractors seem to be incapable of agreeing on what the replacement should be. Alice likes D. Bob likes Java. Charlie likes Ada. Deirdre likes Haskell. Eddie likes Forth. Francine likes Python. George likes Modula-3. Henrietta likes Oberon. (etc)

T_PAAMAYIM_NEKUDOTAYIM

Posted Apr 17, 2012 4:54 UTC (Tue) by pr1268 (subscriber, #24648) [Link]

Wow! I've never seen that before. (Of course, it's been a few years since I last touched PHP code.)

I'm tempted to create a new LWN login account under the username T_PAAMAYIM_NEKUDOTAYIM just for kicks -n- grins. (Just kidding.)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 5:45 UTC (Tue) by slashdot (guest, #22014) [Link]

Wow, I knew it was bad, but didn't realize it was so terrible.

According to a table it links, in PHP, "php" == 0 is true (although it might actually be appropriate for that particular string.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 8:54 UTC (Tue) by tialaramex (subscriber, #21167) [Link]

I love the result that the operator == is not transitive. That's genuinely brilliant, like COME FROM or a rule requiring you to write integer constants in Roman Numerals.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 16:06 UTC (Tue) by dtlin (✭ supporter ✭, #36537) [Link]

To be fair, == isn't transitive in Javascript either.
0  == '';   // true
0  == '0';  // true
'' == '0';  // false

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 16:18 UTC (Tue) by k8to (subscriber, #15413) [Link]

Javascript is a mix of acceptable, interesting, and terrible. The terrible is bounded and javascript professionals must learn to avoid it as part of their work. Tools are built which help to find and avoid these problems, and books are written that guide us in using it acceptably.

PHP is.. well.. the article says it better than I can. There's no book titled "PHP, The Good Parts."

I guess what I'm saying is the "to be fair" thing just damns them both, but Javascript is salvageable, and we sort of must if we wish to program web pages, though we can hope for salvation from Dart.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 16:33 UTC (Tue) by HelloWorld (guest, #56129) [Link]

> though we can hope for salvation from Dart.
Yeah right, a language with explicit typing, the null problem and an unsound type system. Dart is broken, and unlike JavaScript, it's not even widely supported.

If you actually want a sensible language for web development, try js_of_ocaml.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 17:35 UTC (Tue) by k8to (subscriber, #15413) [Link]

Sorry if it wasn't obvious; it was meant as dark humor.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 18:11 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

I'm actually looking at Kotlin right now. It supports compilation into JavaScript and it's fairly OK as languages go.

BTW, it has explicit nullable types.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 19:13 UTC (Tue) by nix (subscriber, #2304) [Link]

Why did I not know about js_of_ocaml before now? Talk about concentrated awesome. (There must be some catch.)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 16:30 UTC (Tue) by khim (subscriber, #9252) [Link]

This is old news. And yes, JavaScript is almost as terrible as PHP. In some sense it's worse then PHP because with PHP you can just say no while JavaScript is often unavoidable. Even if you use something like ASP.NET or GWT you still sometimes need to delve unto generated JavaScript.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 15:59 UTC (Wed) by HelloWorld (guest, #56129) [Link]

JavaScript isn't unavoidable, there are compilers for sane languages that generate JavaScript output. One such compiler is js_of_ocaml.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 17:03 UTC (Tue) by butlerm (subscriber, #13312) [Link]

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 17:32 UTC (Tue) by nybble41 (subscriber, #55106) [Link]

No, I'm pretty sure they meant "transitive". Commutative is (A == B) <=> (B == A). Transitive is (A == B) && (B == C) <=> (A == C).

> To be fair, == isn't transitive in Javascript either.
>
> 0 == ''; // true
> 0 == '0'; // true
> '' == '0'; // false

The first line is backwards, strictly speaking, but ('' == 0) is also true. Substituting that form, we have A = '', B = 0, and C = '0'. (A == B) and (B == C) are thus both true, but (A == C) is false, so the relation is not transitive.

Equality may not be commutative in all cases, either, but for that you would need different examples. All of the cases listed here are commutative.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 15:08 UTC (Wed) by k3ninho (subscriber, #50375) [Link]

Commutivity is more-often defined in terms of the sequence you use operators. It's not obvious, but Equality is the operator in your example. An alternative example: Commutative means that, for functions A:x->x, B:x->x: A(B(x)) == B(A(x)).

K3n.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 19:43 UTC (Wed) by dtlin (✭ supporter ✭, #36537) [Link]

Indeed. The word for a == bb == a is reflexive.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 20:18 UTC (Wed) by nybble41 (subscriber, #55106) [Link]

> Indeed. The word for a == b iff b == a is reflexive.

The answer is "both". The equality _relation_ is reflexive. The equality _operation_ is commutative.

> Commutative means that, for functions A:x->x, B:x->x: A(B(x)) == B(A(x)).

This doesn't fit any definition of "commutative" I was able to find. Every case I could locate involved the order of _operands_ to a single _binary_ function. Of course, you can turn you example into something like that, though with slightly different types, using higher-order functions (in pseudo-Haskell):

f1, f2 :: (a -> b) -> b
f1 = \f -> f A
f2 = \f -> f B
f1 (f2 (==)) == f2 (f1 (==))

but that is equivalent to the much simpler form:

(==) B A == (==) A B

or:

(B == A) == (A == B)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 22:55 UTC (Thu) by mmorrow (subscriber, #83845) [Link]

>> Commutative means that, for functions A:x->x, B:x->x: A(B(x)) == B(A(x)).

> This doesn't fit any definition of "commutative" I was able to find.
> Every case I could locate involved the order of _operands_ to a single _binary_ function.

The elusive binary operator here is function composition ;)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 23:14 UTC (Thu) by mmorrow (subscriber, #83845) [Link]

> The elusive binary operator here is function composition ;)

A reference for the interested being:
http://en.wikipedia.org/wiki/Centralizer_and_normalizer

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 0:03 UTC (Fri) by nybble41 (subscriber, #55106) [Link]

>>> Commutative means that, for functions A:x->x, B:x->x: A(B(x)) == B(A(x)).
> The elusive binary operator here is function composition ;)

I thought you were presenting a general version of the commutative property, not a specialized version for function composition. That explains why I couldn't reconcile your example with other commutative operators (equality, addition, multiplication) without making "x" the operator and "A" and "B", in essence, the parameters.

Writing "(A . B)(x) == (B . A)(x)" or "A . B == B . A" would make the commutative part of the formula a bit more visible--not that it was really hidden. I just wasn't looking at it from the right perspective.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 0:29 UTC (Fri) by mmorrow (subscriber, #83845) [Link]

> I thought you were..

(I wasn't the author of the original comment.)

> Writing "(A . B)(x) == (B . A)(x)" or "A . B == B . A" would make the commutative part of the formula a bit more visible..

It definitely would have made it clearer.

> ..a general version of the commutative property, not a specialized version for function composition..

Ah, but actually the case where a binary operator is commutative over its entire domain is the special case (in the mathematical sense, blah).

It's just that in programming we don't often (explcitly) deal with non-commutative binary operators, and even less often with non-commutative operators which are commutative when restricted to a subset of their domain.

Here's a quick roughly-phrased example:

Consider a rubik's cube. Think of a "move" as a function which maps a cube configuration to another configuration. This is a non-commutative group with elements these cube-config-maps and binary operator function composition. Now, for any two moves f and g which don't "interfere" (e.g. rotate top, rotate bottom), (f . g) == (g . f).

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 1:13 UTC (Fri) by mmorrow (subscriber, #83845) [Link]

Here's a better example:

The "elements" are C stmts thought of as mappings of memory configurations, and the binary operator is `;`. This is a monoid with identity element the empty C stmt.

Define,

modify(S) := the set of memory locations statement S *may* modify.

So now, `;` is commutative for every pair of statements S,T which *must not* (i.e. cannot under any possible dynamic execution path) modify one or more of the same memory locations.

(S ; T)===(T ; S) <==> modify(S)/\modify(T)==empty_set

(where "===" := equivalence wrt effect on memory)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 1:37 UTC (Fri) by mmorrow (subscriber, #83845) [Link]

Actually that's not quite correct, it's more like:

(S ; T)===(T ; S)
<==>
modify(S)/\modify(T)==empty_set
AND
read(S)/\modify(T)==empty_set
AND
read(T)/\modify(S)==empty_set

or something along these lines, but the idea is clear.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 8:19 UTC (Fri) by mpr22 (subscriber, #60784) [Link]

Programmers tell their programs to subtract, divide, and/or shift fairly frequently.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 15:01 UTC (Thu) by yaap (subscriber, #71398) [Link]

What you wrote is commutativity not reflexivity. Reflexivity for equality is the fact that "a == a" is true for all a.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 17:37 UTC (Tue) by k8to (subscriber, #15413) [Link]

More on this javascript behavior can be found in this highly intellectual talk.

https://www.destroyallsoftware.com/talks/wat

(Okay I'm lying, but it's funny!)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 21, 2012 16:10 UTC (Sat) by IkeTo (subscriber, #2122) [Link]

But === is not transitive even for Java! (Exercise: Try figuring out the type T1, T2 and T3, and values v1, v2 and v3, causing:

T1 a = v1;
T2 b = v2;
T3 c = v3;
System.out.println(a == b && b == c && a != c); // print "true"
)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 22, 2012 10:02 UTC (Sun) by ajf (subscriber, #10844) [Link]

I don't have a compiler at hand here, but auto-boxing introduced in Java 5 is usually the culprit behind "surprising" Java behaviour. I sometimes have Eclipse configured to mark up implicit conversion between primitive and boxed object (but to be honest it's usually not worth it; I've never encountered any such surprises anywhere other than intentional puzzles like yours).

One possible answer, then, would be that T1 and T3 are Integer, while T2 is int; v1 and v3 are both new Integer(1000), and v2 is 1000. The a == b and b == c expressions will un-box a and c respectively, but a == c will compare object references (and find them different since both were constructed with new).

Another fun quirk only ever encountered in puzzles like this: if you change v1 and v3 to, say, 7, (ie, a primitive value that will be boxed in order to be assigned to a and c), you'll get "false" instead, because a != c will be false, since Integer.valueOf(int) (which is the method called to convert the primitive values to Integer objects to be assigned to a and c) happens to maintain a pool of Integer objects for small values, and will return the same value for both a and c.

Getting back to the topic at hand, the difference to note here is that these are carefully-crafted puzzles in Java; the problem with PHP is that quirks like this are something you more or less always have to think about when you're writing PHP.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 22, 2012 12:25 UTC (Sun) by IkeTo (subscriber, #2122) [Link]

You're right. The following program exhibit the said behavior:

public class T {
    public static void main(String[] args) {
        Integer a = 1000;
        int b = 1000;
        Integer c = 1000;
        System.out.println(a == b && b == c && a != c);
    }
}

Amazingly, there is another ways to cause the said behavior using only primitive types. (See IPSC 2008 Problem C).

And yes, I just try to be humorous when I said "even Java equality is not transitive". PHP is so horribly broken that I won't even touch it with a ten feet pole.

On the other hand, if even the very well specified Java language has non-transitive equality, you can expect that most other languages have similar behavior. One thus cannot just say a language is bad because of it. Instead, one would instead say something like "PHP equality has very surprising behavior that makes it very undesirable for programmers".

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 22, 2012 18:24 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link]

Well, use of equality for object types in Java is dangerous. Which is told in every textbook on it.

On the other hand, the real equality comparison operation ('equals' method) is transitive and commutative. Well, unless you screw it up intentionally.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 26, 2012 0:10 UTC (Thu) by IkeTo (subscriber, #2122) [Link]

It depends on what you call "screw it up intentionally". The following program output "true" for most numbers larger than 16777216 or smaller than -16777217. It is 127/128 of the range [-2^31, 2^31-1] of int:

public class T {
    public static void main(String[] args) {
        int a = Integer.parseInt(args[0]);
        float b = a;
        int c = a + 1;
        System.out.println(a == b && b == c && a != c);
    }
}
Similar behavior can be found if you replace int by long and float by double.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 26, 2012 1:50 UTC (Thu) by Cyberax (✭ supporter ✭, #52523) [Link]

That's completely expected and correct behavior of equality comparisons involving floating point numbers. It's also noted in every textbook under the DO NOT USE category.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 6:07 UTC (Tue) by frazier (guest, #3060) [Link]

The power in PHP is that many web problems are pretty much already solved in software written in PHP. With WordPress or Drupal you have a largely complete solution for many web projects, and the source and/or structure is there to add on the pieces if needed.

Particularly with small web projects, PHP is great because cheap hosting is plentiful + WordPress is really handy. None of this excuses design inconsistencies in the language, but it does explain why PHP use is so common.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 6:42 UTC (Tue) by marcH (guest, #57642) [Link]

Summary:
Barely good enough + first to market => WIN!

Sprinkle with appropriate vendor lock-in and you get: WIN FOREVER

Early mover is a myth

Posted Apr 17, 2012 8:04 UTC (Tue) by job (guest, #670) [Link]

If that were true, we'd all be coding Perl.

PHP won because mod_php enabled cheap shared hosting. It created a whole new market and exploded in popularity.

It's a market that other languages ten years still doesn't compete in. Only Microsoft really tried and they couldn't even make deployment work consistently across their products.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 8:16 UTC (Tue) by dlang (✭ supporter ✭, #313) [Link]

> Barely good enough + first to market => WIN!

well, Yes

release early, release often is the core of opensource programming.

It requires that the code be 'good enough' (even if barely) and that you update it at a sufficient velocity that competitors can't catch up.

note that 'good enough' will have different meanings for different people, so what is 'good enough' for one use-case may not be for others.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 6:39 UTC (Tue) by Chousuke (subscriber, #54562) [Link]

As far as I can tell, PHP has nothing to offer as a language. It just happened to hit a niche in its time and got popular; therefore today we have working, mature software written in it.

PHP should get the COBOL treatment. Keep the existing software, but... Why would you use it for anything new, when almost anything else would serve better?

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 7:40 UTC (Tue) by khim (subscriber, #9252) [Link]

PHP awfulness and it's popularity are two sides of the same coin: PHP is built to keep chugging along at all costs. When faced with either doing something nonsensical or aborting with an error, it will do something nonsensical. Anything is better than nothing.

This is what makes it usable for non-programmers (it's actually pretty easy to create something which works if you use it just right) and this is what makes it bad fit for the large projects. Sadly successful small projects tend to grow thus we are stuck with this abomination.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 9:20 UTC (Tue) by tialaramex (subscriber, #21167) [Link]

Excel is the same way. Every big number-crunching outfit knows that you mustn't build big important things out of Excel, even if they had to learn that the hard way. Yet, inevitably, somebody in those outfits is doing something in Excel because it was fast and they knew how. One day their pet project will get scaled up and it'll fall to pieces because it's built out of Excel when it really shouldn't be.

Excel has lots of the same frustrating properties. For example reluctance to announce failure (always better to eat reference errors, invalid inputs, etc. and spit out a superficially plausible answer anyway). But backwards compatibility is vital, so most of the problems can never be fixed, or if they are, they'll cause even more unexpected pain and misery for existing users.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 15:47 UTC (Tue) by drag (subscriber, #31333) [Link]

The financial industry runs on Excel.

Most people would think that the large banks, financial execuatives, and top teir accountants would use all sorts of fancy custom software for doing taxes, accounts, figuring out contracts and business loans...

This is far from the reality.

The truth is that while they have custom apps like any other large business, Excel front-end tied to real databases is the principal application. That is app #1.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 16:58 UTC (Tue) by sorpigal (subscriber, #36106) [Link]

The situation is the same for MS Access, only so much worse. Excel's is bug-free, predictable and of limited scope (at least by comparison). There's only so much trouble you can get in to with Excel, with Access you generally shoot yourself in the foot in slow-motion such that nothing really works but no one can tell until months or years down the line when it finally is revealed that all that excellent data you'd been basing your operations on is:

(1) Incomplete
(2) Incorrect
(3) Viewable by Timmy the intern
(3) Deletable by Timmy the intern
(3) Gone (and no one can find Timmy)

This is what happens when rank amateurs are left in charge of database design on a DBMS which allows you to get away with anything and relegates access control to an optional afterthought.

To keep this topical, I think the bad reputation of PHP web apps can be partly blamed on MySQL. If ever a language like PHP could meet its perfect partner in doing friendly disservice to its users, mysql is it.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 10:31 UTC (Tue) by bersl2 (subscriber, #34928) [Link]

Well, except when it's faced with doing something expected... then it errors out.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 7:36 UTC (Tue) by kmike (guest, #5260) [Link]

It's a bit ironic reading this here at LWN which was powered by PHP in the early 2000's (google for "lwn phtml" or "lwn php3").

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 7:41 UTC (Tue) by kmike (guest, #5260) [Link]

Reply fail... was intended for another comment. Please delete!

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 7:51 UTC (Tue) by koch (subscriber, #55163) [Link]

I think PHP is the go-to language for people who have real projects they want to get done. I think this comment on BlitzMax, a BASIC environment for developing games is a nice insight. BlitzMax is used by people who wants to make games, not to program. PHP is used by people who wants to make sites, not to program.

BASIC is, like PHP, a horrible language, but it is used by people getting amazing things done without getting derailed about architecture, monads, or whatnot. I think, in addition to pointing at all the uglyness, low-entry alternatives should be pointed out. Why is PHP so successful? Can a decent language with the same level of popularity be created?

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 8:11 UTC (Tue) by slashdot (guest, #22014) [Link]

Java fits all this, and also has the best IDE overall (Eclipse JDT).

Use it.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 8:24 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

Surely, you're joking. The best IDE is IntelliJ IDEA.

And actually, I'll be switching to Kotlin ( http://confluence.jetbrains.net/display/Kotlin/Welcome ) once it's properly released. It's already WAY better than Java and already has outstanding IDE support (unlike Scala or other "me-too" JVM languages).

This thread now misses only emacs vs. vi flamewars. So somebody should post something about how emacs is obsoleted by modern IDEs to kick off another flamwar.

Ooops. I just did it.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 13:51 UTC (Tue) by SEJeff (subscriber, #51588) [Link]

Ok lets settle this once and for all... The best ide is vim and everyone knows it. vim + ctags/cscope = <3

In seriousness: This is one of the most off topic and awful bunch of comments I've ever seen on lwn. It even has one idiot saying mildly racist (against asians) comments. It is about time for the editors to step in and get this back into lwn land where people are civil and discussion is mostly technical. This isn't /. people, this is lwn.

Lets keep it in on topic folks.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 15:51 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

That's the power of PHP - it can even turn LWN into Slashdot!

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 14:37 UTC (Wed) by Thanatopsis (guest, #14019) [Link]

Very True. However you forgot to include DDD for debugging.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 8:58 UTC (Tue) by gidoca (subscriber, #62438) [Link]

I don't think it does, not for web development anyway. Way too much boilerplate code to get _anything_ running. I think one of the main reasons PHP is so popular with beginners is that you can write <?php phpinfo() ?> into a file and it works.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 9:03 UTC (Tue) by slashdot (guest, #22014) [Link]

JSP allows you to do exactly that:

<HTML>
<BODY>
Hello! The time is now <%= new java.util.Date() %>
</BODY>
</HTML>

This is not necessarily a good idea for larger projects though.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 11:16 UTC (Tue) by alankila (subscriber, #47141) [Link]

JSP -- probably best avoided if at all possible. I inherited an application that used JSP once, and find it an embarrassing piece of technology.

I personally use wicket for everything. But there's a bit of boilerplate there: you have to subclass WebApplication, and you must at the very least define the class which implements the web page rendered at the root of the website. Then you must give an implementation of that Page (the class file can be empty), then you get to write HTML.

I think that templates should have no evaluation capability whatsoever. In wicket's case, dynamic elements are marked with an xml attribute called wicket:id, for instance <div wicket:id="foo"/>, and then it's up to the Page to choose what is rendered into the element identified by name foo. The state of page is entirely on server side. Components can be replaced in the page tree to generate different kind of elements on the page dynamically in response to user interaction. For instance, foo could start out without content, but become replaced with a modal dialog instead when user interacts with some button or link on the page.

The real problem is with understanding the evaluation model. Wicket gives you an impression that you are actually working with a desktop application, because page instances are kept alive on server and access to the same page will automatically preserve the state of the members, so you get state saving for free. That means improved chance to write secure code, as you don't have to write things into form hiddens, or put them into session hashmap where multiple tabs/windows in same session could trample all over each other. But most astonishingly: page instances are versioned, and requests so if the user uses back button, wicket actually resurrects an earlier version of the page to handle that request, which cleanly allows user to back out from choices made earlier (provided they did not cause permanent state changes to components outside wicket).

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 13:07 UTC (Tue) by canatella (subscriber, #6745) [Link]

At the time, installing apache + php + mysql was just a simple apt-get away. Running jsp required finding and installing the sun jre just to see that for this you needed the sdk then setting up tomcat (not that simple), learn how to setup all those xml files needed, generate a war file to be able to deploy your application. And nobody was providing cheap hosting for java application.

So yes for a newbie/amateur, PHP was the easy/quick solution.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 19:24 UTC (Tue) by drag (subscriber, #31333) [Link]

For the longest time php + mysql was your only option. It wasn't until VPS got cheaper that people could really start playing around with things like ruby on rails or python without a bunch of headaches.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 13:02 UTC (Wed) by ekj (guest, #1524) [Link]

Yeah. And this advantage shouldn't be underestimated. I tend to use django these days.

But for an average non-programmer with some el-cheapo web-hosting, the steps needed and the concepts to learn *before* he can run "hello world" can easily consume a week, that is, if his host supports django at all.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 11:34 UTC (Wed) by robert_s (subscriber, #42402) [Link]

Stop. If you think Java is a good language something is going very wrong with your life.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 18:07 UTC (Wed) by juliank (subscriber, #45896) [Link]

What's the problem with the Java language?

* Syntax?
* Semantics?
* Standard APIs?
* The virtual machine?

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 23:10 UTC (Fri) by mathstuf (subscriber, #69389) [Link]

After an attempt at doing some Android development, the main things that bugged me (in no particular order). I do not claim to have a high familiarity with Java, but these things didn't have obvious solutions.

- Eclipse (Using it from vim via eclim is…bearable; I haven't been able to get gvim embedded at all)
- No typedef mechanism
- Excessively wordy API symbols
- One-class-per-file restriction
- Functions aren't first-class types
- as{Int,Double} Cursor methods (Just store the actual type; the DB already knows this (or should…)!)

That said, some things that Java does right:

- I wish final was in C++ (const doesn't really work for vectors unless you required C++11)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 23:16 UTC (Fri) by Cyberax (✭ supporter ✭, #52523) [Link]

Try IntelliJ IDEA. It's so much better than Eclipse and has VI emulation (IdeaVIM plugin). The community version of IDEA (it's OpenSource under GPL) is more than enough for Android devel.

Aaand, IDEA developers are now creating a very nice language - Kotlin, which is compatible with Java and works fine on Android. And unlike most of other JVM-based langs it has splendid IDE support from the start (it was developed as IDEA plugin at first).

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 22, 2012 2:35 UTC (Sun) by mathstuf (subscriber, #69389) [Link]

It's packaged for Fedora, but seems to be languishing[1] :/ . As for Kotlin, I'm a big fan of explicit nullables.

[1]http://koji.fedoraproject.org/koji/packageinfo?packageID=...

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 22, 2012 2:48 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link]

Just download it from their site. It's not hard to setup (just un-tar it and run idea.sh).

Yeah, I really like the explicit nullable ('Maybe' monad from Haskell!), it's much nicer to use than Scala's clusterf#$k with Options. Besides, Kotlin developers are now busy annotating the standard library with nullables.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 11:12 UTC (Tue) by nmav (subscriber, #34036) [Link]

Very nice and sensible comment.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 16:15 UTC (Tue) by HelloWorld (guest, #56129) [Link]

> I think PHP is the go-to language for people who have real projects they want to get done.
The exact opposite is true. People ridicule PHP because it's actually a royal PITA for anyone trying to get something meaningful done. It's unproductive, it's error-prone, yet people keep making up this nonsense about PHP being better to get things done. I'll probably never understand why...

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 17:59 UTC (Tue) by Zizzle (guest, #67739) [Link]

PHP lets people get busy writing gaping security holes you mean.

Non-programmers screwing up a game is one thing. No one gets hurt.

Me entering my credit card details for a purchase into a PHP web app written by a non-programmer is another thing.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 5:59 UTC (Wed) by koch (subscriber, #55163) [Link]

I agree that using PHP is terribly bad, but what is the "obvious" alternative for someone who has a good idea? The problem is, good ideas doesn't necessarily come from programmers, but from people who wants to get started on some good idea.

Of course, it will bite them in the future, and many many of the things you cite can be avoided using a language with sane semantics, but what? Java cited above is hardly entry-level. ASP/.net or whatever it's called is probably the real-world alternative. I don't know how good/bad this is, but it's probably no worse than PHP.

Agreed, entering credit card detail written by a non-programmer in any language is certainly a bad idea. But not all good-idea sites needs to accept data like this.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 8:28 UTC (Wed) by HelloWorld (guest, #56129) [Link]

> I agree that using PHP is terribly bad, but what is the "obvious" alternative for someone who has a good idea?
There are tons of them, such as Ruby on Rails.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 17:58 UTC (Wed) by roskegg (subscriber, #105) [Link]

Ruby has its set of security problems. Django+Python is a better option. Personally I favor newLISP for almost everything. It is a really sweet and consistent little language, comes with a built in web server. http://newlisp.org/

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 19:25 UTC (Wed) by HelloWorld (guest, #56129) [Link]

> Ruby has its set of security problems.
I didn't say Ruby doesn't have problems, but it doesn't have nearly as many as PHP.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 7:52 UTC (Tue) by bersl2 (subscriber, #34928) [Link]

Eevee, you've stirred up a storm once again, you magnificent bastard.

And yet

Posted Apr 17, 2012 16:21 UTC (Tue) by jwarnica (subscriber, #27492) [Link]

Despite all of those things, PHP is used by both professional developers and people who shouldn't so much as turn on a computer, to do productive and useful things.

Sour grapes.

And yet

Posted Apr 17, 2012 16:50 UTC (Tue) by k8to (subscriber, #15413) [Link]

Sour grapes means that you can't have something, so you decide that it must be bad as a way of salving your frustration/denial.

Ie.
Can I have some grapes?
No.
Well, they were sour anyway, I bet.

I'm not sure how that's relevant here.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 19:21 UTC (Tue) by nix (subscriber, #2304) [Link]

It's an impressive condemnation of the mass of horrible misdesign which is PHP, but I was most impressed by this evidence of the grotesqueness of the internals.

Because when trying to avoid integer-overflow bugs, the right solution to detect an input that will wrap at INT_MAX is to compute the size of your memory regions using floating point! (Sure, malloc() still takes a size_t, but I'm sure it'll be able to allocate a floating-point number of bits anytime soon. Just wait.)

(In their defence, they did fix this once they were embarrassed about it in public... but nobody writing code for public consumption should commit horrors like that. Nobody.)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 17, 2012 20:24 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

Gah.

Can we ask INTERCAL maintainers to give PHP developers a hand? They'll fit right in!

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 9:30 UTC (Wed) by alankila (subscriber, #47141) [Link]

And it was a single-precision floating point, if that above is to be believed. Meaning that once allocation grew large enough, somewhere above 16M, there was a round-off error because the lowest bits aren't accurate after integer conversion.

Impressive and truly sad.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 18:09 UTC (Wed) by nix (subscriber, #2304) [Link]

They could have compensated for this by adding an appropriate amount to the final value (wasting a bit of memory), but nooo... so the thing is as likely to error on the low side as on the high side, and they actually managed to introduce a security hole while trying to fix another one. A security hole that I'm fairly sure nobody else has ever introduced (how many floating-point rounding memory allocation bugs can there be in the world?)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 18:26 UTC (Wed) by juliank (subscriber, #45896) [Link]

I also count byte sizes in floating point to avoid overflows, but certainly not for memory allocations. No problem for me, as my code does not have to be very fast when calculating things. And because I convert to floating point anyway, as I want to display human-readable sizes with %.3f digits.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 23:34 UTC (Wed) by cmccabe (guest, #60281) [Link]

I doubt that using floats rather than 64-bit integers is saving you any typing.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 8:15 UTC (Thu) by juliank (subscriber, #45896) [Link]

It doesn't when counting, but since I have to convert to double later on anyway, I can just count in double as well.

I could perhaps rewrite the human-readable size formatting to use integers (i.e. print B,KiB,MiB,GiB, TiB), but if I want precision after the period, things will start to get more complicated. And I usually want that precision.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 18, 2012 20:09 UTC (Wed) by dskoll (subscriber, #1630) [Link]

The other WTF in that bit of code is that sizeof(char) is by definition 1.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 11:20 UTC (Thu) by rev (guest, #15082) [Link]

Well, that, in my not so humble opinion, they did right.

As a general rule if Y has knowledge about X, and one needs attribute a of X, one needs to query Y for X.a: SPOD.

Here, Y=the compiler, X=char and a=sizeof().

There is really no point in relying on sizeof(char) equaling 1. Demonstrating one's macho-ness knowing all this little details about the language to oneself and ones peers? Optimization? Any decent compiler will optimize sizeof(char) away. Saves typing?

Hardwiring sizeof(char)==1 violates the SPOD principle.

In general, relying on this fact implicitly is even worse: it reduces the maintainability of code. Sooner or later the char in my function is going to be changed. Say to w_char_t. 'malloc((size_t) num)' is likely to be overlooked by me or, somewhat less likely, by my peers, leading to spurious problems. 'malloc(num * sizeof(char))' is likely to be caught on the first pass. Thus, using sizeof(char) makes my code more maintainable.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 14:39 UTC (Thu) by nye (guest, #51576) [Link]

I think that can be summed up as 'avoid magic constants'.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 15:34 UTC (Fri) by rev (guest, #15082) [Link]

Nearly.

Defining a constant for sizeof(char) still leaves us with a SPOD violation: AMC: yes, SPOD: no.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 23:18 UTC (Fri) by mathstuf (subscriber, #69389) [Link]

What do SPOD and AMC stand for here?

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 21, 2012 0:05 UTC (Sat) by neilbrown (subscriber, #359) [Link]

AMC is "Avoid Magic Constants".

I'm guessing SPOD is "Single Point of Departure".

PHP: a fractal of bad design (fuzzy notepad)

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

Single Point Of Definition.

Sorry, I thought the meanings of the acronyms where obvious from the context.

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 21, 2012 18:26 UTC (Sat) by mathstuf (subscriber, #69389) [Link]

I had just never come across them before (AMC is strongly tied to the car manufacturer in my mind and SPOD is new).

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 17:26 UTC (Fri) by apoelstra (subscriber, #75205) [Link]

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.)

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.)

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 19, 2012 11:39 UTC (Thu) by tititou (subscriber, #75162) [Link]

Maybe unrelated but interesting anyway (IMO), here is a monthly updated comparison of the use of different programming languages over the time:
tiobe

As stated in the article, "Observe that the TIOBE index is not about the best programming language or the language in which most lines of code have been written".

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 8:41 UTC (Fri) by geuder (subscriber, #62854) [Link]

PHP: a fractal of bad design (fuzzy notepad)

Posted Apr 20, 2012 15:44 UTC (Fri) by rev (guest, #15082) [Link]

What better way of exposing the 'just want to get a job done' attitude for what it is than this.

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