tags:

views:

301

answers:

8

I intend to write a small application to scratch a personal itch and probably make the life of some colleagues easier. Here is what I have:

  • 10+ years of experience in C
  • Plenty of experience in programming against the Win16/32 API in C from the Win3.1 to 2000 days.
  • C library written by myself already doing about 75% of what the application shall do.

What the application shall do:

  • open a binary, feed it into the mentioned library.
  • take the resulting text output and feed it into a new Excel Workbook.
  • apply some formating.
  • integrate nicely with the Windows environment (availability in "Open With...", remember some stuff using the registry etc.)
  • (maybe later) before giving the CSV data to Excel, parse it by looking up the meaning of some values in an XML file.

Except for the XML parsing part I have done all of that stuff before including COM / Office Automation in C/Win32. There is a lot of boilerplate code involved, but it is doable and the result will be a pretty small application without the need for an installer.

So why even think about C# / .Net?

  • no experience with parsing XML
  • the promise of less boilerplate code for the Windows and Excel stuff (yes, I have done C++ with OWL, MFC, ATL etc. but I am not going there anymore - not for free/fun)
  • Since I have also experience with C++, VB(not .Net) and a little Java / Objective-C I suppose learning C# will all be about the .Net libraries and not actually about the language.

My considerations so far:

  • Learning .NET might be fun and might result in less code / first steps in a more modern environment.
  • Sticking with what I know will lead to a predictable outcome in terms of effort and function (except for the optional XML stuff)
  • VB looked great at the beginning until the projects where about 80% done, then the pain started and the DLL coding in C. I am concerned history could repeat itself if I choose .Net.

My primary objective is the functionality. Effort is a concern. The XML parsing is optional.

Please advice.

Update: one thing I forgot to mention explicitly is that I am also worried about easy deployment of the tool to my co-workers. With Win32 I am pretty sure I can come up with an EXE file < 1Mb that can be easily emailed and does not require installation. With .Net not so much. Can I create the necessary MSI or whatever in Visual Studio Express (free) or do I need 3rd party tools?

+1  A: 

It depends. :-) It depends on whether you want to do this quickly or if you want to learn something new. It depends on whether you will be the only maintainer of the code or if others will maintain it in the future. It depends on how complex your xml handling will be and on how complex the COM automation is.

You will probably get a working application quicker if you do it in C than in C#. Both since you have much of the stuff needed already in place and since you know C well.

But this project sounds like a good match for C# and .Net. .Net has great support for XML and COM interop is easy but clumsy in C# (much better in the next version!). So if you are interested in learning C# and .Net this would be a good project to do so.

I would definitely do this in .Net and probably C# (but I am biased). Using .Net would probably result in code that is easier to read and maintain and most probably easier to write. So if you are interested in learning C# I would suggest you go for it!

Edit: You worry about the size of the executable if you write it in .Net. I doubt that will be a problem, for most if not all of the libraries you will use for a project like this will already be installed on your computer. 1 Mb is rather large for a .Net executable, event for a big project.

Rune Grimstad
The thing about the maintenance is a great point. The people who would probably inherit the code are using .Net and Delphi for older stuff.
Sven Semmler
+3  A: 

If you're using COM, you may be interested in using C# 4.0 instead of earlier versions - the downside being that it's only in beta. But basically it makes COM stuff somewhat less ugly for various reasons.

I'd expect there to be plenty of good C libraries for XML parsing by now. I would expect the main benefit to actually be the knowledge gained. I doubt that you'll actually produce the code faster for this project, but the next one may well be a lot quicker.

How much do you care about learning new stuff?

Jon Skeet
Good question. I care a lot actually, but the time I can spend with this project is probably limited to an hour per day. So if I want a shareable result within this year ... I will definitely look into C#4.0 from the COM angle before making my decision.Thank you!
Sven Semmler
+1  A: 

I think you should use C#. With your experience the learning curve won't be too steep. The code will ultimately be cleaner (and less of it) than you probably could with C/Win32. There is probably going to be no problem using your existing C-library with the [DllImport] attribute.

Richard
The code of the library is trivial and probably rewritten in C# within 3-4 hours. The value lies in the knowledge necessary to read the binary which I gathered by interviewing the creators and writing the specification for it.
Sven Semmler
+2  A: 

It sounds like an ideal project for learning C# & .NET.

You know most of what you need to do so you can use that to gain a base level of understanding of C# & .NET which you can then apply to the stuff you need to learn.

As Rune says though, a key driver could be the timescales. If this is something you need in a hurry then coding it in C & using win32 directly might be the answer.

Sorry I couldn't be more definite.

ChrisF
Sven Semmler
I'd go with C# then.
ChrisF
+1  A: 

a short notice on the installation. .NET is as default xcopy-able so you wouldn't need an installer for the exe to be usable. Mail it around (or with the next release of the .NET framework optionaly leave it on a network share)

Rune FS
+1  A: 

You could look at building a hybrid system that uses C++/CLI and C#. C++/CLI provides a nice bridge between the two and lets you easily split different parts of the system between the managed and unmanaged worlds.

Not sure if the setup projects are included in the free versions of visual studio. But you could use clickonce (included with the framework) or WIX (open source XML based msi creation tool).

pjbelf
+1  A: 

learning C# will all be about the .Net libraries and not actually about the language

No there are many things you need to learn about the language (delegates , events , generics ...) and also it is object oriented and it manages the memory by itself and yes no pointers :)

anyway C# and .NET are great all you need is some effort to get up to speed

Yassir
Delegation like in Objective-C, Generics like in C++/STL ... Sorry, I haven't provided the whole background. I learned programming about 15 years ago with Object (Turbo) Pascal on DOS and played a little with x86 Assembler, then moved on to C++/OWL and only after that got into C. VB happened even later ... I was young and needed the money. ;-)
Sven Semmler
One may use pointers inside unsafe code
Luis Filipe
yes you can but you don't use unsafe code everyday :)
Yassir
+3  A: 

Hi, as others have your question mostly covered, I'd just like to quickly comment on your considerations:

  • Learning .NET might be fun and might result in less code / first steps in a more modern environment.

Totally agreed. It is definitely fun and usually it does result in less code. The investment you make now will certainly benefit you in future projects. It is way faster to program in .Net than in C. Not only it is easier, but it is also safer. You are isolated from many programming errors common in C mostly related to memory mismanagement. You also get a very complete managed API to do stuff you would usually need to build your own framework.

  • Sticking with what I know will lead to a predictable outcome in terms of effort and function (except for the optional XML stuff)

Hence your indecision. :-)

  • VB looked great at the beginning until the projects where about 80% done, then the pain started and the DLL coding in C. I am concerned history could repeat itself if I choose .Net. My primary objective is the functionality. Effort is a concern. The XML parsing is optional.

.Net is an entirely different beast from VB. Most of the things you wouldn't be able to do in VB, or at least do them easily, are supported by .Net. For instance, Windows Services are a snap to build in .Net. Socket programming is also supported, but there are very few reasons to do it yourself, as you've got loads of communication APIs with .Net. You've got web-services, .Net Remoting, MSMQ management, and more recently WCF. Proper multithreading is supported by .Net, unlike the idiotic apartment model in VB. In case you really need to go low level, you can also actually use pointers in C#, inside of unsafe code blocks, even though I would never advise to do so.

If you really need to do things in C, then integrating is also relatively easy. You can create COM objects and use interop to work with them from .Net. You can also interact directly with plain ol' dlls using DllImport. Using www.pinvoke.net makes it easier.

When I developed in VB, sometimes I also had to go back to C++ to do stuff that I wasn't able of doing in VB. Since I began programming in .Net, the only extremely rare scenarios I would need to go back to C++ were when I needed to use legacy COM components that used types I was having a hard time to marshal via interop. I wouldn't worry about history repeating itself.

Rui Craveiro
I love all the answers and are amazed about the speed and quality. However your answer comes closest to what I was looking for as you identified and addressed my main concerns. Thank you!
Sven Semmler
Great answer! :-)
Rune Grimstad
Thanks for the comments! :-)
Rui Craveiro