r/ProgrammerHumor • • Mar 20 '24

Meme areJSDevsActuallySane

Post image
14k Upvotes

554 comments sorted by

View all comments

6

u/subject_deleted Mar 20 '24

I get it... JavaScript dumb... But who would EVER try to do this? How could this possibly cause an issue for anyone who has the vaguest sense of what they're doing?

6

u/[deleted] Mar 20 '24

[removed] — view removed comment

3

u/subject_deleted Mar 20 '24

When you test your regex and it doesn't work... That's how you know it's broken and you need to debug it.

It's crazy that people don't shit all over other languages that have generic errors like "seg fault".. sometimes people do things so silly that there's no explicit error message. That's not a fault of the language.

3

u/SoInsightful Mar 21 '24

When you test your regex and it doesn't work... That's how you know it's broken and you need to debug it.

Dude, I hate "JS bad because I did silly thing" criticisms as much as the next person, but "just fix your regex when you finally notice it's randomly failing for no reason" is not a good defense of the language.

sometimes people do things so silly that there's no explicit error message. That's not a fault of the language.

That's absolutely a fault of the language. What else would it be?

1

u/subject_deleted Mar 21 '24

but "just fix your regex when you finally notice it's randomly failing for no reason" is not a good defense of the language.

That's not what I said though....

I said when you write your regex... You should test it. Just like you would for any language...

Also, we're not talking about the regex "failing for no reason". There is a reason... You're passing an empty object into the regex constructor.. that's the reason it's failing.

That's absolutely a fault of the language. What else would it be?

It would be the fault of someone who did something silly.. like passing the output of a function straight to a regex constructor without validating the output of that function first... If you do that and get an unexpected result because you didn't validate first... That's not on the language.

1

u/SoInsightful Mar 21 '24

The issue is obviously not that someone would sit down and write new RegExp({}) and wonder why their regex doesn't work as expected.

It will be a project with thousands and files and even more thousands of dependencies, and at some time, somewhere, a value happened to result in a non-string which 58 stack frames later was passed to a new RegExp constructor. And then suddenly some cog in the system only works some X% of the time.

To be frank, your idea of "a JavaScript function shouldn't throw because you should simply load your entire system into your brain and write everything perfectly" reeks of inexperience.

1

u/subject_deleted Mar 21 '24

The issue is obviously not that someone would sit down and write new RegExp({}) and wonder why their regex doesn't work as expected.

I didn't say that that was the problem.... I said that when you write a new regex,.you should test it. That includes throwing stuff at it that you expect it to receive.... But it also means throwing stuff at it you don't expect it to receive.

If part of your test passes an empty object to your regex, you'll see right away that it's not doing what is expected. Then you KNOW you need to avoid passing an object to that function and you can put a simple conditional statement to throw an error if the argument was an object.

To be frank, your idea of "a JavaScript function shouldn't throw because you should simply load your entire system into your brain and write everything perfectly" reeks of inexperience.

I never said any of that... What is the value of attributing words to me that I never said? What does that accomplish? What do you gain?

I didn't say write everything perfectly. I said sanitize your inputs so that when a function is called and it needs a string as an argument.... Just put a condition that checks if the argument is a string. If this seems like impossibly complex stuff to you, you might be the inexperienced programmer.

1

u/SoInsightful Mar 21 '24

Just put a condition that checks if the argument is a string.

Oh, so something like this?

if (typeof input !== 'string') {
  throw new TypeError('RegExp input must be a string');
}

That's actually a great idea! If only the language did exactly that for me so I wouldn't have to track down obscure bugs if one of my colleagues or library authors accidentally forgot to do that!

1

u/subject_deleted Mar 21 '24

If only the language just checked the strings you wanted it to check without having to call a function....

If only the script could just automatically figure out whether a number was even or odd without me having to write a function to check it..

If only the language automatically grabbed input from the user so we didn't have to bother making forms and processing the inputs.

If only, right?

Essentially what you're doing here is identical to arguing that c is a bad language because you have to indicate what type a variable is when you declare it... It's an unnecessary step for you, because other languages have features built in that automatically determines what the data type is.

Do you think all languages should be interpreted? If not, why not? If not, why would you point to things that a language COULD do automatically and then shit on that language for not doing it automatically?

1

u/CaitaXD Mar 21 '24

Segmentation fault is not an error dude

It's the OS telling you fucked up

1

u/subject_deleted Mar 21 '24

If you fuck up, is that not an error?

A message saying you passed an empty object to a regex constructor is just telling you you fucked up...

1

u/CaitaXD Mar 21 '24

Not a language error a unmanaged language doesn't know weather or not you are addressing valid memory

1

u/subject_deleted Mar 21 '24

An error is an error. If you expect a certain kind or value of output, but instead you get something else, it's an error. Whether it's valid memory or not.

If you write code that could possibly pass an empty object into your regex constructor, that's an error.. and the fault lies with the programmer who didn't validate.

Passing in an empty object instead of a string is not any more or less of an error than passing in a reference to an empty spot in memory, or just the wrong spot in memory.

1

u/CaitaXD Mar 21 '24

Is OS specific not language specific

1

u/subject_deleted Mar 21 '24

I'm trying to figure out how that's relevant to whether or not the programmer should not be passing variables to a function if they haven't verified the appropriate data type first...

Can you help me out?

1

u/CaitaXD Mar 22 '24

Cause you compared it to a segfaults, but segfaults happens for valid reasons that cannot be resolved by the language, this scheiße has exaclty 0 rights to be a thing

→ More replies

-1

u/[deleted] Mar 21 '24

[removed] — view removed comment

3

u/subject_deleted Mar 21 '24

I write JavaScript. Which is why I'm so dumbfounded that people act like these are real problems... In 8 years I have NEVER had an issue like this occur... Nor any of the issues about what NaN matches or doesn't match...

There are myriad ways of doing stupid things in any language. And none of those are a good reason to shit on a language instead of the dumb developer who tried to do something stupid.

4

u/gonzofish Mar 21 '24

But don't you understand?! Because it can happen it's a problem! I've been coding JS for like 20 years in the before times when there wasn't even XMLHttpRequest and I have never run into this.

→ More replies (1)
→ More replies (6)

1

u/[deleted] Mar 21 '24

Skill issue lol. Everyone just assume that they can write good JS code just because they think it's easy

2

u/[deleted] Mar 21 '24

[removed] — view removed comment

1

u/[deleted] Mar 21 '24

It's just a language so if you talk shit, you output shit

1

u/[deleted] Mar 21 '24

[removed] — view removed comment

1

u/[deleted] Mar 21 '24

You blame the developer. Not the tool they used. Every tool has its flaws. Working around on any flaws of the tool, makes you a good developer. Not just cry about its flaws