Development Applications


If you re interested in developing your own applications, or if you simply enjoyed the material in Chapter 13, this section is for you. It looks at a number of development tools, including editors and integrated development environments ( IDEs ), and several programming languages.

jEdit

Before you can start to write code, you need a good and useful editor. The standard Fedora Core distribution comes with a whole slew of text editors, including vi , gedit , and emacs . However, you should also take a look at jEdit, which touts itself as the open source programmer s text editor.

jEdit has a number of interesting features, including autoindenting of code, syntax highlighting for languages, and special plug-ins that extend the core functionality of the editor. These plug-ins implement, among other features, connections to FTP servers to transfer files, access to the external shell, and support for interfacing with project management applications. You can see some of these features in Figure 15-5.

click to expand
Figure 15-5

If you re ready to download and try this editor, you can download the binary RPM package from the following:

 www.jedit.org www.jedit.org/index.php?page=download 

You can use the rpm command to install the application from the command line.

Note

Note that before you can use the editor, you need to make sure that you have the Java language compiler installed on your system. You can do this by downloading the Java 2 Standard Edition (J2SE) Runtime Environment from either Sun Microsystems at http://sun.java.com or from IBM DeveloperWorks at www.ibm.com/developerworks/java; the IBM version is more optimized for Linux..

Then, go ahead and type jedit and you are on your way to developing some cool applications.

Developing C/C++ Applications

We discussed Perl and how to develop applications with it in Chapter 13. The C programming language is similar to Perl, in both syntax and operation. It too has high-level constructs, can produce efficient applications, and can be compiled on a large number of hardware platforms. However, C allows the developer to program at a much lower level and interface with hardware more easily, while providing greater control and the potential for better performance. This is the reason that other programming languages, such as Perl and Python, as well as the Linux kernel are written in C. Unfortunately, this power also makes C a more difficult language to learn.

Most of the software applications that you will see at Freshmeat.net and SourceForge .net are written in C (or its object-oriented counterpart , C++). Here s a simple program written in C to give you a taste:

 [ number.c ] #include <stdio.h> int main(void) {    int number;    printf ("Enter a number: \n");    scanf("%d", &number);    printf("You entered %d, am I correct?\n", number);    return (0); } 

For you to compile this program, you need to install various development tools, including the gcc compiler , which are covered in detail in the Building from Source section in Chapter 11. Once you have installed the necessary tools, you can enter the following commands to compile and run the preceding example program:

   $ gcc -o number number.c     $ ./number   Enter a number: 79 You entered 79, am I correct? 

This creates a binary executable called number . For example, the *.exe files that you see on the Windows platform are examples of binary executables that have been created by a compiled language, such as C or C++. In fact, this is one of the major differences between Perl and C; Perl is an interpreted language, so the interpreter has to parse the program code each time it is run. By contrast, C and C++ are compiled languages ”you compile the code into binary some time before it is needed.

To make C and C++ development easier, you can use one of the various integrated development environment (IDE) applications in existence. These types of tools provide you with a single integrated interface from which to edit, compile, link, and debug your applications, eliminating the need to jump between your editor, your command line, and your debugger. Take a look at the Anjuta DevStudio in action in Figure 15-6.

click to expand
Figure 15-6

You can download this IDE in binary RPM package format from the following Web sites:

 http://anjuta.org http://anjuta.sourceforge.net 

Then, you can install it using the rpm command. You will need to play with the IDE for a while before you start to feel comfortable with its functionality. And once you are ready to develop serious C or C++ applications, you can find a host of resources and helpful tutorials on the Web, including the following sites:

 www.cs.cf.ac.uk/Dave/C/CE.html www.desy.de/gna/html/cc/Tutorial/tutorial.html 

Developing Python Applications

What is it with these scripting languages anyway, with names such as Perl and Python? Python is an object-oriented interpreted language that shares many similarities with Perl, such as the following:

  • High-level syntax and constructs

  • Complex data types, such as arrays and hashes

  • Powerful regular expression support

  • Large source code, module, and extension repository

  • Active community of developers

There is a fierce rivalry between Perl and Python users, each claiming that their language is better. You might want to read the following two columns where each author tries to make a case for why one language is superior to the other:

 www.linuxjournal.com/article.php?sid=3882 www.perl.com/pub/a/language/versus/python.html 

In reality, these two languages support much the same functionality. The choice of language boils down to which syntax you prefer. Take a look at this example, which is identical in functionality to the list_users.pl example in Chapter 13:

 [ list_users.py ] #!/usr/local/bin/python import sys try:     file = open('/etc/passwd', 'r') except IOError, err:     sys.stderr.write("Cannot open file: %s\n" % err.strerror)     sys.exit(1) for line in file:     if line.find(':') != -1:         data = line.split(':')         print "%s, %s" % (data[0], data[4]) file.close() 

In fact, the majority of the Fedora Core installation scripts and GUI applets are written in Python, so it is likely that the interpreter and most necessary libraries should already be installed on your system.

To find documentation, tutorials, and examples of Python scripts and modules, visit the Python home page and the Vaults of Parnassus (the equivalent to Perl s CPAN):

 www.python.org www.vex.net/parnassus/ 

Although the development cycle for creating applications using a scripting language is often simpler than for using a compiled language, you can nonetheless still use an IDE to improve your efficiency. The Komodo IDE by ActiveState is one that you can use with both Python and Perl (see Figure 15-7).

click to expand
Figure 15-7

You can find Komodo at www.activestate.com/Products/Komodo/ .

Komodo is a commercial application that costs $29 for a single user license at the time of this writing. Having said that, it is well worth the cost and can save you a lot of valuable time when developing large-scale applications.

PHP: Hypertext Preprocessor

Have you ever wanted to develop Web applications? The PHP Hypertext Preprocessor (or just PHP) is a cross-platform scripting language. It was designed primarily for Web development, although it can be used for other purposes as well.

To understand how PHP works, it might help to compare it to the Perl sysadmin application. The sysadmin application keeps all of the HTML code in separate templates and uses Perl s HTML::Template module to replace specially marked tokens with dynamic values on the fly. This allows you to keep the logic separate from the display semantics.

With PHP, on the other hand, you take the opposite approach. You can embed PHP code within the HTML, and the PHP processor evaluates it dynamically. Here is an example:

 [ time.phtml ] <html> <head>   <title>Simple Time Example</title> </head> <body bgcolor="#FFFFFF"> <?php $hour   = date("G"); $minute = date("i"); $second = date("s"); echo "<font>$hour:$minute:$second</font>\n"; ?> </body> </html> 

As you can see from this example, the PHP code is enclosed within a special < ?php ... ? > tag; within each page, you can use as many of these tags as you want. Some developers prefer this approach because they can keep the display and logic in one place, without fear of misplacing or deleting the additional dependent files. It boils down to a matter of personal preference.

Fortunately, PHP comes with most of the popular Linux distributions, including Fedora Core, so it is just a matter of installing it. You can install PHP from the Package Management applet located at Main Menu>System Settings>Add/Remove Applications. If you click the Web Server option (which is in the Servers category) and examine its Details, you will see a number of packages selected, including mod_perl, mod_python, mod_ssl, php, squid, tux, and webalizer. Because we will not use most of these tools, we will install only the PHP- related packages shown in Figure 15-8.

click to expand
Figure 15-8

Click the Install Packages button to install the packages; when installation is complete, you will have a PHP-enabled Apache Web server. You can refer to Chapter 9 for more information on how to configure the Web server.

PHP supports a very large amount of functionality that allows you to build all types of Web applications, from dynamically generated graphics to database manipulation. Many resources are available to help you make the most of PHP s power. For example, you can find extensive documentation on PHP at its Web site:

 http://conf.php.net www.php.net 

You could also try Beginning PHP4, by Chris Lea et al., from Wrox Press.

We have discussed C, C++, Perl, Python, and PHP, but these represent only a small number of the available programming languages. Others, such as Tcl, Ruby, and Smalltalk, are also quite popular. You can really pick and choose which one suits your needs, but you should be aware of the following:

  • If you are intent on learning a language, learn one that provides access to developers who are familiar with the language, so you can avoid some of the common programming pitfalls.

  • Look at as many examples as possible, and search for any available modules or extensions to cut down on your development effort.

  • PHP has a smaller learning curve than Perl. For limited Web applications, PHP is preferable, although Perl and Python are more flexible and have a much wider scope.

  • You should typically not tackle C or C++ if you are new to development; it is better to start with Perl or Python and move up when you are ready.

We mentioned database manipulation in the context of PHP Web applications. But what database do we use? Certainly, Oracle and Sybase are not released under any of the open source licenses, but MySQL is.

MySQL Database Engine

MySQL is probably the most widely used open source database engine. Although it does not support some of the enterprise database features found in Oracle or Sybase, such as online (hot) backups , sophisticated transactions, and an internal procedural language, it has more than enough functionality and power to suit most applications. Best of all, it is released under the GPL license, which means you can use it free of charge for both commercial and non-commercial applications.

You can find the MySQL installers , as well as documentation and information on support plans, at www.mysql.com .

MySQL also comes with the Fedora Core distribution. To install it, launch the Add and Remove Software applet and click the SQL Database Server option (which you ll find in the Servers category). Click the Details tab and select the mysql-server option, as shown in Figure 15-9, to install the application.

click to expand
Figure 15-9

After you have installed MySQL, you can enter the following commands as the root user to start the server and view a list of the database users stored in the internal user table:

   # /etc/init.d/mysqld start     # mysql mysql   mysql> select * from user; ... mysql> \q 

The select query that you see is an example of Structured Query Language (SQL). Most of the commercial relational database systems, including Oracle, Sybase, Informix, as well as open source alternatives MySQL and PostgreSql, allow you to use SQL to manipulate the database. You can find more information on SQL at the following:

 http://sqlzoo.net/ www.w3schools.com/sql/sql_intro.asp 

If you want to avoid learning SQL, you can use one of the many database administration GUI tools that exist ”such as Aqua Data Studio , available from www.aquafold.com .

Figure 15-10 illustrates the convenience of this application.

click to expand
Figure 15-10

When you installed MySQL from the Add and Remove Software applet, you may have noticed a listing for the PostgreSql database server. While this database engine is not used as widely as MySQL, it is designed for the enterprise and supports many features that are found in Oracle and Sybase but are lacking in MySQL. Feel free to investigate and learn more about this application.




Beginning Fedora 2
Beginning Fedora 2
ISBN: 0764569961
EAN: 2147483647
Year: 2006
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net