Where ambitious young professionals connect and grow

Already a member?

Click here to login

Welcome to Brazen Careerist!

Emily Ma is using Brazen Careerist to share ideas. Join now to become a member and start networking with Emily Ma and other professionals just like you. Learn more.

  

Yesterday I had to teach the distinction between pass-by-reference and pass-by-value to my first year non-CS students. There are second and third year CS students that don’t grasp this concept. But there you go.

And so I explained it, to a sea of blank faces. They understood what I was saying (I think) but it made no sense to them. Trying to explain that the same thing can have different names, but sometimes it’s a different thing and sometimes it’s just the same value as the other thing but… yeah. It’s a little mystifying.

So I hit upon a better way to explain this (the slight temperature from the swine flu vaccine I’d had the previous day and the copious amounts of Tylenol probably helped), using Ice-Caps, which one of my students keeps telling me I should be drinking (I know, instead of tea – horrifying!). Lets call her Student A.

So Student A can have an ice-cap, which she calls delicious. Then she can pass it to me as a parameter, and I can call it disgusting-like-poutine. Then I can pass it to Student B, and she can call it n’apporte quoi. If we give it back to Student A, she can continue calling it delicious.

If we’re passing by reference then it’s always the same Ice Cap. Student A might have a full one, drink a bit, give it to me, I might pour some away, then my function exits and Student A has the Ice Cap again (in some sense Student A always has it, but let’s just assume that we as a group are running in a single thread), which has whatever was left when I finished pouring it away.

If we pass by value then each of us has our own Ice Cap. When Student A gives me the Ice Cap, it’s like she gives me a clone of hers. If she passes me a full one, and I pour all mine out, she still has a full one when I exit. My actions to the Ice Cap do not affect her Ice Cap.

Make more sense? The problem with teaching programming is that everything seems very abstract. I find adding real world examples (and humor) really helps.

Share and Enjoy:

Got Something To Say?

Got Something To Say?

You Must Be Logged In To Comment
Not a Member? Brazen Careerist is a career management tool for next-generation professionals. Set up a free account today to comment on this post and start sharing your ideas. Learn more.

Virtual Events

Schedule an Event
non-profit-earth.jpeg
iphone4s16gb.co_.uk_.png
social-media-icons.jpg
codes.png

Ask A Citi Recruiter Zone

Q: Hi Amy, me again. l applied IT business analyst in ... (More...)
A: Janna, I have contacted the Recruiter for you. (More...)

Jobs

  • Page 1 of 3
INSURANCE SALES AGENT
Paducah - AGLA
Commercial Banking Relationship Manager NYC
New York - Citi
Security Engineer - (1823)
Toronto - Sourcefire
IT Business Analyst
Melville - Citi
Sales Assistant Sales Associate 1 Ann Arbor MI
Ann Arbor - Citi

Employer? Post a job