Robo_Pi
Posts: 85
Joined: Fri Jun 19, 2015 1:18 am

A batch of questions about C# and geany

Wed Sep 30, 2015 12:24 pm

Hi, I have several questions about the C languages and the Geany IDE for the Raspberry Pi. Also a question at the end about spreadsheets and databases.

Question #1: Does C# count as being in the C/C++ camp?

Question #2: It's my understanding that C# is built upon C. Does this mean that I can write C programs in a C# IDE by simply only using syntax and commands compatible with C and avoiding any syntax or commands that are specific to C#?

Question #3: I have a copy of Geany for Windows. It's a GUI editor. According to their website it is compatible with C, C# and C++ among other languages as listed here. Is that right? I haven't really used it yet. All I've done is open the editor and looked it over briefly.

Question #4: One reason I downloaded Geany for Windows is because I understand that Geany also runs on the Raspberry Pi and can be downloaded using apt-get Geany. The question here: Is the Pi version of Geany a GUI editor that runs on the Pi Desktop, or is it just a command line compiler? I haven't installed it yet on the Pi. Also, will it compile all three too, C, C# and C++?

Question #5: If I write C console programs in the Geany Windows GUI editor, can I then copy that source code to a text file and compile it with Geany on the Raspberry Pi so the programs can run on the Raspberry Pi? The reason I'm asking is because it's much easier to type and edit the source on my Notebook than on my Raspberry Pi.

Question #6: This is just a general question about C/C#/C++ in general. Where can I find a good tutorial for writing an interface program to a spreadsheet or database? I need a tutorial that starts out really simple. The main thing I want to do is store information from the C program in a spreadsheet format that I can also open in Libre Office. I'd like to be able to edit the information from either place. In other words, I want the C program to be able to add, delete, or change the data, but I would like to also retain the ability to manually add, delete or change the data outside of the program as well using Libre Office.

Question #7 Database Question: This question isn't specific to C programming. But I'm just curious what the difference is between a spreadsheet and a database? I use spreadsheets all the time, but I haven't really used the Libre Database. Are they basically the same thing with the database simply offering a different user interface and better query options? Also if I started out with just programming to a spreadsheet could I update that later to a full database without loss of effort? Or would it be better to learn the structure of a Database first and then program directly to that?

Thanks in advance for all replies, suggestions, and comments.

User avatar
RogerW
Posts: 286
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: A batch of questions about C.

Wed Sep 30, 2015 12:38 pm

1) In my view no. C# was invented by microsoft because Java was copyright. C# and C++ no doubt have similarities and other people might disagree with me.
2) I doubt it. C# may be written in C but as far as I know the syntax is not compatible.
3) Yes Geany probably does what it is claimed for. I have used it wit C, C++ and python on the raspberry pi.
4) Yes pi geany is a GUI app.
5) A C source file *is* a text file so you can copy from Windows to pi (I use FileZilla for this)
6) I don't know - it might not be easy.
7) In my view they are completely different animals. Others might not agree.

plugwash
Forum Moderator
Forum Moderator
Posts: 3502
Joined: Wed Dec 28, 2011 11:45 pm

Re: A batch of questions about C.

Wed Sep 30, 2015 1:14 pm

Robo_Pi wrote:Hi, I have several questions about the C languages and the Geany IDE for the Raspberry Pi. Also a question at the end about spreadsheets and databases.

Question #1: Does C# count as being in the C/C++ camp?
No, C# is a managed bytecode language similar to Java (the language in particular is *very* similar, the standard library less so). Like many languages it borrows the basic syntax elements from C and it also borrows some elements from C++ but it's a pretty diferent language from either C or C++.

C++ on the other hand is for the most part an extension of C. Most valid C is also valid C++ (there are a few corner cases where that is not the case).

C# is designed to target the .net framework. There is a project called mono which implements a clone of that framework on linux but there are still some issues with running it on the Pi. Therefore at this point I do not recommend C#/mono for development on the Pi. In particular the version of Mono in the raspbian repositories crashes when certain common controls from "windows.forms" are used.
Robo_Pi wrote:Question #2: It's my understanding that C# is built upon C. Does this mean that I can write C programs in a C# IDE by simply only using syntax and commands compatible with C and avoiding any syntax or commands that are specific to C#?
No (see above)
Question #3: I have a copy of Geany for Windows. It's a GUI editor. According to their website it is compatible with C, C# and C++ among other languages as listed here. Is that right? I haven't really used it yet. All I've done is open the editor and looked it over briefly.

Question #4: One reason I downloaded Geany for Windows is because I understand that Geany also runs on the Raspberry Pi and can be downloaded using apt-get Geany. The question here: Is the Pi version of Geany a GUI editor that runs on the Pi Desktop, or is it just a command line compiler? I haven't installed it yet on the Pi. Also, will it compile all three too, C, C# and C++?
Geany is an editor. When it says it "supports" a language it means it understands enoguh of the language to perform syntax highlighting on it. To actually compile the code it needs to call out to external programs.

I imagine C and C++ will work out of the box. C# will probablly require you to install mono (apt-get install mono-devel ), i'm not sure if any manual setup will be needed beyond that.
Question #5: If I write C console programs in the Geany Windows GUI editor, can I then copy that source code to a text file and compile it with Geany on the Raspberry Pi so the programs can run on the Raspberry Pi? The reason I'm asking is because it's much easier to type and edit the source on my Notebook than on my Raspberry Pi.
You can write the code using a text editor anywhere. Where you can build it will depend on what if any platform specific stuff you use.
Question #6: This is just a general question about C/C#/C++ in general. Where can I find a good tutorial for writing an interface program to a spreadsheet or database? I need a tutorial that starts out really simple. The main thing I want to do is store information from the C program in a spreadsheet format that I can also open in Libre Office. I'd like to be able to edit the information from either place. In other words, I want the C program to be able to add, delete, or change the data, but I would like to also retain the ability to manually add, delete or change the data outside of the program as well using Libre Office.
If you just want to deal with a single table of data at a time there is a fairly simple format called csv that nearly all spreadsheets and databases can read and write and that is not especially difficult to read and write from your own code (you can probablly find a library if you look but it's not exactly difficult to implement from scratch). https://tools.ietf.org/html/rfc4180#section-2

If you want to get into more complex stuff then you are going to have to use formats and/or libraries specific to the program you are interacting with.
Question #7 Database Question: This question isn't specific to C programming. But I'm just curious what the difference is between a spreadsheet and a database?
Spreadsheets and databases represent very different ideas on handling data.

Spreadsheets are very freeform. A simple grid of cells where every cell can contain either data or a formula. So structure is not formally defined anywhere, data and the formula that process it are mixed etc. This is great for doing simple stuff but quickly breaks down as problems get more complex and breaks down almost completely if you want to have multiple users working on the data at once.

Databases are far more rigid. There is a strong seperation between structure of the data (table definitions), the data itself (table contents) and data submission/retrivial/processing (queries). Many database systems use a client-server model and have a "transactions" system for dealing with mutliple simultanious users (whether those users are humans or programs). There is usually a "relationships" system for defining and enforcing relationships between data in different tables.

The upshot is that it takes longer to get things going with a database than with a spreadsheet but as data volumes and problem complexity increase they handle it much better.

Robo_Pi
Posts: 85
Joined: Fri Jun 19, 2015 1:18 am

Re: A batch of questions about C# and geany

Thu Oct 01, 2015 6:08 pm

I thank you very much for the quick replies.

I have two further questions if may:


On Geany
I though Geany was an editor/compiler. I didn't realize that it's just an editor. In that case what do I use to compile the source code? You mentioned, "I imagine C and C++ will work out of the box" What do you mean by "work out of the box?" Does the Raspbian OS include a C/C++ command line compiler? How do I compile the source code if Geany is not a compiler?

I guess I'll learn this eventually in any case, but I was interested in Geany precisely because I thought it was a compiler. I thought I would need it.

On the Spreadsheet versus Database Issue
First I want to thank you for your detailed explanation on this, it was very helpful. This also leads me to believe the following, so I would just like to get confirmation that I'm understanding this correctly.

If I use a simple spreadsheet and CSV this means that I can just have the C program write and edit a text file directly. Right. No need to have Libre Office open at that time. I can then just open that spreadsheet using Libre Office anytime. No need to have the C Program running then either. Is this correct? This is a very simple situation and is quite inviting for now because of the extreme simplicity.

On the other hand, if I use a Database, does this mean that I need to set up a database "server" that the C program would then need to interface with making requests for data or passing data to the Database "server". Is that correct? If so that sounds vastly more complex. It also implies that I would need to have the Database "server" running simultaneously with my C program for that to occur.

Finally, (if my thinking above is correct) can Libre Office "serve" as the Database "server"? In other words, would I just need to open the Libre Office Database and then have my C Program interface with that? Or would I need a whole other Database "server" program?

Sorry for my ignorance. But I'm trying to get a handle on exactly what's involved between these two methods.

The CSV text file is extremely simple. In fact, I've done that before many years ago using Visual Basic, so I already have some experience with that, albeit years in the past. But I've never given any thought to using an actual "database" until just now. However, if I could actually use Libre Office as the Database "server", I might be inclined to at least get my feet wet with that. That doesn't sound too scary.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: A batch of questions about C# and geany

Thu Oct 01, 2015 6:24 pm

To answer the Geany question:
No compiler is included with Geany. It simply calls the compiler or interpreter when you click a button. If it can't find the compiler, then you can't compile it.

I suggest you look into Mono.

Raspbian includes gcc and g++ by default which are the C and C++ compilers.
There are 10 types of people: those who understand binary and those who don't.

Robo_Pi
Posts: 85
Joined: Fri Jun 19, 2015 1:18 am

Re: A batch of questions about C# and geany

Thu Oct 01, 2015 6:44 pm

kusti8 wrote:To answer the Geany question:
I suggest you look into Mono.

Raspbian includes gcc and g++ by default which are the C and C++ compilers.
So much to learn just to get started.

Question: If Raspbian includes gcc and g++ by default which are C and C++ compilers then why do I need Mono?

I haven't done any programming on the Pi yet at all. I guess going through a simple "Hello World" example would suffice to clear this all up. I'll look for a YouTube video tutorial on that.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: A batch of questions about C# and geany

Thu Oct 01, 2015 7:34 pm

Robo_Pi wrote:
kusti8 wrote:To answer the Geany question:
I suggest you look into Mono.

Raspbian includes gcc and g++ by default which are the C and C++ compilers.
So much to learn just to get started.

Question: If Raspbian includes gcc and g++ by default which are C and C++ compilers then why do I need Mono?

I haven't done any programming on the Pi yet at all. I guess going through a simple "Hello World" example would suffice to clear this all up. I'll look for a YouTube video tutorial on that.

You only need Mono if you want something .net like C#.

C or C++ will just work.
There are 10 types of people: those who understand binary and those who don't.

Robo_Pi
Posts: 85
Joined: Fri Jun 19, 2015 1:18 am

Re: A batch of questions about C# and geany

Thu Oct 01, 2015 8:16 pm

kusti8 wrote:You only need Mono if you want something .net like C#.

C or C++ will just work.
I see. Sorry. I guess I need to apologize for not explaining precisely what I'm hoping to do. It's rather complicated so I didn't want to spend too much time trying to explain it.

I've been programming using C# on Windows. I'll probably continue to use C# for my Windows programming. I am currently preparing to write a program (in C#) on Windows, for the purpose of having a Window's GUI interface to my robot which will have a Raspberry Pi for a brain. The programs written on the Pi do not need to be written in C#.

The main reason I was asking how close C# is to C/C++ is because I realize that I'll need to write programs on the Pi in C/C++. So I was just wondering how much source code I'll be able to use from my C# Windows programs. Or will I end up having to re-write everything for the Pi from scratch?

Here's a block diagram of the architecture I have in mind:
Robot Architecture.GIF
Robot Architecture
Robot Architecture.GIF (8.38 KiB) Viewed 1752 times
The Robot Interface Program will be on a Windows Notebook computer. So it can run in any language. I typically use C#.
Any database or spreadsheets I use to keep data on will also be on the same notebook computer, and will only be accessed directly by the Robot Interface Program. That program will also have a GUI user interface on the Notebook computer.

On the Robots there will be a Raspberry Pi "Main Brain". That Pi will be communicating with the Robot Interface Program on the Notebook. So the Raspberry Pi programs can be written in any language. But I thought I'd stick as close to C# as possible simply because that's what I'm used to programming with on the Notebook.

The Raspberry Pi "brains" will also be hardwired to control various Arduino boards located on the robot. The Arduino boards are programmed in C++.

The program that I'll be writing for the Raspberry Pi will only be "talking" to the Robot Interface Program via WiFi, and "talking" to the Arduino Boards via I/O data pins. So the program on the Pi doesn't itself need to be written in C#.

In any case, I think I'm getting a good idea of how to proceed.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: A batch of questions about C# and geany

Thu Oct 01, 2015 8:27 pm

Ah. I've never really used C#, but from my memory it looked a lot like JavaScript. If you want to do it in C++, fine, but you need to remember it is not one of those, let's do it quick languages, it's more of a power and stability language.
There are 10 types of people: those who understand binary and those who don't.

Return to “C/C++”