Programming for Linux


Recommended Posts

OK, here is where I revert back to a complete noob, forget everything I know because I assume it doesn't apply...

I am from a Windows background - but recently got my parents an eeePC. I want to write a few little apps for it, I mean really small stuff, nothing spectacular.

But I know 0% about this.

Under Windows I have experience with VB6, C#, scripting languages and a VERY small amount of Java.

So really the sort of apps would be simple text entry which writes (appends) to a file or such.

Help?!

Link to comment
Share on other sites

Yeah, I've made a few apps with Mono because my friends use Linux servers (I would never). But if your only Linux box is an Eee PC, you could install the same distro on a virtual PC on your desktop computar, and develop inside that. That's what I do anyways.

Link to comment
Share on other sites

C/C++ are the best programming language for Linux. Around 90% of popular apps are written with it. Python is probably second with 6-7% and the remaining part is mostly Java (I am talking about community apps, not enterprise solution, where java and php got a lot more %).

C++ is based (like C#) on C, so if you have used C#, the syntax will not be a problem. I never written stuff in C# and I don't think it is a good idea on Linux. And it will be slower on EEE because it is not really native. Some C++ code:

#include <iostream> //Standard STC library
#include <fstream> //Standard file handling library
#include <unistd.h> //Unix equivalent to WINDOWS.H, some feature are present in <dirent.h> (directory scanning) and <env.h> (environement variable access)
#include <vector> //and <stack> and some other are part of the STL, object oriented container, very usefull

using namespace std; //If you dont want to call all std function with their real name (std::cout for example)

class aClass {
   public: //Public variable, you can access them from external to the object code
	  aClass() {} //Constructor
	  ~aClass() {} //Destructor (I don't know if C# use one (java don't), but it is a function called when you use the "delete" keywork to delete an object. If you used pointer in your object, delete them too in the destructor, or you will have a memory leak)
	  int getMyVar1() {
		 return myVar1; //You dont need to use this.myVar1, but you can 
	   } 
	  void setMyVar1(int value) { //Those are accessor, they are use to access private variable, if you want to produce clean code, use this kind of code, else, just make your variable public.
		  myVar1 = value;

   private:
	  int myVar1;

};

int main() { //Main function

   int aVeriable =0; //Static variable declaration, will die after the next "}"
   int* aPointer = new int; //aPointer now point to a new interger that I just created with the keyword "new". The variable itseld will not die at the end of the function, but the pointer will
   *aPointer = 3; //the "*" point to the variable behind aPointer

   string aString = "some text";
   string aSecondString = "some other text";
   string aThirdString;
   aThirdString = aString + ", " + aSecondString; //Now equal "some text, some other text"

   cout << aThirdString.substr(0, 12) << endl; //Will print on console "some text, s"
   int position = aThirdString.find("text"); //position now equal 5

   aClass anObject1();
   aClass* anObject2 = new aClass();

   anObject1.setMyVar1(25); //will set 25 in myVar1
   anObject2->setMyVar1(30); //will set 30 in myVar1 in the object pointed by the pointer anObject2

   cout << anObject1.getMyVar1() << end; //will print the value of myVar1
   cout << anObject2->getMyVar1() << endl; //will print the result of myVar1 of the object pointed by the pointer anObject2


  return 0;
}

if, else if, else, while, do and for will be the same as in C#, I am too lazy to write example here. It was just to show some base of C++. You should use a .h and a .cpp and not putting everything in the main.cpp. Just dont use {} for function in the .h and write the body in the .cpp like aClass::getMyVar1() { /*body*/ }.

To have a graphical user interface, you need to use an interface toolkit. By default, the EEE use KDE3/QT3, an old, obselete toolkit that have been replaced by KDE4/QT4some years ago. Future version of Xandros (the linux used in the EEE) will switch to KDE4, but the current version still use old software for some (some are good) reason. Learning KDE3/QT3 is a waste of time. You can learn KDE4/QT4 and install both library on the EEE, it is a better idea but will take some space (~150mb for libs, not including developement stuff (forget about them on the eee, use a virtual machine to code and compile)). You can also use GTK, the toolkit used by 2-3 apps on the EEE. It is written in C and is less funny to code with, but also very popular (more than QT because of licensing stuff). It is included on the EEE so you dont have to "waste" more space with libraries.

Link to comment
Share on other sites

What kinds of apps? Launchers? Something complex?

bash shell scripting may work for some items. Create something to double-click and it will just do its thing.

Or write it web-centric, using PHP (you can run php without a browser, too).

I am dabbling a bit in Python, and it is pretty simple, yet can easily allow you to present a GUI window to the user to click.

Link to comment
Share on other sites

OK, here is where I revert back to a complete noob, forget everything I know because I assume it doesn't apply...

I am from a Windows background - but recently got my parents an eeePC. I want to write a few little apps for it, I mean really small stuff, nothing spectacular.

But I know 0% about this.

Under Windows I have experience with VB6, C#, scripting languages and a VERY small amount of Java.

So really the sort of apps would be simple text entry which writes (appends) to a file or such.

Help?!

I came from C#, VB.NET on Windows too.

I now mostly program most of my stuff in JAVA, as alot of the stuff you write can be used on linux and windows.

The syntax is very similiar to C#.

I recommend installing the Eclipse IDE if you want an IDE.

The problem with mono is that not all of the same functions

Link to comment
Share on other sites

I would steer away from mono/C#. Mono is a decent implementation in linux but still resource hungry for a eeePC. give python and pygtk a try ... you'll be creating gui apps in no time ... seriously.

Link to comment
Share on other sites

I would steer away from mono/C#. Mono is a decent implementation in linux but still resource hungry for a eeePC. give python and pygtk a try ... you'll be creating gui apps in no time ... seriously.
If there are any serious performance concerns, then C# is much faster than Python. I don't know about the quality of the mono implementation but C# is JIT-compiled whereas Python is interpreted, so unless Mono is some kind of bloated crap, C# should win by a wide margin.

C++, as already said, is THE language for Linux, but it's overkill for your needs. Based on your description I don't see you running into into the limits of C# anytime soon, so you can stick with it. If I ran into problems with the Mono framework I probably would switch to Java which is very similar to C# and has a more mature Linux implementation.

Link to comment
Share on other sites

If there are any serious performance concerns, then C# is much faster than Python. I don't know about the quality of the mono implementation but C# is JIT-compiled whereas Python is interpreted, so unless Mono is some kind of bloated crap, C# should win by a wide margin.

Well, I was actually concerned about resource management ... not performance. Correct me if I am wrong here ... but the python runtime takes a lot less resource than mono's CLR. I haven't tried it yet (sounds like a good weekend project), but I would like to see some numbers between these two in terms of memory usage and i/o. Since he is talking about eeePc, I thought it would matter to have something thats not going to use up all the limited resources. Also, python compiles to byte code and the compilation is lightning fast. I haven't seen any python application that takes more than a fraction of a second to compile. Again, I could be wrong here... and I have been proven wrong before :)

Another thing I like about python is its simplicity and readability. to be able to write wget in 6-7 lines of readable code ... now thats fun :D.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.