User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Recommeded C++ dev environment ?

Fri Jun 29, 2012 9:15 am

andyl wrote: Instead of sitting here trading comments - how about a test. Someone suggest a smallish (but non-trivial) piece of code - I would prefer C or Java it has been ages since I have touched C++, which they think is a good exemplar of commenting (or just some code without comments). I will try and refactor and remove the comments I feel are redundant. This will probably need to be done on a wiki rather than here. That way people can see and judge for themselves how readable and understandable a low-to-no comment piece of code can be,
Here you go, complete with a very procedural C++ and a Python example to start off. I don't do Java, but new examples can be added easily.
commentdisc.wikidot.com

andyl
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am

Re: Recommeded C++ dev environment ?

Fri Jun 29, 2012 1:11 pm

rurwin wrote:
andyl wrote: Instead of sitting here trading comments - how about a test. Someone suggest a smallish (but non-trivial) piece of code - I would prefer C or Java it has been ages since I have touched C++, which they think is a good exemplar of commenting (or just some code without comments). I will try and refactor and remove the comments I feel are redundant. This will probably need to be done on a wiki rather than here. That way people can see and judge for themselves how readable and understandable a low-to-no comment piece of code can be,
Here you go, complete with a very procedural C++ and a Python example to start off. I don't do Java, but new examples can be added easily.
commentdisc.wikidot.com
Thanks. I will take a look over the weekend.

Reading it it looks like the MicroAudotcode is plain C.

The other example is python.I would also note that your python example doesn't have comments but as you say has pretty good understandability. Some stuff could be named a bit more expressively. A few magic numbers. I probably wouldn't have implemented strlist recursively. I'm not too happy about the proliferation of randrange. The calculation for bearing could well be taken out in to its own function. A little bit of duplicated code for when the monster attacks should similarly be put in its own function. I would probably put the you attack monster in its own function too.

javierbravoconde
Posts: 2
Joined: Fri Jun 22, 2012 8:06 pm

Re: Recommeded C++ dev environment ?

Sat Jun 30, 2012 11:41 am

DogEars wrote:
javierbravoconde wrote:Here (http://linuxtortures.blogspot.fr/2012/0 ... ing-c.html) you can find a post just written by me where you can learn step by step how to cross develop on your Raspberry using eclipse. I hope you enjoy it reading as much as I did writing it :D

Best Regards!!
I tried to get this to work on Ubuntu VM but at the stage where I select new C++ project, I don't have an option for "Cross-Compile Project"

Any suggestions would be welcome.
Cheers,Ears.
If I am not wrong you are using the 32 bits version of Eclipse. I think you can just select a 'Empty C++ Project' and the follow the same steps. The important thing is to select the appropriated compiler and linker on the project options.

Give it a try and write me back if you find difficulties.

andyl
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am

Re: Recommeded C++ dev environment ?

Sat Jun 30, 2012 8:08 pm

rurwin wrote: Here you go, complete with a very procedural C++ and a Python example to start off. I don't do Java, but new examples can be added easily.
commentdisc.wikidot.com
Some comments on the C example.

There is at least one case of the comment not being correct (looks like a copy/paste issue). sprintobject does not take a file pointer but the comment says it does.

Very often the comment says the same thing as the code. For example -

Code: Select all

/**
 * plants the given string.
 * \param    str    The string to plant
*/
 void plantstring(char* str)
{
    printopstring(str);
}
I can't see how that comment adds anything of value to the code. Also "plant a string" I have no idea what that means. Also take the comment on the licence() function - again it adds no value.

In other areas the comment looks OK at first blush, but with decent naming the comment starts to look weaker. Take the following

Code: Select all

/**
 * The error/warning function.
 * prints the error message supplied, and prefixes it with the file, line number
 * and chapter that caused the error.
 * \param    t    The string describing the error level
 * \param    s    The string supplied by Bison.
 * \param    count    The counter of the error level
*/
markerror (char *t, char * s, int * count) {
...
}
If we change the function signature to

Code: Select all

printErrorOrWarning(char *errorOrWarning, char *errorStringFromBison, int *errorCount) 
then a lot of the comment becomes redundant. As this is just a basic printf I dont think we need to specially comment on the fact that filename and line number are printed and where they appear in the output. Also it is very easy to remove the if statement by using a ternary operator in the fprintf. Which leaves us with a function 4 lines long (and hence easier to understand).
This leaves us with

Code: Select all

printErrorOrWarning(char *errorOrWarning, char *errorStringFromBison, int *errorCount)  {
     *errorCount++;
     fprintf(stderr, "%s (%s, %d - ", errorOrWarning, filename == NULL ? "stdin" : filename, fileline);
     printchapter(stderr);
     fprintf(stderr, "): %s\n", errorStringFromBison);
}
TBH if it is just errors or warnings I would refactor the code to make the first parameter an int and use a ternary for "ERROR" or "WARNING" in the frpintf. But that is minor.

In printopchar(char c) I would get rid of the magic numbers.
\f is the standard C character for form-feed and should be used instead of 12 in the switch.
I would use a #define for 1 in that function maybe something like TAB_TO_SOURCECODE_POSITION

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Recommeded C++ dev environment ?

Sat Jun 30, 2012 11:50 pm

Note that the comments are for Doxygen to generate documentation from. Therefore every function needs a comment. In some cases they may be redundant, but in a great many they are not. For example I would argue with your characterisation of the markerror comment as redundant; no matter how simple the code can be made, it is not as easy to understand as one English sentence.
andyl wrote:Also it is very easy to remove the if statement by using a ternary operator in the fprintf. Which leaves us with a function 4 lines long (and hence easier to understand).
The ternary operator is almost never easier to understand. In this case I would separate it out onto its own line. I'd also add a few line separators.

Code: Select all

printErrorOrWarning(char *errorOrWarning, char *errorStringFromBison, int *errorCount)  {

     *errorCount++;

     fprintf(stderr, "%s (%s, %d - ",
          errorOrWarning,
          filename == NULL ? "stdin" : filename,
          fileline);

     printchapter(stderr);

     fprintf(stderr, "): %s\n", errorStringFromBison);
}
In fact if I wrote that now, I'd go back to printchapter and try to get it to return a string rather than printing it (and rename it chaptertostring of course), so I could do the whole thing in one fprintf.
TBH if it is just errors or warnings I would refactor the code to make the first parameter an int and use a ternary for "ERROR" or "WARNING" in the frpintf. But that is minor.
That's a ternary too far in my opinion. If you want to make the parameter an int, then have a const string array and deference it with the int. But an enum would be better than an int, and in C++ it is type-checked.

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: Recommeded C++ dev environment ?

Sun Jul 01, 2012 12:16 am

rurwin wrote: The ternary operator is almost never easier to understand. In this case I would separate it out onto its own line. I'd also add a few line separators.
:-) I love the C if-then-else operator. Such a nice concise way to write a conditional expression. But then, I was exposed to LISP at an impressionable age.

The part I don't understand is calling the conditional operator "the ternary operator". It's like the quaint custom of referring to Macbeth as "the Scottish play". What are you going to do when C adds a second ternary operator in a future version? :-)

andyl
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am

Re: Recommeded C++ dev environment ?

Sun Jul 01, 2012 8:47 am

johnbeetem wrote:
rurwin wrote: The ternary operator is almost never easier to understand. In this case I would separate it out onto its own line. I'd also add a few line separators.
:-) I love the C if-then-else operator. Such a nice concise way to write a conditional expression. But then, I was exposed to LISP at an impressionable age.
So do I, as long as people don't start embedding them - that is when they get confusing.

It is a core part of the language. One that any competent C programmer should be able to read and understand immediately.


The part I don't understand is calling the conditional operator "the ternary operator". It's like the quaint custom of referring to Macbeth as "the Scottish play". What are you going to do when C adds a second ternary operator in a future version? :-)[/quote]

User avatar
exartemarte
Posts: 373
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: Recommeded C++ dev environment ?

Sun Jul 01, 2012 9:33 am

I agree with the comments about drivers, mechanics and engineers, and the importance, especially for the latter, of using and understanding lower-level tools. However, I would go further.

Most students "know" that a computer is a binary machine because they have learned it a fact. The ones who really know are those who have entered code bit by bit directly into memory using front-panel switches, and been required to explain what they have done in terms of the system architecture.

Wolfram23
Posts: 73
Joined: Thu Jul 19, 2012 6:50 pm

Re: Recommeded C++ dev environment ?

Tue Jul 24, 2012 6:49 pm

I thought this would be a straightforward thread. Boy was I wrong. This is me reading it:

Image

I guess I should go buy some Linux and C++ books or something :(

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: Recommeded C++ dev environment ?

Tue Jul 24, 2012 11:15 pm

Wolfram23 wrote:I thought this would be a straightforward thread. Boy was I wrong... I guess I should go buy some Linux and C++ books or something :(
Most of the people posting in this thread are very experienced programmers who over time have learned what works best for each of them. When you've done a lot of programming, you'll find what works for you. However, I'd strongly advise against starting with C++. There are other threads where people argue at length as to what is the best language for learning programming -- Python, Basic, and Pascal appear to lead the pack. I think C++ is tied with PL/I and Jovial as a best first language :-)

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Recommeded C++ dev environment ?

Tue Jul 24, 2012 11:27 pm

I got a qualification in C++ 12 years ago and am comming back to it and am discovering that I have forgotten alot of syntax.

Conversely I also found that it helped me learn PHP recently and that the underlying principles of oo 3rd generation general purpose high level languages are basicly the same.

The thing that anoys me most about programming is having to learn the dev environment. I gave up on Visual Studio back in the day as it seemed more complicated than the language it was supposed to be facilitating.

I am now learning how linux compiles from the command line and hope this will be nice and simple.

If anyone can point me to a simple comprehensive explanation of what all the compile options mean I and perhaps other would be grateful.

I am using Puppy and devx atm...
Ostendo ignarus addo scientia.

Narishma
Posts: 151
Joined: Wed Nov 23, 2011 1:29 pm

Re: Recommeded C++ dev environment ?

Wed Jul 25, 2012 1:34 am

pygmy_giant wrote:If anyone can point me to a simple comprehensive explanation of what all the compile options mean I and perhaps other would be grateful.

Code: Select all

man gcc
should be pretty comprehensive.

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: Recommeded C++ dev environment ?

Wed Jul 25, 2012 4:14 am

pygmy_giant wrote: If anyone can point me to a simple comprehensive explanation of what all the compile options mean I and perhaps other would be grateful.
I don't think there's a simple explanation of the myraid compile and link options, but here's the comprehensive explanation: http://gcc.gnu.org/onlinedocs/

IanLinsdell
Posts: 21
Joined: Fri Jun 29, 2012 9:34 pm

Re: Recommeded C++ dev environment ?

Wed Jul 25, 2012 12:33 pm

Windows, Eclipse IDE with CDT plugin + Cross Compiler.

Cross soft and hard float cross compilers can be downloaded from here:
https://github.com/IanLinsdell/Raspberrypi

Eclipse IDE + the CDT plugin has provided a very fast development environment for me, the IDE will flag errors from the compiler and point you to the line of code when you click on it as well as telling you what is wrong with your code. You can also jump to function definitions etc....

Some people may tell you that it is dangerous to develop on a Windows machine for a Linux target but I have not harmed any Linux devices thus far.

Using this setup I have not had any cross compiler relates bugs or issues in compiling:

1. Compiled the Linux kernel for Cirrus logic ARM boards (several hundred of them): http://www.embeddedarm.com/products/boa ... ct=TS-7400

2. Write a 1st person shooter ray tracing game using SDL for the old Sharp Zaurus many years ago called ZRaycast using fixed point math.(Zaurus did not have any FPU)

3. Compiled all the BroadCom samples, a bunch of GTK+ application and a web server for the Pi so far...

Bakul Shah
Posts: 320
Joined: Sun Sep 25, 2011 1:25 am

Re: Recommeded C++ dev environment ?

Wed Jul 25, 2012 1:00 pm

pygmy_giant wrote: I am now learning how linux compiles from the command line and hope this will be nice and simple.

If anyone can point me to a simple comprehensive explanation of what all the compile options mean I and perhaps other would be grateful.
Basically you will need to know options -I include-dir, -Wall, -Werror, -c, -o, -g, -pg, -O optimization-level, -D definition,-S, and -E. You can ignore rest of the options for the most part. You will also use the "compiler" to link objects. Here you need to know -L library-dir, -l library-name, -s, -o. A few more options will be needed if/when you build shared libraries. "man gcc" to look up gcc/g++ options. "man ld" for linker options, even though typically you'd link via gcc/g++. Use -v to see the steps gcc invokes. Both gcc and ld have far too many options but the above are enough perhaps for 90% of the time. You should also know commands nm, size, ar, gdb, gprof, gmon. And make, to tie it all together. Look at existing makefiles to learn about their structure. Man pages for these commands are comprensive (and can be overwhelming!). You will refer to them many times so probably worth printing them out in a nice format using groff. The key thing to note is you don't have a single boom box of an IDE but a component system!

The above list is already too long for a newbie. You can start by looking at some simple example source directories such as for commands in the /bin directory and studying their makefiles.

jdbennet
Posts: 96
Joined: Sun Jul 22, 2012 2:25 pm

Re: Recommeded C++ dev environment ?

Wed Jul 25, 2012 5:32 pm

Gedit/Geany for editing with CMake for compiling (handles crosscompiling well)

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Recommeded C++ dev environment ?

Wed Jul 25, 2012 11:32 pm

Thanks - lots to digest...
Ostendo ignarus addo scientia.

M2K
Posts: 2
Joined: Sat Jul 28, 2012 7:39 pm
Location: cd /ect/network/m2k

Re: Recommeded C++ dev environment ?

Sat Jul 28, 2012 8:35 pm

hey everyone
i started doing C/C++ aswell and im using Code::Blocks http://www.codeblocks.org/
1 simple reason and also one of the best:
simply because u can use it for bouth linux and windows :roll:

take a look at it and hope u enjoy it

pjc123
Posts: 913
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: Recommeded C++ dev environment ?

Sun Jul 29, 2012 10:55 am

M2K wrote:hey everyone
i started doing C/C++ aswell and im using Code::Blocks http://www.codeblocks.org/
1 simple reason and also one of the best:
simply because u can use it for bouth linux and windows :roll:

take a look at it and hope u enjoy it
I originally looked at a similar program, codelite, but it is not available on Wheezy. code::blocks was included in the repository, so I installed that instead. Now I can write and debug a program that can filter out all the posts in this thread that are totally unrelated to the original posters question so it is easier to find answers.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/

User avatar
exartemarte
Posts: 373
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: Recommeded C++ dev environment ?

Sun Jul 29, 2012 12:59 pm

So, going back to the original question, which I couldn't have answered at the time for want of a PI, this is what I find to be a convenient way to program in C:

I have ssh enabled and Samba installed on the Pi, and I access it from a PC using side-by-side windows. In one window I have my preferred (Windows) editor, in the other I have command line access to the Pi using PuTTY.

Image

I use the editor to create and edit the files, which are all stored on the Pi, and if I'm feeling lazy I might use the Windows file manager to organise them. I compile and execute them using the command line in the terminal window.

An incidental benefit is that I can do the same from a laptop elsewhere in in the house.

Makefiles are a rectal discomfort if you approach them from the ground up, and I start most projects by recycling an existing makefile. In this instance I'm using Gordon's wiringPi and I have recycled his makefile - a nice, simple one which is easy to modify and from which you can actually learn something about what makefiles do.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Recommeded C++ dev environment ?

Sun Jul 29, 2012 1:55 pm

Interesting - will have to look at that... are you programming remotely from another computer via the robot arm?

I've been enjoying C via Geany on Puppy (+DevX) on my Pi. I've learned some of the compile options in the process as I've had to link to a GPIO library which I have had to download and install. I've also figured out that I need to chmod +x compiled files. I think I can configure geany to do alot of this for me.

I like that Geany is just a text editor that calls GCC - which I can understand. The biggest problem I've found is the lack of line numbers when an error is generated - debugging is tricky; I'm used to php helpfully telling me where I slipped up. Still, more of an incentive to be careful in the first place!

By way of another request - can anyone explain how I would compile a 'flat binary' from GCC and whats so flat about it?

User avatar
exartemarte
Posts: 373
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: Recommeded C++ dev environment ?

Sun Jul 29, 2012 4:07 pm

pygmy_giant wrote:are you programming remotely from another computer via the robot arm?
Now that really would be a project!

What I'm doing is resurrecting the robot arm, which is about thirty years old and probably hasn't been used for at least twenty.

My view on programming editors is simple - the fewer the better. The "best" editor as far as I'm concerned is the one I'm used to and feel comfortable with - it does what I want and I use it for programming, web pages, and anything else that needs a text editor. I set things up this way so that I could use my usual editor and, to a lesser extent, Windows' graphical file manager. (I'not interested in whether the Windows file manager is "better" or "worse" that those in Linux - it's a tool, it's what I'm used to, and I don't have to stop and think about how to use it.

The use of familiar tools becomes second nature. Having to use an unfamiliar editor/IDE is an irritant (and one of the several things I dislike about Arduino) - it introduces unnecessary noise into the process and distracts attention from the things that matter - in this case the Pi, its gpio and Gordon's C extensions.

Can't help you on "flat binaries", I'm afraid.

CopperPhil
Posts: 5
Joined: Mon Jul 30, 2012 4:37 pm
Location: Brussels
Contact: Website

Re: Recommeded C++ dev environment ?

Mon Jul 30, 2012 5:04 pm

IanLinsdell wrote:Windows, Eclipse IDE with CDT plugin + Cross Compiler.

Cross soft and hard float cross compilers can be downloaded from here:
https://github.com/IanLinsdell/Raspberrypi

Eclipse IDE + the CDT plugin has provided a very fast development environment for me, the IDE will flag errors from the compiler and point you to the line of code when you click on it as well as telling you what is wrong with your code. You can also jump to function definitions etc....

Some people may tell you that it is dangerous to develop on a Windows machine for a Linux target but I have not harmed any Linux devices thus far.

Using this setup I have not had any cross compiler relates bugs or issues in compiling:

1. Compiled the Linux kernel for Cirrus logic ARM boards (several hundred of them): http://www.embeddedarm.com/products/boa ... ct=TS-7400

2. Write a 1st person shooter ray tracing game using SDL for the old Sharp Zaurus many years ago called ZRaycast using fixed point math.(Zaurus did not have any FPU)

3. Compiled all the BroadCom samples, a bunch of GTK+ application and a web server for the Pi so far...
Yesss, many thanks Ian!

Actually, I spent days searching for a cross-compile & remote debugging solution in order to build the CopperLan engine, SDK and applications on my PC for the RaspberryPi. The source code is huge and I can't imagine doing the job on the rpi itself...

And finally I found your post... Great! I'll try it asap, just have to find out out to glue Eclipse and your toolchain...
-- CopperPhil --

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Recommeded C++ dev environment ?

Tue Jul 31, 2012 9:44 pm

FWIW...

I've just started on a new hobby project. The IDE I'm using is just an editor, jEdit. It does syntax highlighting, and if you run make in its console then you can double click error messages to go to the right line. That's all I need... well that an a hand-cranked Makefile:

Code: Select all

CFLAGS=-ggdb
LDFLAGS=-ggdb -lrt

OBJECTS=main.o atom.o token.o object.o cons.o stack.o

DFObj:  $(OBJECTS) Makefile
	gcc -o DFObj $(LDFLAGS) $(OBJECTS)
	
main.o: main.c atom.h token.h object.h cons.h Makefile

atom.o: atom.c atom.h token.h Makefile

token.o: token.c token.h atom.h Makefile

object.o: object.c object.h Makefile

cons.o: cons.c cons.h Makefile

stack.o: stack.c stack.h object.h Makefile
It doesn't come much simpler than that. It's almost certainly as fast to add a file to that as adding a file in Visual Studio. It would be even easier if I named main.c DFObj.c and dropped Makefile from the dependencies; then I wouldn't need to give the link command either.

fjb
Posts: 24
Joined: Fri Aug 10, 2012 10:49 am

Re: Recommeded C++ dev environment ?

Fri Oct 05, 2012 12:01 pm

"by Morgaine » Sat May 19, 2012 11:37 pm
IDEs are a very bad idea in programming education, because they hide the tools in actual use."

I partially agree but in the context of education only. If you want development efficiency then and IDE is a good idea as you can also configure the tools involved. If you've been programming as long as I have then an IDE saves time :)

Return to “C/C++”