Giter Club home page Giter Club logo

ceylon-config's People

Contributors

qdzo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ceylon-config's Issues

stop catching (and potentially throwing) assertion errors

Assertion errors in Ceylon indicate that something that should never happen in a correctly‐written program has happened; they are not meant to actually be caught. Catching them is not only bad practice, but it’s also inherently wrong by the definition of assertion errors.

Additionally, assertions are meant to check for developer input, and not user input. An uncaught assertion error implies that there is a bug in the program, and not that the user didn’t provide a necessary environment variable.

The correct thing to do would be to have your optional methods potentially return null, and have your existence‐asserting methods check for their result and throw something that is not an AssertionError in case they are null so that it can be caught by the developer for them to display a proper error message.

That is, instead of writing the following:

shared String getString(Object key){
    assert(exists val = get(key));
    return val;
}

shared String? getStringOrNull(Object key){
    try {
        return getString(key);
    } catch(AssertionError ae) {
        return null;
    }
}

it is, by the definition of AssertionError, objectively more correct to write the following:

shared String? getStringOrNull(Object key) => this[key];

shared String getString(Object key)
{
    if(exists string = getStringOrNull(key))
    {
        return(string);
    }
    else
    {
        throw(Something());
    }
}

Perhaps more subjectively, I really don’t think these type‐unsafe non‐OrNull methods are actually a good practice in Ceylon. Ideally you don’t want to give the user of your library the confidence that these values will exist, and instead, you should require them to actually act upon the possibility of them not existing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.