473,581 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Best practices, OOD, Linked List

Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie functions do not take any arguments
)
- returning values using return statement

Anything else?

The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.

Another issue was a LinkedList. I was not supposed to pass the Head
pointer or add a global variable. The class only had *m_pLink (the
tail pointer). Would it be ok to assign the head pointer to m_pLink
(m_pLink does take current pointer values as it progress throuhgh the
chain, but assigned the top current pointer value)? I did that and the
code works fine.

Thank you

Oct 29 '06 #1
17 3020

2005 wrote:
Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie functions do not take any arguments
)
Huh? Is it good practice to pass arguments to functions that take no
arguments? Is that what you are asking? No, it is not. It won't even
compile. Normally one passes arguments to functions when the functions
need input, or arguments.
- returning values using return statement
How else would you return values?
>
Anything else?
Your post isn't making a lot of sense. Maybe you need to think more
clearly about what you are asking.
>
The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.
Ok.
>
Another issue was a LinkedList. I was not supposed to pass the Head
pointer or add a global variable. The class only had *m_pLink (the
tail pointer). Would it be ok to assign the head pointer to m_pLink
(m_pLink does take current pointer values as it progress throuhgh the
chain, but assigned the top current pointer value)? I did that and the
code works fine.
I have no idea if that follows the guidelines to your assignment. You
would normally keep track of the head in a linked list. If you track
the tail and link back to the head then really you are just reversing
terminology as conceptually your list is still from head to tail.

Oct 29 '06 #2

Noah Roberts wrote:
2005 wrote:
Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie functions do not take any arguments
)

Huh? Is it good practice to pass arguments to functions that take no
arguments? Is that what you are asking? No, it is not. It won't even
compile. Normally one passes arguments to functions when the functions
need input, or arguments.
- returning values using return statement

How else would you return values?

Anything else?

Your post isn't making a lot of sense. Maybe you need to think more
clearly about what you are asking.

The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.

Ok.

Another issue was a LinkedList. I was not supposed to pass the Head
pointer or add a global variable. The class only had *m_pLink (the
tail pointer). Would it be ok to assign the head pointer to m_pLink
(m_pLink does take current pointer values as it progress throuhgh the
chain, but assigned the top current pointer value)? I did that and the
code works fine.

I have no idea if that follows the guidelines to your assignment. You
would normally keep track of the head in a linked list. If you track
the tail and link back to the head then really you are just reversing
terminology as conceptually your list is still from head to tail.
Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie design functions so that they
better take no arguments)
- returning values using return statement

Anything else?

The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.

Another issue was a LinkedList. I was not supposed to pass the Head
pointer or add a global variable. The class only had *m_pLink (the
tail pointer). Would it be ok to assign the head pointer to m_pLink
(m_pLink does take current pointer values as it progress throuhgh the
chain, but assigned the top current pointer value)? I did that and the
code works fine.

I do Not think that you can get Head if you know the tail?

Thank you

Oct 29 '06 #3
2005 wrote:
Noah Roberts wrote:
>2005 wrote:
>>Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie functions do not take any arguments
)

Huh? Is it good practice to pass arguments to functions that take no
arguments? Is that what you are asking? No, it is not. It won't even
compile. Normally one passes arguments to functions when the functions
need input, or arguments.
>>- returning values using return statement

How else would you return values?
>>>
Anything else?

Your post isn't making a lot of sense. Maybe you need to think more
clearly about what you are asking.
>>>
The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.

Ok.
>>>
Another issue was a LinkedList. I was not supposed to pass the Head
pointer or add a global variable. The class only had *m_pLink (the
tail pointer). Would it be ok to assign the head pointer to m_pLink
(m_pLink does take current pointer values as it progress throuhgh the
chain, but assigned the top current pointer value)? I did that and the
code works fine.

I have no idea if that follows the guidelines to your assignment. You
would normally keep track of the head in a linked list. If you track
the tail and link back to the head then really you are just reversing
terminology as conceptually your list is still from head to tail.
[SNIP-repeated-post]

When you are asked to clarify please do so. Reposting your original text
verbatim does not help either you, or the people who would like to help.

--
WW aka Attila
:::
How many ears does Mr. Spock have? Three, a left ear, a right ear, and a
final front ear.
Oct 29 '06 #4

White Wolf wrote:
2005 wrote:
Noah Roberts wrote:
2005 wrote:
Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie functions do not take any arguments
)

Huh? Is it good practice to pass arguments to functions that take no
arguments? Is that what you are asking? No, it is not. It won't even
compile. Normally one passes arguments to functions when the functions
need input, or arguments.

- returning values using return statement

How else would you return values?
Anything else?

Your post isn't making a lot of sense. Maybe you need to think more
clearly about what you are asking.
The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.

Ok.
Another issue was a LinkedList. I was not supposed to pass the Head
pointer or add a global variable. The class only had *m_pLink (the
tail pointer). Would it be ok to assign the head pointer to m_pLink
(m_pLink does take current pointer values as it progress throuhgh the
chain, but assigned the top current pointer value)? I did that and the
code works fine.

I have no idea if that follows the guidelines to your assignment. You
would normally keep track of the head in a linked list. If you track
the tail and link back to the head then really you are just reversing
terminology as conceptually your list is still from head to tail.
[SNIP-repeated-post]

When you are asked to clarify please do so. Reposting your original text
verbatim does not help either you, or the people who would like to help.
Sorry, the original post - people didn't understand - so I modified it
& posted.

Oct 29 '06 #5

"2005" <uw*****@yahoo. comwrote in message
news:11******** **************@ e64g2000cwd.goo glegroups.com.. .
>
Noah Roberts wrote:
>2005 wrote:
Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie functions do not take any arguments
)

Huh? Is it good practice to pass arguments to functions that take no
arguments? Is that what you are asking? No, it is not. It won't even
compile. Normally one passes arguments to functions when the functions
need input, or arguments.
- returning values using return statement

How else would you return values?
>
Anything else?

Your post isn't making a lot of sense. Maybe you need to think more
clearly about what you are asking.
>
The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.

Ok.
>
Another issue was a LinkedList. I was not supposed to pass the Head
pointer or add a global variable. The class only had *m_pLink (the
tail pointer). Would it be ok to assign the head pointer to m_pLink
(m_pLink does take current pointer values as it progress throuhgh the
chain, but assigned the top current pointer value)? I did that and the
code works fine.

I have no idea if that follows the guidelines to your assignment. You
would normally keep track of the head in a linked list. If you track
the tail and link back to the head then really you are just reversing
terminology as conceptually your list is still from head to tail.

Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie design functions so that they
better take no arguments)
A function's purpose will determine whether it's appropriate
to define parameter(s) for it. So 'best practice' is to
use arguments when necessary, and don't when not.
- returning values using return statement
As far as I know, the only way to return a value from
a function is with a return statement.
>
Anything else?

The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.
This could work (or not) depending upon what the program is supposed to do.
Perhaps this is simply a lesson to show you that there's often more than
one way to do something, and perhaps to decide which is 'better'.
>
Another issue was a LinkedList. I was not supposed to pass the Head
pointer
Pass it to what?
>or add a global variable.
Global objects are rarely necessary and best avoided.
>The class only had *m_pLink (the
tail pointer).
Here you say 'm_pLink' represents a tail pointer.
>Would it be ok to assign the head pointer to m_pLink
Then 'm_pLink' would not be a tail pointer anymore (except in
the case of an empty list).
(m_pLink does take current pointer values as it progress throuhgh the
chain,
Now you say 'm_pLink' is a 'current pointer'. WHich is it?
>but assigned the top current pointer value)?
What is a 'top current pointer'?
>I did that and the
code works fine.
What code? Show us.
>
I do Not think that you can get Head if you know the tail?
Whether you traverse a linked list from beginning to end, or
from end to beginning, you'll need some way of telling when
to stop (typically with a 'NULL' pointer value).

-Mike
Oct 30 '06 #6

Mike Wahler wrote:
"2005" <uw*****@yahoo. comwrote in message
news:11******** **************@ e64g2000cwd.goo glegroups.com.. .

Noah Roberts wrote:
2005 wrote:
Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie functions do not take any arguments
)

Huh? Is it good practice to pass arguments to functions that take no
arguments? Is that what you are asking? No, it is not. It won't even
compile. Normally one passes arguments to functions when the functions
need input, or arguments.

- returning values using return statement

How else would you return values?


Anything else?

Your post isn't making a lot of sense. Maybe you need to think more
clearly about what you are asking.


The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.

Ok.


Another issue was a LinkedList. I was not supposed to pass the Head
pointer or add a global variable. The class only had *m_pLink (the
tail pointer). Would it be ok to assign the head pointer to m_pLink
(m_pLink does take current pointer values as it progress throuhgh the
chain, but assigned the top current pointer value)? I did that and the
code works fine.

I have no idea if that follows the guidelines to your assignment. You
would normally keep track of the head in a linked list. If you track
the tail and link back to the head then really you are just reversing
terminology as conceptually your list is still from head to tail.
Hi

In C++, are the following considered best practices or not?
- passing aguments to functions (ie design functions so that they
better take no arguments)

A function's purpose will determine whether it's appropriate
to define parameter(s) for it. So 'best practice' is to
use arguments when necessary, and don't when not.
- returning values using return statement

As far as I know, the only way to return a value from
a function is with a return statement.

Anything else?

The reason for this question is that I had an assignment in which I was
asked to modify so that the main will call all the functions from main
itself and also do not pass any arguments except the first function.

This could work (or not) depending upon what the program is supposed to do.
Perhaps this is simply a lesson to show you that there's often more than
one way to do something, and perhaps to decide which is 'better'.

Another issue was a LinkedList. I was not supposed to pass the Head
pointer

Pass it to what?
or add a global variable.

Global objects are rarely necessary and best avoided.
The class only had *m_pLink (the
tail pointer).

Here you say 'm_pLink' represents a tail pointer.
Would it be ok to assign the head pointer to m_pLink

Then 'm_pLink' would not be a tail pointer anymore (except in
the case of an empty list).
(m_pLink does take current pointer values as it progress throuhgh the
chain,

Now you say 'm_pLink' is a 'current pointer'. WHich is it?
but assigned the top current pointer value)?

What is a 'top current pointer'?
I did that and the
code works fine.

What code? Show us.

I do Not think that you can get Head if you know the tail?

Whether you traverse a linked list from beginning to end, or
from end to beginning, you'll need some way of telling when
to stop (typically with a 'NULL' pointer value).
If you only know the m_pLink (ie the tail, NULL pointer or the end),
how can you find/evaluate the Head pointer?

Oct 30 '06 #7

2005 wrote:
If you only know the m_pLink (ie the tail, NULL pointer or the end),
how can you find/evaluate the Head pointer?
You cannot iterate a singly linked list backwards. You also cannot
derive anything about a list if the only information you have about it
is a null pointer. If you consider m_pLink the tail of your list,
which you have decided will be null, which you have decided will
represent the end of your list, you will not be able to acomplish
anything with the m_pLink variable. So, in short, if the only thing
you know about your list is that m_pLink contains a null pointer you
will not be able to find/evaluate the Head pointer.

Oct 30 '06 #8
Mike Wahler <mk******@mkwah ler.netwrote:
As far as I know, the only way to return a value from
a function is with a return statement.
Well, another way is to return a value through an output parameter. Yet
another is to throw an exception as a return value, though this style is
frowned upon. A third that I can think of is to return a value through
a global variable, also frowned upon.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Oct 30 '06 #9

Marcus Kwok wrote:
Mike Wahler <mk******@mkwah ler.netwrote:
As far as I know, the only way to return a value from
a function is with a return statement.

Well, another way is to return a value through an output parameter. Yet
another is to throw an exception as a return value, though this style is
frowned upon. A third that I can think of is to return a value through
a global variable, also frowned upon.
None of those qualify as returning a value; they are all side effects.
Throwing an exception is actually completely outside the normal program
flow and doesn't fit in the function concept at all.

Oct 30 '06 #10

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

Similar topics

55
5139
by: Jonas Smithson | last post by:
I've seen a few attractive multi-column sites whose geometry is based on pure CSS-P, but they're what you might call "code afficionado" sites, where the subject matter of the site is "coding practices." (One example of this is alistapart.com.) However, the project/development realities for small boutique sites are completely different from...
3
1632
by: Sasha | last post by:
Hi everybody, I would like to hear your thoughts on the following problem. We have the following classes. Class Exam int ID* int Version* string Name
1
3084
by: James E | last post by:
I have a question about best practices of how to deal with lookup data from my C# apps. On a couple of occasions I have come across a problem where I have to automate inserting a record into a table that has a foreign key constraint that is linked to a lookup table. E.g. Take the following database structure: SQL-Server Database: Table...
136
9279
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to...
10
15112
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy *enemydata; // Holds information about an enemy (in a game) // Its a double linked list node
13
2269
by: john doe | last post by:
A quick question, about so-called 'best practices', I'm interested in which of A/B of the two examples people would choose, and why. public enum MyEnum { Option1 = 0, Option2 = 1, Option3 = 2, Option4 = 3
15
25793
by: Andrew Brampton | last post by:
Hi, This may sound a odd question, but I wanted to know how you return a list of data from a function. These are some of the ways I know how, and I was wondering which method you normally use. This is more of a best practices question rather than a technical one. 1) Return a list instance ie std::list myFunction() { std::list list();...
26
3617
by: puzzlecracker | last post by:
It'd be interesting to compare the learning practices of c++ practitioners. I'll start with mine The C++ Programming Language C++ Primer Effective C++ More Effective C++ Effective STL The C++ Standard Library : A Tutorial and Reference (most of it) Exceptional C++
16
1811
by: pauldepstein | last post by:
Can anyone give a realistic example of a task for which the list container works better than vector or deque? Paul Epstein
0
7792
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8175
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6553
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5364
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1138
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.