Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C coder moving to C++ - method naming conventions

Being an Objective-C coder, I'm so used to descriptive method names such as

[car insertFuelWithAmount:fuelAmount
                     type:fuelType
  causesCarToSelfDestruct:NO];

How would most programmers name a corresponding method in C++? I have two questions in particular:

  1. My copy of "C++ Primer", 4th edition, mentions (p. 46) that gosh_this_is_an_impossibly_long_name_to_type is a "really bad identifier name". This differs from the mentality in Objective-C, which encourages very descriptive names, even if they are long. Why are long ones not appreciated by C++ coders?

  2. Maybe it's not a matter of just migrating blindly, but rather changing one's mindset completely? If so, what changes need to be made?

Feel free to allow some further general thoughts on your own to float along, if you don't mind. (I know this is not a forum for general and vague questions. Hence, I tried to make things a bit more specific above.)

like image 783
NoobOverflow Avatar asked Nov 24 '25 10:11

NoobOverflow


1 Answers

As Fernandes points out you need to find a balance of sorts. But remember that it is all about taste, though most C++ programmers go for the shorter but somewhat descriptive method names.

Using extremely long names, for anything, is never desirable because the code will become practically unreadable. And personally I find it very disturbing to my programmer's eye.

The languages are different, of course, but the focus of your transition phase would be removing the extraneous names. Like with your method above. I've noticed Obj-C programmers use the "WithSomething" extensions here and there. One thing to change here is to get rid of those by using overloading, for instance.

The method you described I would probably write like this:

car.insertFuel<int>(amount, false);

If assuming some amount of fuel in integer form.

like image 72
Morten Kristensen Avatar answered Nov 26 '25 01:11

Morten Kristensen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!