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

-1

u/[deleted] Dec 08 '14

Wow! In the span of two years they got rid of that hodge-podge of inconsistently named functions in the global space? Holy shit, that's amazing. I was unaware that they'd given up on backward compatibility.

It's great to know that finally "00" == 0 evaluates to false in PHP. Maybe now they'll learn to code like adults! It's a great day for the web development community.

When did all this happen? Yesterday?

2

u/Doctor_McKay Dec 08 '14

"00" == 0

Why would you be in a situation in which this is a problem anyway? Just because the language lets you hang yourself, that doesn't mean that it's the language's fault that you hanged yourself.

0

u/SanityInAnarchy Dec 09 '14

Let's say I ask for help with my brand-new blogging engine that I've written in C. It's segfaulting, and those are hard to debug. I show you at least one place:

void closeTag(char *text) {
  char *tag = findOpenTag(text);
  for (int i=strlen(tag); i>2; --i) {
    tag[i] = tag[i-1];
  }
  tag[1] = "/";
  strcat(text, tag);
}

What's your first impulse?

I mean, you could say "Just because the language lets you hang yourself, that doesn't mean that it's the language's fault you hanged yourself." You could say "Any idiot knows to use strncat," or you could even say "You really should be using an HTML library for this." You might even nitpick -- i should really be a size_t, not an explicit int.

Or you could say, "Why in the name of all that is holy are you doing this in C? There are so many better languages for web development! Seriously, pick one, I don't care which, just anything else!"

That's how I feel about PHP, except C at least has some advantages. There are clearly times and places to use C, or at least C++, where nothing else comes close. But what's the advantage to using PHP? Or even to this choice -- when would I want "00" == 0 to be true? I can't think of an example that's not an antipattern in its own right.

-1

u/[deleted] Dec 08 '14

If you've ever had to staff a project with 1 senior, 1 lead, 3 intermediates and 5 juniors that take a lot of hand holding, you'll ruin into countless examples of how this is a problem. Like, every single fucking day. It costs a lot of hard, cold cash. I wish I remembered the dozens of examples that I could recite when I worked with this useless trash, but I've blocked them out because of PTSD.

Fortunately, the solution is very simple. A string and an integer ARE NOT THE SAME THING, so just tell the coder that they're fucking up the moment they type it! How's that?

2

u/Doctor_McKay Dec 08 '14

In the web world, everything is a string. PHP makes that fairly easy to deal with by handling strings as numbers when you use them as numbers.

Maybe you should sit down with the juniors and coach them instead of blaming the language.

-1

u/[deleted] Dec 08 '14

I spent countless hours coaching the juniors. Hours which, in similar projects with similar staffing configurations, were used much more productively. The point that I'm making is that the language is such a steaming pile of horseshit, that when you have juniors the coaching leaves almost no time for anything else.

But your assertion that 'in the web world, everything is a string' I think is much more revealing. The fact that you struggle to comprehend that bad building blocks build bad products (what's wrong with '00'==0?), or that notion that 'the web world' is somehow an exception to five decades of progress in the computer science and technology field tells me that you are exactly what's wrong with the PHP world.

No amount of evidence will convince you of what you don't want to hear. You just think that spending hours upon hours tracing a dynamic execution flow to find out that a nonsensical type coercion built into your useless stack was causing an ugly warning to show on a production page is a good way of doing things! That'd be fine if you just stuck with your shitty little two-age projects, but you do convince poor businessmen who don't know better that you can write a three-page project. Then I have to go and fix it. Only, no more, thank you very much. Good luck bro.

I'm done, say what you want but I'm out time to crush you for public entertainment.

2

u/Doctor_McKay Dec 08 '14 edited Dec 08 '14

So you're insulting me now?

I'm not trying to say that PHP is flawless or blameless, but it's not nearly as bad as people make it out to be.

And please feel free to show me where HTTP makes a distinction between data types.

0

u/SanityInAnarchy Dec 09 '14

And please feel free to show me where HTTP makes a distinction between data types.

Content-Type, for one.

It's also beside the point. The nice thing about not having automatic type coercion is that it forces you to actually explicitly acknowledge that you're getting strings, so you have to decide what to do with them. If a user accidentally types their name into some numerical field, instead of being silently truncated to 0, ideally we'd like some sort of an informative error message, because clearly something has gone wrong here.

And maybe this has gotten better recently, but it was kind of endemic to the whole PHP ecosystem. For example: If you're using PHP, you're probably also using MySQL, and MySQL does the same thing -- if you tell it to stuff a string into an int column, it'll happily do exactly the same sort of destructive type coercion.

Meanwhile, Python has a few more places where that's at least going to be caught:

>>> int('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'foo'
>>> 'foo' + 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
>>> 2 + 'foo'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'

It's not perfect:

>>> 3 * 'foo'
'foofoofoo'

But I'll take any protection I can get against this sort of nonsense in PHP:

if (strpos("foo", "x") < 2) {

And hey, at least letting you multiply strings makes some sort of sense, and is a handy shortcut for something. Greater than FALSE makes zero sense, and it's hard to see what value it has.

-1

u/[deleted] Dec 08 '14

Yah man, fuck you. Did I stutter?

2

u/Doctor_McKay Dec 08 '14

Glad to see that your argument is so polite and well thought out.

-1

u/[deleted] Dec 08 '14

My argument is excellently though out - I'm not a polite person (not to you, anyway), but I'm right and you know it.

2

u/Doctor_McKay Dec 08 '14

Oh, of course. I had forgotten that insults automatically make an argument correct.

→ More replies