Tuesday, May 29, 2007

Who's programming who?

I write a lot of software to collect and process data. The reasons and data itself is pretty much top secret, but some of the details about how I do it might be interesting, especially to the science types that wander by.

I am not a general-purpose programmer by any means, and I would hang myself if I were responsible for anything called "business logic" or database analysis or the kinds of things my 'real' programmer friends do for a living. I have one buddy who has done some interesting programming for the military and for phone network switching, which sounds kind of fun.

Some stuff I do falls into the area of embedded programming. Imagine your VCR, or your car, or your favorite piece of laboratory instrumentation. It's common knowledge that these contain microprocessors or microcontrollers, and often more than one per device. Embedded programming is the programming done to make this hardware work. Usually, I do this in C these days, but years ago, I did it in assembly language (thinking about this too much gives me the shakes...). There are usually no graphics involved, except maybe an lcd screen, though this has begun to change. Everything is done from memory, there is no operating system (again, this has begun to change as Linux is ported to microcontrollers). In most cases, I have done this to automate some data collection in an instrument that had to be custom built for some reason. Generally, if I can figure out how to do a project with commercial instruments, I'll do it that way, because the time involved in writing any software, but especially embedded software, is amazingly long.

At the extreme opposite of this is programming in LabVIEW. LabVIEW is a graphical programming language designed to allow one to string together instruments, controlling them and gathering data from them by essentially creating diagrams of their interconnections. It is much faster, in most cases, than procedural programming, but it isn't hard to do it really poorly. There really isn't any tool to protect you from the need to think clearly and logically. LabVIEW contains all sorts of mathematical and graphics functions, too, so it's not too difficult, supposing you really think through the logical tasks, to make spiffy, extremely useful software.

I have a handful of tasks where I have used LabVIEW to control a box that contains a microcontroller that I programmed in C to do some task. This combo is really powerful, because you get the fine-grained control of exactly what your hardware does using the embedded computer, but then the data you gather can be displayed and reported in a beautiful, professional fashion.

My latest foray into programming is Java. For years, I have been avoiding it. It always seemed slow and incredibly obtuse. But over the years, apparently, it has begun to get better and better, and best of all, there are lots of really fantastic tutorial and reference materials available on the web. The Java compiler and a good development system (I like Eclipse) are available for free, and there is a really good free pdf textbook suitable for people who know nothing about programming that covers the most recent incarnation of Java.

There's a lot of hype for Java, and a lot of negative bashing on the net about performance. There is a performance penalty in terms of speed for using Java, maybe 20%, in my experience. There are debunkings and counter-debunkings out there, and my advice is to ignore them- some of the worst knocks on Java were true a few years ago, but the language has continued to improve. Java lets a novice programmer do a lot of very cool things, and there is tons of support available on the Web. Ignore the programmer religious wars about which language is better.

Doing things that take a lot of time in other procedural languages are pretty easy in Java (even though there are C/C++/C# compilers available for free, the learning curve for programming in a GUI environment is pretty steep for these. I have found it much less so for Java).

For me the bottom line is this: I can do neat stuff with Java more quickly and with less fuss than with C++ and the other popular languages that I know about. I have been able to teach myself how to make some cool software in a relatively short period of time, and I can run this software on my Mac and my PCs. Is Java the greatest programming language on Earth? Don't know, don't care. Still, searching for info on Java has led me to some interesting name-calling and fighting about whether Java or C++ or C# is the best or sucks the most butt.

There are some weird things I dislike about Java, and I think I'll continue with this in another post. For the price, you can't beat it.

My very favorite thing is that the Eclipse development environment and Java work the same on my Mac and PCs. I have a PC at work, and a mixed-marriage of all sorts of computers at home, but my primary platform at home is the Mac. OS X runs Java stuff very well. Being able to pick up at home where I left off at work without kicking my kid off the PC is nice.


At Tuesday, June 19, 2007, Blogger Ψ*Ψ said...

Labview is pretty nifty. I'm seeing it for the first time this summer.

At Wednesday, June 20, 2007, Blogger David Eaton said...

I guess I first encountered it seriously at NHMFL, the magnet lab in Florida. They control everything with it.

It is easy to do easy stuff in LabVIEW. It is pretty easy to do moderately hard stuff, and it is possible for a non-programmer to do crazy, difficult stuff.

It is worth digging in to if you have the opportunity. I find it useful for banging out little programs that I used to write in C or Visual Basic, whether they are connected to instruments or not.

At Thursday, June 28, 2007, Blogger The Lil'est Naturist said...

"Whom." Sheesh. =P Just kidding.

Interesting post, though outside my normal reading topic. If you like pharm-chem and talk about toxic chemicals and, um, cute pictures of molecules, visit my blog. 5by5b.blogspot.com


Post a Comment

<< Home