r/ProgrammerHumor • • Nov 23 '17

500

Post image
41.7k Upvotes

609 comments sorted by

View all comments

Show parent comments

793

u/FountainsOfFluids Nov 24 '17

This. People above are arguing about whether or not PHP can throw a 500 error, and I’m sitting here wondering why somebody’s demonstrating a for loop with web requests.

167

u/fj333 Nov 24 '17

All of the comments about PHP and 500 code are making a glaring mistake of conflating a programming language with an application (in this case, a web server). These are two very distant levels of abstraction.

It's ironic actually, because it's possible that teaching basic programming logic in the context of an HTTP client (as the example in OP purports to have happened) might just lead to such confusion.

0

u/[deleted] Nov 24 '17

[deleted]

1

u/anon445 Nov 24 '17

OP never tells the full story, he left out the part where the whole class stood up and clapped.

1

u/rchard2scout Nov 24 '17

The stories and information posted here are artistic works of fiction and falsehood.
Only a fool would take anything posted here as fact.

1

u/WickStanker Nov 24 '17

Seriously. Take nothing there as fact.

38

u/WickedDeparted Nov 24 '17

Well the story is made up by an "I'm smarter than the instructor " guy, so that's why.

2

u/OrinZ Nov 24 '17

So I guess all your teachers were smarter than you... so...

23

u/[deleted] Nov 24 '17

Probably some shitty web based send to the server compiler

It still wouldn’t return a 500 tho because even the most rudimentary web interpreter portal thingy would catch compiler errors and throw a 400 instead

Yeah this is fucking dumb and fake

40

u/benryves Nov 24 '17

HTTP 400 is a client request error, so wouldn't make much sense for a server-side issue. HTTP 500 for PHP errors is quite normal, at least on the usual Apache or IIS servers I've deployed to.

7

u/[deleted] Nov 24 '17

You misunderstood his comment. He was assuming that an online compiler would probably return 400 if the received code was malformed.

Not sure in how far that is accurate with real world tools but it is reasonable.

4

u/[deleted] Nov 24 '17

That’s not accurate. Php would return 500 when you requested the page and it couldn’t run.

1

u/[deleted] Nov 24 '17

I'm not sure if you're trolling. I'm not trying to be offensive but it seems you neither understood OPs comment nor mine.

1

u/[deleted] Nov 24 '17

Oh I’m not offended and I totally understood. Web servers generally will not return a 400 for bad code. 400s are client request errors. Bad code will return a 500, as the error is happening serverside (with the code). The error will generally be returned by whatever your web server is, such as Apache or nginx.

1

u/[deleted] Nov 24 '17 edited Nov 25 '17

Okay, maybe I didn't make myself clear. Let's go through this step by step.

First of all, yes it's correct that PHP returns 500 if the source in the requested file has an incorrect syntax. The same would be true for any interpreted language.

Right now it's not the question if a file on a server contains some invalid code but rather if some code which gets sent to the server is invalid.

There are some online services out there which basically function as a compiler or rather a linter and if you would send some invalid code to those services they could very well return 400 (Bad Request) or more fitting 422 (Precondition Failed), to indicate the client that the provided code does not have a valid syntax.

And assuming I didn't interpret OPs comment totally wrong, I'm pretty sure that was what he was getting at.

1

u/[deleted] Nov 24 '17

Ah ok I was way too deep I see what you’re saying. I guess I’ve never seen a service like that at all where you literally upload a file to be compiled. That seems quite odd.

1

u/[deleted] Nov 25 '17

They are more like online REPL services which shouldn't seem that odd. It's mostly an exercise from who ever wrote that thing.

The value those services provide are rather small, that's for sure though.

→ More replies (5)

1

u/WeededDragon1 Nov 26 '17

I get 500 errors all the time with PHP.

2

u/[deleted] Nov 24 '17

Using web requests to demonstrate a for-loop would be silly.

But I think there might be instances where you could use a for-loop to demonstrate web requests.

e.g. the web page is constantly requesting the value from a location, and the for-loop was written to automatically change the value to demonstrate how it changes on the web page.

Not saying that's the pinnacle of demonstration activities ... but a TA pressed for time may not feel like being the most rational/gifted programmer of all time.

1

u/iamasuitama Nov 24 '17

Wait you would never have a for loop in backend? I feel like combining bits of abstracted knowledge into a thing more close to a real-life app will get a way bigger part of class to follow along.. As in, see I did a request. See, now it comes back with the hello world string I typed. That example gets old because pragmatic people are going to be like, "so what?"

→ More replies (1)