News for hackers. Stuff that matters.
Re:Typedefs & Linus by jamesaguilar on Thursday October 14, 2010 @02:25PM (#1791981)
> And people who use ampersand pass-by-reference in C++ ( foo(int &i) ).

Why?

Re:Typedefs & Linus by gryan on Thursday October 14, 2010 @02:28PM (#1791992)
I don't know what the OP's beef is. There's nothing semantically wrong or confusing about this.

However, for simple types like int and float, there's no performance advantage to passing the value as a reference. It generally takes as long to construct the temporary reference as it does to copy the value.

For more complex types like structures or objects, then yeah, you're better off passing by reference.

Re:Typedefs & Linus by leif on Thursday October 14, 2010 @02:46PM (#1792080)
Yeah, I didn't mean "int" to be the offensive part.

Read my response. I'm not talking about performance, you shouldn't be copying around large structs or strings no matter what, I'm talking about code readability.

In general, your compiler will optimize the crap out of primitive type copies (and most struct copies too, these days) anyway, so it's less of a performance argument as it used to be.

Re:Typedefs & Linus by leif on Thursday October 14, 2010 @02:45PM (#1792071)
Because it gives you no more power than passing a pointer. If you're handling pointers, it's better to be totally explicit about what you're doing.

I don't want to read your function call that looks like it passes a whole object and have to check the function header to see that it's actually a reference getting passed, I'd rather see the address taking right at the function call.

Re:Typedefs & Linus by jamesaguilar on Thursday October 14, 2010 @03:40PM (#1792281)
A decent point. Google uses the pointer-ness or const-reference-ness of a parameter to signal what the parameter is going to be used for [1]. But at the end of the day reference modification is the kind of basic language feature that you should expect to see people using.

[1] http://google-styleguide.googlecode.com/svn/trunk/cppguide.x...

Re:Typedefs & Linus by leif on Thursday October 14, 2010 @04:33PM (#1792469)
This actually bothered me to no end at google. At the API level, it's great, I can learn a lot about what your function is going to do just by looking at the signature, but when reading code that uses an API I don't know, it's hell. For me, the extra help you get by looking at a function signature really isn't that great, when I should have the same information available in the documentation that had damn well better accompany the function signature in your header.
Re:Typedefs & Linus by jamesaguilar on Thursday October 14, 2010 @04:47PM (#1792527)
Header documentation and pointer-as-output conventions are both typically available in the Google libraries I've used.

I really don't understand what you are complaining about. Earlier you said you didn't like references being modified by functions to which they are parameters. Now you are complaining about the use of pointers as parameters? In a language like C++, it's pretty difficult to do neither.

Re:Typedefs & Linus by leif on Friday October 15, 2010 @01:56AM (#1793805)
No, I'm not opposed to references being modified by functions, I'm opposed to the "ampersand" syntax of C++. I am fully in support of just passing a pointer and being straightforward about it.
Re:Typedefs & Linus by Locke1689 on Thursday October 14, 2010 @06:26PM (#1792916)
I completely agree with you. Worse, if at some point you actually need a pointer of the object to do arithmetic you end up grabbing a pointer of the reference which just puts everything to hell.