Live data from Hacker News

A proposal for named arguments for C++

open-std.org

31–40 of 62 posts

Re: A proposal for named arguments for C++

#31
This is exactly why I like the Objective-C method call syntax. Instead of "mystery argument soup"

    rectangle->set(10,10,20,20,true,false)
you get something that can be understood without taking a trip to the API docs:

    [rectangle setX:10 y:10 width:20 height:20 updateBSP:YES clipToParent:NO]
It's a pity they are moving away from this syntax in Swift. It's the right move -- I hear nothing but hate for it from those who don't actually use it (i.e. the people who should be Swift's target audience) -- but it's still a pity.

Re: A proposal for named arguments for C++

#32

This is exactly why I like the Objective-C method call syntax. Instead of "mystery argument soup" rectangle->set(10,10,20,20,true,false) you get something that can be understood without taking a trip to the API docs: [rectangle setX:10 y:10 width:20 height:20 updateBSP:YES clipToParent:NO] It's a pity they are moving away from this syntax in Swift. It's the right move -- I hear nothing but hate for it from those who…

I think C++ should use notation similar to designated initializers (that C++ adapted from C99) for names arguments, i.e. rectangle->set(.x = 10, .y = 20, .width = 20, .height = 20)

Otherwise, it would be very confusing that two different syntax are used for similar purpose.

Re: A proposal for named arguments for C++

#33
post #28

Earlier quoted context omitted.

C absolutely has an ABI – you do not need a C compiler to call a C library.

Nonsense. C doesn't even define the width of an int, without which an ABI makes no sense. An ABI is a property of a specific target platform (architecture and possibly OS); every platform defines its own. Windows and Linux on x86_64 don't even use the same ABI (the width of "long" is different, for starters). But both platforms have C++ ABIs just as much as they have C ABIs. The problem with C++ ABIs is that C++ A P…

It's certainly not cross-platform, but in practice you can call C libraries on a given platform the same way, regardless of which compiler generated them.

Re: A proposal for named arguments for C++

#34

Please stop adding features to C++ and standardize an ABI already. The lack of an ABI is why it's impossible to call C++ libraries without an entire C++ compiler – and it generally requires generating mountains of wrapper code a la SWIG – which is then called with the C ABI. The lack of an ABI is why dynamic libraries use C for writing extensions instead of C++: C++ can literally only be called by C++ (and in fact on…

A proposal for C++ to stop being such a moving target.

Re: A proposal for named arguments for C++

#36
This might sound negative, but I'm really curious why this is needed if you have an IDE that tells your the parameter names as you're typing and in a mouseover. If you need it to be more visible, make that a feature in the IDE to show you the parameter names all the time. Why change the language?

Not only that, but why are you passing so many parameters like top, bottom, left, right? At least put them in a struct if you can't make them fields of the object itself.

This feature seems like "too little, too late". Maybe 30 years about it would have been helpful.

Re: A proposal for named arguments for C++

#37
post #28

Earlier quoted context omitted.

Nonsense. C doesn't even define the width of an int, without which an ABI makes no sense. An ABI is a property of a specific target platform (architecture and possibly OS); every platform defines its own. Windows and Linux on x86_64 don't even use the same ABI (the width of "long" is different, for starters). But both platforms have C++ ABIs just as much as they have C ABIs. The problem with C++ ABIs is that C++ A P…

It's certainly not cross-platform, but in practice you can call C libraries on a given platform the same way, regardless of which compiler generated them.

You can do that with C++ too -- assuming they are conforming to the platform ABI. On Linux, for example, all C++ compilers can call each other's code just fine.

You may be thinking of the funny situation on Windows where GCC has historically flagrantly disregarded the platform C++ ABI and implemented its own instead. I assume this decision was made as a matter of practicality: The Cygwin people didn't have the resources to try to implement Microsoft's ABI, whereas porting over the existing code for the Linux C++ ABI was a lot easier. Also, MSVC tends to take much longer to implement new C++ language features than GCC does which means its ABI could often be missing things GCC needs.

FWIW, Clang's port to Windows is taking the correct approach: they're implementing Microsoft's ABI, and will thus be able to link against MSVC-built C++ library. http://clang.llvm.org/docs/MSVCCompatibility.html

Re: A proposal for named arguments for C++

#38

This might sound negative, but I'm really curious why this is needed if you have an IDE that tells your the parameter names as you're typing and in a mouseover. If you need it to be more visible, make that a feature in the IDE to show you the parameter names all the time. Why change the language? Not only that, but why are you passing so many parameters like top, bottom, left, right? At least put them in a struct if…

Named parameters on their own are not all that helpful. (see Obj-C, where the verbosity often outweighs the potential benefits.) But when accompanied with having default parameter values allowing named parameters to be optional (as in Python), they can be very useful, allowing a whole family of functions to be consolidated into one fully general function that can nevertheless be called succinctly in a variety of ways.

Re: A proposal for named arguments for C++

#39

This might sound negative, but I'm really curious why this is needed if you have an IDE that tells your the parameter names as you're typing and in a mouseover. If you need it to be more visible, make that a feature in the IDE to show you the parameter names all the time. Why change the language? Not only that, but why are you passing so many parameters like top, bottom, left, right? At least put them in a struct if…

Optional named parameters with default values can make nice clean calls in the common case while still allowing for the uncommon case.

As far as the IDE goes, for the sort of code I write, reading is more important than writing. When I read the code I'd rather see what it does than what I think it does.

Post reply on HN