views:

119

answers:

8

Hello,

We have a very versatile terminal/sniffer application which can do all sorts of things with TCP, UDP and serial connections.

We are looking to make it extensible -- i.e, allow people to write their own protocol parsers, highlighters, etc.

We created a C-like language for extending the product, and then discovered that for some coders, this presents a steep learning curve.

We are now pondering the question: Should we stick to C or go with something like Ruby or Lua?

C is beautiful for low-level stuff (like parsing binary data), because it supports pointers. But for exactly that reason, it can be tough to learn.

Ruby (etc) are easy to learn, but don't have pointers, so anything that has to do with parsing binary data gets ugly very fast.

What do you think? For extending a product that parses binary data -- Ruby/Lua or C/C++?

Would be great if you could give some background when you respond -- especially if you've done something similar.

+1  A: 

If you have an API written does it make a difference? The person using the C-like API would only have to understand the difference between passing by value or reference.

Derek
Maybe I wasn't being fully accurate. I meant we have a _language_ written, but we feel it may be too difficult and are thinking of shifting over to another language -- but are not sure about it. I'll update the question accordingly.
JelloPenguin
+2  A: 

Your core does one thing very good, so fine. Let it be that way. I think you should create an API based on std in/out, just like the way of good unix design. Then anyone can extend it in any language of choice.

Johan
IME (in my experience) control using stdin/stdout is not reliable enough. GNU chess, GNU gdb, Mplayer use that and occasionally one can cause the problem when the two sides (front-end and back-end) become out of sync. Probably something akin to stdin/stdout, but message-based/delimited file descriptors (AF_UNIX + SOCK_DGRAM), not the default streaming ones.
Dummy00001
A: 

Tcl was designed with the goal to allow scripting for C programs, so it would be much easier to implement.

http://en.wikipedia.org/wiki/Tcl#Interfacing_with_other_languages

qrdl
But does Tcl itself support parsing binary data?
JelloPenguin
I don't know. But anyway you can write parsing functions in C and call them from Tcl.
qrdl
A: 

I second Johan's idea. Although in past when I had to do something like this I stuck to C language APIs and people were restricted to use C language only. But now I look at it, I realize that it would have been more efficient if we would have done the way Johan describes

PS: And by coincidence it was a protocol testing app using packet sniffer

Himanshu
The thing is that the API hooks very deeply into our product, including changing the UI, creating on-screen buttons etc, and also analyzing packets. So providing an IO interface isn't a great solution for the GUI part, I think. Unless I am missing something.
JelloPenguin
I see. Then in this case better leave this as is, Since going to provide enhancement to developers you might break the core part.But if you choose any other language, people who do not have sufficient knowledge of that might have same issue.Conclusion, in my opinion stick to c/c++
Himanshu
Thank you! I appreciate the feedback.
JelloPenguin
You are welcome.
Himanshu
A: 

perl, sed, awk, lex, antler, ... These are languages I'm somewhat familiar with that I'd like to write something like this in. It depends on the data flow, though.

It's really hard to say what the correct thing to use is. Something that I don't think anyone else has mentioned is to keep in mind that the scripts will have bugs. It's very easy to design something like this in such a way that bugs in the scripts (especially run time errors) either just show up a "error in script" or kill the whole system.

You should keep that the scripts should be unit testable and that failures should be reproducible.

nategoose
That's a very good point -- should definitely give some thought to debugging. That's actually another reason to go for a "simple" language, because I think C code is easier to mess up in surprising ways (especially when it comes to pointers).
JelloPenguin
+4  A: 

Wireshark, the "world's foremost network protocol analyzer", is also a packet sniffer/analyzer, formerly also called Ethereal. It uses Lua to enable writing custom dissectors and taps, see the manual.

However, note that I have not used it, so I cannot tell how nice/effective/easy to learn the API is.

MiKy
+2  A: 

Like TCL, Lua was designed to be tightly integrated with an application. Personally, I find Lua's syntax and idioms to be much easier to deal with than TCL.

Lua is easy to integrate with an existing system, and easy to extend. It is also fairly easy to create safe sandboxes in which user-supplied code can run without full access to the innards of your product.

RBerteig
A: 

I don't think it matters what you do as long as you do one thing, drop the in-house language. It sounds like you choose to make C into a scripting language. One issue I see with this is it will look familiar to C programmers, but not be the same. I can't imagine you have mimicked the semantics of C that would make existing C programmers comfortable. And as you have mentioned, others will find it hard to learn.

The company I am working at have developed their own language. It uses XML for structure so parsing is easy. The language grows "as needed." Meaning if a feature is missing then it will be added. I'm pretty sure it went from an XML database to something that needed control flow. But my point is that if you aren't thinking about building it as a language, then you'll be limiting what users can do with it unintentionally.

Personally I've been looking at how I can get the company to start taking advantage of Lua. And specifically Lua for several reasons. Lua was developed as an extension language that was general purpose. It easily interfaces with the language, including Python and Ruby. It is small and simple for use by non-programmers (not really needed in your case). It is simple enough to replace XML, INI... for configuration settings and powerful enough to replace the need for another programming language.

http://www.lua.org/spe.html

he_the_great