Giter Club home page Giter Club logo

Comments (5)

dopplershift avatar dopplershift commented on June 15, 2024 1

Honestly, 95% of my use of assert is when writing tests. I used to use them to sanity check conditions in I/O code, but I've replaced that with logging and trying to continue--it's not helpful to users when your assert needlessly causes reading a file to completely crash out a script.

I think assert does have it's place, but I don't think it's something critically important for scientist programmers to know. Much more important, IMO, is error handling with try...except and raise. Also provides an opportunity to introduce them to reading tracebacks... 😉

from python-aos-lesson.

DamienIrving avatar DamienIrving commented on June 15, 2024

Good point, @dopplershift. From what you've seen of the plot_precipitation_climatology.py script, are there more authentic/appropriate places we could use assertions? (There's currently three assertions in the final version of the script.)

If we can't think of an appropriate use case for assertions in plot_precipitation_climatology.py, we could also consider using the example in the Software Carpentry defensive programming lesson. There are some nice post-conditions in that example where assertions check that the calculated result is within sensible bounds.

We could also introduce catching and handling errors using try/except in the defensive programming section?

Note to self: We should also get rid of the rainfall observations loop at the beginning of the defensive programming chapter and just use assert np.min(rainfall_obs) >=0.0, because we literally just finished the vectorisation chapter where we talk about avoiding loops.

from python-aos-lesson.

CristinaUrizar avatar CristinaUrizar commented on June 15, 2024

For quality controlling code, I believe that assertions can be helpful. Though, I have some suggestions on some of the wording and would also like to suggest another objective.

Oftentimes, meteorologists and oceanographers operationalize their code (run it every day at the same time, for example) to analyze data as it comes in. The assertions can be directed to a log file that tracks the code accuracy (I suggest "accuracy" rather than "reliability" in this context) each time it runs.

Failure to generate a new log file (that may, or may not, include the output from the assertions), or a new entry in the log file, indicates a failure of the code to run. This is oftentimes referred to as "reliable" code.

I would suggest "How can I check my programs' accuracy?" for the lesson question rather than "How can I make my programs more reliable?"

That being said, I would leave both questions and introduce the Objective "Create log files to verify my program's reliability."

As an operational oceanographer who is new to Python, this would be very beneficial to me and my colleagues.

from python-aos-lesson.

DamienIrving avatar DamienIrving commented on June 15, 2024

"Assert is removed with compiling to optimised byte code (python -o producing *.pyo files)."

https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

from python-aos-lesson.

DamienIrving avatar DamienIrving commented on June 15, 2024

Just FYI to anyone on this thread who might be interested - I've done a re-write of the defensive programming lesson taking on board all your feedback. See #55 for details.

from python-aos-lesson.

Related Issues (20)

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.