Tuesday, August 26, 2008

Display your Arch Linux theme information automatically

Often when you come across a desktop screenshot in the forums/websites a myriad of question flows through your mind. "What theme is that? Lovely icon, if only I knew its name. Wow, but is it openbox or fluxbox or something else?" Now while its possible to mention all the details while posting the picture, its a hassle everytime you post a screenie in the monthly screenshot thread.

Instead, wouldn't it be better if we could somehow automatically include all the details in the screenshot itself? Yes, it would be and its possible just by using these two small scripts.




Edit the path to the logos.pl file here in the info.pl file
require '/home/sujoy/bin/logos.pl';


Now all you have to do is put the two files in the same directory and make the info.pl file readable and executable
$ chmod 500 info.pl

and make the logos.pl file readable
$ chmod 400 logos.pl


You can run the script from inside the directory as
$ ./info.pl


Here is a picture of the script in action


While the logos.pl file given here is for Arch Linux only, you can modify it to suit your distro and use the info.pl script along with it.

note: the scripts are not mine, the name of the author is mentioned in the script itself

Tuesday, August 19, 2008

10+ essential programs for the terminal junkie

The command line in a Linux system is one area that a new user despises and a long time pro seeks to master. While the shell is powerfull in itself, there are still some tasks that requires a separate program, for instance playing music, IMs, browsing the web, etc.

Lets take a look at some command line applications that does the job and does it well.


screen


Simply put, screen is a window manager that allows you to run multiple terminals from a single terminal process. It allows session-sharing, persistence and multiple windows. One can simple detach a session and then later attach it to continue a previous work without starting all over again. Specially usefull without a Xession as it allows more than 6 terminals, by multiplexing.


vim


Vim, though not the most intuitive of all, is a power packed text editor that is ideal for programming as well as for general text editing. Vim is modal in nature and includes no menus or mouse features. All the features are accessible via commands and keybindings. Vim also supports autocompletion for various programming languages via add-on scripts called omnifunc. A built in tutorial vimtutor is included, that helps in getting started. While the age old war between vim and emacs continues, both are well accepted in the Linux community.


Latex


Latex is a proffessional typesetting system designed for technical, scientific, mathematical documentaion. It is however a language that accesses the power of Tex, hence a suitable text editor is needed along with it. Latex, used mostly for desktop publishing and word processing, can also be used to create raster graphics.


elinks


Complete with table and frame rendering,tab support,color support,multiple items download in the background, elinks is a powerpacked web browser. The arrow keys can be used to browse through the links, and by using the "." key, one can also just type in the link number to open it. Great for browsing over ssh or just for a low bandwidth connection.See this list for other text based web-browsers


alpine


Alpine, based on the old pine mail client and licensed under the apache license, is a simple yet efficient text-based mail client. Unlike mutt, it doesn't need any external program to fetch mails and with its context-sensitive help, is very easy to use. Mutt is another viable alternative to alpine.
According to an interview published in Lifehacker, Linus Torvalds himself uses alpine.


irssi


Supports add-on perl scripts, auto logging and can also be themed. It has highly configurable keybindgins that ensures maximum customizeability. Also while irssi is specifically targeted towards IRC, when combined with bitlbee, it adds IM functionality also. One point for bitlbee users though, its better not to use public servers for security reasons. WeeChat is a viable alternative to irssi, you may also want to have a look at it.


ncmpc + mpd


Music Player Daemon (MPD) is based on the client-server architecture. The daemon stays in background and actually plays the tracks while the client(ncmpc) is used to control the playlist, sounds etc. The real advantage of mpd over other console based players like cmus, moc, etc is that it allows remote access, that is, the daemon can run in one computer while the client connects to it from a remote computer to control it. Combined with icecast, mpd can be converted into a audio streaming server. These are the other clients supporting mpd.


mplayer


MPlayer supports a wide range of supported output drivers, Xv,X11,DirectFB,etc. It plays most audio and video file types and can be used with or without a GUI frontend. Enabling framebuffer allows one to watch videos on mplayer without even starting a X session. Also included in the mencoder which is a video filtering, decoding, and encoding tool that works from the command line.


rTorrent


rTorrent, as is obvious from its name, is a bittorrent client with ncurses interface. It can watch a directory for torrent files and automatically download them, and if required move them to a separate directory. It supports session control,DHT along with other features and allows the user to select the files to download if the torrent consists of more than one file. rTorrent can be operated over ssh and thus can be used in a torrent slave. For instructions on setting up rTorrent follow K.Mandla’s article.


midnight commander


Midnight Commander is a two-panel file manager, that can open RPM or other archive packages without extracting, serve as a FTP or FISH client and rename multiple files. It has a ncurses based interfaces and is useful for file manegment in a console or via ssh.

I left out those that are shipped with most distros like nmap, htop, etc. Other console applications that maybe of interest include the fbida project, bandwidth monitor, youtube-dl, MS word reader.

Did I miss your favourite application? Tell me about it.

note: images taken from wikipedia or the application's home page

Monday, August 18, 2008

Moving on with python... get rid of any file

Ok this might look pretty silly,but I feel compelled to delete every Thumbs.db file that I tend to recieve from my friends. The file is generated in windows systems when one views the contents of a directory in "Thumbnail" or "Filmstrip" mode. The idea is to store the settings with regard to thumbnail and filmstrip view, as well as to keep a cache of the thumbnail of image and video files.

Whenever I borrow some pics or movies from my friends' DVDs, etc, these tiny little files also gets copied over. Now these are completely harmless as far as I know, but since they are of no use in Linux, I dont want them in my system.

Now, deleting a particular file inside every directory is a pretty troublesome task. Hence, I wrote myself a neat little python program that searches directories, passed to it as the absolute path, for the file mentioned and prompts for its removal.

Here goes my first ever self-written-useful-program.


#!/usr/bin/env python
import os
import sys

def del_thumbs_db (start_path):
for i in os.listdir (start_path):
if i=="Thumbs.db": # change to whatever file you want to remove
del_file = os.path.join (start_path, i)
print """
FILE : %s
""" % del_file
#comment out next two lines to removing prompting for each file
ch = raw_input("\nDelete the file ? ")
if ch == "y" or ch == "Y":
os.unlink (del_file)
i = os.path.join (start_path, i)
if os.path.isdir (i):
del_thumbs_db (i)

if len (sys.argv) != 2:
print """thumbs needs an argument..!!
Usage: thumbs [absolute path]"""
quit ()
path = os.path.abspath (sys.argv[1])
if os.path.isdir (path):
del_thumbs_db (path)
else:
print "path is not a directory ..."


Usage is pretty simple, save the program in a file (say, delete) and make it executable by
# chmod +x /path/to/delete

then run the program like this,

$ delete /absolute/path/to/directory/

The program starts searching for the file mentioned, from the directory passed as argument and goes on recursively to search in subdirectories.

Now a simple bash script like this one
rm `find /home/user/path -name 'pattern_to_search_for'`

would have been easier and better suitable for this task, however, that way I was never going to really get on with python. Hoping for some python expert to come along and provide some insight on this code.

Your comments are welcome. :)

Sunday, August 17, 2008

New to Linux? Make sure you bookmark these

New users in the Linux/Unix land are often confused and overwhelmed by the marked differences between the OS they come from and Linux. It takes some time gettting used to the new environment and the new way of doing things. Now while you are at it, take a look at these websites that are there to help you make the smooth transition, these provide extensive documentation to step-by-step howtos, and also community support.

Now while there are scores of material worthy of a mention, in the internet, I list the ones that every new user must bookmark (or atleast take a look at).


Distrowatch.com

Image Hosted by ImageShack.us

Here, you can find reviews and news about the most popular Linux/Unix distributions as well the new ones that just came in. Regularly updated upon each new version release of the distributions and also ranks them based on page views. Overall, this is the place to be in if you are trying to find a new distro to try out.

The Linux Documentation Project
Image Hosted by ImageShack.us

This site contains tons of materials to get you started or help you if you get stuck in the middle. From HowTos, guides, manpages, to Linux Gazette, an online magazine, this site is so full of information that its almost overwhelming in itself.

The Gentoo Wiki
Image Hosted by ImageShack.us

While the name might indicate that its specifically for the gentoo users, its not. The guides and howtos here can be related to most of the distributions with minor modifications like the actual download process involving the package managers, etc. Here one can find guides for a broad range of topic covering almost all aspect of Linux, from kernel configurations to wine and cedega, the gentoo wiki is for all linux users, irrespective of the choice of distribution.

The Ubuntuforums
Image Hosted by ImageShack.us

Once again I mention something attached to a particular distribution. However, ubuntuforums, as all of its members knows, isn't just a place for ubuntu users. The sub forums in the other OS sections exists as well, although the real charm is the sheer number of people active here and the awesome community section. Nice place to get to know fellow linux users while engaging in some non-technical chat. Offcourse, you can also take a peep and find yourself comfortable in the programming section solving challenges. Its just a fun place to be here, even for the non-ubuntu users.


Linux Manpages

Image Hosted by ImageShack.us

As the name suggests this site is dedicated to the manpages. No distraction at all as you dive into man to find that lost option or switch. Specially beneficial for the ones who dislikes reading from the terminal. The ability to search and click also adds charm to the whole man page reading thing.


Other than these, you may also register to the forum or mailing lists of the distro you are using. IRCs are again a good place for support and discussion. Thats it fellows, read the FAQs, learn how to google and soon you will have a wealth of information at your disposal to make computing fun and comfortable.
Your comments are welcome. :)

Friday, August 15, 2008

Diving into python and projecteuler

While solving a trivial problem presented at ProjectEuler, I went for python instead of C, which is my usual language of preference. I am quite new in python programming though, hence the interest in applying my newly accuired skills.

The problem was pretty straightforward,
What is the largest prime factor of the number 600851475143 ?

Now considering the number being too big and my new found interest in python, it was an obvious choice. So, here is my solution,

#!/usr/bin/env python
import math

NUMBER = 600851475143
i=int(math.sqrt(NUMBER))

while i>1:
if not (NUMBER%i): # so i is a factor of NUMBER
# checking if i is prime
flag = 0
if not ((i+1)%6) or not ((i-1)%6):
for j in range (2,int(math.sqrt(i))+1):
if not (i%j):
flag = 1
break
else:
flag = 1
if not flag: # i is prime, so i is the answer
break
i -= 1
print "The largest prime factor is %d" % i


All this while, when I was reading about python, I kept stumbling into language purists who would say that interpreted languages are no good and that they take up too much time. Hence I put my code to the time test and this is the result,

[ProjectEuler]$ time python 003_problem.py
The largest prime factor is 6857

real 0m0.827s
user 0m0.816s
sys 0m0.006s
[ProjectEuler]$


I think, considering the hassle of computing big numbers like this one in other languages, specially ones like C, and the fact that it still gets interpreted in about 0.827 seconds speaks volumes about its power. For all I know, experienced python programmers might still be able to improve the solutions.

Monday, August 11, 2008

Iptables and TruStealth

I saw a thread in ubuntuforums.org yesterday, its been there since a week now, but somehow I missed it earlier. Anyways, its about the Shields UP test in Gibson Research Corporation's website.

Testing for all service ports, got me nowhere near true stealth. This is what I got after the first test,

Solicited TCP Packets: RECEIVED (FAILED) — As detailed in the port report below, one or more of your system's ports actively responded to our deliberate attempts to establish a connection. It is generally possible to increase your system's security by hiding it from the probes of potentially hostile hackers. Please see the details presented by the specific port links below, as well as the various resources on this site, and in our extremely helpful and active user community


Unsolicited Packets: PASSED — No Internet packets of any sort were received from your system as a side-effect of our attempts to elicit some response from any of the ports listed above. Some questionable personal security systems expose their users by attempting to "counter-probe the prober", thus revealing themselves. But your system remained wisely silent. (Except for the fact that not all of its ports are completely stealthed as shown below.)


Ping Reply: RECEIVED (FAILED) — Your system REPLIED to our Ping (ICMP Echo) requests, making it visible on the Internet. Most personal firewalls can be configured to block, drop, and ignore such ping requests in order to better hide systems from hackers. This is highly recommended since "Ping" is among the oldest and most common methods used to locate systems prior to further exploitation.



It was only after that, did I realise that I had no active firewall running! Iptables was not running at all. So I scoured the internet for some iptables guide. An hour and half later of reading tutorials and man-pages, it seemed quite interesting. Hence, instead of going for some already-available scripts, I set up my own rules.


# Generated by iptables-save v1.4.0 on Mon Aug 11 21:32:50 2008
*mangle
:PREROUTING ACCEPT [8311:783078]
:INPUT ACCEPT [8311:783078]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4155:229785]
:POSTROUTING ACCEPT [4167:230625]
COMMIT
# Completed on Mon Aug 11 21:32:50 2008
# Generated by iptables-save v1.4.0 on Mon Aug 11 21:32:50 2008
*nat
:PREROUTING ACCEPT [4219:185647]
:POSTROUTING ACCEPT [1808:81444]
:OUTPUT ACCEPT [1808:81444]
COMMIT
# Completed on Mon Aug 11 21:32:50 2008
# Generated by iptables-save v1.4.0 on Mon Aug 11 21:32:50 2008
*filter
:INPUT DROP [6:336]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [19:1289]
:OPEN - [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -j OPEN
-A INPUT -i lo -j ACCEPT
-A OPEN -s 192.168.1.0/24 -i eth0 -p tcp -m multiport --dports 21,22,23,3306 -j ACCEPT
-A OPEN -s 192.168.1.0/24 -i eth0 -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A OPEN -p tcp -m tcp --dport 65000:65010 -j ACCEPT
-A OPEN -p udp -m udp --dport 65000:65010 -j ACCEPT
COMMIT
# Completed on Mon Aug 11 21:32:50 2008


I opened the ports for ping, ftp, ssh, telnet and mysql server only for my local network and that 65000:65010 port range is for torrents. Other than that everything else is blocked unless its already established or related to an established connection, or if the interface in question is the loopback. And as I wished for, this time around I got a perfect "TruStealth" rating. Here is the complete summary,

Your system has achieved a perfect "TruStealth" rating. Not a single packet — solicited or otherwise — was received from your system as a result of our security probing tests. Your system ignored and refused to reply to repeated Pings (ICMP Echo Requests). From the standpoint of the passing probes of any hacker, this machine does not exist on the Internet. Some questionable personal security systems expose their users by attempting to "counter-probe the prober", thus revealing themselves. But your system wisely remained silent in every way. Very nice.

Thursday, August 7, 2008

Debian Lenny frozen!

Debian Lenny (Debian 5.0) has been frozen, meaning automatic transition of new version of packages from the unstable branch (Debian Sid) has been stopped. So a stable release is near. The Debian mailing list puts is this way, "Lenny is still scheduled to be released in September 2008."

I am currently using Debian as a dual boot with Zenwalk on my desktop PC. Its Debian Testing (Lenny), so I am beginning to wonder, if I should just stay with Lenny since everything is just working perfectly, or should I upgrade to the latest Testing branch after Lenny becomes stable.
As for people using Debian Etch, there has been another upgrade, called "etch and a half", once again from the mailing list,

While this update mainly includes security fixes and fixes for severe bugs,the Debian project has for the first time also added support for newer hardware by adding new drivers with updated Linux kernel and X.org packages. The new drivers are optional and the old versions will still be supported.


Personally, I am of the opinion that Debian Stable packages gets too old for desktop usage, hence I use the Testing branch. However, this time around I am going to stick around with Lenny to see if Debian Stable gets too old too quickly. Now, if things work, then there shouldn't be a problem.

Tuesday, August 5, 2008

Reasons not to use Linux

Now while scouring the internet you will find billions of posts as why to use linux and finally make the shift from your closed source OS, two of which I have written myself. However, this time around let me tell you or rather convince you "why NOT to install linux in your PC".

1. Please do refrain from installing linux in your PC if you are used to spoonfeeding. While its perfectly acceptable if a new user asks about whats KDE and Gnome, it gets irritating if after telling you to edit xorg.conf in your third month into linux, you ask where that file is!

2. Are you afraid of text files? No matter its opened in vim or gedit? Then I am sorry to say, you are better off with your fancy drop-down-menu GUI system. Spare us the trouble of porting every console app or configuration method into clumsy GUI subsystems.

3. If you think having too many choices is confusing and that the linux community has to justify why there are hundreds of distributions to confuse you, besides around 20 different window managers, then either make an informed decision or ask for help in choosing one, but please do not whine about how confusing it all is. Otherwise think thrice before switching.

4. "OMG! there is no real flow of money behind linux projects. So they must be trash!!" - if this is what you believe, then kindly do some web-research on GNU, FOSS, and opensource (you know like wikipedia, google ...). Come back later when you are convinced that free doesn't necessarily means bad.

Just my views though, however, seeing the same whining posts in different forums and communities, I wonder, if people trying out a different OS really wants to do that. They just seem to expect the same things done in the same way from a different system! Its like asking why streets in Norway are any different from the ones in China.

Sunday, August 3, 2008

Zenwalk 5.0 .. yes a bit old but..

I just found that old (well not that old) Zenwalk 5.0 CD lying around and hence took it for a spin. Some 20 minutes or so later I am starring at a XFCE desktop. Not bad, but its the same old blue color everywhere. Now while I have been using Linux for a while now, it was mostly awesome, xmonad or openbox, with Gnome in the earlier days. The first time I used XFCE, and I was impressed.

Zenwalk brings smoothness to the desktop. Apps are well integrated and the choice of apps are good too. No more bulky open-office or evolution. Instead I get abiword, gnumeric, ice-dove (thunderbird without the brand name) and gmusic-browser, which I must say is gtk's best answer to amarok.

Some quirks are there like the package-management for instance, dont even try to compare it with pacman or apt! But then anyone trying a slack or its derivative already knows that. It may even be a plus point since every thing is under manual control. Gslapt was ok but not upto the mark. Netpkg comes default, and while it does the job, I find manual control to be much better in zenwalk.

Stability is something I cannot really report on in a weeks time, so I will post on that later. However, it does feel really smooth amd fast and is good in resource management. Also solves the hal issues with slackware 12 (which got rectified in 12.1 I heard).

I already posted some screenshots in the screenshot gallery in deviantart. So let me know what you think of it, if you are using Zenwalk or are planning to use it. Offcourse you should go for the 5.2 version, I used the old one because I didn't feel like downloading again.

Monday, June 23, 2008

The Arch way ...

I took a liking to command line applications when I switched to ArchLinux from Ubuntu during the start of the year. Seeing that Arch by default didn't have Xorg or Xfree86 I thought I might as well try and stick with the console.

However, soon enough I got an X running and for a change I now use Window Managers exclusively. No KDE, no Gnome, no XFCE. I have openbox, awesome, xmonad and wmii installed. I liked the tiling approach to window management and hence the biased decition of keeping three tilled WMs, although I mostly use awesome.

Currently my most used apps are mpd-svn, ncmpc-svn, elinks (for flash and pics I have Opera, and I also have to keep Kazehakase since my ISP allows only firefox and IE to check my usage), vim, rxvt-unicode, mplayer, feh, antiword, epdfview and gftp (the only client I found thats easy on resources and don't need commands, any other suggestions? ), nmap.

I have tried and kept my system as bloat free as possible by only installing things when I need them. The startup memory usage is around 110MB with Slim as the login manager, I could do with startx probably, but slim looks quite pretty :)

No problems with the setup as of now, just a pacman -Syu once or twice a week keeps it bleeding edge. Only I tried the whole afternoon but couldn't get mutt working, settled for claws-mail as of now.

Any nice apps you know of? Please let me know.

Wednesday, January 23, 2008

LAN between UBUNTU and XP

Here is an excellent video tutorial I found on youtube that demonstrates how to set up LAN between Ubuntu and XP. I used this myself and works perfectly, and this also works for any other Linux, the steps are the same.



One point to note is that my lan was set up in roaming mode and it couldn't detect the windows shared folders/drives. I didn't notice it at first and finally when I changed it to static ip, I could easily access my shares.

Daryna KDE CE Beta 044 is out now and ready for download.

Daryna KDE is nearly as minty as the main edition now. The packages are (safely) upto date and the kernel is the Gutsy Gibbon kernel 2.6.22-14.

Mint applications:
mintInstall
mintwifi (new)
mintUpdate (new)
mintAssistant (new)
mintUpload (new, done via konqueror—> right click file-->Actions-->Upload file )

minted versions of:
firefox
Sunbird

See the main Release notes for info and pictures on the mint applicaions.

Known issues in Daryna KDE

When shutting down or restarting the live CD it will freeze about 25% of the time at the last step. I had this problem with Gutsy too and have not found a fix for it. This happens more in virtual machines than on real ones.

After adding a new user log in as them and check their kmix settings because they will have no sound. Check the output and PCM levels. Install with an old home partition

This is what is recommended.

Boot off the live DVD.
Start the install.
At the partitioning screen choose manual.
Format the old / partition, now called /media/sda?.
Set the old / partition to be the new /.
Next.
Continue to the end and start the install.
After the install has finished reboot the system.
Login
Open a terminal window to setup your old /home partition.
Check your partitions
df -h
Check your old /home partition for home directories.
ls /media/sda?
Un-mount your old /home partition.
sudo umount /media/sda?
Update your /etc/fstab file to mount your old /home at boot.
sudo vi /etc/fstab (or use another editior)
change the /home partiton from /media/sda? to /home
save and exit
Reboot to have your old /home back again.
Rember if you want to reset an applications config or KDE's, delete the application's hidden config file/directory in you home directory. eg rm -rf /home/boo/.kde
your sound will no longer work. To fix open up kmix, check your output is not muted or the level is set to low and check the PCM level (I had to nearly max mine out).

Linux Mint Daryna KDE CE Upgrade Notes.

Just don't. It will cause you more problems than it is worth and it will not be anywhere near as beautiful and clean as a fresh install.

source

My experience with Ubuntu Gutsy

I have been using Ubuntu all the way since October, 07 with a little testing of the other distros every now and then. I must say , I am really pleased with the way things are shaping out. I didn't care much about the desktop environment or the so called window manager, and hence, I stuck around with the default Ubuntu 7.10 package.

I use some KDE applications though, like K3B and Amarok, and I have also replaced firefox with my favourite Opera, might as well try out epiphany someday later.Yes, I love the effects and use both compiz and the emerald manager with the effect that most of my friends are amazed at the sheer looks of it.

Programming and the occasional text edition is usually accomplished with vim, and when I need a GUI I use geany for coding and abiword for text processing. Open Office runs too slow, thereby,  I tend to ignore it whenever I can. Bluefish is good enough for me, for the occasional HTML works.

For watching movies and other videos, I use VLC, mplayer doesn't work for me with all that monstrous subtitle don't size that I couldn't decrease. Have kept it though for the odd ones that needs some adjustment with the subtitle's timers. (VLC really needs to improve here). I also quite like Rythmbox, except that its too simplistic for my music needs. Amarok does bring in some extra KDE libs that I could do without otherwise, but I love it beyond all arguments, so it is there as well. K3B works great, just haven't figured out how to burn files greater than 4GB yet !! I use another useful application,. gcstar, it catalogues movies and books, and I being a movie buff, always find it useful.

All in all I really like my set up of the Gutsy and I doubt that I will take the risk of upgrading to Heron, even though its going to be a LTS.

Thursday, January 17, 2008

Open Source alternatives

Open Source software comes with a freedom that is unmatched by rest of the licenses. While most of the open source software is predominantly for Linux/Unix systems, some also have installers for Windows.

Lets take a look at some open source alternatives for the existing applications that are commonly used.

ApplicationsOpen Source alternatives
PhotoshopGimp
MS OfficeOpen Office / Star Office
Corel DrawInkscape
Windows Media PlayerVLC Player / Mplayer
WinampAudacious / Amarok
3D MaxBlender
DreamweaverBluefish / Screem
Internet ExplorerOpera / Mozilla Firefox
Windows Media CenterElisa / Myth TV
Outlook ExpressEvolution / Thunderbird
Adobe Acrobat ReaderEvince
Winzip / WinrarArk / Tar / Gzip

and the list could just go on and on ...

So lets take a stand and use only the open source applications, unless offcourse there isn't one, which is a rarity !

Good programming practices

We all have our own style of coding, a style that suits us and makes the code easier to refer to at a later time. However, considering the situation that someone else might need to understand it, and to ease the process of maintenance, say a year from now, its often a good practice to follow certain norms while coding.

Proper variable names

Say you are using a variable to hold the average marks of students. Now a variable named 'a' will do fine. But the problem is over the entire span of program, it might not make any sense at all. Instead it could be named as 'average', which would give some idea about the data contained in it, or you might as well name it as 'averageMarks'.

Proper indentation

Indentation has a lot to do with how easil;y one can grasp the code you have written. A poorly indented code is hard to maintain. Just have a look and tell which one is easier to comprehend?

if(n==0){
printf("Hello");
}else{
printf("Bye");
}
if(n==0){
printf("Hello");
}
else{
printf("Bye");
}
Initialising variables, arrays, etc

Some languages force all variables to be initialised before their first use and some languages don't force. However, it is generally a good idea to initialise the variables, arrays, lists and such, before using them in the program. Unless the developer wants to work with garbage values !

Commenting where necessary

Comments are usefull in understanding the logic of the code and the flow of the program in general. With balanced use of comments in the code, the author makes his program easier to understand and maintain. Obscure use of logical operators and pointers are a few examples where comments are really helpful.

Debugging routines

Debugging routines must be embedded in the code itself so that during testing or later in the maintenance phase work can continue smoothly. Although developers can argue that its the work of the debugger but some lines displaying intermidiate values of variables can save hours of work.

Checking array bounds

Most of us have heard of vulnerabilities in software applications and in many of those cases the culprit is some buffer overflow problem. So as a rule of thumb, its a good practice to check the bounds of arrays, lists and such data structures where there may be a chance of an overflow or an underflow occuring in the code.

Garbage collection

Yes, main memory might be getting cheaper by the day, but gives no excuse for hijacking precious system resources. Garbage collection routines must be coded properly and ensured that all dereferenced objects and out-of-scope dynamic variables and freed. No one wants a simple piece of software to hang on to their memory foot prints forever, isn't it?

Following coding standards

The general coding standards of the programming language being used must be stricly adhered to. That includes defining prototypes of functions in languages that recommends it, and providing explicit return types and proper type casting. Non standard codes are the last thing any developer would like to work on.

Keeping lines under 80 characters

Remember that a single line of code is easier to see, understand and debug. Since almost all of the monitors nowadays are 80 columns wide, its better if your statements are bounded within it.

Explicit casting of variables

Lastly, and most importantly, never rely on implicit type casts. You might get away with some but not all. Specially, where acuracy is of prime importance. Floating numbers are hard to comprehend in general as their arithmetic is mostly machine dependent, so its better to use explicit type casts at all times

Tuesday, January 15, 2008

Perl, Python or the good old C ?

The C language is definitely a good one and is capable of doing almost everything. However, in modern times when processing power is increasing everyday in leaps and bounds, perhaps its time to reconsider its effectiveness.

Although it still holds its forte when it comes to development of system softwares and those where performance time is of greater importance than development time, more casual programming tasks and general programming routines like say a 10-digit calculator or even a spell checker, might be done with equal effectiveness using a modern language like Perl or Python, where development time is much less owing to the use of a large number of easily available library files.

Now this effective reduction of time in the coding phase might be a trade-off for proper resource utilisation, but whereas C demands strict coding principles, requiring more time with less resource, these may require more reourse but that problem is negligible because of the rapid increase in processing power, coupled with the availability of cheaper and bigger main memory.

Hence, its important to know them all so that one may choose the best there is for a particular task. Otherwise it would be like coding in assembly when there is no need for it! Besides, programming logic remains the same, no matter what language is used, the only difference, in my opinion, lies in the flexibility a language allows to a developer, and the availability of good and usefull library functions.

Wednesday, January 9, 2008

The various desktop environments and window managers.

One of my friend, a recent linux user asked me while installing openSuse, which one of KDE and GNOME to install and what are their advantages? I didn't know how to answer it in simple terms as the question itself is so complex.I can't really expect a newbie to understand the concept behind having several desktop environments and window managers. As if the choice of a distro was not enough to start with, but then these are the true charms of Linux for me. :)

Each of these DE and WM is made by people who tried to be different and were inspired by the open source philosophy. For me, KDE is quite professional looking and has generally better quality apps, although it is most certainly not suitable for older machines. GNOME, on the other hand, has a nice blend of ease-of-use and not-resource-hungry. XFCE, different from both of these, offers a solution for the ones who want to squeeze out that extra bit of performance from their machines without having to compromise a great deal on the ease-of-use. The *boxes are a different issue altogether.

FLuxbox eats up even less resource than XFCE and its quite natural since it adopts a minimalistic approach to window managing. No fancy panels or icons. One can have them if needed (fbpanel and idesk). Its also compatible with most Blackbox things, since its a derivative of it. Openbox, FVWM, and the rest of the box category are for the real minimalists who insists on having a set up just the way they want. No real issue of applications in these *boxes though, since these are just window managers which can be used either with a DE or without it.

Compiz and Beryl are composite managers, since they need a window manager or desktop environment. Its great if one seeks eyecandy, although most certainly its more of a bloat for me than functionality, but we all love tranparencies and things like that. Don't we?

So, if you are still asking which one to use, I can only say that try out all and eventually you will like one better than the rest. Just for information though, I use GNOME with compiz (transparencies are real cool) in Ubuntu most of the time, while I also made myself a Gentoo installation with fluxbox.

Linux for the average desktop

Almost every now and then there crops up a thread in the forums discussing whether Linux is ready yet for the average home user. This is usually followed up with heavy discussions on how it still loses out on professional applications like Photoshop, 3D Max, MS Office or even iTunes.

Frankly Gimp does a good job but its still not comparable to Photoshop, or is it? Then again, huge acceptance of the iPod ensures that iTunes is a must have application for most music lovers and the apple store allowing seamless downloading of your favourite songs directly makes it even more usefull.

However, the average home user does get all the basic applications like word processor (open office), image editor (gimp), multi-format media player (vlc / mplayer) and an excellent text editor (vi /emacs), music apps (amarok / audacious) and lots more, all along with the distro. So its really not a question of getting things done. Maybe someone prefers photoshop to gimp, but spending $650 doesn’t seem all that prudent for a home user with a $500 computer. MS Office costs another $500 and to use all these one would need another $200 for windows XP Home, Vista will cost even more !!! So Linux does really seem to be a good, valid option.

Now provided money doesn’t matter at all (it generally does though), one would still need an anti-virus solution along with a spyware removal application and all the headaches of updating virus definitions. System stabilty is yet another problem.

With Linux and a good power supply you may never need to turn of your system unless offcourse for cleaning the rig. Gone are the days when Linux used to be a command line only OS. Now with distributions like Ubuntu and Suse one can actually have a pretty good looking desktop.

Not to forget the obvious point that there exists a Linux distribution for almost every system of every decade, be it a moster Core2Duo or an aging Pentium Pro!! The customizability that it offers is unmatched and why spend money on a new system when a few minor modifications (an extra RAM chip) or none can get you the work done?