7

Here's a great talk about the wonders of Ruby & JavaScript that every dev should see at least once https://destroyallsoftware.com/talk...

Comments
  • 0
    I understand that this video is supposed to be funny, but most of these results actually make sense. They may not be intuitive, but with type coercion you would expect most of this behavior.

    It's really fun to make fun of the "script kiddie" languages like Ruby and JavaScript, but when you say things like "I don't understand what person with a brain in their head would think any of this is a good idea", you've gone too far.
  • 1
    @nathanasius even with knowing type coercion you wouldnt expect most of the examples. The nanana one sure but others nah. You'd had to know how js evaluates every operator.
  • 0
    @musician what example doesn't make sense with knowledge of type coercion? The most confusing one is {} + [], but that's because it's evaluating {} as a block rather than object literal.
  • 1
    @nathanasius I know how it works but only because I studied it. I dont think its that intuitive. Especially when you expect a + operation to be communative
  • 0
  • 0
    Why would you ever expect string concatenation to be commutative?

    "a" + "b" == "b" + "a" // false

    In the case from the video, it actually does have the same result regardless of order since the array coerces to an empty string. For example:

    var x = {}, y = [];
    (x + y) == (y + x) // true

    Seeing {} as a block is just a quirk with the parser since there is no easy way for it to know if it should interpret {} in {} + [] as an object literal or a block.

    Again, I did not say that it is intuitive, but programming languages often aren't. Having some unintuitive bits can be justified, and in the case of JS I think they are. Since objects can override the toString method, coercing objects to strings when using the concatenation operator can be useful.

    To a beginner, pointers and references in other languages are far from intuitive. Having some types pass by reference and others pass by value can also be unintuitive. But with basic understanding they come to make sense.
  • 0
    @irene if you don't have an understanding of pointers you may not understand why you need to dereference to get the value. They're not intuitive to someone who doesn't have an understanding of them, but once you learn the reasoning behind them they make sense. That's my point.
  • 0
    @irene that's my point. It's easy once you understand, but using it without understanding can give unexpected results.
  • 0
    @irene Exactly. That's my point here. If someone were to make a "WAT" video for C where he performs arithmetic on pointers and then makes fun of the output, we wouldn't say he has a good point. We'd say he has a poor understanding of the way the language works.
  • 0
    @irene well, that's a fair opinion. I have no problem with people who have an issue with a language's principles (implicit conversion), I just don't think people should be surprised when a language follows it principles and say it makes no sense. It makes sense, you just may think it's a bad idea.
Add Comment