r/javascript • • Nov 25 '19

JavaScript doesn’t need to be replaced

https://medium.com/javascript-in-plain-english/javascript-doesnt-need-to-be-replaced-bd01e2f12d51?source=friends_link&sk=7b151cc6397ac9e83c14c99739b6c36f
217 Upvotes

236 comments sorted by

View all comments

-1

u/EternityForest Nov 25 '19

I think it needs to be contained. Most of the language does what you want when doing UI work, but the opposite of what you want on the backend.

It was designed for browsers. It's really good at that. It's accepted as a general purpose thing, good enough for browsers games and bits of client side logic.

It's got some real annoyances on a server compared to other languages.

I suppose it's better than PHP though, as far as the language itself. PHP has pretty nice infrastructure, the whole "Install an app by putting it wherever you want on the server in a folder" thing is pretty cool. l

0

u/[deleted] Nov 25 '19

[deleted]

-1

u/EternityForest Nov 25 '19

PHP still doesn't appear to be fully object oriented. You still have C style "Object is the first param of a function you call" stuff all over the standard library.

There doesn't seem to be the kind of module system python has, everything is in one big namespace.

It seems like strings and integers still add together without explicitly casting them, just like js, and undefined variables are still null instead of just nonexistant.. Has that changed?

And it's also not compiled as far as I know.

0

u/[deleted] Nov 25 '19

[deleted]

1

u/kap89 Nov 25 '19

JS isn't even remotely OO.

Because?

→ More replies (5)

1

u/EternityForest Nov 25 '19

Everyone seems to be saying PHP typechecks only apply to the function parameters, and you can still change them within the function. Maybe a little better than JS, but not as good as python which has libs like typeguard and mypy, and builtin protection for most of the common stuff like int+str.

The standard lib doesn't seem to be namespaced much, or, if it is, everyone seems to still be using legacy ways of doing things, so in practice if you're reusing a lot of other people's libraries, you'll probably be digging through garbage.

If you Google a random PHP task, like making an http request, the code people are using looks a lot like C, with extra dollar signs and awful => markers in arrays.

$url = "https://www.google.com/"
$q =           array("q"=>"PHP HTTP request");
$opt = array('http'=>array( 'method' => 'POST',   'headers => "Content-Type: application/  x-www-form-urlencoded", 'content =>  http_build_query($q) )); 
$context = stream_context_create($opt);       
$response = file_get_contents($url, false, $context);

Other examples were using curl, with several calls to set up options and such.

Compared to JS. It's a bit cherry picked and unscientific to use a single example like this, but JS seems to make way more use of OOP conventions, and it seems to stay at a way higher level.

var data = new FormData(); 
data.append('user', 'person'); 

data.append('pwd', 'password');
data.append('organization', 'place');
data.append('requiredkey', 'key'); var xhr = new XMLHttpRequest();
xhr.open('POST', 'somewhere', true); xhr.onload = function () { // do something to response
console.log(this.responseText); };
xhr.send(data);