473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

About method naming

Yesterday I discussed with my boss about method naming.

In the RPC argument pack / unpack classes, packing & unpacking remote
procedure
calling arguments into / from a byte buffer. I named the methods as
following.

class PackRPCPara
{
public:
INT8 PackInt8(const INT8 value);
INT32 PackInt16(const INT16 value);
INT32 PackInt32(const INT32 value);
INT32 PackInt64(const INT64 value);
INT32 PackBoolean(const BOOL32 value);
INT32 PackBytes(const INT8 * value, const INT32 length);
INT32 PackString(const CHAR * value, const INT32 length);
};

He said, PackInt8, PackInt16, ... PackInt64 should use overrided method
name, i.e. Pack.
It is easy to use and low error prompting.

I strongthly suggest it should be named as above. Because we are
developing a cross-platform
project. Overide Pack method uses implicit argment type calling
conducted by compiler. It is
not easy to read and difficult to maintain.

We did not agree with each other. Will anyone give me some points on it?

Jan 26 '07 #1
5 1695
Allen wrote:
Yesterday I discussed with my boss about method naming.

In the RPC argument pack / unpack classes, packing & unpacking remote
procedure
calling arguments into / from a byte buffer. I named the methods as
following.

class PackRPCPara
{
public:
INT8 PackInt8(const INT8 value);
Why a different return type from the rest?
INT32 PackInt16(const INT16 value);
INT32 PackInt32(const INT32 value);
INT32 PackInt64(const INT64 value);
INT32 PackBoolean(const BOOL32 value);
INT32 PackBytes(const INT8 * value, const INT32 length);
INT32 PackString(const CHAR * value, const INT32 length);
};

He said, PackInt8, PackInt16, ... PackInt64 should use overrided method
name, i.e. Pack.
It is easy to use and low error prompting.
I'd strongly recommend using the new standard types, int8/16/32/64_t.

Did you consider

template <typeneme Tint32_t pack( T value );

with appropriate specialiseations where required?

--
Ian Collins.
Jan 26 '07 #2
* Allen:
Yesterday I discussed with my boss about method naming.

In the RPC argument pack / unpack classes, packing & unpacking remote
procedure
calling arguments into / from a byte buffer. I named the methods as
following.

class PackRPCPara
{
public:
INT8 PackInt8(const INT8 value);
INT32 PackInt16(const INT16 value);
INT32 PackInt32(const INT32 value);
INT32 PackInt64(const INT64 value);
INT32 PackBoolean(const BOOL32 value);
INT32 PackBytes(const INT8 * value, const INT32 length);
INT32 PackString(const CHAR * value, const INT32 length);
};

He said, PackInt8, PackInt16, ... PackInt64 should use overrided method
name, i.e. Pack.
It is easy to use and low error prompting.
When you write "overrided" it seems you mean "overloaded".

Generally it's not a good idea to embed implementation issues in names,
so in that regard your Boss Is Right(TM).

However, say you have the following client code:

UINT8 const value = 255;
PackRPCPara packer;
packer.Pack( value );

Assuming INT8 is a signed type, this does not call the INT8 overload of
Pack. Most likely it calls the INT32 overload. So just naming all of
these functions "Pack" is probably not a good idea: it can introduce
silent errors, only detected at run time (if at all).

There is also another issue, that BOOL32 might be the same type as
INT32, in which case these functions can't both be named "Pack".
However, for the boolean you probably /want/ all kinds of boolean
argument to end up in the same function. So call that function e.g.
'addBool'.

By the way, if you have any choice in this matter, do reserve all
uppercase names for macros (see this group's FAQ as well as Bjarne
Stroustrup's FAQ): don't use them for types or typed constants.

I'd do

#define COMPILE_TIME_ASSERT( e ) int x[!!(e)] // Whatever.

namespace rpc
{
class PackedParameters
{
public:
template< typename IntType >
void add( IntType value ) { COMPILE_TIME_ASSERT( false ); }

template<void add<INT8>( INT8 value );
template<void add<INT16>( INT16 value );
// ... etc.
};
}

This way the erronous client code shown above won't compile, but must be
written as

parameters.add<INT8>( value );

or as

parameters.add( static_cast<INT8>( value ) );

Note, by the way, that the 'const' in the first five member functions
you've shown is entirely superflous and removed by the compiler.

I strongthly suggest it should be named as above. Because we are
developing a cross-platform
project. Overide Pack method uses implicit argment type calling
conducted by compiler. It is
not easy to read and difficult to maintain.
See above.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jan 26 '07 #3
Ian Collins wrote:
Allen wrote:
>Yesterday I discussed with my boss about method naming.

In the RPC argument pack / unpack classes, packing & unpacking remote
procedure
calling arguments into / from a byte buffer. I named the methods as
following.

class PackRPCPara
{
public:
INT8 PackInt8(const INT8 value);

Why a different return type from the rest?
> INT32 PackInt16(const INT16 value);
INT32 PackInt32(const INT32 value);
INT32 PackInt64(const INT64 value);
INT32 PackBoolean(const BOOL32 value);
INT32 PackBytes(const INT8 * value, const INT32 length);
INT32 PackString(const CHAR * value, const INT32 length);
};

He said, PackInt8, PackInt16, ... PackInt64 should use overrided method
name, i.e. Pack.
It is easy to use and low error prompting.
I'd strongly recommend using the new standard types, int8/16/32/64_t.
Actually, they aren't standard types in C++. They are typedefs that were
introduced with the C standard library header stdint.h in C99. But C++ is
based on C90, so it doesn't officially have it. On compilers that support
both C++ and C99, you can ususally use that header in C++, too.

Jan 26 '07 #4
Rolf Magnus wrote:
Ian Collins wrote:
>>
I'd strongly recommend using the new standard types, int8/16/32/64_t.


Actually, they aren't standard types in C++. They are typedefs that were
introduced with the C standard library header stdint.h in C99. But C++ is
based on C90, so it doesn't officially have it. On compilers that support
both C++ and C99, you can ususally use that header in C++, too.
Or POSIX platforms. Even it your environment does not have stdint.h,
it's easy to roll your own.

--
Ian Collins.
Jan 26 '07 #5
In article <ep*************@news.t-online.com>, ra******@t-online.de
says...

[ ... ]
I'd strongly recommend using the new standard types, int8/16/32/64_t.

Actually, they aren't standard types in C++. They are typedefs that were
introduced with the C standard library header stdint.h in C99. But C++ is
based on C90, so it doesn't officially have it. On compilers that support
both C++ and C99, you can ususally use that header in C++, too.
Just FWIW, TR1 has cstdint and stdint.h, and it's essentially certain
that the next C++ standard will require them as well.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jan 27 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
1
by: David Sandor | last post by:
I have been looking at the source code for the CLR (rotor code)... I have some questions about the naming conventions that Microsoft is using as I have found what appear to be inconsistencies (or...
1
by: Jack Addington | last post by:
I am just looking for some advice on naming my methods - I am getting confused as to what some of them mean now I have the following scenario - A Visual Data Object and a Logical Data Object. ...
6
by: Charles Law | last post by:
As a matter of practice, where would people put the following elements of object creation/initialisation: Create shared member objects Initialise shared member objects Create non-shared member...
3
by: Sam Kong | last post by:
Hi group, I want to have some advice about immutable objects. I made a constructor. function Point(x, y) { this.x = x; this.y = y; }
5
by: CharlesG | last post by:
Hi all, Can you let me know if there is a standard naming convention for webservice methods ? I have seen some with a lower case first letter and some with an upper case first letter. Also what...
25
by: Nicholas Parsons | last post by:
Howdy Folks, I was just playing around in IDLE at the interactive prompt and typed in dir({}) for the fun of it. I was quite surprised to see a pop method defined there. I mean is that a...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
3
by: vunet | last post by:
It has been widely used nowadays to wrap JavaScript libraries, as seen in JQuery. (function() { var global = this; // ... })(); The advantage, as I learned, is the isolation from other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.