-
-
Save smtalimett/9d14e90a604bd4cf14ed4a8b3e110152 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.0; | |
// A simple smart contract | |
contract MessageContract { | |
string message = "Hello World"; | |
function getMessage() public constant returns(string) { | |
return message; | |
} | |
function setMessage(string newMessage) public { | |
message = newMessage; | |
} | |
} |
@istiaque010 isn't this the long way around though?
cant you just so something like:
` string public greeting;
function greeter(string memory _greeting) public {
greeting = _greeting;
}`
This way you'll be able to call the greeter function and still be able to see the greeting since the visibility is public? Just wondering.
@orlundo-wursta Public variables are bad practice because it is difficult to keep control over them thus they should be avoided. The contract should be a black box to the outside world following the rules of encapsulation - you could use getter and setter functions if it really has to be global.
https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/
@orlundo-wursta Public variables are bad practice because it is difficult to keep control over them thus they should be avoided. The contract should be a black box to the outside world following the rules of encapsulation - you could use getter and setter functions if it really has to be global. https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/
bro this isn't java, this is THE blockchain! keep the needed vars public so you don't have to waste gas or deploy extra code for nothing!
private stuff should stay private ;)
@orlundo-wursta Public variables are bad practice because it is difficult to keep control over them thus they should be avoided. The contract should be a black box to the outside world following the rules of encapsulation - you could use getter and setter functions if it really has to be global. https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/
bro this isn't java, this is THE blockchain! keep the needed vars public so you don't have to waste gas or deploy extra code for nothing! private stuff should stay private ;)
Well if the code is not too big then go ahead. This reminds me on the Atmega 128 microprocessor programming days where you don't care much about architecture because the code cannot be big enough on those tiny processors to be super unreadyable anyway.
pragma solidity 0.8.11;
contract Greeter{
}