RSS LJ

August 25, 2004

Friends don't let friends use friend ()

by fluffy at 10:45 AM
Or, more generally, coworkers.

Comments

#3371 08/25/2004 08:17 am
I'm fairly sure something just went zooming over my head.
#3372 08/25/2004 08:23 am
It's a C++ thing.
#3373 Conspyre (unregistered) 08/25/2004 09:58 am
While normally, I approve of letting idiots write bad code, if he does, don't you have to fix it at some point?
#3374 Anonymous 08/25/2004 11:05 am I respectfully disagree.
Friends are just like members. No difference whatsoever, except for syntax.
#3375 08/25/2004 11:22 am
I think you mean that friends are like public members, with the exact same syntax (I mean, friend is totally orthogonal, so I'm not sure what you could say is "different" about the syntax). Which are also something to avoid.
#3382 08/25/2004 02:02 pm friend
In ten years of C++ programming, I don't think I've ever intentionally used friend once.
#3383 08/25/2004 02:36 pm
Yeah. friend is a crutch for people who don't know about return-by-reference and operator[] and so on.

Like a certain novice programmer I could mention.
#3384 Skywise (unregistered) 08/25/2004 03:58 pm I tried it once (I didn't inhale)
And I've never used it professionally...
In my off hours, I've been experimenting with various object architectures to gain some experience in *what works*. I tried friend in a MVC type system where I needed some initimate data binding because, y'know, that's what all the IMPORTANT BOOKS say to do.

And boy, it just... sucked. You're better off just making everything public (or use a struct) because now you have to maintain the "relationship" between these items and it kills reuse because now the objects are even more bound together. Never mind that friendship isn't inheritable (I don't "have-a" friend class, I'm "is-a" friend class, but you aint no friend of mine...)

But doesn't this all degenerate down to the "an accessor method is just as bad as a public variable" religious argument?
#3387 08/26/2004 06:19 am
An accessor method can be validated and bounds-checked, and in the case of return-by-reference it can also be set const (making it read-only) or whatever.
#3393 celeriac (unregistered) 08/26/2004 11:57 am Friend
It's onle of those ty[ical c++ features that only make sense when you are doing something highly dubious with other such c++ features. In practice, it's somewhat useful for writing unit tests.
#3394 08/26/2004 12:01 pm
Really? I've always been writing my unit tests by writing a program which uses the module and simulates a wide range of possible valid inputs to it, and comparing it with the expected output, trying to keep everything high-level and abstract. Silly me.
#3395 celeriac (unregistered) 08/26/2004 02:01 pm White box
Snarkiness aside, there are times when you want to use white box tests. Especially if you are using code coverage or fault injection.
#3396 08/26/2004 02:03 pm
And when I think of one of those times, I'll let you know!
#3403 Anonymous 08/28/2004 06:20 am
fluffy
I think you mean that friends are like public members, with the exact same syntax (I mean, friend is totally orthogonal, so I'm not sure what you could say is "different" about the syntax). Which are also something to avoid.

No, that's not what I mean. A friend function is just like a member function. Only the calling syntax is different, f(x) vs x.f(). Otherwise they are fully equivalent. There's no reason whatsoever not to use friends. Of course if you're foolish enough to make a class and its friend function parts of two different functional units, you don't have anyone to blame for your stupidity.
#3407 08/30/2004 06:09 am
Oh. I'm talking about friend classes, not friend functions.
#3695 10/11/2004 02:15 pm
hi fluffy
#3696 10/11/2004 02:17 pm
what do u know about friend classes
#3697 10/11/2004 02:19 pm
no
#3698 Anonymous 10/11/2004 02:27 pm
u cann't help me in likked list?
#3699 10/11/2004 02:29 pm
I can.
#3700 10/11/2004 02:38 pm
could u please give me a syntax of friend class
#3701 10/11/2004 02:38 pm
could u please give me a syntax of friend class
#3702 10/11/2004 02:41 pm
1st ...i'm new to this Embarassed
how can u help me?
#3703 10/11/2004 02:55 pm
If you can wait a few days and write in proper English I might be more willing to help, but right now I'm busy.
#3704 10/11/2004 05:07 pm
fluffy is not your comp-sci professor.

At least, not as far as I know.
#3707 Anonymous 10/12/2004 06:38 am
thanks for your kindness.
you are so encouraging.
#3708 10/12/2004 06:40 am
Because I run a free tutorial service for everyone who wants to be a programmer.
#3709 10/12/2004 06:47 am
i'm acomputer science student and this is my 3rd year.i was looking for extra information but since it will be from people like you ...i don't want it.........and by the way.. if u don't know the chatting language....it is not my fault
#3710 10/12/2004 06:59 am
I know "the chatting language" just fine. This isn't IM, and it reeks of disrepect to ask me to make a huge time commitment to helping someone out with their studies without even bothering to be even remotely polite, especially when I have absolutely no obligation to helping out every random stranger who comes by. It disturbs me that you can be a third-year university student and not understand this. What are they teaching kids in school these days about politeness and respect?
#3711 Anonymous 10/12/2004 07:09 am
i thought helping people has nothing to do with the way they type.
but i guess not here.
thanks again for your kindness
#3713 10/12/2004 07:13 am
You totally miss my point. But, have fun being righteously indignant anyway. Maybe in a few years when you're busy working 80-hour weeks under an intense deadline you'll understand not wanting to take a few hours out of your day to help a third-year student who doesn't even understand a basic linked list or even make the vaguest effort to be pleasant.

Some peoples' children. Rolling Eyes
#3714 Anonymous 10/12/2004 07:29 am
"to help a third-year student who doesn't even understand a basic linked list "
we are taking it now but u wouldn't say this if you were the one who has the problem to know the a basic linked list. thats why i'm looking for help....but i didn't think i would meet people telling me things you said .....don't forget that when i first asked i said please but i didn't expect others to tell me that u r not my proffesore or telling me that if i write correctly you will conceder my requist. you could simply say that you are busy or you can not help me. there was no need for all that.....
#3715 10/12/2004 07:47 am
First off, I didn't say I wasn't your professor, that was zetawoof.

Secondly, I was simply making an observation that you're not really going out of your way to make me want to help you. So far you've continued to make me not want to help you. Not many people would be willing to help you with the way you presented yourself. In fact, I think I'm being very helpful by even taking the time to respond to you with advice on how to ask for help. That's way more useful in life than knowing how to do linked lists.