473,396 Members | 2,036 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.

What data type would you prefer and why?

I wanted to practice some Linked List stuff, so I set out to create a
linked list. The plan was to create the following:

(1) A linked list class in Visual Basic
(2) A non-class based linked list using functions in C
(3) A linked list class in C++

I started with Visual Basic and I wrote an IList interface that I
wanted my list to implement. When I had started, somehow I thought
this time, I'd first use a collection as the ingredient, and so it
would not really be a linked list. It would be an extended collection
behaving like a (not linked, but just a) list, as in list of things.
And my new agenda would then be,

(1) A list (not a linked list) class in Visual Basic by extending the
Collection object.
(2) A linked list class in Visual Basic
(3) A linked list in Visual Basic that is not class-based but has a
struct (Type) and global functions in a standard module (.bas).
(4) A non-class based linked list using functions in C
(5) A linked list class in C++

I don't like to create lists if they have no meaning, so I thought it
would be a good idea if the list was a list of something and not just
"ints". So, I made a list of my friends on the Joel On Software forum.
I called the list MyFriends.

I have just finished implementing a list by extending the Visual
Basic's Collection object. My list has the following interface:

Expand|Select|Wrap|Line Numbers
  1. Public Function AddAtPos(ByRef Object As Object, _
  2. ByVal Index As Long) As Boolean
  3. End Function
  4.  
  5. Public Function PeekAtPos(ByVal Index As Long) As Object
  6. End Function
  7.  
  8. Public Function RemoveAtPos(ByVal Index As Long) As Boolean
  9. End Function
  10.  
  11. Public Property Get Count() As Long
  12. End Property
  13.  
  14. Public Function Contains(Object As Object) As Boolean
  15. End Function
  16.  
  17. Public Function IndexOf(Object As Object) As Long
  18. End Function
  19.  
  20. Public Sub Serialize()
  21. End Sub
  22.  
  23. Public Sub Deserialize()
  24. End Sub
  25.  
  26. Public Sub Clear()
  27. End Sub
  28.  
  29. Public Sub Sort(ByVal SortOrder As SortOrders)
  30. End Sub
  31.  
  32. Public Sub Reverse()
  33. End Sub
  34.  
If you're interested, you can find the source code and the executable
for my first experiment here.

http://www.vbforums.com/showthread.p...hreadid=303400

Now, I am set to implement item number (2) in my agenda - the linked
list class in Visual Basic. Once again, the semantics remain the same.
I intend to keep the list as a list of friends. So each node in the
list is a friend. While designing the "node" class or the "MyFriend"
class, I stumbled accross this problem. I am recording two pieces of
information about each friend:

(1) Name
(2) Phone Number

Both are of String type. The problem was not with these, but with the
"node pointer" item. I have three data types in mind that I can use to
point to the next node. I am confused as to which one would be a good
choice, and I want your opinion on the same.

Here's what I have thought the node/MyFriend class as:

Expand|Select|Wrap|Line Numbers
  1. Implements IList
  2.  
  3. Private mName As String
  4. Private mPhoneNumber As String
  5.  
  6. '===Which one do I choose?=======
  7. 'Private mNextFriend As MyFriend
  8. '         OR
  9. 'Private mNextFriend As Long
  10. '         OR
  11. 'Private mNextFriend() As Byte
  12. '==================================
  13.  
Let me argue each case, as I thought about them. Starting with the
last, if I take the mNextFriend field as a Byte array, it would help
me....do nothing, basically. So, ruled out.

Next, if took the mNextFriend field as a Long, I think it would be the
ideal thing to do, because VB6 Long's are indeed 32-bit values, and
then I would use the mNextFriend Long field to point to a new instance
of MyFriend type, using the ObjPtr function. I would dereference the
mNextFriend Long type by using RtlMoveMemory. That sounds like a nice
plan. However, the problem with this is that it does not strictly
confirm to a Linked List set up, because of the generic nature of this
Long pointer. This pointer could be used to point not only to MyFriend
types but to anything. Since I am going to be the developer audience
for this class, and hence this is only dogfood, it is no problem, but
in general, I don't like it as a habit and I always want my code to
represent what it ought to represent. So, this would be like
compromising on a trivial issue.

If I use mNextFriend as a MyFriend type, I solve the problem of the
generic pointer by restricting it to the MyFriend type. So, it's more
disciplined this way, but now, the field is not really a pointer. It
is an object. Of course, it is still a 32-bit reference to the actual
object, but it is still not a real pointer.

So, I am confused. If you were to be doing this, what option would you
choose and why? To me, the Long seems like ok, although it is a little
bit of a compromise on the type-checking.
Nov 14 '05 #1
3 2058

"Sathyaish" <Vi****************@yahoo.com> wrote

If I use mNextFriend as a MyFriend type, I solve the problem of the
generic pointer by restricting it to the MyFriend type. So, it's more
disciplined this way, but now, the field is not really a pointer. It
is an object. Of course, it is still a 32-bit reference to the actual
object, but it is still not a real pointer.


IMHO, the field is a type safe pointer, and I would have thought

Private mNextFriend As IList

would have been the obvious choice for the task. That would
have restricted those fields to objects that implement the IList
interface, no matter what type of object they actually were....

LFS
Nov 14 '05 #2
Sathyaish wrote:
I wanted to practice some Linked List stuff, so I set out to create a
linked list. The plan was to create the following:


No real advice here except.... check out these samples.... they may give
you some ideas (plus they're great samples)

DataBagLib and LinkedListLib
http://killervb.com/Libraries.aspx

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Nov 14 '05 #3
Sathyaish wrote:

I wanted to practice some Linked List stuff, so I set out to create a
linked list. The plan was to create the following:

(1) A linked list class in Visual Basic
(2) A non-class based linked list using functions in C
(3) A linked list class in C++


This VB and C++ junk is foully off-topic here in c.l.c. F'ups
set. See the links in my sig below for help. Singly linked lists
are extremely simple. For an example in C see the freverse.c
example contained in:

<http://cbfalconer.home.att.net/download/ggets.zip>

--
Some useful references:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> C-library
Nov 14 '05 #4

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
11
by: modemer | last post by:
If I define the following codes: void f(const MyClass & in) {cout << "f(const)\n";} void f(MyClass in) {cout<<"f()\n";} MyClass myclass; f(myclass); Compiler complain that it can't find...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
3
by: Andrew Mueller | last post by:
Hello, I tried this question prior and got no response, so thought I would try to explain differently.. I am not sure which type of object to pass between a VB 6.0 ActiveX dll and C#. I am...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
12
by: Robert.Holic | last post by:
Hi All (first time caller, long time listener), I've stumbled across a problem that I have yet to figure out, although Im sure I'll kick myself when I figure it out. Here it is: I need to...
5
by: rockdale | last post by:
Hi, all: I have a website with its own login page. Now one of my clients want their employees log into my website from their website. They want to have their login page (look and feel are...
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
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:
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
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,...
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.