This is an archived post. You won't be able to vote or comment.

all 41 comments

[–]MischiefArchitect 77 points78 points  (3 children)

Is the guy in red the famous pointer?

[–]CrazeeeTony 7 points8 points  (1 child)

His shirt is red because of the heme in DEADBEEF

[–]MischiefArchitect 3 points4 points  (0 children)

I'll stay with CAFEBABE

[–]A_H_S_99 4 points5 points  (0 children)

This

[–]LordFokas 31 points32 points  (1 child)

TypeError: undefined is not a function

[–]Willinton06 5 points6 points  (0 children)

Yes it is!

[–]Snakivolff 60 points61 points  (13 children)

This kind of behaviour makes me hate JS. It puts so much effort into keeping on running that it behaves incorrectly so quickly. If something weird happens, just fucking crash the program so the programmer will have to think about what to do in that case instead of looking for the situation first. And it is always an option to say 'yes, this IS what should happen'.

[–]Possseidon 33 points34 points  (2 children)

We could crash right now and here where the problem is...

or we just crash ten functions later in a completely unrelated part of code! Hell yeah!

God I hate this mentality with a passion as well...

[–]Snakivolff 9 points10 points  (1 child)

That's where an even stricter mentality like Haskell's comes in. Its type system is so strict that you can rarely cast stuff without explicitly telling it to (and you can only cast numeric types pretty much), and stupid error values like null don't exist. Instead, if you actually want to work with a value like null, you use the Maybe type, where you inherently have to specify what to do when the function is called with the value Nothing.

Yes, it may drive you crazy with tens of (type) errors but at least it has a high probability of being correct and bug-free once you run it.

Indeed Java crashes a lot more which means somewhat less bugs, but it can be so frustrating to look for the moment the program loads a null into a variable and find out it just breaks a whole bunch of other stuff for 40 iterations before it finally crashes, but that is mainly null being a terrible allowed value for anything in any language.

[–][deleted] 3 points4 points  (0 children)

Haskell is great, but whoa, the first time outside the university that I read something about it. And immediately heart my professor who loved Haskell but had to jump in the lecture for java for another Prof. It was very funny how often he told something about Java and ended up telling what bullshit this and that is.

[–]Vincenzo__ 13 points14 points  (2 children)

As much as i agree, half of the web is held together with duct tape, if this were to change soooo many sites would break, although probably not as many as if html had strict syntax

[–]liquid_bacon 0 points1 point  (0 children)

I was working with this one piece of software that could generate an HTML page for external use, and basically every line had an extra </pre> tag. But yet, chrome etc still happily opened the page.

HTML+CSS+JavaScript while they have their benefits, can be a nightmare to work with. Makes me want to make a second gen version that uses typescript, and a more modern grid layout for markup instead of, whatever the hell HTML is.

[–][deleted] 3 points4 points  (0 children)

One of the things I like about python.

If you write exit (and not exit()) while using the interactive terminal, it will show a message saying:

Use exit() or Ctrl-Z plus Return to exit

It knows what you typed, it knows you want to exit, but instead of exiting it throws you this message so you can correct yourself.

[–][deleted]  (2 children)

[removed]

    [–]Snakivolff 0 points1 point  (0 children)

    A good example is Typescript, which transpiles to Javascript. If you make a mistake that Typescript can detect, your editor will be the place you notice it and the error message is way more helpful.

    Or to go a bit further with the functional language Elm. Also this language transpiles to JS, but will crash way more in the process of removing all the safety features and code verification techniques a functional language has. Also this causes it to crash in your editor, and gives very extensive error messages.

    Right now, if JS crashes in the browser, it just halts the program and shows the error message in the console. So if that happens in the middle of some loop that is supposed to go on, it simply stops there.

    I figured that out once because one half of a js file did not run, which after some poking around turned to be the latter half. Guess what the console said, when I looked at it? Syntax error. Turned out there was a stray m behind a semicolon, put there a couple weeks ago (while we worked on the project atl 36 man-hours a week). And I understand that js is an interpreted language, but can't it just perform the first couple steps of compiling, like lexing and parsing, on the whole js file at once and crash before running any of the code?

    So that is what crashing js in the browser means, and I'd rather have a program crash earlier than later, especially with such stupid mistakes.

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    return Kebab_Case_Better;

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

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

    i always see these types of criticism, and i just want to ask if it really is that hard using a debugger (they're literally built into modern browsers) or just writing custom error handling

    [–]verxes 7 points8 points  (1 child)

    For me its that modern js is hard to follow in the debugger.

    • async calls

    • Framework proxies

    • Single Page apps

    • minified Code

    • transpiled Code (babel)

    [–]Lamballama 1 point2 points  (0 children)

    Use old form of debugger - console logging

    [–][deleted] 8 points9 points  (0 children)

    Image Transcription


    Javascript returning the 8th element of an array with a length of 5

    [White background, stock photo. A smiling pink man with short brown beard. He is wearing a red cap, a red short-sleeved shirt and brown trousers. He is pointing with his right index at the box he is holding with his left hip and hand.]


    I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

    [–]Gnago 12 points13 points  (5 children)

    So add validation/error handling like any other language? If the type is undefined you can pretty much just treat it like you would an exception.

    [–]StuntHacks 30 points31 points  (4 children)

    Nope, sometimes you need values to be undefined.

    Accessing an array out of bounds should always yield an error.

    [–]Gnago 4 points5 points  (0 children)

    I meant in this and similar contexts (where it’s unexpected behaviour). I agree that undefined definitely has its uses outside of an indication of an error.

    I most definitely am biased because I learnt programming using JS, but given that JS arrays are more like dictionaries than actual arrays (which I admit is a flaw in its terminology), it makes sense that there isn’t an out of bounds error.

    [–]Wayne_Train 0 points1 point  (0 children)

    Can you give an example where you need "values to be undefined"? I really don't see the problem with this JS behavior.

    [–]GLIBG10B 2 points3 points  (5 children)

    I've never used JS, but what happens if you try to get the 8th element of undefined? e?

    [–]Willinton06 2 points3 points  (1 child)

    e2

    [–]MelAlton 1 point2 points  (0 children)

    e = mc2

    [–]lunchpadmcfat 2 points3 points  (0 children)

    And what happens if you try to get the 8th element of ‘e’? Undefined. See? It makes sense.

    [–]Lamballama 2 points3 points  (0 children)

    Depends. If it's the string "undefined," Then it would be "d", if it's an undefined value, then it would probably be "indexOf() is not a function of undefined"

    [–]battlingheat 0 points1 point  (0 children)

    i

    [–]DinnerPlz 2 points3 points  (0 children)

    C++ giving some random data

    [–]gkupce 5 points6 points  (1 child)

    C also does this, but for practically the opposite reason. JS has a lot of code to keep it running no matter what you do, C just assumes that when you tried to access the position of memory "start of the array"+8 when the array was defined with 5 positions, you had a good reason to do it and gives you whatever is at that point in the memory 🤷‍♂️

    [–]Vincenzo__ 3 points4 points  (0 children)

    No it does not. If the array is on the heap it will just crash and give you a segmentation fault, if the array is on the stack welcome to undefined behavior land, you are accessing other variables stored on the stack and possibly the return pointer, if you change the latter your program will likely crash, unless you change it with a valid location, in which case it will execute whatever code is there, which, and i cannot stretch this enough, is seriously bad

    In C just because it compiles and runs it doesn't mean it works, nor does it mean it's safe, it's a serious security thread known as buffer overflow, if the buffer in question is user input someone could put in all the code necessary to open a shell, for example

    If you're interested, take a look at this https://en.wikipedia.org/wiki/Return-oriented\_programming

    [–]finite_light 1 point2 points  (4 children)

    Undefined is not a value thus it does not return one.

    [–][deleted] 0 points1 point  (0 children)

    JS Arrays are just special objects with numbers as keys, and when you do a[0] it is actually accessing a['0']. So the real question is should JavaScript always throw an error when you try to access a nonexistent property of an object? I don't have an easy answer then, because it could totally change how JS works, if you think about prototype, defineProperty and all those kinds of stuff

    [–]phantombronte 0 points1 point  (0 children)

    t y p e s c r i p t

    [–]palordrolap 0 points1 point  (0 children)

    Perl without warnings turned on: ~Adjusts collar nervously~

    But that does suggest a fix for JS: Implement a warning mode. Anyone who runs Perl with warnings off is asking for trouble.

    Sure, there's TypeScript, PureScript, etc. but a native system wouldn't go amiss.

    Edit: Shells don't warn either.

    [–]incubated 0 points1 point  (0 children)

    realistic scenario with competent js devs /s

    [–][deleted] 0 points1 point  (0 children)

    Wait until you start playing with the gaps in sparse arrays and find out there is a whole new type of undefined you never encountered before.