Friday, May 16, 2008

Useful ways of using Views

Here are a few ways I found Views to be useful for me.


Data Cleansing

If I have a column that needs to be cleaned or tested in some way. For example:

Select mycolumn, if(mycolumn is null, TRUE, FALSE) as mycolumnisnull from mytable
This example is not that amazing, but it lets you place conditions for the data. Then instead of re-writing these conditions in your application layer, you can re-use the View from the database.
Another example:
Select email, regex ['some amazing email verification/cleaning regex line'] as cleaned_emails from emails
Here again, we have some condition that placed in the database. We can now call the emails table and tell it to give us only the cleaned emails according to the defined conditions.


Decision Making

You can place some business logic in your Views. I wrote about it in my blog before.
This time I will just use an example:

Select business_loan, if (business_loan > 30000, 'Allow Discount', 'No Discount') as discount from loans
So here, you have an embedded rule that says if the loan is over 30,000, then give a discount. Otherwise, no discount.
There are advantages and disadvantages to using business rules in your database. One advantage is the visual way of verifying that your code is working. You can see next to your data if your code works or if you need to make changes.


Displaying parts of many-column tables

Very simply, if you know you only need a few columns from a table with many columns, you can just specify it in a View. It just keeps things tidier.

Create View contact_details
Select col11 as firstname, col52 as lastname, col37 phonenumber from 100columntable
I have used this (a lot) for finding tables to extract data from when I did some ETL-data warehouse work. This is an example:

Create View src_thetableiwaslookingfor
Select * from database1.tablethatiwant
This helped me a lot in the past and also helped when I worked with other developers on the same project. We just all used the same interfaces (Views).


Fashioning your data

You can use some basic text manipulation on your data to help you display it better.
For example:

Select concat(title,'. ',firstname, ' ', lastname) as fullname from contact_details.
Here, we just added the title, first name and last name into one string (example, Mr. John Smith).
If you really want to go crazy, you can do this

Create View HTML_export
Select concat('[tr] [td] ',firstname,'[/td] [td] ',lastname,'[/td] [/tr] ') as list from contact_details

So, if in the future you want to get a quick list of all the contact names in HTML format, you can just use the View.


Conclusion
Views are very useful :)
Especially if you dislike long-winded languages when you can do it in 1 line of SQL.

I plan on writing a more detailed article soon about this topic

Tuesday, May 13, 2008

A Blog about Blogging

Many of you may have already noticed that blogs are becoming more and more influential as mediums of information. I personally read tens of blogs everyday to keep up with events.

But who decided that blogs are good sources of information?
After all, a blog is someone's opinion. It might be a better educated opinion with more facts then other opinions, but its still someone's opinion.
A blog can be defined as:

Short for "Web log," a specialized site that allows an individual or group of individuals to share a running log of events and personal insights with online audiences.

News

News is still someone's opinion. News companies try to be neutral and say that they report the news the way it is. But anyone probably knows that if they open the TV to a certain news channel, they will see the news in a different way then other channels.
Whether it be if the news channel is usually more right, more left, if the news anchors are tougher then news anchors on other channels, etc..
So there is no "actual" news, there is just how people see the world. Truth is relative to how you see the facts.
In a sense, you can validate blogs as being reasonably "true" by saying that news channels are not 100% "true" anyway.



Chatting with Friends

But not everyone is a news journalist. So what motivates people to write blogs?
Obviously, some people have different reasons. But since its my blog, I will express my opinion to what I think it is.
I think that people like to chat with their friends or other people and share ideas.
It is always nice to talk to a friend who thinks a bit like you and discuss issues that you find interesting.
This is where I think the motivation lies. People want to share ideas and instead of maybe sharing it with one person, they can share it with many people. People who think this issue is interesting. People who either want to learn the issue or people who already know enough about the issue to comment on it.


Facts and Opinions

Opinions are ways of trying to understand the world around us. If there were facts to help us understand the world around us, then we don't need someone's opinion about the issue, we already know or can find out.
If however, there is no formal way of finding out something, we use informal ways. We have opinions about things because we don't have any other formal way of understanding them. We like to give our opinions and discuss them to either affirm them with other people (if they agree) or change them, if we are found out to be wrong.
In this spirit of co-operation, we discover new things when we discuss our opinions.


My Opinion

I think blogs are now at a very mature stage. Already, blogs are compared to news channels and news channels reference blogs some of the time.
A good point to take from this, I think, is that even with news, its important to remember that its still someone's opinion. Its always good to take many different opinions from different sources as well as share your own opinions before coming to your own conclusions.
And its even more important to note, that a lot of our current conclusions are based on opinions. With that, we should be open to new opinions that could possibly change our previous conclusions.

Monday, April 28, 2008

Thank You Ubuntu

Well, I decided to take the plunge and migrate from Windows XP to Ubuntu. Now, technically, I have been wanting to do this for a while, but I was dependant on my windows to dial up to my internet (some problem with my ISP here). I tried to do it in Ubuntu a few months ago, but it was too complicated for me. However, it left me with a yearning to try again.
So, I waited for the new Ubuntu to come out and in parallel fixed my router.

Why?
The reason I thought it was a good idea to move to linux was mainly for self-improvement.

I recently read some blogs (couldn't find them now) that mentioned that with all the new web apps, there will be less and less emphasis on the OS. In 2011 (gartner says), this will hit a crucial point.
I was thinking, maybe more people will adopt free linux when everything important will be in "the cloud" and all you really need is a browser anyway. So I know how to use linux, I will be ready for that time and help people start adopting it.

Another 2 important reasons for me were:
1) That all servers use linux for their web apps and to be more comfortable in that environment will be a big plus.
2) To get myself more into the developing frame of mind. This maybe just me, but I noticed that the hardcore developers use linux or macs. Not that I am knocking windows, but I don't really feel that developers in windows are as serious as linux or mac for some reason (did you see some online presentation videos for a new technology. ALL the presenters use macs. Especially ones from Google. Am I missing something?)

Installing
I did some research, downloaded some pdfs and was all ready to go. I decided to make my current windows into a VMware image in case I needed something from it.
I downloaded Ubuntu and tried to figure it out. Bascially, you get 700mbs which you download of the net and anything else you want, you need to download. Fedora, comes with 4gbs and you need to download very little.

I had real problems understanding how to install things.. until I discovered DAM DAM DAM... repositories. Ok, so forgive me if you now are saying to yourself "Duh, I already knew that". I am new to it.

What I learned was, if you type "sudo apt-get install the-whole-universe-for-free-woohoo-I-love-it", you just magically get it. No need to download, configure (well, most dont) and all that trouble. You just use apt-get. You can even do it visually with the package manager.

This for me, is a huge advantage over other platforms. Its just so welcoming and encourages you to improve.
For example, I could download MySQL off the website, then install it manually. Or, I could just write 1 line and it will download, install itself, do some configuring and automatically upgrade (I think) when a new version goes into the repository. How cool is that?


The Tipping Point
So I was trying to install VMware and this was really difficult. Opening the bin/rpm file was difficult enough, but after succeeding in that, it gave me some error.
I almost gave up, until I found this article. It shows you that you can do everything with command lines and after playing around with linux, I am becoming more and more comfortable with them.
However, the important part is in the comments.
Someone posted the exact error I had.. and the guy told him how to solve the problem... by changing the ACTUAL CODE. Oh my god! change the actual code of the supplier? Unheard of in windows. If you have an error, you file a report somewhere and wait a week if your lucky.

Just the fact that I was allowed to look into someone else's code (and VMware is a big company) and learn and/or change it (I wont go into licenses), really makes me feel part of something.
I now really understand that open source doesn't mean free as in free beer, but free as in freedom of expression (sorry, that was a bit deep).


In conclusion.
I really like Ubuntu. Its not perfect and it needs some work, but this time, I feel that I can be part of it and help it improve.

A useful article to install Ubuntu <--