How do I define and register a shortcode function in a namespaced functions.php file?

Thanks to Stanislav Khromov (also active on WPSE!), I learned any Callable referenced in add_shortcode() must be fully qualified, even if it is defined in the same file you’re referencing it.

<?php
/**
 * theme's functions.php
 */

namespace MyNamespace;

//[foobar]
function foobar_func( $atts ){
    return "foo and bar";
}
add_shortcode( 'foobar', '\MyNamespace\foobar_func' );

You may omit the leading backslash, if you prefer: add_shortcode( 'foobar', 'MyNamespace\foobar_func' );