nell

Tuesday, May 28, 2013

Why are Keyboard Keys not in Alphabetical Order?

If you have been using a computer for quite sometime now, then you must be aware of the fact that the layout of the keyboard that you use to type words, is not in accordance with the sequence of letters in the English alphabet. Just have a look at the keyboard you're using right now. It is difficult to find a logic behind such a haphazard arrangement of letters, isn't it? Fancy the letters not finding their "deserved" positions on the keyboard! Consider the alphabet 'A', for example. Should it not ideally be the starting key of the first row? But alas, it was not to be. The "poor" letter is seen nowhere in the first row but can only be found in the second! Similar is the case of the letter 'W', which has been moved up to the first row. This arrangement of letters is termed as the 'QWERTY' arrangement after the first 6 letters of the keyboard. So, what is the reason behind this arrangement, and is there a reason in the first place? Let's look for answers in the subsequent section.

Reason Why Keyboard Keys are not in Alphabetical Order

To understand the logic behind the present arrangement of letters on the keyboard, the QWERTY arrangement, we have to go back (albeit for a while!) to the later part of the 19th century, when typewriters were the norm, and the invention of the computer was almost half a century away.

The typewriter was a simple device invented by C.L. Sholes in the year 1873. The typewriter had metal bars known as type bars and each type bar had the mirror image of one letter or character on its end. These type bars were arranged such that all the letters appeared from A to Z. Typists found it easy to look for the letters on the keyboard and hence, began to type very fast. But there was a problem with this 'normal' arrangement of letters. Rapid typing made the adjacent type bars stick to each other and this called for additional efforts from the typist, who had to manually separate them before resuming work. This problem was more often observed for adjacent keys that were frequently used together.

To counter this problem, Sholes made a list of all frequently appearing combination of letters in the English language and after studying them, came up with a new layout. The objective of this layout was to place these letters far apart on the keyboard, thus preventing the type bars from getting entangled. However, some people are of the opinion that the objective of developing the QWERTY keypad was merely to disturb the alphabetical sequence of letters so that the typists took a longer time to look for each letter, slowing down the speed of typing, in the process. A lesser speed meant less chances of the adjacent type bars getting jammed!

With the arrival of the computer in the 1940s, typewriters were fast replaced by these new advanced machines that promised to make things easier than before. However, there was one dilemma: the people operating typewriters in offices were the same people who were to now operate computers. The situation demanded that they be trained to operate the new machine, but training so many people was not considered worth the money spent. So, the computer keyboards came with a layout that was similar to what was already on the typewriters and this continues even today, as the QWERTY layout has become the industry standard.

Quick QWERTY Facts!

Before I sign off, I'll share with you some interesting facts about the preferred keyboard layout of our times, the quirky QWERTY!
  • You can still find traces of the original A to Z keyboard in the QWERTY. Just look in the middle row where you'll find the letters 'DFGHJKL' in alphabetical order except for the vowels 'E' and 'I'.
  • Eight keys of the middle row of the keyboard constitute the 'home row': the keys on which you need to place your eight fingers to learn how to type faster by the process of touch typing.
  • The QWERTY keypad is more beneficial for those who primarily use their left hand for typing because the layout is such that more words can be typed using the letters on the left side.
  • Interestingly, you'll find all the letters of the word 'typewriter' in the first row of the keyboard!
Thus, we see that it is the typewriter that is to blame for the difficulty in typing that we face today. However, people have more or less grown used to the layout and it is fast replacing the traditional keypad in cell phones as well.

Monday, May 27, 2013

Segmentation vs. Paging

Ever wonder what the terms segmentation and paging refer to? or heck, what is the difference between the two? Well you're not alone, many people out there are confused when it comes to these terms...

Let’s start by making sure we have a clear understanding about what exactly Paging and Segmentation is. We have tried to simplify this in a way which would be the easiest to understand.

Paging – Computer memory is divided into small partitions that are all the same size and referred to as, page frames. Then when a process is loaded it gets divided into pages which are the same size as those previous frames. The process pages are then loaded into the frames.

Segmentation – Computer memory is allocated in various sizes (segments) depending on the need for address space by the process. These segments may be individually protected or shared between processes. Commonly you will see what are called “Segmentation Faults” in programs, this is because the data that’s is about to be read or written is outside the permitted address space of that process.

So now we can distinguish the differences and look at a comparison between the two:

Paging:
Transparent to programmer (system allocates memory)
No separate protection
No separate compiling
No shared code

Segmentation:
Involves programmer (allocates memory to specific function inside code)
Separate compiling
Separate protection
Share code

SWAPPING AND PAGING

5.4 Swapping and Paging


SunOS uses virtual memory, so that disk area (swap space) is used as an extension of physical memory for temporary storage when the operating system tries to keep track of processes requiring more physical memory than what is available. When this happens the swap space is used for swapping and paging.

Paging is when individual memory segments, or pages, are moved to or from the swap area. When memory is low portions of a process (data areas, but not instructions which are available from local or remote file systems) are moved to free up memory space. Segments are chosen to be moved if they haven't been referenced recently. When the process next tries to reference this segment a page fault occurs and the process is suspended until the segment is returned to memory. A page fault is normally returned the first time a program is started, as it won't be in memory. It's then paged from the local or remote file system.

Swapping happens under a heavier work load. With swapping the kernel moves all segments belonging to a process to the swap area. The process is chosen if it's not expected to be run for a while. Before the process can run again it must be copied back into physical memory.


Friday, May 24, 2013

Difference between ID and CLASS in CSS

ID's and Classes are "hooks"

We need ways to describe content in an HTML/XHTML document. The basic elements like <h1>, <p> and <ul> will often do the job, but our basic set of tags doesn't cover every possible type of page element or layout choice. For this we need ID's and Classes. For example <ul id="nav">, this will give us the chance to target this unordered list specifically, so that we may manipulate it uniquely to other unordered lists on our page. Or we might have a section on our page that has no relevant tag to signify it, for example a footer, where we might do something like this: <div id="footer">. Or perhaps we have boxes in our sidebar for keeping content over there separated in some way: <div class="sidebar-box">.

These ID's and Classes the "hooks" we need to build into markup to get our hands on them. CSS obviously needs these so that we may build selectors and do our styling, but other web languages like Javascript depend on them too. But what is the difference between them?

ID's are unique

  • Each element can have only one ID
  • Each page can have only one element with that ID

When I was first learning this stuff, I heard over and over that you should only use ID's once, but you can use classes over and over. It basically went in one ear and out the other because it sounded more like a good "rule of thumb" to me rather than something extremely important. If you are purely an HTML/CSS person, this attitude can persist because to you, they really don't seem to do anything different.

Here is one: your code will not pass validation if you use the same ID on more than one element. Validation should be important to all of us, so that alone is a big one. We'll go over more reasons for uniqueness as we go on.

Classes are NOT unique

  • You can use the same class on multiple elements.
  • You can use multiple classes on the same element.

Any styling information that needs to be applied to multiple objects on a page should be done with a class. Take for example a page with multiple "widgets":

<div class="widget"></div>
<div class="widget"></div>
<div class="widget"></div>

You can now use the class name "widget" as your hook to apply the same set of styling to each one of these. But what if you need one of them to be bigger than other other, but still share all the other attributes. Classes has you covered there, as you can apply more than one class:

<div class="widget"></div>
<div class="widget big"></div>
<div class="widget"></div>

No need to make a brand new class name here, just apply a new class right in the class attribute. These classes are space delimited and most browsers support any number of them (actually, it's more like thousands, but way more than you'll ever need).

There are no browser defaults for any ID or Class

Adding a class name or ID to an element does nothing to that element by default.

This is something that snagged me as a beginner. You are working on one site and figure out that applying a particular class name fixes a problem you are having. Then you jump over to another site with the same problem and try to fix it with that same class name thinking the class name itself has some magical property to it only to find out it didn't work.

Classes and ID's don't have any styling information to them all by themselves. They require CSS to target them and apply styling.

Barcodes and Serial Numbers

Maybe a good analogy here is bar codes and serial numbers. Take an iPod in a store. On the packaging will be a bar code. This tells the store what the product is, so when it is scanned, the system knows exactly what the product is and what it costs. It might even be able to know what color it is or where it was kept in the store. All iPod of this same type have the exact same bar code on them.

The iPod will also have a serial number on it which is absolutely unique to any other iPod (or any other device) in the world. The serial number doesn't know the price. It could, but for the store this wouldn't be a very efficient way to store and use that data. Much easier to use the barcode, so that for example, if the price changed, you could just change the price for that bar code and not every individual serial number in your system.

This is much like ID's and Classes. Information that is reuseable should be kept in a class and information that is totally unique should be kept in an ID.

ID's have special browser functionality

Classes have no special abilities in the browser, but ID's do have one very important trick up their sleeve. This is the "hash value" in the URL. If you have a URL like http://yourdomain.com#comments, the browser will attempt to locate the element with an ID of "comments" and will automatically scroll the page to show that element. It is important to note here that the browser will scroll whatever element it needs to in order to show that element, so if you did something special like a scrollable DIV area within your regular body, that div will be scrolled too.

This is an important reason right here why having ID's be absolutely unique is important. So your browser knows where to scroll!

Elements can have BOTH

There is nothing stopping you from having both an ID and a Class on a single element. In fact, it is often a very good idea. Take for example the default markup for a WordPress comment list item:

<li id="comment-27299" class="item">

It has a class applied to it that you may want for styling all comments on the page, but it also has a unique ID value (dynamically generated by WordPress, nicely enough). This ID value is useful for direct linking. Now I can link directly to a particular comment on a particular page easily.

CSS doesn't care

Regarding CSS, there is nothing you can do with an ID that you can't do with a Class and vise versa. I remember when I was first learning CSS and I was having a problem, sometimes I would try and troubleshoot by switching around these values. Nope. CSS doesn't care.

Javascript cares

JavaScript people are already probably more in tune with the differences between classes and ID's. JavaScript depends on there being only one page element with any particular, or else the commonly used getElementById function wouldn't be dependable. For those familiar with jQuery, you know how easy it is to add and remove classes to page elements. It is a native and built in function of jQuery. Notice how no such function exists for ID's. It is not the responsibility of JavaScript to manipulate these values, it would cause more problems than it would be worth.

If you don't need them, don't use them

As you can see, classes and ID's are very important and we rely on them every day to do the styling and page manipulation that we need to do. However, you should use them judiciously and semantically.

This means avoiding things like this:

<a href="http://css-tricks.com" class="link">CSS-Tricks.com</a>

We already know this element is a link, it's an anchor element! No particular need here to apply a class, as we can already apply styling via its tag.

Also avoid this:

<div id="right-col">

ID is appropriately used here as the page will likely only have a single right column, but the name is inappropriate. Try and describe the context of the element, not where it is or what it looks like. An ID here of "sidebar" would be more appropriate.

Microformats are just specific class names

Think microformats are over your head? They aren't! They are just regular markup that make use of standardized class names for the information they contain. Check out a standard vCard:

Tuesday, May 14, 2013

SQL: CREATE a table from another table

You can also create a table from an existing table by copying the existing table's columns. It is important to note that when creating a table in this way, the new table will be populated with the records from the existing table (based on the SQL SELECT Statement). Syntax #1 - Copying all columns from another table The syntax for CREATING a table by copying all columns from another table is:
CREATE TABLE new_table AS (SELECT * FROM old_table); For Example:
CREATE TABLE suppliers
AS (SELECT *
FROM companies
WHERE id > 1000);
This would create a new table called suppliers that included all columns from the companies table.
If there were records in the companies table, then the new suppliers table would also contain the records selected by the SELECT statement.