News for hackers. Stuff that matters.
Re:Bypassing GitHub's OAuth Flow with a Head Request by progval on Thursday November 07, 2019 @03:12PM (#21476846)
Some languages have good alternatives to this. Examples:

* Rust has an unreachable!() macro that tells readers and static analyzers that it should be dead code; but raises an error if executed at runtime. https://doc.rust-lang.org/std/macro.unreachable.html

* Languages with pattern-matching will either crash at compile-time if the set of clauses is non-exhaustive, or at run time if a case is missing. That is, if you don't have a catch-all clause.

Re:Bypassing GitHub's OAuth Flow with a Head Request by ryandrake on Thursday November 07, 2019 @03:55PM (#21477152)
Cool language feature! I’ve done this in other languages using a code style policy where all “naked” else statements and ‘default’ inside a switch statement must throw an uncaught exception or otherwise deliberately crash.

    if(option==1)
        do_somethimg();
    else
        do_something_else();
...must then be rewritten as:

    if(option==1)
        do_somethimg();
    else if(option==2)
        do_something_else();
    else
        abort();
This kind of defensive coding would have helped to prevent the famous ‘goto fail’ bug from a few years ago.
Re:Bypassing GitHub's OAuth Flow with a Head Request by rtpg on Friday November 08, 2019 @01:31AM (#21480367)
Typescript has the `never` type, which is meant for values that are never used. You can combine that with other stuff to get something _like_ `unreachable!` but it's a bit hard to get working right to be honest.