9

How can you explain variables concept to 10year old kid, with simple basic examples??

Comments
  • 3
    By the example of water and bottle. Bottle contains water that is a variable(bottle)
  • 0
    @Eklavya assigning values? Initialization? Types? How can you further explain
  • 2
    What about drawers?
    There are different drawers for different things and a struct or array can be a cabinet with different drawers. Guess I would use those as analogy.
  • 4
    And for pointers: these are like a house address on a paper mail envelope, as opposed to the actual house itself.
  • 0
    There's a pizza in my box
  • 3
    @SanthuLavri You can't explain the whole concept of variables to a 10yo at a go... There are some things learnt progressively.
    Variables are vague and can have different explanation ranging from one language to another. It's hard to even explain correctly to a 30yo, you'd likely give instances which maybe wrong.
  • 3
    If you ask a C developer what a variable is... You may likely get a question for a response like "Do you mean static or pointer variables ?" Because in C you can have a variable which points to a permanent address in memory... Or have it point to a short-lived address using "auto" keyword, Or have it point to another pointer that points to another pointer, or even have its value stored directly into registry using the "register" keyword which makes the value not available in memory.

    While in Java, C#, and many other languages, primitives like float and integer are always simple variables passed by value, whereas complex types such as Objects, are passed as managed references.

    So explanation may vary by language.
  • 0
    @Eklavya

    Yeah my first thought was some kind of cup or box and you put stuff in it too.

    I think if you're teaching folks you gotta be careful about

    1. "This is a variable."

    2. "Also here is ALL THE THINGS ABOUT VARIABLES!!!!"

    That doesn't work for folks not going through a 4 year degree. Sometimes you have to just do 1... let them do 1 for a while. Then talk about 2 as things come up.
  • 2
    Nevertheless you start with @Eklavya's analogy even though it doesn't explain the whole concept. It's a start.
  • 0
    Food boxes.
    Pizza box can contain n slices of pizza for example.
  • 0
    I think if he is 10 years old then , he would be knowing the concepts of variables and constants in mathematics. So the same thing is applied in java (because you mentioned it in tags).
  • 0
    I would get 10 envelopes, put them all next to one another and put papers in them. Some things only fit on a larger paper. A pointer is the number of an envelope written on a paper in another envelope. This is a reasonably good explanation for the phenomenon as seen in C, it also works for the stack and I think would be understandable for even a 10 year old.
  • 2
    @Eklavya "variables" in mathematics are better modelled by immutable values (generally) from functional programming. The box analogy doesn't apply to maths "variables" in general (what even does x = x + 1 mean in (most) maths?). This was a source of confusion for me for quite a while.
  • 0
    I don't normally explain this to 10 year olds, but for young teens just drawing the concept in a notebook is enough. The key thing is that I start with memory as a read-write tape and build up more complex constructs from there.
  • 0
    @RememberMe Yes! Normal algebraic expressions are immutable......so, can make him understood by simply telling "Variables can store different values and are of different types. Such as boolean, integers, floats but not strings".
  • 4
    @GiddyNaya The hell are you talking about? I learned at 8, and didn’t find it difficult. I read the TI83 manual.

    Variables don’t differ much between languages, either. Pointers are probably the only difficult concept.
  • 2
    @Root

    I'm having flash backs to every bad math teacher I had who just 'got it' and couldn't teach ;)
  • 0
    @N00bPancakes That’s probably me. 🤷🏻‍♀️

    Related:
    Awful teachers usually didn’t cause me problems because I just taught myself anyway.
  • 1
    @Eklavya why not strings?
  • 0
    @RememberMe Strings cannot be changed.
  • 0
    If you want a top-down approach, just use a container. Bottles can store things of type liquid, envelopes can store things of type paper. Except here the types are different kinds of numbers. Wholes, fractions, choices.
  • 2
    @Eklavya static strings, immutable strings sure. Strings in general? Nope. Mutable strings are very important in a lot of applications.

    They're literally just collections of characters, what does mutability have to do with that? The abstract description of a string doesn't say anything about its implementation.
  • 0
    @RememberMe See the tag is of java....in which every string is immutable and hence cannot be changed instead, new strings can be made with the same variable name
  • 1
    @Eklavya Even in Java you can get different string implementations some of which allow mutability (I'm sure there's a rope data structure implementation somewhere for example, or buffers).

    You're taking string to be "objects of type String in Java", I'm talking about strings in general. String is just one kind of string, even in Java.

    Besides, the String variable still varies since it's a reference to a string object. You can reassign it just fine, it'll just reference some other object. I don't remember if Java just overwrites the reference or overwrites the name (also called shadowing, in which case it's also a new variable, but this is generally used in FP languages so idk).
  • 0
    @Root I'm glad you learnt about variables that early, and just like the OP said...
    How can you explain it to a 10yo?
    I would like to know your concept. Just curious.
  • 3
    @GiddyNaya
    They’re just placeholders for values that can change.

    In TI83 basic,
    `X <- 12` (Read “12 store as X”)
    Means the letter X now holds the value 12.

    `Disp X`
    Prints 12

    ```X <- 96
    Disp X```
    Prints 96

    You and I both know how vars work, but this is the same way I learned them. No fancy similes or analogies. I understood them as a placeholder for a value that can change.

    And later when I learned C, I learned those placeholders can hold a reference to the actual value — or to another reference — and that the reference is a memory location.
  • 1
  • 1
    walks to whiteboard

    What is your name kid?
    kid: Pepe

    me: so I want to something that represents your name. Something that holds the information in memory that reflects your name because we are going to use it over and over again. here I say that this box called el_pepe is equal to "Pepe" and so if I want to use your name all over the place, add to it, change It or use it to answer the question "who is a lil puto" I will go ahead and reference that information by the use of the variable el_pepe.

    Math also works.
  • 1
    I got the simplified concept of variables when i was making games. There was variable by name "ammo" that stored amount of "bullets" that weapon can fire. So variables have a name and could store some useful data in them.
  • 0
    A 10 year old already saw variables in Math class.

    Something like 3 + _ = 5
    Calculate what the missing number is
  • 0
    i usually do drawers.
    the variable is the drawer, the value is what you put in it, you don't actually care about the drawer but what's inside, you just refer to what's inside by the drawer name.
  • 0
    @Pogromist am an civil engineer by degree having little CS knowledge from college.
    Want to learn java, where can i start the topics from to understand good code and to write.
  • 0
    @Pogromist From which topic should I start in order to learn java theory and practical, without any hassle or confusion.
    I want to learn slow(zero knowledge of coding) and get clear cut vision on the topic I learn first and proceed.
    Give me a sequence of 3-5 thorough topics to start java.
  • 0
    @SanthuLavri Roadmap for beginners :-
    1.) Learn Python (Easiest OOP Language)
    2.) Learn C/C++ (Connects the user with the comp)
    3.) Learn Java (If already learnt C/C++, then java would be more easier.)

    My recommendation is to learn python at first.
Add Comment