Solidity Basics

how do you describe this in english, not computer?

Person memory newPerson;

is this a statement that exists only within a function? is it the equivalent of x = y even though there is no operator? Does the ‘memory’ sort of act as an equivalence operator?

you can teach an old dog new tricks…just takes us a bit longer

what is WRONG with this function identity statement ( x = x ) or (x memory x)

function createPerson(string memory name,uint age, uint height) public {
    Person memory Person;
    Person.id=people.length;
    Person.name=name;
    Person.age=age;
    Person.height=height;
    people.push(Person);
    //people.push( Person(people.length, name, age, height) );  
}   

to me this seems more logical (could be completely wrong, but hey…I’m trying to learn!)
…it seems to work and push the array without fault.

Thank you for clarification.
I wonder if in the future the massive amount of addresses would slow down exponentially the Ethereum network?

It’s more like this:

typeOfValue dataLocation variableName;

uint memory x;

Person         memory         newPerson;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
type       data location        variable

“=” and “memory” are not equivalent.
“=” is an assignment operation;
“memory” is a data location specifier;

1 Like

function createPerson(string memory name, uint age, uint height) public {

why is dataLocation mandatory of ‘string name’ but not for ‘uint age’ nor ‘uint height’…need to understand what appears inconsistent.

1 Like

@rostyslavdzhohola
Cryptography and blockchain are separate entities, hence blockchain does not scan through all the cryptographic keys in the space rather only those whole UTXO are stored in blockchain.
As mentioned previously the read-only mechanism is not an issue with blockchain and also with other traditional technologies. :slight_smile:

1 Like

@John_Okoye
Let me know, the answer from @rostyslavdzhohola helped you or not? :slight_smile:

@rostyslavdzhohola thanks for answering :slight_smile:

1 Like

@John_Okoye

  1. yes, you are right ‘to set’ is basically to assign values/inputs, I won’t say instance rather it occupies a space in EVM storage.
  2. You will always be our customer :slight_smile:
  3. its always best to follow a standard convention among developers, the use of quotation marks denotes string data type hence its always better to use quotation marks to avoid confusion especially writing large code base

Yes, it did help

  • yes, you are right ‘to set’ is basically to assign values/inputs, I won’t say instance rather it occupies a space in EVM storage*

yes, it’s important for me to understand this, not monkey see monkey do. EVM storage must be cloud…

  • You will always be our customer :slight_smile:

yes, definitely a repeat customer and remedial student…doing ehtereum 101 over even though issued certificate…don’t dare move on until I undertand basics better

  • its always best to follow a standard convention among developers, the use of quotation marks denotes string data type hence its always better to use quotation marks to avoid confusion especially writing large code base

advice well taken, I guess I should be doing more monkey see monkey do before I try reinvent the wheel
[/quote]

yes, thank you for the follow up

@John_Okoye Thanks for reaching out!

Every expert was once a nube!

  1. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
    An array with numeric indexes is called numeric array
    An array with string indexes (or both number and string indexes) is called as associative array or Dictionary
    All arrays consist of contiguous memory locations i.e. it is stored continuously in the CPU storage (EVM in our case).
    Every memory/storage location in the CPU (or EVM) has a hexadecimal address, and there are tons of such address (as per the size) hence we cannot guess the hexadecimal address rather its easier for us to get the index.

Every index has only one value in an array and indexes are alway unique but their values can be same e.g.
array A = [0=>12, 1=>13, 2=> 12, 3=>44]

from the above example we will Never have 2 array index same like [0=>12, 0=>11, 1=> 212] - this is not possible

but as you can see the value of index 0 and 2 are same and are same

  1. Regarding security,

All arrays are secure

if you declare a dynamic array and keep it accessible to anyone, then obviously the values can be changed by anyone. But if you declare fixed-size array and keep in private, no one can change it :slight_smile:

  1. Mapping are similar to arrays with only one index and one corresponding value

This relationship can be performed with both array and map but array behaves exactly like a map that is why we should use map instead of using array behaving as a map. Also the solidity community gave us map for this reason only.

the array index and map index are the same thing :slight_smile:. its easier to find both

No, I’m still lost. I have remix working, but don’t know how to save what I did for tomorrow. Sometimes it saves it and sometimes it doesn’t. I don’t understand how to make my code stay put!! What am I doing wrong?

Isn’t ethereum uses Accounting model instead of Unspent Transaction Output like in bitcoin?

Hi @John_Okoye,

The first thing you need to understand is that there are two categories of data:

Value types:  booleans, and all integers < 256 bits.
Complex types:  structs, strings, arrays, mappings

All state variables (whether holding value data-types or complex data-types) and mappings, are always saved permanently in storage and so we don’t need to specifically state their data location as storage when we declare them.

Value-type function parameters are always saved temporarily in memory and so we don’t need to specifically state their data location as memory when we pass (input, throw… :wink: ) them into the function. This is why the data location for the unsigned integers ( unit age  and  unit height ) hasn’t been specified in the example you’ve given:

Value-type local variables (i.e. variables we declare within the body of a function) are always saved temporarily in the stack and so we don’t need to specifically state their data location as stack when we declare them.

However, both complex-type function parameters, and complex-type local variables, can be saved either temporarily in memory or permanently in storage. It is because this choice exists that we always have to specify their data location as either memory or storage. And this is why the data location for the string value ( string memory name) has been specified in the example you’ve given.

I hope that clarifies things for you.

would you go back to ‘Person memory newPerson;’ my original question and rephrase the answer into something perhaps I can understand?

I realize that ‘memory’ is not an operator but it is functioning as an operator of sorts no as 'Person memory newPerson is a statement…it isn’t an expression.

I tried to put ‘Person memory newPerson’ outside of a function body and it just doesn’t work…

a memory operator?

1 Like

clear as MUD Jon, thankx. just kidding, well sort of. I’ll have to read it a few times and, more importantly, start using this by rote repetition and pray for the osmotic pressure learning theory to work…it’s true if you hammer hard enough on the square object it will eventually go through the circular hole…done it several times in my life, why stop now? lol.

Now all this is tied to the ‘mysterious’ EVM no? Which isn’t really in the cloud but right here on earth in individual nodes??? This concept I am not getting either about where all this storage is for the smart contracts…I guess it will flesh itself out eventually…I’m repeating ethereum 101, even though I was issued the certificate, back in 'my day, they didn’t pass everyone, they held people back…I self-holding myself back! l lol, cheers

1 Like

Hi @dbeelow0323,

Whenever I close Remix in my browser (I use Chrome with a Windows 10 OS), I always get a message saying something like, “Are you sure you want to close this web site. Any changes may not be saved.” However, I’ve always just clicked Close and my changes have always been saved, enabling me to just continue from where I left off, and also with access to all my previously coded contracts.

I know someone who lost all their saved data in Remix when they deleted their cookies. Maybe this is the problem you are having. You may want to check that your browser is configured to enable cookies for Remix. I think it’s the cookies that enable you to recover what has been saved when you last exited. If that doesn’t work, you may want to experiment to see what happens using Remix in a different browser. Apart from these two suggestions, I really wouldn’t know what else to try, to be honest, so I’m also tagging a couple of colleagues, to see if they have any other possible suggestions.

@thecil, @gabba, @Taha

2 Likes

I see you’ve already watched the data location video, and done the data location assignment. What I’ve explained is based on the information given there (maybe fleshed out a bit with my own style of explaining). One thing that could help is to rewatch that and look at the assignment again with a fresh pair of eyes. With a lot of these concepts it pays to revisit things and you then find yourself understanding them in a deeper way as a result of the additional insights you’ve aquired since (via osmotic pressure).

I understand your frustration, as I too have struggled with loose ends not being tied up before moving on, but I will say that I have found that most of the time these loose ends do eventually get tied up when you have a deeper understanding overall. So many of these concepts are interlinked, and as you have pointed out, they also depend on a wider understanding of the Ethereum blockchain and how the EVM works in practice. A lot of that won’t fall into place until you actually move on to deploying smart contracts on the test net (which mirrors what happens on the live blockchain).

3 Likes

well said…

BTW, I’ve only watched ‘Get Out’ once, you have to watch it several times too, I have heard, to really get it…and I’m invested in blockchain, I can’t get out, lol.

have a good day!

2 Likes

You too John! (or do you prefer Chinedu?)

I haven’t seen this film yet, but I’m definitely putting it on my “to watch” list… and yes, once down the crypto rabbit-hole, it’s a one-way ticket it seems… no crawling back out :joy:

2 Likes

I have seen the film and also US
LOL

3 Likes