Hacker News new | ask | show | jobs
by bitbuilder 1295 days ago
I don't believe they're saying the feature doesn't exist or never gets used, but rather it's rarely something that's taught to junior developers, and rarely something you see highlighted as a best practice.

I've been developing for 25+ years in any language you can imagine, and know how to use pass by ref just fine, and know there are situations where it might be the best solution.

But I can't remember the last time I've used pass by ref. It's really just a coding style quirk for me, I find it "ugly" and it breaks my train of thought when reasoning through the flow of code. I certainly don't begrudge anyone who uses it though.

And OP's anecdote about the interview is certainly disheartening. You'd hope the interviewer would at least be open to the idea of learning something new. I've learned countless things from developers I've interviewed over the years, and I was incredibly happy about it each time.

Edit: In re-reading your comment and below replies it seems you may be misunderstanding what's being discussed. Yes, the things we pass into and out of functions tend to be object references by default. But when we say "pass by ref" (in some languages at least) we mean, essentially, modifying a value in a calling function without actually returning anything from the called function. That's a horrible way to explain it, but the MS documents for the "ref" keyword do a good job of showing examples:

https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

2 comments

It's like the other day there was a post where someone wrote an entire blog post about how they changed a tight loop with a function call in Golang to pass a pointer to a struct instead of by-value so they stopped allocating and copying on each call.

Like...duh?

I suppose that's why I find Golang less weird to work with than others in my cohort. I spent a semester in the depths of C and OpenGL so I'm intimately familiar with by-value vs by-ref.

I haven't used C++ pass-by-reference in years, but I'd recognize the syntax. Perhaps the interviewer just wasn't very good.
doesn't really matter, all they have to do is run the code.