So you want to program huh? (Part 1)

July 27, 2008 – 6:27 am

There are many programming languages out there, and perhaps it’s the vast selection of languages that have discouraged any wannabe programmers.

Fret not, if you are not interested in using any utility to start your programming interest, there is always a few options that are already available on your computer without you knowing it.

Yeap OMG, it’s the command prompt window. You are probably already familar with a few commands for it. Today we are taking those commands to it’s full potential, and hopefully proving that programming isn’t a dead subject.

Starting Batch

Now, reach to your notepad. Yes notepad, there is no need for any Visual Studio or any IDEs. We will be using only notepad today.

Now let’s type in some codes shall we?

@echo off
echo hello world
pause

Save it as hello.bat on your desktop. Now double click the file you just saved.

If you see the above, congratulations! You have just wrote your first Hello World program. If nothing runs, make sure you are pasting the code correctly, make sure you wrote the extention .bat at the back of your filename.

Taking it further

Now that you have made your first program, you are probably not satisfied with what you can do now. No problem, let’s add in some input shall we?

@echo off
set /p name=Type in your name :
echo Your name is %name%
pause

Before we run the code, let me explain what is the code about. You should be wondering what is @echo off , well the purpose of echo off is to make the command prompt as clean as possible. This is due to the nature of the command prompt, as it usually shows the path in front of your commands, such as “C:\>”. Putting echo off, takes away that.

Echo itself is a command that tells the command prompt to show something, and for this program, I am asking the command prompt to show the name variable. A variable is always wrapped up by two percentages sign “%”, this will allow it to be replaced by it’s stored value.

Set is a command that assigns a value into a variable. By writing SET A=Apple , you are asking it to set “Apple” as a value of “A” variable. The /P means you are going to get the input from the user instead of assigning one. By putting SET /P , you are demanding the user to input something, and the prompt will ask the user to input by showing the question you wrote after the “=” sign.

Pause will ask the command prompt to stop processing for awhile, so that the user can see what is displayed.

Now, save the file again, and execute it. You should see the following :

Of course, the name can be anything you typed in.

Now try putting some creative touches to your program, let it input your phone number, address and so on. Try launching it.

Delicious variable

Now of course, you can name your variable anything. %stupidname%, %funnynumber%. But there are a few variables that are determined by the computer, which you can use for different purposes.

Let’s say if you want to know the current date, what do you type?

@echo off
echo The current date is %date%
pause

The %date% variable is also known as a system variable, where it’s value is already determined by the system. Same goes for time, just use the %time% variable.

Try experimenting on ways you can implement time and date variable in your program! Maybe like a prompt when the user logs in.

Welcome to the system !
Enter Your Name : John
Welcome John, the time now is 12:00:02

What’s Next?

All these are suffice for you to begin your programming adventure, in Part 2, we will see how we can use inputs to direct users to different portions of the program. As well as how we can implement looping in the program.

Getting Started With SQL

July 27, 2008 – 5:44 am

Working with lots of information can be troublesome. There are thousand of ways to organise information, but how can we do it at the least time period and without the hard work of manually arranging them.

This is where SQL comes in.

Talk Like A Human

There are many situations where we wished that the computer was more humane. I always wanted my computer to do things I can think of, and not limited to a set of programs it has. But the reality is far from that, and I am partially glad that our mechanical overlords have not overtaken our intelligence.

SQL, also known as Structured Query Language, is most commonly used to store various information on the internet. In fact, every known websites and forums are using it. People who have not used SQL would wonder, if SQL is the monopoly in the internet database business. The truth is far from that.

There are many thousand ways to store information on the internet server, but many have failed in terms of simplicity and speed. Take flat files database for example, information are separated by commas or other structure which is not commonly known. These flat files do not require any external server to run, but they can be corrupted easily, and it takes quite awhile to parse a large flat file database.

On the other hand, SQL works like a secretary. Asking SQL to store information, is similar to asking your secretary to get your finance records. And that is why it is the industry standard for information storage.

Working with SQL

SQL is platform independant, and most of the common programming languages out there have ways to connect to a SQL server. The good thing about SQL is, regardless of which programming language you use, the SQL queries you will be using is the same for the rest of the programming languages out there.

So how do I tell SQL that I wanted to get Smith’s phone number from my list of contacts? (Assuming I have one).

SELECT phone_number FROM contacts WHERE name="Smith"

Looks like standard english isn’t it. That’s the power of SQL, the above will run assuming I have a table named contacts with a name & phone_number field.

So what if I want to add a contact into my contacts table?

INSERT INTO contacts (name,phone_number) VALUES ('John Appleseed','131250001')

Okay, so the front looks humane enough, but the back part is a little confusing. What’s with the two brackets?

The first brackets is where you specify what fields you want to add your information to, and the 2nd bracket is where your information is. Of course, to let the computer know that the 2nd bracket stores the information, we have to tell it that the 2nd bracket contains VALUES. So we put VALUES in front of it.

I assume you would have guessed how deleting an information would be.

DELETE FROM contacts WHERE name="John Appleseed"

Yep, its that simple =D

Unleash the Monster

You are probably wondering now, if SQL is that simple, why isnt everyone using it? The answer is, when it comes to complicate systems like a forum software. It is a beast to write SQL queries. The developer will most likely want to cut down as many queries as possible to make the software fast.

Here’s a good example, where I want to get information from many tables :

SELECT user.name, phone.number, address.street FROM contacts user, phonebook phone,
addr_book address WHERE user.name="Smith" AND phone.id=user.id AND addr_book.id=user.id

This is perhaps the least complex code in Advanced SQL queries, but you get the drift. SQL is more than just updating, adding and deleting values. It is also possible to do operations using SQL.

For example :

SELECT avg(marks) FROM scores

This query gets the average for all the marks in the scores table. And the possibilities for SQL functions are endless.

What can I do with SQL?

Now that you have learn a little about the power of SQL, as a developer you would probably be excited to implement it on your projects. So here is a little tip on where to apply SQL and when we won’t be needing it.

USE IT :
-
Your project requires a user authentication to access, and there are levels of permission for access control.
- Your project stores alot of statistics regarding application usage, click counts and logs.
- Your project works across a network or the internet, and deals with alot of visitors.
- Your project needs to work with dates and schedules.

DONT USE IT :
-
Your project only stores default settings
- Your project involves working with files and text editing
- Your project runs only at a small period of time
- Your project is an utility application

I hope you learnt alot through this article, there are more to come in the future =D

The Sudden Influx of iPhone apps

June 30, 2008 – 12:07 pm

As a mobile developer, the sudden huge interest of developers on the iPhone platform should be news to your ears. The mobile platform, after all, have been pretty dull since the beginning. For example, the Nokia’s Ngage platform, which was promising at start, ended up with lukewarm response.

Why is that happening? After all, isn’t mobile computing the future of computing? Let’s trace back to how Windows became the de-facto operating system in the world.

Third Party applications!

The reason why some legacy platforms still exist today, is due to this very reason. Palm, a failing business, is still prominent in the handheld world. That is because thousands of apps are available for Palm, and users who are accustomed to using these apps just didn’t have the time to transition to newer platforms.

Apple probably knew this from the start of their iPhone project, and built iPhone upon a proven, solid and familiar platform. The Mac OS X platform, has strong roots with Unix, which is a proven secure platform. With the added benefits of the powerful Cocoa touch framework, the iPhone platform is a guaranteed success.

Well, Windows Mobile have been around for more than a decade, why not Windows Mobile? Let’s just say, there is no simple route to developing for it. Apple’s XCode IDE is provided free for all registered developers, while Microsoft sells Visual Studio for more than a hundred bucks. An Indie developer would probably stayed away from Windows Mobile, just because of the cost of the development package itself.

Second, Visual Studio for Windows Mobile always insists that it’s apps should be run through the .NET Compact Framework runtime, which by the way, is not installed by default. Not to mention, the runtime itself is huge, memory intensive, and extremely taxing on the mobile processor. Developers knew better to save themselves from all the trouble.

Here comes the iPhone platform to save the day. The freely downloadable XCode IDE, includes a simple to use interface which bundles with a time saver named “Interface Builder”. Drag and drop interface have never been easier. Programming is all done using objective C, which can be learnt in under a day. The iPhone platform is the programmer’s dream.

No wonder all the top 10 companies are gaming in, EA games, SEGA and other famous software developers, are putting their best programmers on the iPhone platform. It is the beginning of the golden age of mobile computing.

A nice brew of Java, needs quality Cocoa

June 30, 2008 – 10:40 am

Programmers who are coding entirely for the Windows Platform might not be familiar with this powerful language named “Cocoa”, and it’s not hard to see why, since it is more widely used in Apple products.

As few of Apple’s products began to gain popularity within consumers (e.g: iPhone), more developers are beginning to discover the power of Cocoa, and even fall in love with the language itself (Objective C). Which is why recently, there has been several attempts to port the smalltalk inspired language over to the form of Javascript for use on web development.

The result? Simply amazing. Not to mention, a little mac inspired.

The above is 280slides, which closely resembles Keynote. Do not let the looks of the web application fool you, it’s entirely running on a web browser. 

Many of you might think that 280slides is using Prototype or Scriptaculous for all the web 2.0 goodies it runs. Surprise! 280slides creator, 280north, coded the web application entirely out of their inhouse Cocoa inspired javascript library (Obj-J).

This also marks a start on more advanced web application development, which involves native app syntax within a web application. Hopefully, this will bring a positive impact on web 2.0 applications, and not making them more bloated than ever.

[ Portions of article is referenced from ajaxian.com ]

 

 

Coding it efficiently

June 28, 2008 – 1:15 pm

There are many times when tasks can be simplified, and written more efficiently. This will all depend on how well the developer manages his codes, as well as his choice of programming language.

That said, it is important to broaden your range of programming languages, instead of limiting yourself to just Java and C++. Because not every language are designed for all purposes, some applications are better off coded from scratch in another language. Take this into consideration :

JAVA

BufferedReader input = new BufferedReader(System.in);
int hello = input.nextInt();

As opposed to :

C++

int hello;
cin >> hello;

Or what about some other flavors? Yummy!

BATCH

@SET /P hello=Enter a number?

PHP

$hello = $_POST['hello'];

BASIC *gasp*

INPUT “Enter a number?”, $hello;

It’s obvious, that some language are more suitable for different purposes. Not being bias or anything, Java syntax would most likely turn many wannabe programmers away, due to the excruciating declaration required to even produce something functional.

So what can a programmer do to prevent this so called “code redundancy” problem?

Let’s just say, early planning.

Take for example, my application requires rapid conversion between string and integers, and it doesn’t have to be a desktop application, why not take PHP for a spin? After all, it’s the most insensitive towards datatypes (not a good habit to keep tho).

<?
//Integer to string
$number = 11;
$stringnumber = “$number”;
$number = $stringnumber;
?>

Wow, I mean, just look at that! How often do you see a programming language that is so flexible towards datatypes? There are no “casting” ( int hello = (int)world; ), no special methods ( int hello = [hello intValue]; ), nothing! That is one way to cut down on some serious code redundancy.

Another way to efficiently writing your code would be to make functions, take this as an example :

Instead of a For loop that loops through the entire code, tagging HTML fields to be hidden :

for (x=0;x<count($array);x++;){
if ($array['hidden']==1){ $type=”hidden”; } else { $type=”text”; }
echo “<input type=’$type’ name=’”.$array['name'].”‘>\n”;
}

Why don’t we use the str_replace function to do the job? We can even do away with arrays!

//Dump all html data into string
$bigstringwithhtml = “<input type=’1′ name=’hello’>\n<input type=’text’ name=’world’>”;
echo str_replace(”type=’1′”, “type=’hidden’”, $bigstringwithhtml);

Both runs the same, but the codes are significantly reduced to a degree, better yet, you are not using loops! That is one extra guarantee that your loop won’t end up as an infinite loop!

So the next time, before you start clicking on “New Project” in an IDE, think about the syntax you are about to endure, perhaps your application might run better on another different runtime. It’s just a matter of optimization.

Sexy?

June 28, 2008 – 12:06 pm

Here it goes, picture in its full glory. Bill Gates officially retired yesterday, and what’s better to announce his departure than to post one of the Windows advertisement that didnt quite make it out of the marketing dept. (Maybe you can tell us why)

Marketing Dept.

Ballmer : Ok guys, damn that Steve Jobs, all with their mac sexiness and style. We need something that can plaster our brand into everyone’s mind. Something, as sexy as a mac.
Bill : Hey, you know, I could be a model or something?
Ballmer : Hmm, I guess we could try..

Hello world!

June 28, 2008 – 7:10 am

Hello World

Since this is the first post, there’s not much to be said except WELCOME! This place is seriously empty right now, but fret not, I already have plenty of stuffs on my mind now, each frantically shouting “me! me!”. You can imagine the enthusiasm.

So please! Bookmark this page. Who knows, this might one day replace your good ol’ newspaper.