Whats Been Done

Lets see what have we looked at so far

- Basic SQL ( CRUD – Creat , Read , Update , Delete )
- Basic Programming ( Loops , If-Else , Functions … )
- Basic OOP ( Classes/Subclasses/Constructors … )

This about covers all the basic , I think. Maybe we should move into integration with SQL and Programming Languages. Probably LINQ and PHP/MySQL. After all that , we can talk about basic networking. Once all that is done , next would be security. Great!

Programming Functions

Lets talk about a new topic today. Functions aka Methods. We looked at them here and there but never really talked about them in detail until now. Here are some of them functions in SQL that we have looked at ,

  • Count() function – select count(*) from employee; –> returns the number of rows.
  • Password() function – to encrypt the password text

Of course for past few days we have also been looking at functions in C/C++/C#/Java/PHP and so on. So what are functions? And why do we need them at all? TO illustrate why we need functions , here is an example that has nothing to do with computers. Lets cook!

To cook a dish or a meal , first of all we need to prepare ingredients , lets make a list of the steps we will be doing ,

  1. skin the chicken
  2. boil the vegetables
  3. prepare the broth
  4. make the sauce

Each of the above mentioned steps could be thought of as a function by itself. For example , skin the chicken. Here are the steps you might need to skin a chicken.

  1. buy a frozen chicken at the market
  2. thaw the chicken
  3. choose a knife
  4. remove the skin

What this means is that instead of saying all these every time we need to skin a chicken , we just need to say “skin the chicken” and it is understood what are the steps involved. Also when there is a need to change the way the chicken is skinned , we would only need to modify it in one place and one place only. That simplify the process.

Of course , we use functions all the time in our daily life. When we say “I took the bus to here” , what you meant was you waited for the bus , boarded the bus , paid the bus fare and finally alighted from the bus. I think you get the drift by now.

So how do we use it in programming context? Here is one function we have used ,

Console.WriteLine("Hello");

the function , “WriteLine” , is neither written by you nor me , yet it is available to whoever that is writing a C# language. Thats what makes it so special , you would only need to write it once and could be reused not only by you but everyone else , given the right permission.

I hope you are now much clearer about what are functions in the context of programming and also how we use them. Till next time. Cya!

The Last Words On Variables

This is the last topic on variables , I promise!!!!!!!

Today , we shall talk about special type of variables , GLOBAL variables. I put the word global in all caps for a purpose , it is generally ‘understood’ that global variables should be in capitals. Why you may ask. It is to make them different from every other variables. And saying that I realised I have not gone though the lifetime of the variables. Perhaps I should do that now.

Lifetime of a variable , or scope of the variable is basically in the bracket , to be more precise , curly brackets. Here is one example ,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Variables
{
    class Program
    {

        public static String testString1 = "test1";

        static void Main(string[] args)
        {
            String testString1 = "test2";
            Console.WriteLine(testString1);
            printTest();
        }

        public static void printTest()
        {
            Console.WriteLine(testString1);
        }

    }
}

If you were to run this C# program in Visual Studio, you would have gotten this result ,

test2
test1
Press any key to continue ....

The thing to take note is of the output of the variable testString1 , which prints out as “test1″ even after it has been changed to “test2″. This is mainly due to the fact that the variable testString1 in the Main function , I have not been to functions too I know , is a local variable. Meaning once the function ends , so is its life. Btw , to create global variables in C# , you would need to create a static class first then a static method.

To use the variable everywhere ,

StaticClass.StaticVar = "Some value";

It is much simpler in C/C++/Java though. But I think you get the drift. Ok , so why need such variable that is available to all files/classes/functions in the project? One of the main reason is to standardization.

Suppose you are doing a math program/website , and you will need a variable for the value of pi. It is possible to declare it everywhere you need it , “float pi = 3.14;”. But what if later you are told more precision is needed? Then are you going to go through the files one by one and change each pi variables? Another example would be school grades , for a school website. It is obvious that highest grade/mark is 100. You might be tempted to it everywhere. Then the school change to 110 marks as the highest mark. Then what are you going to do??

As you can see from the above examples , for values that would be standardized everywhere , it is much more efficient and easier to put them in one place and only at one place. Easy to change now and later as well.

Hope this has given you some thoughts. Thanks for reading. Cya!

Programming Languages In Brief

I was thinking of doing short notes on Programming Languages and seems like a good idea. So here it goes.

Programming Languages are technically separated into broad categories such as Functional Programming , Procedural Programming , Object-oriented Programming , Logic Programming and so on and on. Thats in theory. In practice , what programming language you’ll be using depends more on the preference of the organisation that you belong to rather than your own personal preference. So if you comes from MIT , you will probably learn LISP. For Google , it would be Python and so on. So instead of separating them into such categories , we can group them into families.

Here is one such family , probably most familiar to you ,

C , C++ , Java , C# , PHP

Here is another , scripting languages ,

Bash , Perl , Python , Ruby

Then another , these are languages used for artificial intelligence research and statistical ,

LISP , Prolog , R

Somemore , SQL related languages ,

SQL , T-SQL , PL/SQL

Of course , there is also HTML , XHTML and many more including those are specific to individual environment such as Maya scripting language. You could further subdivide them but then it would be a waste of time mostly. Each of them has their own pros and cons. For example, Ruby is a very beautiful language to learn and combining with rails web framework , it is amazing. I love it. Yet , it updates fairly quickly and has yet to stabilize. If you are hold a book about Ruby , it is probably outdated. LISP , my favorite and one of the most advanced languages , is not as widely supported as other languages.

So then what are some of languages to learn?

  • C/C++/C#/Java -> Major Major languages , you can’t avoid them and if you know one you probably be able to learn the rest in no time.
  • HTML/PHP/CSS/SQL -> If you are into web development
  • Perl/Ruby -> Here I didn’t include Perl and not Python , my personal opinion. Ruby is for future.
  • LISP -> Cause its fun. Need I say more?

So if you really really really think about it , there is only 4 such categories and only 3 needs to know well if you are not a geek. If there is any other languages you would like to include or have opinions , pls feel free to comment. Thanks

Moving Forward

I think more or less we are done with SQL for now. For 90% of the time using a database, what we been doing would suffice. The process of Creating , Reading , Updating , Deleting information is aka ‘CRUD’ in some programming and database textbooks. What we havn’t covered would be

  • ORDER BY
  • In-Depth details of SQL Functions
  • SQL Programming , eg T-SQL and PL/SQL
  • Database Administration
  • SQL Security

Before we go into those , I would like to take a detour around the whole ‘Relational Database’ and explore the shallow water of programming. Of course , both topics will overlap eventually. For example , Microsoft LINQ or Ruby on Rails require that you understand both the programming side , such as loops and functions as well as database statements such as SELECT. You will eventually have to know both. The higher you go , both are inseparable. In fact , you could say Google is nothing more than a giant database full of information on the websites. How do you extract data out of it? By using programming languages , Google uses Python extensively , if you want to know.

So here is what I plan to do for foreseeable future…

  • General Programming Topics , eg functions , loops ..
  • Dive deeper into 2 or 3 languages
  • See how both programming languages and database can be integrated
  • Have Fun!