73

Been feeling like a caveman after moving from Java to Ruby. Reminded me of this.

Comments
  • 25
    Welcome to devRant. Post legit rants and you'll quickly get the ++ you need.

    Also,
    You're an idiot if you're using a plain old array in C++ and complaining about the lack of bounds checking. Because the Java array is a mammoth object with a fuckton of methods and metadata while the C++ array is literally just a block of memory that you have to manage on your own.

    Most C++ STL containers have functions that return elements after bounds checking, like std::vector's at(). Unlike Java, the C++ language philosophy is to give you choices and trust you to pick the right ones.
  • 13
    Edit: I seem to spend a lot of time defending C++, lol. Not just on dR, but irl too. Don't mind me.
  • 3
  • 2
    @RememberMe to be fair, working with raw chucks of memory has it's own flair 😁
  • 3
    In C++ you make sure you can do something before you do it. If you dereference a null or invalid pointer, that’s your fault. Java on the other hand teaches lazy coding with training wheels that try and catch you when you fall.

    I can’t abide any meme that tries to make Java look in any way superior to C++.
  • 4
    C++ gang ✊🏽🤘🏽 lol@RememberMe
  • 3
    @devios1 Java << C# << C++, the truth has now been spoken
  • 0
    @7Raiden Kotlin ~ C#, in case you want still want to reap the benefits of java.

    I know this must sound to you like a joke
  • 0
    @Awlex never tried that TBH :)
  • 0
  • 3
  • 0
    @devios1 undefined behavior is way worse than a bit of a penalty for exception handling.
  • 0
    @beegC0de An uncaught exception is arguably not much better.

    An exception might help you catch* a problem that happens in production more easily, but if you’re expecting/relying on exceptions, you’re doing it wrong.

    *It’s impossible to talk about exceptions without accidental puns.
  • 1
    @devios1 I know it is bad to rely on them, but I would rather have an exception thrown that literally makes it impossible to index out of bounds or follow a null pointer.
  • 0
    @beegC0de It’s better than crashing hard with a seg-fault, I’ll give you that.
  • 0
    …but don’t forget it comes with a cost. C++ is really just a thin layer on top of the hardware: you can do stupid and dangerous things with it, but it’s also blazingly fast.
  • 1
    @devios1 c++ has its own version of exceptions as well. See http://cplusplus.com/reference/... it is a bounds-checked vector accessor that throws an exception for a bad index.
  • 2
    @beegC0de Interesting. It’s been a while since I’ve used C++ admittedly. I’m not personally a fan of exceptions whenever they can be avoided. I’d rather document the inputs and outputs of the function and return null if given invalid input.

    I do think exceptions are useful on a low level when it truly is an unexpected condition: unwinding the stack back to a place where it can be handled gracefully is better than crashing hard, as I said.

    An example of a good exception is if the disk is full. Imo that’s a proper use of an exception. However, as a counter example, catching an exception if you try to write to a file that doesn’t exist is sloppy. That’s relying on the exception to tell you whether the file is there or not. Instead, if you follow my personal approach, you would have to first attempt to instantiate an object that represents the file you want to write to. If it’s null, there’s no file object to even try. If it disappears unexpectedly though, exception.
  • 1
    @vlatkozelka yeah, heh, that's why I posted the second comment. Didn't want @clonancodes to leave because of me 😅

    I've been kinda annoyed at the pointless hate that C++ gets, lel.
Add Comment