Results 1 to 8 of 8

Thread: little question about naming and organizing functions....

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    little question about naming and organizing functions....

    I'm making a utility class for myself. I have a little question which is hard for me to explain, so I just wrote this code:

    VB Code:
    1. Class GraphicsUtil
    2.       Public Function RectToRectF ...
    3. End Class
    4.  
    5. Public ConvertorUtil
    6.      Public Function ArrayListToString .....
    7.  
    8. [color=red]heres my question, should I do this? it helps me
    9. organize my code better, but it results in multiple declaration of a
    10. function:[/color]
    11.  
    12.      Public Function RectToRectF ()
    13.              ' Calling the function from the other class
    14.             Return GraphicsUtil.RectToRectF...
    15.      End Function
    16. End Class

    I just have too many functions and I'm trying to categorize them by putting them in different classes. But some of them like the above function dont fit into one category, so I decided to put them in more than one class. Is this considered bad coding or something? should I aviod this?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    Have a look at this link http://msdn.microsoft.com/library/de...guidelines.asp. It provides guidelines on naming conventions of classes, variables etc.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If the functions do the same thing and aren't different version with the same name then I would put them as shared in a class and then nest the other classes by category inside that class. It basically works like using the namespace but namespaces can't have functions.

    VB Code:
    1. Public Class Utilities
    2.  
    3.     Public Class GraphicsUtil
    4.  
    5.     End Class
    6.  
    7.     Public Class ConvertorUtil
    8.         Public Function ArrayListToString()
    9.  
    10.         End Function
    11.  
    12.     End Class
    13.  
    14.     Public Shared Function RectToRectF()
    15.  
    16.     End Function
    17.  
    18.     Private Sub New()
    19.         'if you don't want the namespace type class to be able to be an actual object then use this
    20.         'then it can't be made with the New keyword
    21.     End Sub
    22.  
    23. End Class
    Last edited by Edneeis; Jan 16th, 2003 at 01:22 AM.

  4. #4
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    If we put a class inside a class wont it make the class hard to maintain when the no of lines of code increase?

    is there another way around it?

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why would it make it hard to maintain?

    The only way the objects are linked is through their namespace really. That and the children can access private members of the parent (although they are not tied to an instance mind you).

    If you mean because of the amount of room on the screen then just set some regions up to make each class or parts of them collapsable.

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Edneeis
    If the functions do the same thing and aren't different version with the same name then I would put them as shared in a class and then nest the other classes by category inside that class. It basically works like using the namespace but namespaces can't have functions.

    VB Code:
    1. Public Class Utilities
    2.  
    3.     Public Class GraphicsUtil
    4.  
    5.     End Class
    6.  
    7.     Public Class ConvertorUtil
    8.         Public Function ArrayListToString()
    9.  
    10.         End Function
    11.  
    12.     End Class
    13.  
    14.     Public Shared Function RectToRectF()
    15.  
    16.     End Function
    17.  
    18.     Private Sub New()
    19.         'if you don't want the namespace type class to be able to be an actual object then use this
    20.         'then it can't be made with the New keyword
    21.     End Sub
    22.  
    23. End Class
    well, ahem, there are more than 2 classes and those functions arent supposed to be shared with all classes I either have to go with my own way, or I have to aviod doing this...
    In my first post, I'm just declaring another function with the same name, which calls the function from the GraphicsUtil class. Is it bad if I leave it like this?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I don't think your way is going to harm anything. The only thing you will be doing is adding another object to the call stack. If speed is your ultimate concern, you might want to run some tests to see what the performance hit would be, if any.

  8. #8

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hellswraith, I'm not worried that much about performance So I guess I would go with my way.
    I want the user to be able to access the class like this:

    Utility.GraphicsUtils.RectToRectF
    Utility.Convertors.RectToRectF
    Utility.Convertors.....
    Utility.....

    something like that
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width