Do all Smart Contracts use the eosio namespace?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I'm new to creating Smart Contracts on EOS and I've followed a few tutorials (for example the official Hello World guide).



Would someone be able explain why all of the examples seem to use the namespace eosio?



Is it possible to use a different namespace?




#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;

class hello : public eosio::contract
public:
using contract::contract;

/// @abi action
void hi( account_name user )
print( "Hello, ", nameuser );

;

EOSIO_ABI( hello, (hi) )


If it is possible to use a different namespace, what are some example situations in which you would use one?



If it isn't possible to use a different namespace, is there any reason why this needs to be in the code and couldn't be left for the compiler to add?







share|improve this question


















  • 1




    the eosiolib is under eosio namespace to avoid collisions and maintain good practices. it's just standard language-agnostic programming practice to namespace imports
    – confused00
    Sep 2 at 13:23














up vote
3
down vote

favorite












I'm new to creating Smart Contracts on EOS and I've followed a few tutorials (for example the official Hello World guide).



Would someone be able explain why all of the examples seem to use the namespace eosio?



Is it possible to use a different namespace?




#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;

class hello : public eosio::contract
public:
using contract::contract;

/// @abi action
void hi( account_name user )
print( "Hello, ", nameuser );

;

EOSIO_ABI( hello, (hi) )


If it is possible to use a different namespace, what are some example situations in which you would use one?



If it isn't possible to use a different namespace, is there any reason why this needs to be in the code and couldn't be left for the compiler to add?







share|improve this question


















  • 1




    the eosiolib is under eosio namespace to avoid collisions and maintain good practices. it's just standard language-agnostic programming practice to namespace imports
    – confused00
    Sep 2 at 13:23












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I'm new to creating Smart Contracts on EOS and I've followed a few tutorials (for example the official Hello World guide).



Would someone be able explain why all of the examples seem to use the namespace eosio?



Is it possible to use a different namespace?




#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;

class hello : public eosio::contract
public:
using contract::contract;

/// @abi action
void hi( account_name user )
print( "Hello, ", nameuser );

;

EOSIO_ABI( hello, (hi) )


If it is possible to use a different namespace, what are some example situations in which you would use one?



If it isn't possible to use a different namespace, is there any reason why this needs to be in the code and couldn't be left for the compiler to add?







share|improve this question














I'm new to creating Smart Contracts on EOS and I've followed a few tutorials (for example the official Hello World guide).



Would someone be able explain why all of the examples seem to use the namespace eosio?



Is it possible to use a different namespace?




#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;

class hello : public eosio::contract
public:
using contract::contract;

/// @abi action
void hi( account_name user )
print( "Hello, ", nameuser );

;

EOSIO_ABI( hello, (hi) )


If it is possible to use a different namespace, what are some example situations in which you would use one?



If it isn't possible to use a different namespace, is there any reason why this needs to be in the code and couldn't be left for the compiler to add?









share|improve this question













share|improve this question




share|improve this question








edited Sep 2 at 15:17









confused00

2,589326




2,589326










asked Sep 2 at 13:19









SteveJaxon

1184




1184







  • 1




    the eosiolib is under eosio namespace to avoid collisions and maintain good practices. it's just standard language-agnostic programming practice to namespace imports
    – confused00
    Sep 2 at 13:23












  • 1




    the eosiolib is under eosio namespace to avoid collisions and maintain good practices. it's just standard language-agnostic programming practice to namespace imports
    – confused00
    Sep 2 at 13:23







1




1




the eosiolib is under eosio namespace to avoid collisions and maintain good practices. it's just standard language-agnostic programming practice to namespace imports
– confused00
Sep 2 at 13:23




the eosiolib is under eosio namespace to avoid collisions and maintain good practices. it's just standard language-agnostic programming practice to namespace imports
– confused00
Sep 2 at 13:23










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










eosiolib uses the eosio namespace to avoid collisions when imported in a different scope--this is standard programming practice and is not specific to EOSIO. The using namespace <name> directive only brings that namespace in the current scope in order to avoid overusing the scope-resolution operator ::. How you actually use it in the end is just a styling distinction. You can write the same contract in many ways:



No using



#include <eosiolib/eosio.hpp>

class hello : public eosio::contract
public:
using eosio::contract::contract;

/// @abi action
void hi( account_name user )
eosio::print( "Hello, ", eosio::nameuser );

;

EOSIO_ABI( hello, (hi) )


With using namespace



#include <eosiolib/eosio.hpp>
using namespace eosio;

class hello : public contract
public:
using contract::contract;

/// @abi action
void hi( account_name user )
print( "Hello, ", nameuser );

;

EOSIO_ABI( hello, (hi) )


With using eosio::<name>



#include <eosiolib/eosio.hpp>

using eosio::contract;
using eosio::print;
using eosio::name;

class hello : public contract
public:
using contract::contract;

/// @abi action
void hi( account_name user )
print( "Hello, ", nameuser );

;

EOSIO_ABI( hello, (hi) )


I personally find the last one most readable as it is clear where every name is coming from, but it requires more typing than the second example.






share|improve this answer



























    up vote
    0
    down vote













    I don't think you have to use the eosio namespace, but given that your contract will inherit from eosio::contract, it would be standard practice to also use the eosio namespace.






    share|improve this answer




















    • but the contract is not namespaced under eosio in OP's example. the using directive only brings the eosio namespace into the local scope so one can write contract instead of eosio::contract even if the example doesn't actually take advantage of this when inheriting
      – confused00
      Sep 2 at 14:30











    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "696"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2feosio.stackexchange.com%2fquestions%2f2217%2fdo-all-smart-contracts-use-the-eosio-namespace%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    eosiolib uses the eosio namespace to avoid collisions when imported in a different scope--this is standard programming practice and is not specific to EOSIO. The using namespace <name> directive only brings that namespace in the current scope in order to avoid overusing the scope-resolution operator ::. How you actually use it in the end is just a styling distinction. You can write the same contract in many ways:



    No using



    #include <eosiolib/eosio.hpp>

    class hello : public eosio::contract
    public:
    using eosio::contract::contract;

    /// @abi action
    void hi( account_name user )
    eosio::print( "Hello, ", eosio::nameuser );

    ;

    EOSIO_ABI( hello, (hi) )


    With using namespace



    #include <eosiolib/eosio.hpp>
    using namespace eosio;

    class hello : public contract
    public:
    using contract::contract;

    /// @abi action
    void hi( account_name user )
    print( "Hello, ", nameuser );

    ;

    EOSIO_ABI( hello, (hi) )


    With using eosio::<name>



    #include <eosiolib/eosio.hpp>

    using eosio::contract;
    using eosio::print;
    using eosio::name;

    class hello : public contract
    public:
    using contract::contract;

    /// @abi action
    void hi( account_name user )
    print( "Hello, ", nameuser );

    ;

    EOSIO_ABI( hello, (hi) )


    I personally find the last one most readable as it is clear where every name is coming from, but it requires more typing than the second example.






    share|improve this answer
























      up vote
      2
      down vote



      accepted










      eosiolib uses the eosio namespace to avoid collisions when imported in a different scope--this is standard programming practice and is not specific to EOSIO. The using namespace <name> directive only brings that namespace in the current scope in order to avoid overusing the scope-resolution operator ::. How you actually use it in the end is just a styling distinction. You can write the same contract in many ways:



      No using



      #include <eosiolib/eosio.hpp>

      class hello : public eosio::contract
      public:
      using eosio::contract::contract;

      /// @abi action
      void hi( account_name user )
      eosio::print( "Hello, ", eosio::nameuser );

      ;

      EOSIO_ABI( hello, (hi) )


      With using namespace



      #include <eosiolib/eosio.hpp>
      using namespace eosio;

      class hello : public contract
      public:
      using contract::contract;

      /// @abi action
      void hi( account_name user )
      print( "Hello, ", nameuser );

      ;

      EOSIO_ABI( hello, (hi) )


      With using eosio::<name>



      #include <eosiolib/eosio.hpp>

      using eosio::contract;
      using eosio::print;
      using eosio::name;

      class hello : public contract
      public:
      using contract::contract;

      /// @abi action
      void hi( account_name user )
      print( "Hello, ", nameuser );

      ;

      EOSIO_ABI( hello, (hi) )


      I personally find the last one most readable as it is clear where every name is coming from, but it requires more typing than the second example.






      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        eosiolib uses the eosio namespace to avoid collisions when imported in a different scope--this is standard programming practice and is not specific to EOSIO. The using namespace <name> directive only brings that namespace in the current scope in order to avoid overusing the scope-resolution operator ::. How you actually use it in the end is just a styling distinction. You can write the same contract in many ways:



        No using



        #include <eosiolib/eosio.hpp>

        class hello : public eosio::contract
        public:
        using eosio::contract::contract;

        /// @abi action
        void hi( account_name user )
        eosio::print( "Hello, ", eosio::nameuser );

        ;

        EOSIO_ABI( hello, (hi) )


        With using namespace



        #include <eosiolib/eosio.hpp>
        using namespace eosio;

        class hello : public contract
        public:
        using contract::contract;

        /// @abi action
        void hi( account_name user )
        print( "Hello, ", nameuser );

        ;

        EOSIO_ABI( hello, (hi) )


        With using eosio::<name>



        #include <eosiolib/eosio.hpp>

        using eosio::contract;
        using eosio::print;
        using eosio::name;

        class hello : public contract
        public:
        using contract::contract;

        /// @abi action
        void hi( account_name user )
        print( "Hello, ", nameuser );

        ;

        EOSIO_ABI( hello, (hi) )


        I personally find the last one most readable as it is clear where every name is coming from, but it requires more typing than the second example.






        share|improve this answer












        eosiolib uses the eosio namespace to avoid collisions when imported in a different scope--this is standard programming practice and is not specific to EOSIO. The using namespace <name> directive only brings that namespace in the current scope in order to avoid overusing the scope-resolution operator ::. How you actually use it in the end is just a styling distinction. You can write the same contract in many ways:



        No using



        #include <eosiolib/eosio.hpp>

        class hello : public eosio::contract
        public:
        using eosio::contract::contract;

        /// @abi action
        void hi( account_name user )
        eosio::print( "Hello, ", eosio::nameuser );

        ;

        EOSIO_ABI( hello, (hi) )


        With using namespace



        #include <eosiolib/eosio.hpp>
        using namespace eosio;

        class hello : public contract
        public:
        using contract::contract;

        /// @abi action
        void hi( account_name user )
        print( "Hello, ", nameuser );

        ;

        EOSIO_ABI( hello, (hi) )


        With using eosio::<name>



        #include <eosiolib/eosio.hpp>

        using eosio::contract;
        using eosio::print;
        using eosio::name;

        class hello : public contract
        public:
        using contract::contract;

        /// @abi action
        void hi( account_name user )
        print( "Hello, ", nameuser );

        ;

        EOSIO_ABI( hello, (hi) )


        I personally find the last one most readable as it is clear where every name is coming from, but it requires more typing than the second example.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 2 at 15:15









        confused00

        2,589326




        2,589326




















            up vote
            0
            down vote













            I don't think you have to use the eosio namespace, but given that your contract will inherit from eosio::contract, it would be standard practice to also use the eosio namespace.






            share|improve this answer




















            • but the contract is not namespaced under eosio in OP's example. the using directive only brings the eosio namespace into the local scope so one can write contract instead of eosio::contract even if the example doesn't actually take advantage of this when inheriting
              – confused00
              Sep 2 at 14:30















            up vote
            0
            down vote













            I don't think you have to use the eosio namespace, but given that your contract will inherit from eosio::contract, it would be standard practice to also use the eosio namespace.






            share|improve this answer




















            • but the contract is not namespaced under eosio in OP's example. the using directive only brings the eosio namespace into the local scope so one can write contract instead of eosio::contract even if the example doesn't actually take advantage of this when inheriting
              – confused00
              Sep 2 at 14:30













            up vote
            0
            down vote










            up vote
            0
            down vote









            I don't think you have to use the eosio namespace, but given that your contract will inherit from eosio::contract, it would be standard practice to also use the eosio namespace.






            share|improve this answer












            I don't think you have to use the eosio namespace, but given that your contract will inherit from eosio::contract, it would be standard practice to also use the eosio namespace.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 2 at 13:52









            Phillip Hamnett - EOS42

            655220




            655220











            • but the contract is not namespaced under eosio in OP's example. the using directive only brings the eosio namespace into the local scope so one can write contract instead of eosio::contract even if the example doesn't actually take advantage of this when inheriting
              – confused00
              Sep 2 at 14:30

















            • but the contract is not namespaced under eosio in OP's example. the using directive only brings the eosio namespace into the local scope so one can write contract instead of eosio::contract even if the example doesn't actually take advantage of this when inheriting
              – confused00
              Sep 2 at 14:30
















            but the contract is not namespaced under eosio in OP's example. the using directive only brings the eosio namespace into the local scope so one can write contract instead of eosio::contract even if the example doesn't actually take advantage of this when inheriting
            – confused00
            Sep 2 at 14:30





            but the contract is not namespaced under eosio in OP's example. the using directive only brings the eosio namespace into the local scope so one can write contract instead of eosio::contract even if the example doesn't actually take advantage of this when inheriting
            – confused00
            Sep 2 at 14:30


















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2feosio.stackexchange.com%2fquestions%2f2217%2fdo-all-smart-contracts-use-the-eosio-namespace%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery