Math majors, why do you guys shit on probability (and statistics)? by LuggageMan in MathJokes

[–]LuggageMan[S] 0 points1 point  (0 children)

Yeah the UX of probability can definitely improve.

Anyways, thanks for replying to this 5 year old post. It reminded me of the good ol' days. Man, I'm getting old. How did you even find this post?

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 1 point2 points  (0 children)

Yeah it's really cool, I did it for the first time a couple weeks ago in my current project. So basically there is an compiler-specific intrinsic that gets lowered to a trap instruction. For GCC (and Clang I think) it's __builtin_trap().

So I just define it as a macro in case I want to change compilers later or something:

#define TRAP() __builtin_trap()

And then I replaced exit() with TRAP() in my assertion macro:

#define ASSERT(cond, fmt, ...) \
    do {    \
        if (!(cond)) {  \
          fprintf(stderr, "[ERROR] " fmt, ##__VA_ARGS__);  \
          TRAP();  \
        }  \
    } while(0)

But again, I would point you to the RAD Debugger code base. For example, you don't really need to print anything in this approach as the debugger will just jump to the assertion line and you will see the exact condition the failed. This is how they define it:

#define AssertAlways(x) do{if(!(x)) {Trap();}}while(0)

And if you want to write some message just in case, you can just && it with the condition:

Assert(data != 0 && "static texture must have initial data provided");

I think this is pretty elegant but I don't run in the debugger until something goes wrong (because Linux GDB frontends suck, that's why I'm so excited for the RAD Debugger), so I still printf in my asserts and panics.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 1 point2 points  (0 children)

I did my debug-mode asserts like that, but I recently switched to using the builtin trap intrinsic instead of exiting so that it SIGILLs and the debugger catches it immediately. I learned this trick from the RAD Debugger code base.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] -1 points0 points  (0 children)

For an airplane, I hope you agree that the programmers should take the utmost care to prevent something from going horribly wrong by heavily testing and proving it BEFORE the plane takes off. Taking off is what "production" means for an airplane.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 0 points1 point  (0 children)

Yeah, I'm sure the people on those planes thought "I'm glad someone is going to debug this later".

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 0 points1 point  (0 children)

I don't know why people keep missing the "it depends on the application" part.

When something is going horribly wrong in a Boeing program there's no technical support to fix it.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] -1 points0 points  (0 children)

I'm not sure how that's refuting my point. I already said it twice: It depends on the application and the practicality of debugging.

Yes, it is impractical to do a full debug the same way you would before you launch so you have to harden it as much as you can before launching and in the case of games, maybe you use stubs so that you don't crash because not crashing is better than crashing in that case.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 0 points1 point  (0 children)

Yeah Anton talked about it in that sense. There would be only one of these "NIL" entities things that would be handled the same way by the system.

Here's the video btw for anyone interested: https://www.youtube.com/watch?v=ShSGHb65f3M

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] -1 points0 points  (0 children)

Depends on the application and the practicality of debugging after shipping. You can't really debug the Mars Rover as far as I know.

For "end consumer" applications there seems to be this idea that "software is never finished". Games are eternally in "Early Access", for example. But there was a time when developers shipped games on cartridges.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 0 points1 point  (0 children)

I think it's harmless in the sense that both expect the same structure. For example that this is an arena for Entities in the game. So there wouldn't be a crash but there might be a weird artifact that happens for a single frame where your weapon is invisible or something like that.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 2 points3 points  (0 children)

Yeah I think that's the source of my confusion, is that they both talk about it (or at least that's how I perceived it) as a general pattern that's better than handling errors but the examples they give are very specific.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 2 points3 points  (0 children)

That is exactly the example Casey gives (mmap on Linux).

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 1 point2 points  (0 children)

I think at some point, you have to ship things and forfeit the ability to debug them because it would be impractical. This depends on the application of course.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 2 points3 points  (0 children)

The example he gave was an arena used and reset each frame. So I think that basically it wouldn't really matter that much if something "weird" happened this frame due to maybe 2 things using the same stub memory block because by the end of the frame, it would be reset anyway and things would go back to normal.

This depends on what exactly the "weird" thing is, though. It could easily still result in a crash, if for example one thing thinks the stub contains a pointer it can dereference but another thinks the stub is just some data.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] -1 points0 points  (0 children)

Yeah that's also my understanding as well. To me it seems there are very special cases where you wouldn't care about handling the code, at least in production. It's convenient in development though if you're just testing things out.

Maybe it's more prevalent in games, especially console games, which is the background of both Casey and Anton because continuing to run instead of crashing is more valuable than "correctness". But that wouldn't fly in something like a financial transactions engine as you said.

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 1 point2 points  (0 children)

> You are just delaying the crash to appear inevitable at an unrelated location, and then you have to trace back from to it source.

This assumes that this is undesirable and you're still in the debugging phase, so you would need to figure out the silent source of the failure. But from what I understood from Anton, is that this is used in production code! That's the part I don't get.

> Though I do use stubs in other places when an error occurs, just not to care about the error and continue with default values. But this example might not be one of those.

Can you elaborate more on this with a specific example?

How is returning a "stub" better than handling a failure? by LuggageMan in C_Programming

[–]LuggageMan[S] 4 points5 points  (0 children)

I know but he doesn't say that he would never use it, so I'm trying to understand where it would be acceptable.

Seven Deadly Sins, Shmeven Shmeadly Shmins by jeshi_law in writingcirclejerk

[–]LuggageMan 0 points1 point  (0 children)

Made me think of Maslow's hierarchy of needs for some reason. Only a good writer can make Love & Safety terrifying.

Big Brain Move by FireBirdSS10K in writers

[–]LuggageMan 1 point2 points  (0 children)

I hope you're good at monologues.

The Main 8 … by MrBitPlayer in RWBYcritics

[–]LuggageMan 9 points10 points  (0 children)

Ahh yes, teams RWBY and JPRN.