It's probably a terribly unpopular opinion, but I think the weak typing is the main attraction of JS.
When I want stronger typing, I have C or (god forbid) C++.
If you've ever written typescript, you can see how a strongly typed JS gives you the worst of both worlds.
I like clean, elegant, expressive code, just like everyone else.
I don't particularly care for the attitude that because something can be used to write horribly unmaintainable messes, it must necessarily be bad and have few practical applications.
No, if you get horrid unmaintainable messes it's because you're either inexperienced or a bad programmer, you may be able to hide that in layers and layers of corporate Java that adheres to every guideline, but the second anyone tries to touch it, you'll be found out anyway. I'm going to take a wild guess that you're also imbued with a similarly low opinion of PHP based on that (insightful if somewhat one-sided and flawed) article that guy wrote.
In my opinion, the flexibility and elegance you can get out of exploiting, not abusing or misusing, the dynamic nature of JS, is the main appeal of the language, it's really damn fast to get stuff done, and even done in a nice and safe way, provided you have some idea what you're doing.
There are terrible things that you can do in JS, and those are terrible even in the context of JS, but, what is a terrible thing to do in one language may be just fine(tm) in another, so trying to force some Java or C++ ideas onto any other language is just not a good way of going about things. Every language must be considered on its own.
What is reasonable to do when writing machine code may not be reasonable in assembler, and what is reasonable in assembler may not be reasonable in C and up you go.
I mean... let’s keep in mind we’re talking about a language and community that uses the keyword “const” to define mutable objects. Logic went out the window a long fucking time ago.
> we’re talking about a language and community that uses the keyword “const” to define mutable objects.
Nope they use const to define immutable references, the same way that val/var define mutable references.
If you don't understand the difference between mutability of a reference and mutability of the value it refers to, JavaScript is far from the only language you’ll have a problem with.
I understand the difference. The problem is that you can completely change the shape of the object that’s “const”, so it’s hardly fucking constant is it.
TIL relying on a bunch of boilerplate “typeof o.prop” checks is “clean, elegant, expressive code”, while knowing implicitly that o.prop is always an integer is not?
> TIL relying on a bunch of boilerplate “typeof o.prop” checks is “clean, elegant, expressive code”, while knowing implicitly that o.prop is always an integer is not?
Clean and elegant are certainly debatable, but, yes, code that is explicit in its preconditions (whether through explicit runtime checks or explicit static declarations or other mechanism) is pretty clearly more expressive than code that relies on the developer “knowing implicitly” the same information.
When I said knowing implicitly I was referring to for example, declaring that class `Foo` has an integer property `prop`, and function `bar` only accepts an instance of `Foo` as argument `obj`, thus `obj.prop` is always an integer. The developer doesn’t need to add typeof checks on the argument, on the property, etc.
The above comments point to (a) not using classes or declared properties at all, and regardless JavaScript has no support for automatic type checks on properties or function arguments.
> I think you’re confusing strong/weak with static/dynamic. The former happens at runtime, the latter at compile time.
Strong typing usually describes the combination of compile and runtime typing; Haskell code doesn't have types after compilation, so there is no runtime enforcement of typing, but no one calls it weakly-typed, because the static typing prevents any of the conditions which would display weak typing behavior fromm happening.
You can absolutely write server web apps in C (there are even web app frameworks in C), though I wouldn't want to, or...
> The one in Node/Go/Python where you will write your business logic then `http.listen()`.
You definitely can link and call C code from Node, Go, and Python; they'd be much less useful otherwise; it's not at all hard in Python, and I assume the same is true of Node and Go.
Node is absolutely excellent server side, and if you have something where you want it to be much faster, and slower to develop, go with C or C++, there are libraries out there for writing webservices, or go another route and write your critical parts as native node modules, against V8.
If you've ever written typescript, you can see how a strongly typed JS gives you the worst of both worlds.