I now consider myself moderately confident in NXC, but I run into limitations with the hardware(mostly graphics)
So I thought about using C++ on a computer.
I've never programmed before, and I was wondering what are the differences between NXC and C++?
Would it be easy to learn a C language if I know NXC?
C++ and NXC differences
-
- Posts: 16
- Joined: 09 Oct 2010, 16:50
C++ and NXC differences
"To be able to ask a question clearly is two-thirds of the way to getting it answered."
-John Ruskin-
-John Ruskin-
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: C++ and NXC differences
The differences are vast. I won't go into the details -- that would require a list of hundreds of items. I will give you the short list of what I personally consider the most important differences.
1. C++ has no standard graphics API. You will have choose an add-on library.
2. C++ is object oriented. You will need to learn about classes and objects.
3. C++ is pointer oriented. You will need learn about pointers.
4. C++ has no automated memory management. You will need to learn how to allocate and deallocate memory. You will enter the wonderful world of NULL pointers, aliased pointers, and memory leaks.
From personal experience, I think it might be better to learn Java before going on the C++. With Java you will only have item 2 (object oriented programming) to deal with. Of course Java has a huge graphics API and there is a lot to learn there.
1. C++ has no standard graphics API. You will have choose an add-on library.
2. C++ is object oriented. You will need to learn about classes and objects.
3. C++ is pointer oriented. You will need learn about pointers.
4. C++ has no automated memory management. You will need to learn how to allocate and deallocate memory. You will enter the wonderful world of NULL pointers, aliased pointers, and memory leaks.
From personal experience, I think it might be better to learn Java before going on the C++. With Java you will only have item 2 (object oriented programming) to deal with. Of course Java has a huge graphics API and there is a lot to learn there.
Regards, Morton
-
- Posts: 224
- Joined: 30 Oct 2010, 04:10
- Location: 127.0.0.1
- Contact:
Re: C++ and NXC differences
And also , with C++ (or most non interpreted languages (eg not Java))
it also depends on the OS more (I've heard Windows is an absolute b***h to program in)
-Tim
it also depends on the OS more (I've heard Windows is an absolute b***h to program in)
-Tim
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
Re: C++ and NXC differences
Windows is not an absolute batch to program in. ...Well, as long as you use Qt or somethin'.timpattinson wrote:I've heard Windows is an absolute b***h to program in
-Tim
All those events "drive" me insane. (Get it?)
----
And don't listen to what Morton said! Java sucks! (Besides, you'll have to learn about OO anyways, and you won't have the power of pointers backing you up! And garbage collection is for wimps! Be strong, be fast [be static], Godspeed, C++!)
Also, almost all programs needing speed are written in C++. All the major web browsers, games (.exe ones), and lots of Windows programs.Why? Because it's fast! Using pointers (properly) increases speed.
This is why C++ is mainly used in microcomputers... bcse its fst! Zooom! (Actually, it's so fast you can't even hear the swooosh; C++ goes at the speed of light!)
----
From here:
Sound like anyone* you know?dsimcha wrote:My biggest absolute no is any language that doesn't treat its users as consenting adults and tries too hard to enforce its vision of "correct" programming. To me a language should make it easy to write good code, not hard to write bad code.
Examples:
- Purely functional languages.
- Requiring that everything be declared inside a class to force OO-style programming.
- A general avoidance of highly expressive features (lambdas, operator overloading, dynamic typing, type inference, default function parameters, etc.) just because they can lead to obfuscated code when used incorrectly.
- Extremely rigid type safety, even when I explicitly ask to get around the type system.
- Pedantic "features" like checked exceptions and requiring that every file contain only one top-level, public class.
- Abstractions that you can't get underneath when there is no good technical reason for these limitations.
* Any thing but Java lovers like treating Java as a person and get upset whenever we state the facts about it.
----
Disclaimer: Actually, C++ only goes under half the speed of light.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: C++ and NXC differences
Pax, muntoo. I didn't say the OP should should dedicate himself to Java rather than C++. I merely recommend approaching C++ by way of Java. I'm no fan of using Java for big-time applications. But there is no doubt in my mind that Java is easier to learn than C++, and most of what one learns from Java is applicable to later C++ programming. For the kind of programs one writes for learning purposes, Java's limitations are not a problem.
P.S. For most non-trivial applications, the speed of execution is determined mostly by 1) the speed of the frameworks and libraries used, 2) the speed of the runtime engine on the specific platform it is running on, 3) the design efficiency of the algorithms used, and 4) the design efficiency of the program's overall architecture. The choice of programming language comes in fifth at best.
P.S. For most non-trivial applications, the speed of execution is determined mostly by 1) the speed of the frameworks and libraries used, 2) the speed of the runtime engine on the specific platform it is running on, 3) the design efficiency of the algorithms used, and 4) the design efficiency of the program's overall architecture. The choice of programming language comes in fifth at best.
Regards, Morton
Re: C++ and NXC differences
related to the TO question, as far as I understand it with my poor English, just my 2ct:
I acknowledge your experience concerning the NXC limitations. As far as I meanwhile think (and what I mostly didn't recognize that at all during the last years programming with NXC and formerly NQC): the biggest problem is not NXC itself but the underlying Lego firmware which diminishes the possibilities which NXC might have.
- there are already millions of differences between NXC and ANSI C, but a Billion differences between C++ and NXC (ok, a little exaggerated, but look at Morton's post), most of them relate to the chunk-based operating system (and not a stack/ heap based operating system which is needed for pointers, dynamical memory allocation, recursions).
- there is only 1 or 2 real good way to have both C and C++ for autonomous NXT robots, and that's by using nxtOSEK / Eclipse (the 2nd I just can't recall): that's supposed to be very great indeed, it's a very fast and probably the only existing real-time operation system for the NXT, but you'll need MUCH experience before starting with this. With Eclipse it uses the gnu gpp C/C++ compiler. The community is not too big, consider this if you start with it for cases when you'll need help and programming attendance.
- other C++ environments you may only use for NXT remote control by a PC.
- With JAVA and the LeJos fw you may control both autonomous and remote NXT robots. The API functions are magnificent, but to use all the encapsulated methods in objects and classes and extend them by others - well you'll need a lot of experience with object oriented programming. Like nxtOSEK, you may use Java/Lejos with Eclipse. ( Personally to me it's far too complicated, but honestly, I'm probably too dumb - both for Eclipse and for OOP.) But if you'll manage to handle these conditions and difficulties, you will have almost unlimited possibilities - and the community is very big to help you if you need.
ps:
I once had a dream: using NXC with BricxCC (without objects) for the LeJos fw.
But it was just a dream ;)
pps:
@muntoo: C is really faster than Java on it's VM, but only if C generates native cpu machine code; in these cases it's as fast as asm code. In cases "C" is generating code for a VM, it depends on the speed of the VM's. E.g., Java byte code runs faster than NXC bytecode, but RobotC is faster than Java and C++ for nxtOSEK is the fastest; but embedded C for ARM7 is by far the fastest of all.
I acknowledge your experience concerning the NXC limitations. As far as I meanwhile think (and what I mostly didn't recognize that at all during the last years programming with NXC and formerly NQC): the biggest problem is not NXC itself but the underlying Lego firmware which diminishes the possibilities which NXC might have.
- there are already millions of differences between NXC and ANSI C, but a Billion differences between C++ and NXC (ok, a little exaggerated, but look at Morton's post), most of them relate to the chunk-based operating system (and not a stack/ heap based operating system which is needed for pointers, dynamical memory allocation, recursions).
- there is only 1 or 2 real good way to have both C and C++ for autonomous NXT robots, and that's by using nxtOSEK / Eclipse (the 2nd I just can't recall): that's supposed to be very great indeed, it's a very fast and probably the only existing real-time operation system for the NXT, but you'll need MUCH experience before starting with this. With Eclipse it uses the gnu gpp C/C++ compiler. The community is not too big, consider this if you start with it for cases when you'll need help and programming attendance.
- other C++ environments you may only use for NXT remote control by a PC.
- With JAVA and the LeJos fw you may control both autonomous and remote NXT robots. The API functions are magnificent, but to use all the encapsulated methods in objects and classes and extend them by others - well you'll need a lot of experience with object oriented programming. Like nxtOSEK, you may use Java/Lejos with Eclipse. ( Personally to me it's far too complicated, but honestly, I'm probably too dumb - both for Eclipse and for OOP.) But if you'll manage to handle these conditions and difficulties, you will have almost unlimited possibilities - and the community is very big to help you if you need.
ps:
I once had a dream: using NXC with BricxCC (without objects) for the LeJos fw.
But it was just a dream ;)
pps:
@muntoo: C is really faster than Java on it's VM, but only if C generates native cpu machine code; in these cases it's as fast as asm code. In cases "C" is generating code for a VM, it depends on the speed of the VM's. E.g., Java byte code runs faster than NXC bytecode, but RobotC is faster than Java and C++ for nxtOSEK is the fastest; but embedded C for ARM7 is by far the fastest of all.
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: C++ and NXC differences
gamemaker99,
If you have used NXC, you have programmed ; )
The main difficulty is learning the basics behind programming which you should already have some experience in. However there will be some new programming concepts that you will need to learn as you move to more advanced languages.
C++ is just C with objects (almost), so to compare NXC with C:
What do you want to do? Are you intending to use your PC as a master for you NXT, sending it commands on what to do? Or are you dropping the NXT to make games on the PC?
The main issue with using C/C++ is that the step from console programs to GUI programs is a bit steep.
If you have used NXC, you have programmed ; )
The main difficulty is learning the basics behind programming which you should already have some experience in. However there will be some new programming concepts that you will need to learn as you move to more advanced languages.
C++ is just C with objects (almost), so to compare NXC with C:
- NXC have it own set of functions like NumToStr() and some array functions. A rule of thumb: every function that starts with a upper case letter is a NXC function and do not appear in C. In C you have functions for writing and reading from the console and files on the HDD. Everything else is genetic programming functions mainly, for example for manipulating arrays. However there is a lot of libraries out there for most things, like graphics.
- NXC do not support dynamic memory. C does. However as m-goldberg said, C does not manage the memory for you, you need to do it yourself.
- Since NXC doesn't support dynamic memory, arrays are implemented a bit different than true C. In C arrays are implemented by use of pointers.
- NXC doesn't support pointers, C does. It is not a difficult concept, but it is easy to screw up if you are new to it. However if you know how to do it in NXC, then you don't need to use them.
What do you want to do? Are you intending to use your PC as a master for you NXT, sending it commands on what to do? Or are you dropping the NXT to make games on the PC?
The main issue with using C/C++ is that the step from console programs to GUI programs is a bit steep.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: C++ and NXC differences
Yeah, I went from NXC to C"++" * Console to Win32 API, which was incredibly difficult (at the time; I didn't know that much C++ back then, either).
Then, I went to DirectX, which increased my knowledge a lot. (I read Windows Game Programming For Dummies.)
At the moment, I'm working on JavaScript, HTML(must learn more 5!). I plan on learning CSS3, and Qt soon...
But that's enough of my life story.
* The only C"++" part back then was that I used std::cout instead of printf().
Then, I went to DirectX, which increased my knowledge a lot. (I read Windows Game Programming For Dummies.)
At the moment, I'm working on JavaScript, HTML(must learn more 5!). I plan on learning CSS3, and Qt soon...
But that's enough of my life story.
* The only C"++" part back then was that I used std::cout instead of printf().
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Who is online
Users browsing this forum: No registered users and 3 guests