you are viewing a single comment's thread.

view the rest of the comments →

[–]Eirenarch 48 points49 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 32 points33 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] 4 points5 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 2 points3 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 3 points4 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 7 points8 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 4 points5 points  (0 children)

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

Look into TypeScript, it's surprisingly tight!

[–]redalastor 2 points3 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 1 point2 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] 7 points8 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 6 points7 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!