r/programminghorror • • Jun 12 '25 • This 1

Javascript Javascript is filled with horror

Post image
2.4k Upvotes

337 comments sorted by

View all comments

Show parent comment

11

u/AmazingGrinder Jun 12 '25

Yeah, that's a good explanation for statically typed languages.

JS is dynamically typed tho.

7

u/Tyfyter2002 Jun 12 '25

JS is dynamically typed tho.

Exactly, that's the problem, it's possibly the language that's most likely to have user input, and it has all of the traits that make data more likely to be misinterpreted except using pure string concatenation to provide arguments like SQL.

7

u/AmazingGrinder Jun 12 '25

I'm sorry, but it sounds like a non-issue to me. Developer need to validate every user input and reject if it's somehow wrong. Without it, strongly typed langs, like Python, Java or Kotlin, will throw an exception and your server now returns 500. Weakly typed ones, like JavaScript, will implicitly coert it to one of the types (in this case - a string). Now you have obviously wrong data.

Input validation is independent from language's typing.

6

u/Tyfyter2002 Jun 12 '25

Input validation is almost inherently part of the conversion process in most cases with strongly typed languages, only needing to be manual when there are invalid values the resulting type could contain, because giving the user an error message when they do something wrong is what you should be doing.