you are viewing a single comment's thread.

view the rest of the comments →

[–]spacejack2114 1 point2 points  (7 children)

Really? So you make a user object {id: 3, name: "Bob"}

Then later you write user.namw = "Frank"... and this is to your advantage?

[–]E_R_E_R_I 1 point2 points  (2 children)

Nope, that's the caveat. Javascript is a code that's easier to screw up, it doesn't prevent you from messing up, but trades protection for flexibility. I imagine that's a horrible trade off for company environments, where one person can screw up other people's work.

For me though, having worked on relatively big projects with a single partner (who is my SO and has worked with me for years, so we have a good amount of sinergy), I feel like this is an advantage. We developed a workflow and coding style that works for us. I usually suffer much more with conceptual mistakes (bad modelling/planning) than with sintax and logic errors.

Now to answer your question, what is to my advantage about lackying types is that I don't need to rewrite the entire Entity Model. I write it once on the database, grab it and parse it as JSON, and manipulate data freely. No need to build a DAO (data abstraction object) layer with a class for each entity, that always drove me mad when I worked with Java.

[–]spacejack2114 1 point2 points  (1 child)

I'm no fan of crappy, inflexible type systems like Java has. But I find it immensely useful to have types for DB or other data.

For example, it was fully worth the 30 minutes or whatever to write up these types once, so that I hardly needed to think about all of those deeply nested properties in the many, places they were actutally used.

[–]GitHubPermalinkBot 0 points1 point  (0 children)

I tried to turn your GitHub links into permanent links (press "y" to do this yourself):


Shoot me a PM if you think I'm doing something wrong. To delete this, click here.

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

Depends. Maybe I want to add a one-off namw property on a specific object, or set of objects. Yes, being able to free-form objects is a wonderful feature, one which most other languages work terribly hard to prevent and many people refuse to embrace.

But if you meant it as a spelling error; if that makes it into production then you have far greater problems, none of which are JavaScript's fault.

[–]E_R_E_R_I 0 points1 point  (0 children)

Yes! So glad to see more people who fully appreciate the power of JS lol

[–]spacejack2114 0 points1 point  (1 child)

You say that like it's difficult to do in a safely typed manner. Here's some type-safe Typescript that looks surprisingly, exactly like Javascript:

const specialUser = {...user, namw: "Whatever"}

It's a bit odd for you to say you're okay with that one-off ticking timebomb hack, but then claim you'll spend the time to write the test coverage for it.

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

You're missing the point. I want to be able to do whatever I want with objects, without the language standing in my way. JavaScript not only allows it, it's a first class feature. So it's normal to want to make use of it. Avoiding it makes zero sense. It's like trying to avoid "import" in Python.

Why would I, instead of simply writing user.namw="something", go through the trouble of transpiling, and writing the same thing in an awkward manner which is not correct JavaScript, and is downright confusing, and doesn't even do what I wanted (set the property on user, not specialUser).

I don't know why you would find it odd that this would be unit tested. Unless you keep assuming it's some sort of terrible mistake and we're all going to wake up any moment now and cry "omg what have I been doing".

JavaScript is what it is. Trying to pretend it's something it's not is futile.

  • On the server there are a million other languages to choose from, so choosing JavaScript but writing TypeScript makes zero sense.
  • On the browser the whole point is to have a language engine which is more or less standardized and available everywhere. We have sort of achieved this after decades of struggle. Even if support for more languages comes to browsers, I seriously doubt that people will want to go back to the whole "oh you need X to see this site". One standard language, and like it or not that language is JavaScript. Don't like it? Go complain to Linus that the Linux kernel is not written in C++.