Do all Smart Contracts use the eosio namespace?
Clash 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?
smart-contract c++
add a comment |Â
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?
smart-contract c++
1
theeosiolib
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
add a comment |Â
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?
smart-contract c++
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?
smart-contract c++
edited Sep 2 at 15:17


confused00
2,589326
2,589326
asked Sep 2 at 13:19


SteveJaxon
1184
1184
1
theeosiolib
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
add a comment |Â
1
theeosiolib
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
add a comment |Â
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.
add a comment |Â
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.
but the contract is not namespaced undereosio
in OP's example. theusing
directive only brings theeosio
namespace into the local scope so one can writecontract
instead ofeosio::contract
even if the example doesn't actually take advantage of this when inheriting
– confused00
Sep 2 at 14:30
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered Sep 2 at 15:15


confused00
2,589326
2,589326
add a comment |Â
add a comment |Â
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.
but the contract is not namespaced undereosio
in OP's example. theusing
directive only brings theeosio
namespace into the local scope so one can writecontract
instead ofeosio::contract
even if the example doesn't actually take advantage of this when inheriting
– confused00
Sep 2 at 14:30
add a comment |Â
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.
but the contract is not namespaced undereosio
in OP's example. theusing
directive only brings theeosio
namespace into the local scope so one can writecontract
instead ofeosio::contract
even if the example doesn't actually take advantage of this when inheriting
– confused00
Sep 2 at 14:30
add a comment |Â
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.
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.
answered Sep 2 at 13:52


Phillip Hamnett - EOS42
655220
655220
but the contract is not namespaced undereosio
in OP's example. theusing
directive only brings theeosio
namespace into the local scope so one can writecontract
instead ofeosio::contract
even if the example doesn't actually take advantage of this when inheriting
– confused00
Sep 2 at 14:30
add a comment |Â
but the contract is not namespaced undereosio
in OP's example. theusing
directive only brings theeosio
namespace into the local scope so one can writecontract
instead ofeosio::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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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