Archive

Archive for July, 2008

Programming Tutorial – Lesson 1: Instructions

July 15th, 2008

Programming or coding as some call it, is the backbone of the software industry. It comprises of writing Programs – lines of instructions. These instructions are fed to the computer for processing and output. Sounds simple, doesn’t it? Well, trust me, its no Rocket science. But, I have seen students think of it as such and ultimately scraping the entire idea of learning how to program.

Many courses being taught at the higher levels of education, today, don’t start off at the absolute beginning of Programming. For a person who has no prior experience in programming, knowing the basics is very essential. In these series of tutorials, I will take you on the journey that I did, back at school and learned whatever little of Programming, that I know today. We will begin by using LOGO, the programming language. I believe it will impart good insights into the bare-bones of Programming.

We need to know a few terms before we begin using LOGO. Don’t worry these are no jargons, only the bare minimals.

Instruction

An instruction is a command to the computer which causes a certain action to be performed.

Program

Lines of instruction that are executed or processed by the computer one by one.

We will need the MSWLogo software to go any further. You can get it from here. Once installed, start Microsoft Windows Logo from the start menu. The application is composed of a pair of Windows. The upper one with a white background and a Triangle in the middle is your drawing area.

The lower one titled Commander is where you will write the instructions and feed it to the computer.

LOGO is a programming language that works on turtle graphics. A triangle shaped object (the Turtle) is used to draw lines & curves on the screen. To draw these lines you instruct the turtle to move forward or backward and while doing so, it leaves a line behind. Try typing the instruction given below in the textbox to the right of the Execute button in the Commander window and then press enter or click on Execute.

As you can see, the turtle moved upward, or forward in its own orientation, leaving behind the black line. The instruction we provided is composed of two parts: FORWARD – the command to make the turtle go forward and 50 the distance it moved forward by. Now type in the following command and press enter.

The turtle comes back 100 units drawing over the old line and extending it by 50 at the bottom. Unlike in real life, an overwrite on the same line doesn’t make the line thicker. Let us try some more tricks, type in the following instruction and press enter.

This makes the turtle turn right (clockwise) by 90 degrees allowing us to draw a horizontal line. The RIGHT command is followed by an angle in degrees. The turtle can turn in any direction with this. But, we have a command to make it turn the other way too – the LEFT command. Now execute the following command.

FD command is an alias (another name) for the FORWARD command and it provides the exact same functionality. The Aliases for the commands are given in the table below.

Command Alias
FORWARD FD
BACK BK
RIGHT RT
LEFT LT

Lets complete our diagram by executing these instructions one by one.

There we have it; Mr. Paniter has drawn us our very own Square. The third instruction, RT 270 can be replaced by an equivalent LT 90. You can provide a negative value to the FD and BK commands to make them go the opposite way. You can even give negative angles or angles greater than 360 degrees and make the poor turtle go round and round (apparently, the slow dude turns so fast, we won’t be able to see it spin its head off, or maybe it has some sharp geomerty skills and does only one round).

Drawing dashed lines or discontinous figures

Did I mention how the turtle goes about drawing all those lines? The guy uses a pen! Not your average pen that runs out of ink every second day, though. Just as we raise our pen in between writing two words, you can make the turtle raise its pen and move to some place else. During this movement, it won’t draw a line. We use the PENUP command to raise the pen up. While in this state, moving in no direction will result in a line being drawn. To lower the pen use the PENDOWN command. When the pen has been lowered, lines will again begin to be drawn following an FD OR BK command (unless offcourse if you move it by 0 units).

Note: PENUP & PENDOWN commands are not followed by any numbers. You can also use their aliases PU & PD.

Clear the screen using the CS command and execute the following instruction to draw a dashed line.

Chaining Instuctions in one line

You can write multiple instuctions in one line. For example, the dashed line can be drawn using the following command.

The REPEAT command

The REPEAT command is used to repeat a series of instructions a given number of times. For example, you can use the following code to draw a square.

The dashed line can be drawn with the REPEAT command.

The REPEAT command is followed by a number specifying how many times to repeat the steps and the set of instructions to be repeated. The instructions to be repeated are enclosed between the square brackets [ and ].

Syntax

Syntax is the grammar of instructions. Every command has a syntax. For example, the FD command is followed by a number, whereas the syntax of PU & PD commands don’t contain any numbers following them. We can express these syntax in general forms:-

Command Syntax
FD FD distance
RT RT angle
REPEAT REPEAT count [ instructions ]

Syntax helps us understand the structure of the command, how its written/used. Every Programming language has its own set of commands, statements & their corresponding syntaxes.

Note: Description of statements is not relevant to the LOGO language. We will go through it in a later tutorial.

In this tutorial we have seen what instructions are and how to write them for the LOGO language. The LOGO language offers more than what we have covered here. But, our aim was only to get familiar with instructions. In the next tutorial we will be continuing our journey into the world of Programming.

partho Tutorials , ,

Say NO to Anti-viruses

July 7th, 2008

Anti-viruses today, are increasingly becoming more and more resource hungry. Gone are the days when you could keep one on your machine while doing your daily computations. Without a multi-core processor you are doomed to even attempt to multi-task with your applications when a scan is in progress. Not all of us can keep up with the constant hardware upgrades that each new version of these softwares require.

This is why I have said NO to memory resident anti-viruses. You can easily go on without them by following some basic precautions. Let us look at the most common ways that viruses infect a computer.

Downloaded Applications from the Internet

Such problems never occur if the source of the application is a trusted company such as Microsoft, Yahoo, Download.com, Softpedia, etc. If you don’t fully trust a brand or if its new to you, do some googling with the keyword virus along with the name of the company or the concerned product. It is very likely that if somebody has had problems with any such softwares, they would have reported it somewhere on the Internet and it is our responsibility to do the same and keep the net safe.

A greater issue with internet downloads is the widespread use of pirated softwares. Cracked/Patched editions of the softwares may allow users to use them unrestricted. But, they are also bloated with Trojans and viruses that steal away your sensitive information.

Removable Media

Applications in removable media such as Pen Drives & CD/DVD ROMs spread the viruses when they are shared among computers. The infection only occurs when an infected file is executed on the machine. Never execute doubtful applications received in untrustworthy or custom burned discs. Remember, viruses these days are silent and have no real visible interfaces. They run in the background logging your key-strokes and monitoring your activities. Thereafter, the information is sent to the hackers’ website.

Not executing applications alone will not solve the problem. Many viruses use the Autorun feature in Windows to automatically execute the application when the disc is inserted. Disabling Autorun in Windows XP is a solution to this problem. Vista’s User Access Control (UAC) lets you choose whether to execute an Autorun program residing in a disc.

Sharing USB Drives

Pen Drive viruses spread by replicating themselves onto drives as soon as they are plugged into the port on an infected PC. The infection consists of two files – the infected application (EXE file) and an Autorun.inf file which automatically executes the infected application on a system when the Pen Drive is jacked in.

Because the file system in Pen Drives resembles that of a Hard Disk Drive, the write operations are trivial for the lightweight viruses. This vulnerability does not exist on CD/DVD ROMs because burning to discs is a much more complex job.

Worms in Network

Worms are one of the most dangerous kinds of viruses. They exploit the security vulnerabilities in Operating Systems to spread without notice across the network(s). Whenever a new worm with the ability to exploit such vulnerabilities is released, thousands of computers get infected and turned into zombie machines. Its imperative to install a good Firewall if your computer is connected to the Internet.

Popups in Sites

Ironically, many viruses are spread via popups in Web Pages that claim to have found virus infections on your systems. New users unaware of this, install their so called “Solutions” and let them into their system. NEVER, and I mean NEVER install such applications. No web page can scan and detect Viruses & Spywares on your system, unless off course supported by a browser Add-On which installs a scanner on the system and that too with your permission.

These are only a few but common methods viruses spread by. The average user can easily protect himself from these by exercising his experience. Without a heavy Antivirus the performance & responsiveness of the system is very satisfying, more so if you are a heavy multi-tasker. All having said & done, it is wise to install an Antivirus once in a while and do a full system scan, after which the program can be de-installed.

partho Tips