Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Eklavya17724yBy the example of water and bottle. Bottle contains water that is a variable(bottle)
-
Crowns2024yWhat 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. -
And for pointers: these are like a house address on a paper mail envelope, as opposed to the actual house itself.
-
@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. -
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. -
@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. -
Nevertheless you start with @Eklavya's analogy even though it doesn't explain the whole concept. It's a start.
-
Eklavya17724yI 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).
-
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.
-
@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.
-
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.
-
Eklavya17724y@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".
-
Root825284y@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. -
@Root
I'm having flash backs to every bad math teacher I had who just 'got it' and couldn't teach ;) -
Root825284y@N00bPancakes That’s probably me. 🤷🏻♀️
Related:
Awful teachers usually didn’t cause me problems because I just taught myself anyway. -
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.
-
@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. -
Eklavya17724y@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
-
@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). -
@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. -
Root825284y@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. -
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. -
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.
-
mundo0349794yA 10 year old already saw variables in Math class.
Something like 3 + _ = 5
Calculate what the missing number is -
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. -
@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. -
@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. -
Eklavya17724y@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.
Related Rants
How can you explain variables concept to 10year old kid, with simple basic examples??
question
basic it knowledge
variables help
variables
java
code