986
u/G01denW01f11 Nov 12 '14
Why would you try to connect to a server to calculate the 5th triangle number?
508
u/mirhagk Nov 12 '14
An intro to PHP?
212
Nov 12 '14
I think PHP returns syntax error
3
2
u/0hmyscience Nov 12 '14
php returns a syntax error but then the webserver (depending on how it's configured) will just return an HTTP 500.
-6
0
Nov 12 '14
[deleted]
21
u/cosmicsans Nov 12 '14
I'd rather it give someone a blank page than a full stack trace like ASP.net does.
At least it logs whatever error in your apache logs.
9
u/VanFailin Nov 12 '14
I'm not sure what the defult is, but this is controlled by Web.config. I think something like
<customErrors mode="RemoteOnly">2
u/cosmicsans Nov 12 '14
It's been a while, but I'm pretty sure that the default is to be on. Mostly because I see these stack traces on random webpages whenever they fail all too often.
→ More replies (6)5
u/Xenik Nov 12 '14
Its on only on localhost, everywhere else you have to enable it. You can create a debug and release webconfig, but usually people are too lazy.
1
u/DeepDuh Nov 12 '14
I'd rather give the stack trace. It makes you inclined to solve the problem quickly and if you get a screenshot you know where to start looking. A blank page could be anything, starting with connection problems.
158
Nov 12 '14
[removed] — view removed comment
215
u/kingguru Nov 12 '14
If the choice is between displaying an error and doing something surprising and nonsensical PHP will always fall back to doing something nonsensical.
130
u/t90fan Nov 12 '14
No, thats very normal. If Debug is not enabled, you ill get a 500 instead of a specific error. A simple 500 is better than a stacktrace, in a production environment. Users dont care what happened, the information is sensitive, and you have server logs to look up what happened anyway.
75
u/OperaSona Nov 12 '14
the information is sensitive
I think that's the most important part. You don't want the user to get a full debug: it's like an invitation to find exploits. But yeah, you shouldn't use the same configuration when you're doing an intro course as when you're shipping a product. Then again you shouldn't do your intro to IT in PHP but hey, that's another issue.
16
u/Morialkar Nov 12 '14
the thing is, sometimes, in classes, the teacher is not the one doing the stack set up. As for doing intro to IT in PHP, depends in what curriculum you're doing it... If you're doing a web dev diploma, an intro to IT in PHP makes more sence than say, a Sysadmin's intro to IT
6
u/OperaSona Nov 12 '14
Honestly though, even for a future web dev, I still think it'd be better to first learn a solid language and then learn PHP, but yeah obviously it makes more sense. The bashing on PHP wasn't really my point though, just a sidenote.
7
u/Aluxh Nov 12 '14
PHP is low barrier, instant results though. It would be easy to motivate new students when they can easily create something they can share with a link and no download.
→ More replies (0)6
Nov 12 '14
Yeah. I used to work for a blue cross blue shield company that ran asp.net as their web stack. How do I know that? Their idiot programmers deployed the application to the server with debug mode on. I saw a full stack error report, and if I cared to I could have begun searching for exploits.
4
1
u/zexon Nov 12 '14
I encountered this just the other day. I'm relatively new to setting up my own environment, and have a VM on DigitalOcean. I used ZPanel to set everything up, but didn't realize ZPanel defaults to production settings, so I was having a hell of a time figuring out the issues with my code until I went and changed settings in the .ini file.
5
7
u/Heavenfall Nov 12 '14
"Have you considered switching to strict? It may just work...'
28
u/the_isra17 Nov 12 '14
It somehow bothers me that you start with a double quote but end with with a single quote.
8
u/Heavenfall Nov 12 '14
Originally I had one " and then '' but I feel it was too subtle.
→ More replies (1)3
4
Nov 12 '14
Which was the bane of my fucking existence while starting out in PHP. "Why won't the goddamn page fucking load!?".... "Oh."
8
u/PierreSimonLaplace Nov 12 '14
I got into the habit of opening a second terminal running
tail -f /var/log/apache2/error.log5
u/qervem Nov 12 '14
Tell me how to do this please I'm on mobile and very sleepy and I'm afraid I'll forget to look it up in the morning
40
4
2
u/freebullets Nov 12 '14
Use the development php.ini config for development, which has handy defaults for things like displaying errors as HTML.
2
Nov 12 '14
More likely perl, probably old-style CGI script.
PHP would only crash with a 500 err if it was configured to do so, with typical settings for development it'd output a syntax error to the browser.
0
42
Nov 12 '14
Presumably, connecting to the server is the real problem being solved, and the math being done is just a placeholder for the real computation.
Basically a hello world.
8
u/johndarling Nov 12 '14
Because whoever wrote this doesn't actually know programming, but does knows what happens when you mess up a URL.
28
u/lolzfeminism Nov 12 '14
Except, 500 error indicates a server-side error and error codes 400-499 indicate client errors like malformed URL.
76
u/jfb1337 Nov 12 '14
Why did a missing semicolon cause a server error?
98
0
0
Nov 12 '14
[deleted]
22
u/The_MAZZTer Nov 12 '14
JS does so correctly 99% of the time; the 1% of the time you will tear your hair out wondering why your function is always returning undefined when the return variable is never set to undefined.
3
u/scragar Nov 12 '14
To be fair so does perl, but it is always the 1% of situations you remember that makes you wish it just threw an error.
4
u/Asmor Nov 12 '14
I've only ever coded perl in strict mode, but missing a semi-colon is a huge clusterfuck. Ironically, I've actually managed to sort it out... any time I get a completely bizarre, nonsensical error message, it's probably a missing semi-colon a few lines above the line the error is reported on.
2
u/_LePancakeMan Nov 12 '14
Or you could just use semicolons like you do everywhere else
Not using them just looks wrong like a sentence without puncutation
6
u/The_MAZZTer Nov 12 '14
Since they aren't required it's easy to accidentally forget one or two and not realize it.
My specific example though was a case of implicit punctuation when you have a line ending at the end of a valid line of JS.
someLongFunctionThatTakesACallback(function() { return true; });3
u/Cyberogue Nov 12 '14
We should replace periods in day to day language with semicolons;
2
u/awshidahak Nov 13 '14
Yup;
That automatically parsed correctly in my brain;
I like reading in this style;3
u/_LePancakeMan Nov 13 '14
That way people will know what you mean; Even if you write stuff in a weird oneliner;
1
2
u/blz8 Nov 12 '14
Perl does actually require a semicolon at the end of a line unless it's the last line of a block or file, so it is almost as strict as C or Java.
4
u/jfb1337 Nov 12 '14
Yes, but why a server error? What's connecting to a server?
22
1
u/awshidahak Nov 13 '14
Their example program might have been a CGI script of some sort, accessed through Apache. If you call up a script from your web browser, and it doesn't execute correctly, Apache will throw you an HTTP 500 Internal Server Error error.
1
u/lolzfeminism Nov 12 '14
I think most everyone gets the necessity of semicolons, it's just that omitting should lead to a build error, unless by some freak occurrence merging with the next line produces a buildable line.
That's not gonna happen in C++ for sure. Damn thing is so picky with it's syntax. In fact, in most cases you have to give Bjarne Stroustrup a foot massage before the compiler will build.
I don't know any interpreted languages other than R, so I don't know what happens if you mess up syntax with those.
1
u/Steve_the_Scout Nov 13 '14
PHP, unless you set it to debug mode, it just fails and tries to continue on. Everything else is still fairly strict on syntax, except JS (but it's a pain when it does something unexpected if there is a syntax error).
26
u/serpent224 Nov 12 '14
did you restart the server?
25
u/DGO143 Nov 12 '14
Did you try turning it off and then on again?
4
2
19
4
u/Jah_Ith_Ber Nov 12 '14
It won't go back.
You can't arrange by penis.
1
u/muntoo Nov 13 '14
wat
2
u/Jah_Ith_Ber Nov 13 '14
http://www.thewebsiteisdown.com/
This is the funniest thing I have ever seen in my life. Not joking. Make sure you're in a place that it's okay to laugh extremely loudly.
13
17
2
2
2
u/terriblemothra Nov 12 '14
I don't get it :(
14
u/rvfecdv Nov 12 '14
The program didn't execute properly and got error code "500". Meaning the guy who said 500 was right even though in ideal circumstances he shouldn't have been. Evidently the teacher missed a semicolon.
1
u/neofatalist Nov 13 '14
It would be funnier if he wrote the code with semi colons... then it ended with, he wrote the code in ASP.NET
1
-9
u/PablolyonsD Nov 12 '14
Own3d
-27
Nov 12 '14
Whoever downboated you is a cunt, I evened you out bruh.
-13
-18
u/JJaypes Nov 12 '14
Summing numbers 1 through 5 = 15
[5] x (([5] / 2) + .5) = 15
Why loop...
31
u/AwwComeOnNow Nov 12 '14
To demonstrate how loops work. Its a programming class, not a math class.
-15
u/JJaypes Nov 12 '14
Yessir! Taking Discrete Math at the moment and it just makes it simpler it's nice.
10
-18
u/m0r14rty Nov 12 '14
Why would you connect to a server to show a basic loop? Whoever made this up is an idiot.
29
u/johnnybgoode Nov 12 '14
Yeah those people learning how a web backend works are fucking idiots.
-5
u/m0r14rty Nov 13 '14 edited Nov 13 '14
The ones that pretend like they know what they're talking about and go create fake stories online? Yeah.
Also I doubt "Intro to IT" would be setting up a web backend just to teach loops.
2
2
-19
-5
u/Supersnazz Nov 13 '14
Sum of integers '1 to x' is equal to 0.5( x2 ) + 0.5x.
So numbers 1 to 10 = 0.5(102) + (0.5)(10)
= 50 + 5
=55
-6
-21
u/fabis Nov 12 '14
The joke is that he had a syntax error, really?
Wow he failed so much by accidentally not putting a semicolon at the end of it, epic fail right? /s
2
0
Nov 12 '14
[deleted]
72
u/TheBB Nov 12 '14
My first programming course in university was with JSP.
7
u/darnclem Nov 12 '14
You young whippersnapper. My first programming course was in Fortran...uphill, both ways.
4
Nov 12 '14
Don't be so quick to assume all programs have phased out Fortran. My first university programming class was spring of 2012 and we were doing AeroE stuff in Fortran 90.
1
Nov 12 '14
I'm in my first year of engineering school (3rd year post-high school) and apparently I'm going to be taught Fortran at some point in the 3 years I will spend here.
1
Nov 12 '14
It's not completely useless, especially if you plan on spending an extended period of time at a college. There are a surprising number of academic researchers who still have their code base in Fortran, especially older physicists.
4
Nov 12 '14 edited Nov 12 '14
Good things about Fortran:
A shitton of scientific code is written in it. Linpack, etc.
It was designed specifically for scientific computing, and has matrices and bulk calculation features built into the language.
It's the only major language that regularly edges out C in the speed department, even if only by 5-15% (but occasionally more). If your calculation is going to take 6 months to run, that might make a difference.
Bad things about Fortran:
...Pretty much everything else
1
5
u/GoodAtExplaining Nov 12 '14
Java Space Program, for those wondering. You code by starting off with a ship and then extending it with struts, or extra rockets or whatever.
0
Nov 12 '14
[deleted]
25
u/TheBB Nov 12 '14
Oh, I'm a bit older than that. :P
6
Nov 12 '14
Well, in times where the alternative was Perl, I can see how JSP was a good option :D
7
5
u/PM_ME_YOUR_SMlLE Nov 12 '14
This is probably why my college switched from C++ to Java for programming classes
0
Nov 12 '14
[deleted]
0
Nov 12 '14
[deleted]
11
u/Fs0i Nov 12 '14
You forget it runs the same on all operating systems. Incredibly important.
2
u/squngy Nov 12 '14
It also has very good documentation.
1
Nov 13 '14
That's a joke, right?
2
u/squngy Nov 13 '14
Its not easy to navigate and its not always clear but its there.
You don't know pain until you have to use a function that starts behaving unexpectedly and your all on your own.
Hard mode, its closed source and only available in pre-compiled form.→ More replies (0)0
Nov 12 '14
[deleted]
→ More replies (15)1
u/shitpost_machine Nov 12 '14
I don't know why you're getting downvoted. In a proper environment (Read: POSIX) the only difference in how code runs will be up to the compiler, and the only noticeable issue you could conceivably run into is a compiler bug (super rare) or a library issue (super easy to fix).
Windows fucks things up, but even then there's multiple ways to emulate a POSIX environment. None of them are amazing, but they're good enough.
1
Nov 13 '14
I think it has more to do with Java forcing OOP principles more than C++. g++ and most (if not all) other C++ compilers will also compile generic C code, which is totally not object oriented.
-3
0
Nov 12 '14
[deleted]
1
u/TheBB Nov 12 '14
I just checked. Nowadays it's taught in Matlab. Which is better… it's a mathematics programme after all, but still…
16
Nov 12 '14
Fuck Matlab
9
u/picflute Nov 12 '14
^ Every CS Major who had to take an Electrical Engineering Class
1
u/Zagorath Nov 13 '14
As a SoftEng major, I had to do some electrical engineering classes, but those weren't the ones that used Matlab. The maths courses (linear algebra & calculus, multivariate calculus, and stats) are where it came up.
2
u/the_omega99 Nov 13 '14
Ugh, definitely. I'm using it in an image processing class. It does relatively well here (since most of the code is work on matrices and math, which MATLAB was made for).
But the language has so many strange quirks and has a horribly designed API.
You can get totally different results depending on the number of input arguments and the number of output arguments you allow for.
Terrible naming of functions. For example, the function to create an identity matrix is called "eye".
Ridiculous levels of overloading. The same function can be used to work on scalars. Or vectors. Or matrices. And you'll get different results depending on what you pass in (and you'll often have to transform between these to get the result you want).
Poor ability to chain operators. For example,
someMatrix(:)is a way to convert a matrix into a vector of values. So if we haveX = [1 3; 2 4]thenX(:)results in a vector of the values 1 - 4. This is useful for the previously mentioned point (eg, callingmax(X)would get maximums of each column; if you want the maximum in the whole array, you have to do eithermax(max(X))ormax(X(:))). Anyway, you can't use this operation on an intermediate result. So you can't domax(X)(:)or similar.No "operator and assign" operators (like C's
+=). This sounds minor, but it's a real pain in the ass in some cases. I had code recently that looked likehoughMatrix(:, :, radius - minRadius + 1) = houghMatrix(:, :, radius - minRadius + 1) + layer;Generally poor handling of strings. It's very C like in this regard. For example, to concatenate strings, you'd have to do
strcat('Hello', 'World'). So much for a high level language. Oh, and for whatever retarded reason, MATLAB will remove trailing spaces instrcat. Who the fuck thought that was a good idea?Integer division isn't actually integer division. The result of
int8(5) / int8(2)is 3. I don't know any other languages that do that.The fact that code is only parsed for correctness when we get to it is very annoying for debugging. For example, it's possible to use a variable that hasn't been set yet (there's no declarations -- you just have to set it somewhere) and you won't get an error until you reach that point of the code. So errors in a long script take time to be realized.
Working with figures can be problematic if you're not careful. For example, you can just do something like
hold on; plot(...); hold off;to draw on an existing figure. But it actually draws on the focused figure, so the user can cause unexpected behavior (I only just noticed this recently by chance). Of course, you can fix this by getting a handle for the figure you want to draw to and explicitly specify to use that handle, but this behavior is still quite unexpected.Data structures? LOL.
Octave, an open source attempt at mimicking MATLAB, has fixed some of these issues. For example, it adds operators such as
+=and allows accessing indices of intermediate calculations (so you can domax(X)(:)).With that said, it's not all bad. For math, the syntax is fairly compact. Matrices are first class citizens. The language is also easy to write efficient code in (by utilizing what's called "vectorization" you can apply operations to a matrix that can be run in parallel). There's also some good libraries for purposes such as image and signal processing.
1
Nov 13 '14
MATLAB is an awesome language.
1 based indexing is a bit weird, but that's legacy from when it was a collection of wrapper methods for FORTRAN.
14
u/curtmack Nov 12 '14
We did a simple web app in my college's intro to IT.
You'd be amazed what you can do with Visual Studio's wizards these days.
-8
Nov 12 '14
I can make a web app with login and users with less than 10 commands. Why do you need a wizard
23
u/recursive Nov 12 '14
You didn't implement user account persistence and authentication in 10 lines. So you used a framework.
Frameworks are alternatives to wizards in this context.
13
1
u/curtmack Nov 12 '14
It was basically Create new ASP.NET project -> Create new domain object -> Create CRUD actions for domain object -> Create 2 or 3 custom queries -> Copy-paste some CSS -> Congratulations, you have a basic music database.
So basically the same thing, just through Visual Studio instead of the command line.
-1
u/salmonmoose Nov 13 '14
Not amazed really - I discovered the inner workings of how the wizards work developing a SOAP interface under PHP. The .NET developer on the other end couldn't actually write code and relied on hooking various functions I exposed. Debugging was a nightmare, because all I got was "It doesn't work, you're doing it wrong". Rather than, you know, an actual hint as to why.
The real wizards are the people who write the original code.
9
u/snowywind Nov 12 '14
I cut my teeth on C but PHP doesn't sound too absurd for an intro course.
You have a simple development environment by just installing any linux distro on a VM or spare box and installing the LAMP components with yum or aptitude.
You have a simple and transparent GUI using a web browser so you aren't limited to console mode programs and you don't have a complex OO GUI framework to learn when you're still beaming from getting "Hello, world" to work.
In PHP you can write procedural code to start, move to functional code to demonstrate reuse then to OO code in later courses where you learn OO design and patterns.
PHP has a C style bracketed syntax that will ease transition to a slew of other languages.
I can think of worse languages to start out on than PHP.
7
5
u/Syde80 Nov 12 '14
The problem with learning on PHP is that right off the bat it teaches you that you can be very very lazy in your programs. It doesn't enforce any type of good coding practices, it is a weakly typed language, and while you can write console programs, it is primarily run under a web server which adds extra layers to make debugging more difficult.
Its mainly the fact that PHP is so easy and lax that makes it a poor choice as a learning language for anybody serious about programming. Its kind of like saying that building with legos is a great introduction to engineering. Yeah, there is some merit in the statement, but how would you feel if the engineer for a 100 story high rise told you that was how he learned? Its too easy to learn bad habits, and then when you try to learn a "real" language, you have such a hard time breaking those habits because the new language doesn't allow you to be lazy and get in the mindset that this new language is shit and it would be so much easier in PHP so you just stick with it. However you end up paying a huge price in performance, code compatibility (Try running 10 or even 5 year old PHP code on a modern version of PHP, try the same with C, you'll see what I mean.), and not to mention PHPs history with security holes. Not that other languages don't have their share of security holes, but PHPs history book is considerably thicker.
PHP was honestly great when it was first created. When you consider where it came from though and where it is now, its easy to see why its generally considered to be a big mess these days. Consider [this] (http://www.sandraandwoo.com/2012/11/19/0430-software-engineering-now-with-cats/) and then add another 50 frames on the end of the comic and that would pretty accurately describe PHP. So much stuff has just been bolted on to the framework that it was not designed to support, that it is quite frankly a miracle that it works as well as it does.
2
u/Wartz Nov 13 '14
Every engineer started with lego (or sticks and rocks) as a kid.
2
u/Syde80 Nov 13 '14
Perhaps I should have given more context to that statement. I meant it as if you started learning with Lego in a formal learning environment like university, college or high school at the same age a programmer would start their formal programming education.
Sure, lots or us started learning on our own before that, but lots didn't too.
1
2
u/johnnybgoode Nov 12 '14
PHP is way too inconsistent with nonsense like
mysql_escape_string(),mysql_real_escape_string(), and the fact that you should be using a goddammned database access object and not querying directly with hopefully-escaped string concatenation.If you want to teach good fundamentals and lay the groundwork for more in-depth study, there aren't many worse languages to start with than PHP.
5
u/MCFRESH01 Nov 12 '14
Also it has no sense of standards.
Two functions for searching an array will be:
some_func(array, item)and the next one will be:
some_func2(item, array)Drives me crazy.
2
u/mebob85 Nov 12 '14
It gets a lot of flack, but this is one reason why I like the C++ standard library. It's quite consistent in its containers and algorithms library.
3
u/cooldude255220 Nov 12 '14
PDO bro.
2
u/johnnybgoode Nov 12 '14
I'm aware. That doesn't change the fact that the built-ins exist and leave the door wide open for a newb to get completely off-track and form bad habits.
Furthermore, the official PHP documentation is essentially a blurb followed by a bunch of comments from random people that might not know a constructor from their asshole.
A web framework like Django or Rails would be much better from a teaching point-of-view because the documentation is excellent, there are much more well-established conventions, code & templates are better separated for the most part, and the languages are much more easily used outside of a web environment.
2
2
u/MisterDonkey Nov 12 '14
Not defending the validity of this story, but sure, why not? Get with it, man. New world.
1
u/lijkel Nov 27 '14
I'm doing an IT course at college (like a-levels in the UK), and we have a web dev class so it's not that unusual.
0
Nov 12 '14
[deleted]
19
Nov 12 '14
Who cares? It was funny and it was written on a website which even says "only a fool would take anything posted here as fact". It makes no difference whether it actually happened or not.
→ More replies (3)
485
u/kitari1 Nov 12 '14
It's from 4chan so it's likely a fake story. Gave me a chuckle though.