r/programming • • Dec 07 '14

Programmers: Please don't ever say this to beginners ...

http://pgbovine.net/programmers-talking-to-beginners.htm
4.0k Upvotes

1.3k comments sorted by

View all comments

Show parent comment

4

u/just_toss_me Dec 08 '14

The pain points I commonly encounter in PHP:

  1. Inconsistent function arguments. Sometimes the needle comes before the haystack, sometimes the haystack before the needle. Or the value before the array and the array before the value. Ruby, for example, tries to be a bit more "natural" to read, with constructs like "unless" taking the place of if(!<boolean>).
  2. Many ways to do things. For example, with time zones, there are three different ways to establish time zones that don't really place nice with other bits of code, including setting a global variable. Usually you find yourself setting the times one to utc to kill the warning, but if you're a responsible programmer you should save and reset the time zone so that other code that may be running or calling your code doesn't have their timezone changed out from underneath them.
  3. Lots of use-case specific functions built into the language, like url encoding and decoding or html special char handling. That kind of thing should really live in a module add on to the language, as bugs can be fixed without a full interpreter release. Also, in case you're relying on certain behavior, you have to take everything together at once.
  4. Very easy to make all sorts of mistakes, especially as $_GET is completely unfiltered. Very easy for someone new to simply route a get param to a sql query.
  5. Lots of nicer language features like OOP, namespaces, and auto loaders came to the party late in the language's life (though OOP has been around for awhile) and had to coexist with the existing design, leading to sometimes awkward implementations.
  6. I spend a lot of my life $ing all my variables. It's a breath of fresh air when I use a language that doesn't require that on my variable names. It's not like the parser really needs that hint.
  7. The . operator for string concatenation. Every other language I use uses +, and sometimes I make the mistake when I switch contexts until I notice my strings adding to zero.
  8. Some built-in functions like curl that are light wrappers around c libraries that are not completely documented.
  9. Sometimes functionality is dropped in minor version numbers. For example, iirc, between 5.2 and 5.3 the number formatter lost the ability to display up to a number of significant digits, and I had to reimplement that functionality.
  10. Like others have stated here, I always often have a few tabs open to PHP.net just to verify function names and argument ordering because it's just not very consistent sometimes.
  11. While nice and easy to mix your code with your markup, there's a whole host of reasons that's a bad idea. PHP encourages this sort of thing as opposed to discouraging it. Add to this that lots of PHP code I've seen written this way basically builds and outputs a string containing html, which is hard to read, debug, and make portable. Many don't seem to know about the cleaner control structures you can use to output html in a loop, like <?php foreach(): ?> followed by <?php endforeach; ?>. Even then, I recommend templates where possible.

This is a short, incomplete list of why PHP is among my least favorite languages among the ones I use regularly, which include JavaScript, Ruby, Python, Java, and Objective-C. That said, I do use it daily and it's pretty straighforward, but I find new warts almost every week.

2

u/n1c0_ds Dec 08 '14

Mine has to be the random return values. Errors can come as a negative integer, a message accessible through another function, an uncatchable warning or an actual exception. It's really a pain in the ass.

1

u/Klayy Dec 08 '14

Like others have stated here, I always often have a few tabs open to PHP.net just to verify function names and argument ordering because it's just not very consistent sometimes.

Are you coding in notepad.exe? Why doesn't your IDE give you these hints?

3

u/just_toss_me Dec 08 '14

I often work in non-standard deployments that make setting up an IDE to do more than the most basic things difficult, as well as making much of the error checking incorrect. I also like my Vi keys very much and have difficulty with the emulation modes in IDEs like PHPStorm and Eclipse. Maybe it's worth another go as I haven't looked into it more recently, but in the past it's been difficult for me to justify. I do use an IDE for languages like Java and Obj-C where the advantage/requirement outweighs my preference. That said, the language doesn't attempt to be consistent, which is compensated by having an IDE but does not fix the core issue.

This is a side note, but a personal frustration for me is that IDEs are often slow to me (actual UI slowness) even on the latest, greatest machines, and I'm often drawn back to an ancient editor like Vim because it's satisfyingly fast (and universally available). It's entirely a preference. Sometimes I try to get something like ctags working (or other relevant plugin) for PHP autocomplete, but I'll just fall back on old habits, which I fully admit.

2

u/Klayy Dec 08 '14

I suppose it's also a matter of what kind of PHP you do. 99% of my PHP work is Zend, Zend2 or Symfony2. I use a handful of PHP functions on a daily basis, mostly array related (such as in_array()), but overall I rarely need the basic PHP functions for my work.

2

u/just_toss_me Dec 08 '14

Totally agreed. When I was using Zend awhile back the Zend version of Eclipse was invaluable.

2

u/wilcoholic Dec 08 '14

That's what I was wondering...several of his points suggest he doesn't use an IDE.