473,385 Members | 1,275 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,385 software developers and data experts.

function prefixes... are they needed?

Recently I've came to a small problem... I've read few coding
guidelines, to improve and standardize my style. Most of them advised
me to use function prefixes such as Get, Set, Compute etc..

I understand that avoiding Set prefix might be very confusing and I
feel that one is right.

But what about others?

class Rectangle
{
public:

inline int ComputeArea() const { return w_ * h_; }

inline int GetX() const { return x_; }
inline int GetY() const { return y_; }

inline int GetWidth() const { return w_; }
inline int GetHeight() const { return h_; }

private:

int x_, y_;
int w_, h_;
};

I feel like it's just too verbose... what about:

class Rectangle
{
public:

inline int Area() const { return w_ * h_; }

inline int X() const { return x_; }
inline int Y() const { return y_; }

inline int Width() const { return w_; }
inline int Height() const { return h_; }

private:

int x_, y_;
int w_, h_;
};

Can anyone advise me one of these? Or at least show me some pros &
cons?

Thanks

Mar 25 '07 #1
2 1960
* ms****@gmail.com:
Recently I've came to a small problem... I've read few coding
guidelines, to improve and standardize my style. Most of them advised
me to use function prefixes such as Get, Set, Compute etc..

I understand that avoiding Set prefix might be very confusing and I
feel that one is right.

But what about others?

class Rectangle
{
public:

inline int ComputeArea() const { return w_ * h_; }

inline int GetX() const { return x_; }
inline int GetY() const { return y_; }

inline int GetWidth() const { return w_; }
inline int GetHeight() const { return h_; }

private:

int x_, y_;
int w_, h_;
};

I feel like it's just too verbose... what about:

class Rectangle
{
public:

inline int Area() const { return w_ * h_; }

inline int X() const { return x_; }
inline int Y() const { return y_; }

inline int Width() const { return w_; }
inline int Height() const { return h_; }

private:

int x_, y_;
int w_, h_;
};

Can anyone advise me one of these? Or at least show me some pros &
cons?
The first is Java, the latter starts to look like C++. The word
"inline" is superflous and should be removed. Otherwise style is
subjective, so even though I have other preferences, if you like the
second example's style, go for it.
--
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?
Mar 25 '07 #2
<ms****@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
Recently I've came to a small problem... I've read few coding
guidelines, to improve and standardize my style. Most of them advised
me to use function prefixes such as Get, Set, Compute etc..

I understand that avoiding Set prefix might be very confusing and I
feel that one is right.

But what about others?

class Rectangle
{
public:

inline int ComputeArea() const { return w_ * h_; }

inline int GetX() const { return x_; }
inline int GetY() const { return y_; }

inline int GetWidth() const { return w_; }
inline int GetHeight() const { return h_; }

private:

int x_, y_;
int w_, h_;
};

I feel like it's just too verbose... what about:

class Rectangle
{
public:

inline int Area() const { return w_ * h_; }

inline int X() const { return x_; }
inline int Y() const { return y_; }

inline int Width() const { return w_; }
inline int Height() const { return h_; }

private:

int x_, y_;
int w_, h_;
};

Can anyone advise me one of these? Or at least show me some pros &
cons?
I used to use SetX and GetX, but after a conversation here on the newsgroup
about if I'm using setters and getters, why not just make it public, etc...
I decided that it made more sense not to use them.

I use youre second method, although without inline.
Mar 25 '07 #3

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
9
by: Chris Spencer | last post by:
Does anyone know how to make ElementTree preserve namespace prefixes in parsed xml files? The default behavior is to strip a document of all prefixes and then replace them autogenerated prefixes...
4
by: Andy | last post by:
What do people think of this? 'prefixed string'.lchop('prefix') == 'ed string' 'string with suffix'.rchop('suffix') == 'string with ' 'prefix and suffix.chop('prefix', 'suffix') == ' and ' ...
0
by: S ML | last post by:
Hello, I use the Xerces XS* classes to parse and get the definition of an XML schema. I don't seem to find a way to get the namespace prefixes using this framework and I read somewhere that the...
6
by: Nels Olsen | last post by:
Our company is rewriting our product in .NET. The old product is in PowerBuilder, which is heavy on Hungarian notation. We are approaching the time where we have to finalize naming conventions for...
23
by: g.ankush1 | last post by:
#include <stdio.h> /* 1st example int a() { return 1; }
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
10
by: Simon Brooke | last post by:
I'm struggling to understand what 'exclude-result-prefixes' does and is for; the language of the standard http://www.zvon.org/xxl/XSLTreference/W3C/xslt.html#literal-result-element is not...
2
by: JackC | last post by:
Hi, I have written the following function to retrieve a class instance from a vector, if found it returns the object. CServer CServerControl::GetServer(string alias) { ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.