News for hackers. Stuff that matters.
Re:You’re better off using Exceptions by burtonator on Monday February 03, 2020 @12:21PM (#22226333)
The biggest issue I've seen with exceptions is that people bring up the issue when they are abused. I SORT of agree with you that an 'Record not found' exception is an abuse. This should probably be a null-object like an Optional ALA Java or Scala.

They are trying to avoid returning null in this scenario.

Unfortunately, if the API is designed poorly you're stuck with it.

I can sort of understand why people hate checked exceptions but working without exceptions is just terrible.

Re:You’re better off using Exceptions by jfengel on Monday February 03, 2020 @12:38PM (#22226603)
Nulls are also called the billion-dollar mistake (and that was decades ago; it's much more than that now). Both nulls and exceptions are ways of trying to make the main line of processing clear, while handling other lines in structured ways.

There's no one-size-fits-all solution. In a lot of ways, the best response to "record not found" is that you get the same result as finding one, except with zero answers. That means your main line can process the same way -- unless that doesn't produce the result you need. In which case maybe you an if(null) somewhere, or a special fake record, or an exception.

Re:You’re better off using Exceptions by aikah on Monday February 03, 2020 @12:57PM (#22226865)
> Nulls are also called the billion-dollar mistake (and that was decades ago; it's much more than that now). Both nulls and exceptions are ways of trying to make the main line of processing clear, while handling other lines in structured ways.

At the same time before NULL, devs used to use "guard values", so NULL is really just a convenience.

for instance, just to illustrate what I'm saying:

    let NULL = {} /* should every lib define its own null value? */

    function GetOneRecord(){
        let dbResult = queryRecordsFromDB();
        if (dbResult.length === 0){
            return NULL
        }
        return dbResult.records[0];
    }
Optional types, are better, but one needs functional programming features for it to be really useful.

What's people opinion on zero values by the way?

Re:You’re better off using Exceptions by loopz on Monday February 03, 2020 @04:41PM (#22229485)
Zero values may act as nice defaults. Programmers who care about their code, often want initial state or default state to reflect something useful. What zero value should reflect depends on context, but you get to state that once and for all, for that type. It's just one less thing off a mind when building code, although you'd want to catch any invalid usage. Ie. referencing zero value, could result in error if due to control flow, and panic() in case of programmer error. I don't think the language or library should choose for you, unless being bound by that is a very useful trade-off.
Re:You’re better off using Exceptions by Gibbon1 on Monday February 03, 2020 @01:03PM (#22226962)
Yeah the problem really is 'in band signaling' See SQL injection attacks for an another example why the practice is dodgy.
Re:You’re better off using Exceptions by detaro on Monday February 03, 2020 @01:01PM (#22226922)
What "functional programming features" does one need for useful optional types?
Re:You’re better off using Exceptions by kibwen on Monday February 03, 2020 @01:23PM (#22227203)
Putting aside the "functional" bit, for a language to allow user-defined (i.e. not hardcoded into the language itself (which may not necessarily be a bad thing, but that's beside the point here)) optional types, you'd want the ability to say "this variable is either _this_ XOR _this_" (a.k.a. tagged unions/sum types/what Rust calls "enums"), and then in a statically-typed language you'd additionally want generics.
Re:You’re better off using Exceptions by vraivroo on Monday February 03, 2020 @02:26PM (#22227942)
Null _pointers_ are called the billion-dollar mistake, not null values.