Monday, December 14, 2009

Java For-Loop Effeciency: .size()

Many majors in most colleges require Comp Sci to some degree, generally teaching java. I have always found the underlying pinnings of languages very interesting, so this may bore some of my readers, and some, it may catch your interest.

This makes perfect sense, but I do not think many people realize it. It is better to allocate a variable outside a for loop as apposed to using a .size method inside it. Of course, being ever curious, I decided to test this. Bellow is the code I made (yes, its bad, but it was written quickly.)


import java.util.ArrayList;


public class Tester {


public static void main(String []argv) {

ArrayList test = new ArrayList();

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

test.add("a");

test.add("b");

System.out.println("The array has " + test.size() + " objects");

long startTime = System.nanoTime();

withSize((ArrayList)test.clone());

long timeDiff = System.nanoTime() - startTime;

System.out.println("With bad coding style :" + timeDiff + "");

long startTime2 = System.nanoTime();

withoutSize((ArrayList)test.clone());

long timeDiff2 = System.nanoTime() - startTime2;

System.out.println("With good coding style :" + timeDiff2 + "");

}

public static void withSize( ArrayList ar) {

for(int a = 0; a<ar.size()-1; a++) {

ar.set(a,ar.get(a)+ar.get(a+1));

}

}

public static void withoutSize( ArrayList ar) {

//Notice that ar.size() is not in the loop

int b = ar.size();

for(int a = 0;a<ar.size()-1;a++) {

ar.set(a,ar.get(a)+ar.get(a+1));

}

}

}

You will find pretty consistently that the second loop executes quicker. As for memory allocation assigning int b outside a loop, an int is a 32 bit object, which is really not much considering how big we make our memory and that it will be dealloc'd after the method completes. Of course, the time difference is in nanoseconds, but over time I am sure the for loops in code do build up, especially as code gets longer and longer.

An important, almost ironic note, this will not work on Windows, the timer does not have a good enough resolution.

Sunday, December 6, 2009

Midnight Maddness

So, its midnight again. Half awake, half asleep, more homework to do, but don't want to do it. I am sure everyone here has had that feeling of oncoming dread that is work, or even worse, last minute assignments before exams.

So what is my solution? Google!

Yep, thats right, google to the rescue! Google is the mastermind of anything. Is there anything google cannot do?

Give it another year, and we wont even need to click dial to order pizza, Google will know our preferences via our search habits, we will just search it and google will call and order pizza for us! Google pioneers everything. Try to go a full week without hearing something about google. Lets just face it, Google is awesome, and the ultimate distraction!

Wednesday, December 2, 2009

Weave: The future of cross-computer browsing

Every browser implements bookmarks in some way, and almost every user type, despite their technical skill levels, use them. Browsers are made initially an audience, and to shape into a perfect fit for a person.

What makes firefox so great? Why do people love it so much?

Personalization

Thats right, the ability to add their own plugins, and set up features just the way they like it. Every time I use internet explorer or safari on a friends computer, it almost always feels the same, with firefox, it feels different. Every time you open it up, the user has different plugins, different awesome-bar results, themes, etc. Google knows that the browser is a personal experience, hence their implementation of the uni-bar idea in the Google Chrome browser.

But I digress, my point is, that the browser becomes a personal experience, it knows what you commonly open, it can save passwords, it can hold bookmarks, and when you go to a different computer, it just does not feel the same. So how do you make your computers feel the same, when you go from your desktop to your laptop, how do you keep everything you have on one with the other. The answer is simple: Weave.

Weave is a plugin for Mozilla Firefox being developed in Mozilla Labs. It allows you to sync *everything* in Firefox, from search results, to bookmarks, to your open tabs, to your passwords, and whats more, it does it securely. Thats right, a completely secure way to transfer all of your data.

For the more technical readers, the security system goes something like this. You create a name and a password on the server so you can retrieve your data. Then your data is encrypted by a locked key. When you try to retrieve your data, it first sends you the key that you must unlock with a super secret passphrase. Everything you send is encrypted before it hits the server and is decrypted only at the end computer. The server has no way to read the data since it never sees your passphrase.

Right now, this program is still in heavy development, eventually it will let you sync plugins and eventually even sync your bookmarks with mobile devices. Everything is open and new ideas are as always welcome to this project. I highly recommend everyone takes a look at this. Worst comes to worse, if your computer crashes, your bookmarks will be safe. :P

Sunday, June 21, 2009

Linux VS Mac VS Windows

I am tired of the constant battle of computers on which is better. Some people are completely set on windows and will defend it to the very end, others insist on the ultimate power of the mac, and finally, a handful stand strong for under-appreciated Linux.

People constantly say one is the best for everything, but anyone who has worked with computers long enough knows that there is not necessarily one best solution for everything. So therefore, I will try to lay out clearly and in plain english the advantages and disadvantages of the three in the way that I see it.

Windows

Although this applies to most modern windows platforms, I would like to note that I tend to use Windows XP more than Windows Vista, so the review will tend to favor that version.

Advantages:
  • Most common OS in the world, with millions of apps worldwide made for it
  • Easy to use, yet with a decent degree of easy to get to control.
  • Program for anything you need, almost anything you can find on another OS, you can find on windows
  • Standardized installers and all applications have a very uniform look and feel
  • Computer itself with basic OS is cheapest
  • Can be virtualized
Disadvantages:
  • Worst memory management of the three
  • Difficult to customize
  • Applications have to be updated separately using their own updaters
  • Common Microsoft apps are expensive, plus licensing issues can crop up.
  • Most computers put a lot of trialware and "crapware" on the new computers, making them feel slower.
  • Drivers can sometimes be hard to locate, not work right, or be difficult to set up
  • Although sometimes faster virtualized, it is slightly less efficient as a host and with less virtualization optimizations.
Mac
This is based off of primarily OS X, Leopard.

Advantages:
  • Most ease of use
  • Consistent interfaces
  • Can run *some* windows apps in wine and some have Mac candidates
  • Most linux apps can run on Mac OS X, but not all
  • Easiest Application installation
  • Consistent Hardware (No hardware incompatibilities or bad drivers, its all made by mac in a controlled environment to allow for this better compatibility.)
  • Most things just work
  • Better memory management
  • Can run other OSs in a virtual machine with high efficiency.
  • App Suites are mostly automatically updated through one updater
  • Always *feels* fast due to handing off a lot of graphics to a dedicated GPU.
Disadvantages:
  • Hardest for fine control and extreme customization
  • Expensive Expensive Expensive
  • Not *all* applications get a central updater, just some
  • Some drivers just are not available for the Mac
  • Cannot write to NTFS formated disks, which is the most common format for USB disks that are used on windows computers.
  • Takes some getting used to if you tend to use other OSs such as Windows or Linux
  • Cannot be virtualized
Linux
This is based on general Linux experience, although I tend to use openSuSE, Fedora, Ubuntu, Debian, and some other random distros.

Advantages:
  • Tons of options and choices
  • Drivers for almost everything, possibly the most compatible OS
  • Runs on almost anything, even low powered computers
  • Free, office suite and all
  • Most distros have a single updater which means less background update processes
  • Most customizable
  • Applications for everything
  • Best virtualizing host and memory management.
  • Most degree of control and can be optimized for ones specific machine the best
  • Can read and write NTFS from windows and can dual boot them all
Disadvantages:
  • Tons of options and choices
  • Complex install and requires knowledge about the OS (AKA, steep learning curve)
  • Highly inconsistent interfaces and many options
  • High terminal text based use
  • *Feels* the most foreign to new users.

It is ironic, Linux's best asset is also its worst pitfall. It is so customizable and so optimize-able, that it sacrifices simplicity. If you look, I found less disadvantages, but the disadvantages are more notable to the average user than the other two OSs.

It is important to note that these are *not* the only three operating systems out there. Others still exist, although these three are commonly considered the most viable for desktop operating systems.

This comparison is geared towards those who have a moderate to low knowledge of computer operating systems, so if you have any questions, feel free to ask them in the comments.

Friday, January 2, 2009

User Interface Remixed

Although used by systems engineers and many computer experts, the command line has been a dying art. When the debate of Linux vs. Windows is brought up, one of the most common points is that in Linux, you get a much greater degree of control due to the still powerful command line. Windows users can respond to this that it is harder to use and slower to do basic functions we can do every day.

But what if these two ideas where combined. Using existing point and click interfaces, yet enhancing them with command line like abilities. This is the idea behind Ubiquity. They have taken the idea of user interaction to a whole new level through their innovative method of graphically issuing commands. Lets say you are reading the tabs for Blackbird by the Beatles on the guitar. Its great to read the notes, but it would be so much better if you can hear the music, so you simply activate ubiquity, and start typing youtube blackbird and it will give you options as you type. When you select one, it will automatically move you to a new tab with your music.



This is just a snap of one of the search functions Ubiquity can do, however it can do a lot more. Lets say you have a section of text that is in Russian. I cannot read Russian at all, so I would just highlight it, and issue the translate command. Ubiquity automatically picks up the selected text and knows my default language. It can also create emails on the fly, update your facebook status, and more.

And the best part of this, is the core design is made so that it allows people to make additions easily. You can write simple scripts in javascript and add it locally, or you can load it online and it will automatically add to the herd. A collection of commands that the community can share to make the application even better.

It is so easy to make a fully functional command, that I was able to make a simple command myself in less than five minutes. The page for the command is avalible here in case you are interested.

Although I will admit, Ubiquity is still in beta with the version checking in at .2 just recently, I can easily see this plugin as where the web as a whole will move. More powerfull interfaces that allow us to exert an amazing amount of control over our web expirence. These interfaces will let us interact and alter our view of pages on the fly. We will be able to take links to youtube videos, highlight them, and play them on the same page where the link used to be. We will be able to reformat data on a page into graphs on the fly, and email data forms easily.

I encourage anyone and everyone to watch this tool, I can easily see it becoming integrated into the next version of firefox, maybe even integrated into the uni-bar at the top itself.

If you have any questions or would like to make your opinion known, feel free to make a comment.