Main Site Documentation

Classes and dll`s


#1

just wondering what most people do or whats the best practice.

personally when i write code i like to seperate it into smaller reusable classes. what i usually do is create a directory in the app say called api drop the class in there, then add somethiong like using whatever_this_apps_app_name_is.api; so the classes is included in the main class.

and different approach is to create a seperate dll class and the add this to the project like you would say ghi.namespaces.

so which approach is best for managing your own classes, and proably more importantly resouses usage in the deployed code, im guessing it wont make any differnece but i dont know.

anyone got any advise or experiance to give ?

thanks


#2

I personaly do the same as you

All my classes go in a directory called “storage” and it keeps them all together. I have never tried the “accumulating into a dll”. Surely it would be harder to debug…

Cheers Ian


#3

Im not entirely sure how the c# compiler handles it’s unused code optimisation in the .netmf but i assume if you include your classes in your main exe, any unused methods get optimised out, saving on code space. With a dll all code is included since the compiler has no idea what will and wont be used. In a resource constrained environment I like to only include what’s needed so I include all my classes in the exe and let the compiler do its thing.


#4

You should do this to a degree, but not go overboard with it. If you have a look at some enterprise design guidelines you’ll probably find it quite enlightening. There are always tradeoffs with such things, you just need to pick the method that you get the most functionality/code separation/reuse abilities (or whatever your goals are) for the lowest cost (cost will depend on your requirements, be it flash space, memory overhead, etc).

You shouldn’t have too many assembles, group similar things together - sensors in 1 assembly, gps devices in another, network comms in another. Make sure everything is independent and not tied together.


#5

Oh, in the regular .NET space on a PC I do the full use of dll files, it definatly helps with code maintainability, it’s great.

In the .NETMF space though, I still go through the full seperation process in source (separate namespaces, folders, etc) but put all the class files in the .exe so the optimisation can keep my code usage down. Kind of like a best-of-both-worlds arrangement.


#6

@ heffo “Im not entirely sure how the c# compiler handles it’s unused code optimisation in the .netmf but i assume if you include your classes in your main exe, any unused methods get optimised out, saving on code space”

I can’t seem to verify this. Unused methods and method names seem to be added to both the IL and *.pe file that MetaDataProcessor creates for deploy. I would think it do a noop, but that does not seem to be the case either. Adding more code to an unused method keeps increasing the size of the pe. It does seem to optimize variable names.

It would be reasonable if MetaDataProcessor did some simple method name compacting for non-public names.