Monday, 28 May 2012

Exception Help

Keep find myself searching which exceptions to throw when, in regards to 'this code should never be reached' exceptions. Found a great post by Kevin Bourrillion, a software engineer at Google, which can be found here. Which I've copied below.
I've noticed a lot of confusion about what type of unchecked exception is the right one to throw under various circumstances. Here's a very simple explanation of the most common types.

Multiple schools of thought on this one. Of course, it's thrown automatically by the runtime when you try to dereference null. Many say that you should never rely on this behavior, and should always check for null explicitly. Many also believe that when you find a null reference, you should throw IllegalArgumentException instead of NPE. This way, a thrown NPE always indicates some programming error in the implementation of the method, not a failure of the caller to pass valid parameters. I'm not taking a stand on this issue right now.

Throwing this exception implies that there exists at least one other value for this parameter that would have caused the check in question to pass. If the caller can't remedy this exception by substituting another value for the argument in question, it's the wrong exception to throw. Note that in some of these cases IndexOutOfBoundsException is more appropriate (and strangely, IOOBE doesn't extend IAE).

This exception implies that there are no argument values that could have caused the check to succeed, yet, there does exist at least one alternate state that the instance in question could have been in, which would have passed the check. Note that this type almost never makes sense for a static method, unless you rely heavily on static state (shame on you). Note also that this exception is appropriate whether or not it is possible to actually mutate this aspect of the instance's state, or it's already too late.

This means that the method invoked will always fail for an instance of this class (concrete type), regardless of how the instance was constructed.

This is the right exception to use whenever a statement should by rights be impossible to reach.


Monday, 20 February 2012

By The End of 2012, I Will [Continued]

An update on this, as we are almost 2 months in.

1. Books read: 
The Stand, by Stephen King.
A Brief History of Time, by Stephen Hawking.

Currently reading:
Cell, by Stephen King

I'm not counting these but I'm also reading / have read a bunch of MLP fan fiction.
My Little Dashie, by ROBCakeran53.

Heonnshy, by Fenix.
And a bunch other short one chapter stories not worth mentioning.

2. Marathon Training:
Got a stationary bike and riding that on occasion. Making progress and that's the main thing.

4. Flip:
Not much done here. Doing handstands and stuff. Surely my overall fitness increase is helping this too.

5. Android Game:
Another game. This one based on Raiden.
Also have a working prototype. Doing this one straight to Android instead of coding to PC and then porting, like I tried with the last one. Once I get the prototype working, I'll post it up here.

6. Foods:
Had some Takoyaki a couple weeks ago. Pretty damn good so had some more this week again. That will do it for me, but I'm going to keep eating odd stuff where I can.

3. 7. 8. 9. 10. The rest:
Yeah, nothing. Some of these are one off things that I don't really need to prepare for, and will just happen when they happen.

On a funny note, this guy:


Tuesday, 24 January 2012

By The End of 2012, I Will

Walking down the road and I saw these on the bus stops. Pretty awesome really.

And so, here is my list.

By The End of 2012, I Will:
1. Read 12 books. (I don't read enough)
2. Run a marathon.
3. Get my full drivers licence. (Seriously, that's long overdue)
4. Do a flip.
5. Release something on the Android market.
6. Try a food I've never tried before.
7. Walk along the train tracks. (I'd walk for weeks if I had the time)
8. Catch a bird with my bare hands.
9. Experience free fall from a great height.
10. Learn all the first generation Pokemon in order.

What are you going to do?


Friday, 20 January 2012

A message from TPB

With the take down of MegaUpload I thought I was due another post. Below is the latest press release from ThePirateBay. Link to original. And yes I will get round to a post of Tor because it is well worth knowing about.

Over a century ago Thomas Edison got the patent for a device which would "do for the eye what the phonograph does for the ear". He called it the Kinetoscope. He was not only amongst the first to record video, he was also the first person to own the copyright to a motion picture.
Because of Edisons patents for the motion pictures it was close to financially impossible to create motion pictures in the North american east coast. The movie studios therefor relocated to California, and founded what we today call Hollywood. The reason was mostly because there was no patent. There was also no copyright to speak of, so the studios could copy old stories and make movies out of them - like Fantasia, one of Disneys biggest hits ever.
So, the whole basis of this industry, that today is screaming about losing control over immaterial rights, is that they circumvented immaterial rights. They copied (or put in their terminology: "stole") other peoples creative works, without paying for it. They did it in order to make a huge profit. Today, they're all successful and most of the studios are on the Fortune 500 list of the richest companies in the world. Congratulations - it's all based on being able to re-use other peoples creative works. And today they hold the rights to what other people create. If you want to get something released, you have to abide to their rules. The ones they created after circumventing other peoples rules.
The reason they are always complainting about "pirates" today is simple. We've done what they did. We circumvented the rules they created and created our own. We crushed their monopoly by giving people something more efficient. We allow people to have direct communication between eachother, circumventing the profitable middle man, that in some cases take over 107% of the profits (yes, you pay to work for them). It's all based on the fact that we're competition. We've proven that their existance in their current form is no longer needed. We're just better than they are.
And the funny part is that our rules are very similar to the founding ideas of the USA. We fight for freedom of speech. We see all people as equal. We believe that the public, not the elite, should rule the nation. We believe that laws should be created to serve the public, not the rich corporations.
The Pirate Bay is truly an international community. The team is spread all over the globe - but we've stayed out of the USA. We have Swedish roots and a swedish friend said this: The word SOPA means "trash" in Swedish. The word PIPA means "a pipe" in Swedish. This is of course not a coincidence. They want to make the internet inte a one way pipe, with them at the top, shoving trash through the pipe down to the rest of us obedient consumers. The public opinion on this matter is clear. Ask anyone on the street and you'll learn that noone wants to be fed with trash. Why the US government want the american people to be fed with trash is beyond our imagination but we hope that you will stop them, before we all drown.
SOPA can't do anything to stop TPB. Worst case we'll change top level domain from our current .org to one of the hundreds of other names that we already also use. In countries where TPB is blocked, China and Saudi Arabia springs to mind, they block hundreds of our domain names. And did it work? Not really. To fix the "problem of piracy" one should go to the source of the problem. The entertainment industry say they're creating "culture" but what they really do is stuff like selling overpriced plushy dolls and making 11 year old girls become anorexic. Either from working in the factories that creates the dolls for basically no salary or by watching movies and tv shows that make them think that they're fat.
In the great Sid Meiers computer game Civilization you can build Wonders of the world. One of the most powerful ones is Hollywood. With that you control all culture and media in the world. Rupert Murdoch was happy with MySpace and had no problems with their own piracy until it failed. Now he's complainting that Google is the biggest source of piracy in the world - because he's jealous. He wants to retain his mind control over people and clearly you'd get a more honest view of things on Wikipedia and Google than on Fox News.
Some facts (years, dates) are probably wrong in this press release. The reason is that we can't access this information when Wikipedia is blacked out. Because of pressure from our failing competitors. We're sorry for that.