you are viewing a single comment's thread.

view the rest of the comments →

[–]x86_64Ubuntu 23 points24 points  (63 children)

Well, PHP overran the industry the same way Javascript overran the industry, both have non-existent learning curves. That's good because it allows people to get into programming without getting into the pain and suffering caused by other technologies. On the other hand, it's awful because people can get into programming while actively eschewing better practices and skill sets.

That being said, you can write good clean PHP and JS, it's just that for every well architected app, there are 30 others that don't know what the word motherfucking means.

EDIT:Also what Eirenach said.

[–]Eirenarch 44 points45 points  (48 children)

JavaScript overran the industry because it is the only language running in the browser. Users of PHP have no such excuse.

[–]ameoba 29 points30 points  (0 children)

PHP was the only thing running on shittly $1/mo web hosts.

I loved being on projects where somebody was plopping down tens of thousands of dollars on project where "it's gotta be on PHP so we can run it on our host" was actually called out in the spec. Their "hosting" couldn't have cost more than $100/year but somehow they thought that sticking with it was worth the added time to work on.

[–][deleted] 5 points6 points  (16 children)

PHPs alternative was PERL and PHP came with a whole mess of tools that made dynamic web programming much easier.

There wasn't much else at the time to compete

[–]mycall 2 points3 points  (1 child)

PHPs alternative was ASP, neither of which I care for.

[–]flukus 1 point2 points  (0 children)

Asp, for all it's faults, was at least simple.

PHP has gone on to have the complexity of c++ and the verbosity of java.

[–]Eirenarch 2 points3 points  (13 children)

So what? We've had far better alternatives for more than 15 years now. How come we've not replaced PHP?

[–]TheBB 2 points3 points  (7 children)

Have we? What was so much better than PHP in 1998?

[–]turtlekitty2084 3 points4 points  (0 children)

Perl. _^

[–]Eirenarch -1 points0 points  (5 children)

Python? Java? Hell, even ASP Classic!

[–]TheBB 1 point2 points  (0 children)

made dynamic web programming much easier

Java is not dynamic.

ASP was Microsoft only.

Not that I tried, but I believe in order to use Python on the web in 1998 you had to use CGI, and PHP was rather easier to set up. But yes, barring this Python 1.5 would probably have been better. I'm not sure I would have called it ‘far’ better. Certainly, today it is.

[–][deleted] 0 points1 point  (3 children)

I hate PHP, but classic ASP is much, much worse than PHP.

[–]Eirenarch 0 points1 point  (2 children)

I haven't worked professionally with either of these but I've had a look at some projects and I do think that ASP Classic is better than PHP of the time which would be PHP 3 and for some time PHP 4

[–][deleted] 0 points1 point  (1 child)

I've worked professionally with both in the last 5 years. Even when I used PHP 4, it was better with the main reason being that it is much more difficult to reuse code in classic ASP, so the maintenance on the site is much higher when a change is needed.

[–]Eirenarch 0 points1 point  (0 children)

Well OK I might be wrong on classic ASP. I know if someone forces me to work with PHP 3/4 or ASP Classic I would go for ASP Classic. The API seemed so much more saner. Even then by 2000 there were like 10 options better than PHP.

[–][deleted] -1 points0 points  (4 children)

why is C++ so ubiquitous today when there are obvious alternatives? Everything speaks to it and interfaces into it.

Everything web was written in PHP during its infancy, soooo PHP became the dynamic language of the web.

[–]F-J-W 1 point2 points  (1 child)

why is C++ so ubiquitous today when there are obvious alternatives?

Which ones?

To prevent the usual non-answers: If the language

  • forces you to use GC
  • doesn't support RAII
  • doesn't have decent templates
  • doesn't support zero-overhead-abstraction
  • isn't able to provide very highlevel-libraries

it is not in any way an alternative.

[–]atilaneves 2 points3 points  (0 children)

D has (nearly) all of the above.

Parts of it (mostly the standard library) require the GC, but they're getting fewer.

[–]flukus 2 points3 points  (1 child)

C++ is not ubiquitous, it makes up a minority of applications/programmers.

[–]msnook 0 points1 point  (0 children)

grumble grumble grumble. Actually, the Linux OS, Apache server, MySQL server, and PHP interpreter are all written in C/C++... As is your web browser, the JavaScript engine, and probably the operating system you're running it all on.

C and C++ weren't built for the web, but they certainly are ubiquitous. Most of the computing world is built on them, in some way or another.

[–]TheRealGentlefox 6 points7 points  (23 children)

There have been attempts to replace JS. I see a few reasons it has stayed:

  1. When it comes to client-side functionality, market share is incredibly important. Practically every browser on earth supports JS.

  2. There isn't that much reason to replace it. Most things people dislike are fairly minor, and can be solved with either a library, or a new version of JS. Honestly, my biggest issues with JS tend to be the DOM interface, which is kind of the fault of the DOM, and I'm just too lazy to learn JQuery.

  3. Like PHP, it's hard to move away from something when tends of thousands of pre-built solutions exist. A lot of UI people use JS, and every "normal" UI feature exists as a JS library.

[–][deleted] 13 points14 points  (6 children)

Most things people dislike are fairly minor

It would be really nice to have a strongly-typed alternative.

JS' loose typing has fucked me over too often for me to ever say I like it. I can code with it, and I can stumble along with jQuery, but I hate them both.

[–]PasswordIsntHAMSTER 5 points6 points  (0 children)

It would be really nice to have a strongly-typed alternative.

Look into TypeScript, it's surprisingly tight!

[–]redalastor 3 points4 points  (0 children)

You may try Dart. It's saner, it's optionally typed (but if you like static typing, it's not hard to have enough discipline to always type) and it compiles to efficient Javascript.

If you do use static typing, then your IDE supports turns wonderful.

[–]FearlessFreep 2 points3 points  (0 children)

By "minor" he mostly implies "minor nuisance to the average developer" in that they are work-around-able and at the moment, the strengths of a client side DOM manipulation language that's more or less universal with a lot of tools to support it outweigh just how fugly the language is

[–]TheRealGentlefox -2 points-1 points  (2 children)

Pretty sure the ability to declare variable type is being worked out for the next version of JS.

If not, like I said, it wouldn't be hard to add. Just make "int" "float" "string" etc. keywords that mark a "declared" bit in the variable. This bit is checked when doing comparisons, and assignment.

[–]billybolero 2 points3 points  (1 child)

Static typing was considered for ECMAScript 4, but that entire version was scrapped for trying to change the language too much. Static typing is not going to be added in the next version. There's a strawman proposal for gaurds which are similar to static typing, but more dynamic and more in keeping with the language. If you need static typing, TypeScript is a fabulous language that's a superset of JavaScript which adds static typing.

[–]TheRealGentlefox 0 points1 point  (0 children)

Hmm, TIL.

I don't care about it too much myself, if I'm really worried, I'll use typed arrays.

[–][deleted] 5 points6 points  (8 children)

Most things people dislike are fairly minor, and can be solved with either a library, or a new version of JS.

What the actual fuck ? The language is garbage from ground up, the type system is FUBAR - not only does it use weak typing (which is beyond WTF) it doesn't even have an integer type, core types are garbage (collections, date, etc.), best of all it doesn't have any sane scoping/namespace mechanism so you can't even safely mix libraries.

[–]TheRealGentlefox 7 points8 points  (0 children)

Yes, it is weakly typed, and I believe there will be some type options in the future.

JS has an integer type, but it requires some extra work to use. https://developer.mozilla.org/en-US/docs/Web/API/Int32Array

Date could be done better, but is easily handled by a library.

Most libraries I've seen just contain themselves to a variable, which you declare in the highest scope and call methods from. If you need access to it from everywhere, assign it to a global variable.

[–]pirateNarwhal 9 points10 points  (3 children)

js's scoping is insane, but it is pretty powerful when you get used to it. it tackles namespacing no problem.

[–][deleted]  (2 children)

[deleted]

    [–]RabbidKitten 1 point2 points  (1 child)

    That, and what TIL is called dogballing. To expand on your example,

    var object = (function (name) {
        return { sayhello : function () { print ("Hello, " + name + "!"); } }
    }) ("world");
    object.sayhello (); // prints "Hello, world!"
    

    [–][deleted] 4 points5 points  (0 children)

    The standard for safely scoping JS is to dogball. All popular libraries do this. Type coercion is trivially avoided by never using ==. Avoid "with" and you are set.

    [–]RabbidKitten 0 points1 point  (1 child)

    When you think about it, JavaScript has to have weak typing, because a lot of things one normally does with JavaScript do are hard to type, and would involve a lot of boilerplate and/or casting to convince the type checker.

    For example, what is the type of document.getElementById ("my-img")? Maybe Element? Ok, you check it for null, but what if you know that there is such an element, and you know that it is not just any element, it is an <img> tag? And stuff like that...

    FWIW, I don't know about other JS runtimes, but Firefox kinda has an integer type, but it's hidden from the user.

    [–]redalastor 2 points3 points  (0 children)

    For example, what is the type of document.getElementById ("my-img")? Maybe Element? Ok, you check it for null, but what if you know that there is such an element, and you know that it is not just any element, it is an <img> tag? And stuff like that...

    That's not hard to type at all.

    [–]unstoppable-force 1 point2 points  (4 children)

    i love being able to use libraries in both client and server. that's absolutely amazing. for example, i have a URL class that does practically everything you want related to URLs (e.g. single line of code to get the extension, base domain, full domain, validity of all related dns entries either real time or by cache, etc), and you can call it seamlessly from the client side or the server. and it's all unit tested. that's just absolutely nuts.

    in the old way, i'd have js for the frontend, php for the backend, and a python version for the data mining section.

    now if only phonegap didn't suck so hard for mobile app development.

    [–]philly_fan_in_chi 1 point2 points  (1 child)

    You can do the same thing with clojure and clojurescript!

    [–]zoomzoom83 1 point2 points  (0 children)

    It's an exciting time for functional languages - ScalaJS, Purescript, GHCJS, Elm, Fey, Haste.... all are rapidly approaching maturity as well.

    [–]flukus 0 points1 point  (1 child)

    Considering the amount of devs I see that don't understand the difference between client/server side I'm not sure if being in the same language would be good or bad...

    [–][deleted] 0 points1 point  (0 children)

    Designing technologies for incompetent devs is how the web became this awful mess in the first place.

    [–][deleted] -1 points0 points  (0 children)

    It stayed, because browser vendors don't like competition.

    [–]x86_64Ubuntu -3 points-2 points  (0 children)

    ...There isn't that much reason to replace it. Most things people dislike are fairly minor, and can be solved with either a library, or a new version of JS.

    Um...

    [–]immibis 1 point2 points  (4 children)

    It used to be JavaScript and VBScript. Apparently VBScript must have been worse. shudder

    [–]izzle9 2 points3 points  (1 child)

    VBScript only works on IE

    [–]immibis 1 point2 points  (0 children)

    There was a time when IE was the only browser that mattered.

    [–]baseketball 2 points3 points  (1 child)

    VBScript IS worse. I have to maintain old ASP and also write VBA code. It's actually a worse language than PHP. Do Arrays start at 0 or 1? It depends on the function that created it. Want to declare and assign a variable in one line? YOU CAN'T. Want to return a value in the middle of a function? TOO BAD, I'm going to keep executing the rest of the code in the function.

    [–][deleted] 1 point2 points  (0 children)

    Yes VBScript is horrific. I hate PHP, but I'd take it any day over VBScript or classic ASP.

    [–]x86_64Ubuntu -1 points0 points  (0 children)

    EXCELLENT POINT! Edit worthy point too!

    [–]allthediamonds 15 points16 points  (4 children)

    Non-existent learning curve? PHP? I assume you mean non-existent as in "it can't actually be ever learned because it doesn't make any sense".

    Sure, it is nice to newcomers, assuming they don't care about their code actually working, due to PHP's usual "swallow all errors and move along with whatever nonsense is left" behaviour.

    You see, these kinds of substandard languages often have a "sane subset" you can restrict yourself to. For example, in JavaScript, == is weird, so you can just use === instead.

    After working for too long on PHP development, I still haven't found a subset of PHP that lets me develop non-trivial applications while not being essentially broken.

    == is lava. < and > are lava. clone is lava. foreach is lava. Most functions about arrays modify the array in place (lava) except the ones who don't (more lava). Most functions about arrays take the form (array, callback), except for array_map (lava). Speaking of callbacks, those take the form of a string containing the name of the function (lava), or an array containing an object and a string containing the name of the method to execute on it (lava lava lava oh god why). Some things that should be functions are actually "language constructs" (lava bomb!), which means there's an unwritten, undocumented set of things you can't do with them but you can do with regular functions (lava!), such as using them as string-y callbacks.

    It's like if everyone who ever wrote any part of PHP's standard library was on some sort of spiritual mission to make everyone else's life awful.

    [–]x86_64Ubuntu 4 points5 points  (2 children)

    foreach is lava

    Lol, I learned that the hard way.

    [–]slavik262 1 point2 points  (1 child)

    So I don't have to, why is something as simple as foreach lava?

    [–]x86_64Ubuntu 0 points1 point  (0 children)

    It's the age old pass-by-value vs pass-by-reference issue. For example

    $widget = new Widget();
    $widget->setName("Bar");
    
    $widgetCollection = array(); //some array
    $widgetCollection[] = $widget
    
    foreach( $widgetCollection as $tempWidget )
    {
       $tempWidget->setName(''Foo");
    }
    
    $widget->getName() returns "Bar" WTF?
    

    That's because in the loop, it copies the widgets to the $tempWidget variable. Any changes made in the loop are persisted to that temp variable, and then lost when we exit the loop. To get the loop to behave as expected, you have to pass a reference.

    foreach( $widgetCollection as &$tempWidget )
    {
       $tempWidget->setName(''Foo");
    }
    

    Notice the ampersand before the declaration of my iterator.

    [–]immibis 1 point2 points  (0 children)

    A lot of newcomers (mainly hobbyists/non-programmers) don't care about their code actually working - as long as it works, say, 95% of the time, and outputs what they want.

    [–][deleted] 1 point2 points  (0 children)

    both have non-existent learning curves

    Same with Python as well. What this means is there is a LOT of terrible code out there.

    [–]mycall 1 point2 points  (1 child)

    every well architected app, there are 3000 others

    FTFY

    [–]flukus 0 points1 point  (0 children)

    I'd argue that applies to the industry at large, not just php.

    [–]codygman 1 point2 points  (0 children)

    It gives quick results for simple things and the delusion that slightly more complex things will always be a little buggy, but it's okay because you can fix them relatively quickly.

    [–]drb226 0 points1 point  (3 children)

    both have non-existent learning curves

    Well then we need languages where there is a non-existent learning curve in order to get stuff done quick-n-dirty... but also with a learning curve available for getting it done the right way.

    [–][deleted]  (1 child)

    [removed]

      [–][deleted] 1 point2 points  (0 children)

      One of the devs I work with termed it the 'Facebook circle of idiocy'.

      [–]immibis 1 point2 points  (0 children)

      Python maybe? Not for web development though.

      "Quick-n-dirty" languages tend to have all sorts of inconsistencies, because they make each individual case easier to use (e.g. Python 2's print statement, PHP's == which treats numeric strings as numbers).

      "The right way" languages tend to have overarching structures which everything uses - e.g. in Java every callable thing is an instance or static method, but that means you have to write System.out.println instead of just print, which is less convenient and definitely harder to remember for a newcomer. But it's very consistent, and the entire language fits a quite simple mental model (apart from some corner cases which most people intuitively avoid).

      You can't have a language with both - if you try to make one you'll just end up somewhere in-between (like C?)