Results 1 to 9 of 9

Thread: organising code

  1. #1

    Thread Starter
    Addicted Member donut's Avatar
    Join Date
    Mar 2001
    Location
    London, UK
    Posts
    165

    organising code

    now that you can create class files pretty much anywhere in VB code, what would be the best way to organise them? for example, in form1.vb you have the form1 class, but you could also have several other classes in that file as well. so would it be best to have any form classes in their own file, and any other classes in class files? also, when would you decide to use namespaces? would that just be if you have a bunch of classes that relate to a similar thing, and would you typically have each namespace in a seperate class file?

    i know these are pretty simple questions, but i feel i must ask them. thanks

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Namespacing comes from c++
    and from what i gathered and learned its best to namespace things that are related
    for example
    if i have a Namespace called MyArrays
    then i will have all functions related to arrays in here
    such as quicksort, heapsort, binary and so on

    so to answer your question, its frowned upon when you namespace unrelated things

    that is what i learned and heard anyways

  3. #3

    Thread Starter
    Addicted Member donut's Avatar
    Join Date
    Mar 2001
    Location
    London, UK
    Posts
    165
    ok, thanks, that answers one of my questions. how about where to create classes/namespaces?

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    like this..in any .vb file


    Code:
    Namespace mySpace1
       Class myClass1
          'beeotch
       End Class
       
       Class myClass2
          'beeotch 2
       End Class
    
    End Namespace
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Addicted Member donut's Avatar
    Join Date
    Mar 2001
    Location
    London, UK
    Posts
    165
    Cander, yeah, but you wouldn't just start shoving classes all over the place would ya? i know it's basically down to preference where you put them, but would you normally create classes in class files, rather than in a form file?

  6. #6
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    now that you can create class files pretty much anywhere in VB code, what would be the best way to organise them? for example, in form1.vb you have the form1 class, but you could also have several other classes in that file as well. so would it be best to have any form classes in their own file, and any other classes in class files?
    Personally I would leave the form class in a .vb file on it's own, and then have another .vb file for each other class. I would however consider have one .vb file for all classes in a specific namespace (see Canders example).

    I guess the main consideration is making it easy for the programmer to find the code for any specific class without having to search through too many vb files. It should be fairly obvious where they have been defined. (imho).

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    like I said , put it in a .vb file.

    in .net you dont have seperate file extensions for class/modules/forms.

    its all .vb.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  8. #8

    Thread Starter
    Addicted Member donut's Avatar
    Join Date
    Mar 2001
    Location
    London, UK
    Posts
    165
    ok, thanks, that's cleared that up for me. i know that it was a pretty simple question, and i kinda knew that's how it worked, i just wanted to make sure.

  9. #9
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    in .net you dont have seperate file extensions for class/modules/forms.
    No you don't - but that doesn't mean you have to lump them all into one .vb file. Personally I still like to separate them out a little.

    I also still tend to prefix my .vb files with f or c to denote if they contain class structure(s) or a form class structure. I know to .net they are all classes - but I find it easier to maintain my apps buy doing this. I appreciate that this may just be personally preference.

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