Design a new library over existing c codes. What is the best way?

G

Guest

Hi there,

I had a scenario here.

I had many tonnes of C codes in my office. Each C codes are used in low level stuff. Like connecting to smart card readers or even the OS itself.

I was being hired to push .NET into it and fully object oriented.

I had some questions to ask.

1) Is C# is the right way to do a rewrite over those existing C codes. I have to use platform invocation all the way, and do some marshalling. Just i seen too many p/invoke, and starts to wonder whether it will cause performance breakdown.

2) If i use C++.NET, i heard i can call directly from the windows.h. in C#, i need to use dllimport can direct call into kernel32.dll or winscard.dll. Quite tough.

3) I am not calling the C dll, if i do, i don't fit my job requirements.

4) Is C++.NET or C#, which one is the best way to create this whole new design of the library? I had the design planned using some design patterns?

5) In C, we can use pointers, but in C# i am preventing myself to use unsafe. Better stick on the safe side. Just too many pointers in there, and it takes time to understand the code. I am not that strong in C, only can read but cannot code it.

Please share some time to shed some comments for me. Thanks.
 
N

Nick Malik

Hi Chua Wen Ching,

First off, take a look at the Facade pattern for places where you are using
P/Invoke to windows level services. Create a couple of facades for lower
level services so that you can call them from you code without dealing with
the mechanics. I do not know if P/Invoke is slower or not (perhaps some
other folks know). However, you have been assigned to do this, so don't
sweat it too much. On the other hand, if there's some code that needs to
make dozens of calls in a row, and if there is a performance penalty, you
may want to leave some of the C code in place to do the Windows API work,
and just make a single P/Invoke to your old C code.

As for which is better:C++.NET or C#: don't ask about efficiency... ask
about what languages you and your company want to support! Every line of
code has to be maintained. One language is better for your company.

Use design patterns. I encourage that. That's the best way to get to a
good OO design.

Whenever I have to rewrite code that I don't know, I try to start by
learning what the code is trying to accomplish, and then look for the places
where the code catches errors or handles exceptions. Start with intent.
(There's an entire field of research called "intentional programming" based
on this concept).

I hope this helps,
--- Nick

Chua Wen Ching said:
Hi there,

I had a scenario here.

I had many tonnes of C codes in my office. Each C codes are used in low
level stuff. Like connecting to smart card readers or even the OS itself.
I was being hired to push .NET into it and fully object oriented.

I had some questions to ask.

1) Is C# is the right way to do a rewrite over those existing C codes. I
have to use platform invocation all the way, and do some marshalling. Just i
seen too many p/invoke, and starts to wonder whether it will cause
performance breakdown.
2) If i use C++.NET, i heard i can call directly from the windows.h. in
C#, i need to use dllimport can direct call into kernel32.dll or
winscard.dll. Quite tough.
3) I am not calling the C dll, if i do, i don't fit my job requirements.

4) Is C++.NET or C#, which one is the best way to create this whole new
design of the library? I had the design planned using some design patterns?
5) In C, we can use pointers, but in C# i am preventing myself to use
unsafe. Better stick on the safe side. Just too many pointers in there, and
it takes time to understand the code. I am not that strong in C, only can
read but cannot code it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top