7

In order to avoid namespace bloating, I use packages. For example, let Foo be a function in a package called FooPackage

function Foo()
   disp('Foo');
end

I want to use this function in another function called Bar.

function Bar()
    InFunc1();
    InFunc2();
    InFunc3();
end

this function calls sub-functions. The Naive way is to say explicitly the package name in each call

 function InFunc1()
    FooPackage.Foo();
end

function InFunc2()
   FooPackage.Foo();
end

function InFunc3()
   FooPackage.Foo();
end

Alternatively I can use an import in each and every function:

 function InFunc1()
    import FooPackage.*
    Foo();
end

function InFunc2()
    import FooPackage.*
    Foo();
end

function InFunc3()
    import FooPackage.*
    Foo();
end

Both of the ways are exhausting. The answer in here says that thes are the only ways. Does anyone has a better suggestion?

Community
  • 1
  • 1
Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104

1 Answers1

4

Maybe you could use a private directory. The functions in the private directory can be seen only by functions in its parent directory, and they can be called just by their names.

It's not a completely satisfying solution, but that can help.

Oli
  • 15,935
  • 7
  • 50
  • 66