Which programming language to learn

I have recently become interested in robotics - I've done a bunch of
reading, and am about to embark on a "first robot tutorial" on the
Society of Robotics website.
When I reach a more advanced level, I know I will need programming
skills. I haven't done any programming apart from some BASIC at
school 20 years ago! But I'm willing to learn. So, what would be the
best programming language for me to learn in connection with hobbyist
robotics? C++? Some form of BASIC? Or something else entirely?
Reply to
dapunka
Loading thread data ...
Both C and BASIC are well supported by microcontroller compilers / interpreters, so either language is a good choice. I personally prefer compiled C for my micro work (I use CCS's awesome C compiler). On the (Windows) PC side, I recommend C# or VB.NET. Don't bother with C++, as it and its COM/DCOM ilk are deprecated. .NET / C# / VB.NET is where it's at now.
BRW
Reply to
BRW
I agree, unless you are writing a huge program, plain old C is much simpler and reduces your risk of encountering compiler induced bugs. Don't repeat that out loud on the C++ news group though or they will start screeching and throwing feces at each other in protest. They can be an ornery bunch when you suggest that C has any use in modern day life.
For robot control C is great although I can see if you get into heavy image processing or very complex behavior heuristics then C++ could help insure isolation between software components. Of all the programming languages, learning C will give you the best return on your investment long term. An interpreted language like C# might help speed things along when you are making constant changes but I dont think you are going to find a C# interpreter for your 8 or 16 bit micro controller.
Oh, and try to start with a PC as your experimenting platform. Buy a few servos and hook them up to your serial port (or USB port) using that Mini-SSC adapter thingy and just start making things move.
-howy
Reply to
howy
Agreed. Not all Basic's are the same, but if you learn one you can usually get something working on the other. ANSI-C is really quite standardized, but most microcontroller C compilers only implement a sub-set of ANSI-C. Thus, code written for one microcontroller C compiler tends to need some "tweaking" to get it to run on another microcontroller C compiler. I'd vote for ANSI-C, but Basic is not a bad choice either.
Many people are extremely happy with the CCS C compiler for Microchip PIC microcontrollers. For the Atmel AVR folks, most people use the GCC (Gnu C Compiler) tool chain which is "free".
C# tends to be mostly Windows these days (although there is the mono project for Linux.) C++ is available on more platforms. Also, Java is quite popular. These languages tend to require pretty beefy machines to run. There are exceptions (C++ on the AVR) and the Java on PIC effort out of the Netherlands, but for the most part you need a 32-bit processor for the Java/C++/C# stuff.
Your mileage may vary,
-Wayne
Reply to
Wayne C. Gramlich
Seems like a civil group....let me ask a question too.
What are the differences between C C++, C#, C.Net? and any other variations out there?
I used to BASIC and PASCAL...each had its place.
I especially liked PASCAL...it allowed one to write readable and well structured code.
TMT
Reply to
Too_Many_Tools
I recommend reading the appropriate Wikipedia articles to answer your question. Anything I write here would be a rehash of what the articles already say.
Many people have fantastic religious wars about how language A is better/worse that language B. These religious wars obscure the fact that a programming language is a tool. In the hands of a skilled programmer, each language can be made to sing; likewise, in the hands of an amateur, the resulting code is not pretty to read or debug.
Rather than focusing in on a particular programming language it is probably more important to learn basic programming skills that are applicable across most languages. Particularly important programming skills for programming are 1) data structures and 2) debugging skills. There are many books on data structures, but rather few books on debugging.
My $.02,
-Wayne
-Wayne
Reply to
Wayne C. Gramlich
Thanks everyone for your advice! It's a coin-toss, C or BASIC... I'll have to give it some thought. Thanks again.
Reply to
dapunka
There is the option of learning both BASIC and C so you can use whatever is suitable at the time.
-- jc
Reply to
JGCASEY
check out this site.......
formatting link
Reply to
imma
You're right, of course. Why limit myself?
Reply to
dapunka
Based on my experience, you pretty much have to learn C before you can learn C++ (of course, I learned C roughly two decades before I learned C++, so I might be biased. But we tend to teach our students concepts that apply to both languages first, and then move to C++ constructs). But no single event has improved my C code as much as learning C++ did -- you end up thinking in objects, which is (IMHO) just plain a better way to think, no matter what the application or the language you're working in.
So I'd say learn C, then C++. I'd suggest a scripting language like PHP (or Perl, or Python -- but PHP is the one I know) next, but that's not really useful for a robotics project.
You'll notice BASIC didn't make my list. As a historical note, it was the first language I learned.
Reply to
Joe Pfeiffer
C++ is a superset of C (well, not quite, but pretty close) which adds object-oriented constructs -- classes, in particular. The syntactic differences are small, but you think very, very differently when programming C++, and that bleeds over (in a good way) to your C code. It has some features supporting genericity in functions, which can lead to huge problems with bloat in the generated machine code.
I don't do Windows, so I don't speak C# or C.net, and can't comment on them.
Me too -- in my experience, BASIC's place was in a wastepaper basket. To the extent that BASIC has become a useable language, it's been by adopting C constructs -- you're much better off with a more modern scripting language (in a post I made a couple of minutes ago, I mentioned PHP, Python, and Perl -- forgot Ruby, which should also be listed).
I was a real Pascal bigot (first structured langauge I learned, and the group that wrote the VAX Pascal compiler for DEC was in the department where I got all my degrees) until the day I had a tape with data in Data General floating point format data and needed to convert it to run on a VAX. I think that may have been my last Pascal project. C will let you do what you want to do, and not argue with you about it -- it's got lots of flaws that the programming languages researchers will complain all day long, but that one virtue covers almost anything.
Reply to
Joe Pfeiffer
C, originally a portable but high level "assembler" is a procedural language designed in and around the original Unix operating system at AT&T, and become useful for portable OS development, system level coding and indeed, embedded programming, as it is a relatively low level language which gets close the iron, and supports structures and syntax easily supported directly by most processor instruction sets. C is simple, straightforward, efficient and widespread with many implementations both open source and commercial. (see also predecessors BCPL, B and variant D)
C++ was an extension to C created by Bjarne Stroustrup, and originally consisted of a preprocessor which added object oriented features (objects, classes, inheritance, operator overloading ...) to the intial C language, which remains a valid subset of C++ by the way. Modern C++ implementations are full compilers, rather than a preprocessor tacked onto the front of a C compiler. C++ is often criticized as being a write only language, and indeed it is easy to write convoluted and undecipherable C++, and this is exacerbated by the features which continue to creep into the language over time. Smalltalk, it is not!
C# is a language developed by Microsoft to counter Java, and in this regard has many similarities to Java (as opposed to C). C# was closely linked to the .net environment on Windows, and was more about locking software onto the Microsoft platform. This has been countered to some extent by the existance of the open source Mono project which has a portable implementation of the .net environment on Linux/Unix, and which is not on Microsoft platforms.
C.net? Visual C? Visual C++? simply a compiler/IDE with bundled Windows libraries for Win32, and the .net wrapper for the Microsoft environment.
Pascal is similar to C in certain respects, but indeed, has aspects common to Ada, in that strong type checking, nested functions, and some aids to prevent programming errors. Assignment (:= vs =) is sufficiently different from logical test (= vs ==) to avoid many common C bugs.
Basic is an ideal language for babies, or hw engineers who think that programming is mostly done with solder, and can't be bothered to learn programming in a proper language (eg: C or Forth). The BASIC various dialects are so numerous and so different from any standard, that no two basics share much in common. Microsoft's Visual Basic as a case in point has very little to do with basic, and was named mostly to impress potential programmers as to how easy it is to use (propaganda).
Having said this, I'm surprised that noone on this thread has mentioned Forth as an embedded language, as it in certain respects beats most languages hands down for robotics. Originally used to control telescopes for astronomical tracking, this langage has been around since Charles Moore described it in the very early 1970's, and literally exists on just about every processor invented by man.
Forth is often "available" as an option wherever embedded basic is available, and typically offered as a me-too. Having gone through the learning curve with Forth, with its embedded assembler(s) cross compilation, metacompilation simple multitasking, and inherent ability to bit-bang, it is very close to the hardware, high level words can be re-written in assembly for efficiency when needed, there are all kinds of advantages.
Anyway, I hope the above (admittedly biased) descriptions help ... 8-)
Cheers, Rob Sciuk
Reply to
spam
One of the biggest differences is that its pretty easy to get your application written in C to run on a $2.50 (qty 1) CPU. Using avr-gcc I once put a 600 byte application on an AVR that cost less than $2.50 from DigiKey.
Microchip has been the darling of hobbyists in the past. Today I suggest looking at the Atmel AVR products. Also the free WinAVR and other avr-gcc tool chains.
Don't go more than a day into your project without some form of revision control. Starting cold turkey you should give preference to Subversion. TotoiseSVN would be my recommendation for Windows. CVS is also a good choice. Nightly backups is not as good altho you should routinely backup the version control repository.
You should commit your changes every time you have mostly completed something. Use short descriptions to the commit, "Started serial command processing routines." Should commit several times per day, and always at the end of the day. Then for fun use the version comparison functions in TortioseSVN (or TortoiseCVS) and it should become obvious why one should use version control if it wasn't already.
Ironically one of the most common practical uses I get of CVS and SVN (have projects under both that are not practical to convert) is file synchronization between machines. Just go to the project directory and "update". CVS or SVN goes to the proper place and updates local files and/or flags those that have changed locally so that one can reconcile the differences.
formatting link
has good AVR stuff, robotics oriented. I have used a MAVRIC board to prototype before laying out my own board optimized for my application.
For $40 this is an awfully good value for programming and in-circuit debugging of most (double check first) AVRs which support JTAG interface:
formatting link
The $4 10-way Ribbon Cable and $3 Cable Adapter are very handy. If you need them you will have spent more than $7 in frustration learning that you needed them. Forgot why the Cable Adapter is needed.
The AVR Dragon for $52 will handle some newer JTAG AVRs the ICECube will not, has Debug Wire the ICECube lacks, but will not handle the larger AVRs (as used on the MAVRIC boards) that ICECube does.
Reply to
David Kelly
formatting link
-- especially. it's not always obvious which quotations are supporters and which are detractors, though.
technically speaking what you really mean is that in the hands of a skilled programmer any language can be used to simulate a turing machine. sing is subjective. if you take a brilliant lisp hacker and make him write java servlet pages, he'll be able to do it, but he won't describe it as "singing". he'll tie a noose with his mouse cable and hang himself. the desire to avoid that leads to fanaticism.
while programming concepts are similar across languages, language choice affects how you think about programming (see also: sapir-whorf) as well as which operations are simple vs. contrived. in the last week, i have worked on code in three languages: c, c++, and perl, for three projects: a website i'm writing, an avr in a robot, and a high performance distributed server system for my job. assuming for now that i'm a skilled programmer, do you really think i could make those "sing" in any language/project combination?
if the goal is programming small microcontrollers for robots, in the long run the best option is to learn c.
-chris.
Reply to
e c kern
people do tend to think that but the truth is you only need to learn c first if you want to be a *good* c++ programmer. pretty much everybody who knows c++ writes "c/c++" on their resume. when i interview software engineer candidates i usually ask coding questions in c. it is astounding how many "senior c/c++ programmers" fall on their face when you ask them to use malloc.
the scary part about c++ is how much you can do without understanding what you are doing.
-chris.
Reply to
e c kern
Or even knowing where the "shift" key is.
Deep.
Reply to
Deep Reset
Thank you chris, and everyone else who replied. It's been very helpful, and has focused my attention.
Reply to
dapunka
I was not trying to say that the languages are interchangable; they are not. What I was saying is a that a skilled programmer will know how to write reasonable code for each language. Indeed, they will choose the language based on the problem at hand.
Actually, I do know some phenomenal LISP hackers and they have largely moved onto other languages. Many of them now regularly program in languages other than LISP with committing suicide.
In the likely situation where you are a skilled programmer, I suspect that you use the best language for the application at hand. I repeat, I was not trying to say that languages are interchangable.
I've been writing code since the 1960's, so I have quite a number of programming languages that I've used over the years (Algol, FORTRAN IV, APL, PDP-8 assembler, PDP-10 assembler, 8080 assembler, Bliss-10, SAIL, Pascal, Bliss-11, K&R C, Clu, Snobol, 808x assembler, C++, Bourne Shell, Tcl/Tk, Java, Perl, SQL, Python, Microchip PIC assembler, etc.) Many of the skills that I learned in now obsolete languages have been transfered to newer languages. Thus, my paragraph above was trying to focus on learning useful transferableprogramming concepts rather than just programming languages.
I agree, C is an excellent choice for embedded microcontrollers.
-Wayne
Reply to
Wayne C. Gramlich
Typo: I meant "... with[out] committing suicide."
oops.
-Wayne
Reply to
Wayne C. Gramlich

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.