Monthly Archives: July 2011

Using this when referencing a member variable

Originally I wrote this whole article using the words “global scrote” instead of “global scope”. My intention was to include a picture of the world inside a scrotum. It was going to be hilarious. Then I had to switch it all back after I started searching for a picture of a scrotum that would be suitable to Photoshop the earth into. I just couldn’t any more. Urgh!

Anyhow, back in 1999 I started learning Object Orientation and Java. I learned that you used the keyword this to denote that you are talking about the class you are currently in. So you could have something like this:

public class bar{
    private Int abc;
    public function foo()
    {
        this.abc = 21;
    }

    public function foobar()
    {
        this.abc = 92;
        this.foo();
    }
 }

It made sense.

Recently I have been playing around with Adobe Flash and Java. I’ve noticed is that there’s no requirement to use the keyword this. I really want to say how this is wrong, and how the language designers have made a poor decision. I have no idea how I can say those things and be taken seriously. Taking into consideration the small fact that I have a total of maybe 6 months experience in both of those languages combined, I can’t help but feel the language designers have a bit more knowledge on the subject than I do. So it probably makes sense in the larger context.

Having said that, I have no idea why this was allowed. I think Java and code written OO in general have large increases in verbosity compared to non-OO. The verbosity allows for readability and maintainability.

Coming from a background where my professional coding has largely been PHP, where PHP allows for (but frowned upon) functions and variables to be defined in a global scope I have learned that you ALWAYS ALWAYS use this. You have no idea whose code you have inherited and you have no idea who will inherit your code. Using this does two things:

  1. In the case of the function, this.foo(), tells you that the code to be executed is the code defined in the function just in this class. No matter if someone defines a foo() in the global scope outside of the file and includes it into the local scope the function in the class will always be run.
  2. In the case of the variable, it says we are using the variable defined inside the class we are currently in.

In the case of point 2 above you may think: “ok… yeah so?”. Well take a look at the code below. This is an example of the code I have been seeing in the Java examples and tutorials:

public class bar extends kablah{
    private Int abc;
    public function foo()
    {
        abc = 21;
    }

    public function foobar()
    {
        abc = 92;
        foo();
    }
 }

That just seems confusing to me. Maybe it’s because I come from an environment where global scope was allowed (but frowned upon as the language and its developers matured). If I am looking at function foobar(), I think ok fuck where does this variable come from? What was it’s previous value, should that really get changed. Do I need to worry about it. Let me try find out. Then (in larger classes) you have to go searching to find out it’s a member variable. Same with the function foo(), I spend some mental energy thinking where is that function defined what does it do (this is even more of a problem if the functions don’t have descriptive names)?

Not entirely sure if I should stop here. Basically I answered myself. It is my PHP background that is causing confusion. With Java everything is an object, so if you started on Java and you see foo() you know that it refers to the current object. Where as if you come from maintaining really old PHP4 code as I have, you have seen some really horrible bugs from people using calling functions and variables defined in the global scope. “How the fuck has this variable changed it’s value?!!? This code isn’t even executing!!?!?”

It’s probably just a choice of style and makes no difference (I am not sure if this is always the case and there may be some special cases in more advanced or fringe OO techniques) but I think using this makes it implicit and adds to the readability. So, I’ve come to the conclusion that I will use this and attempt to incorporate what I have just learned into my frame of reference.

Edit: Turns out it does make a difference if you use this or not in java. Which is what I think Jon was trying to tell me in the comments. If you look the example code below

 

public class bar extends kablah{
    private Int abc;
    public function foo()
    {
        abc = 21;
        Object anObject = new Object();
        anObject.setSomething(new Asdf{
            public void barfunc(){
                foobar();
            }
        });
    }

    public function foobar()
    {
        abc = 92;
        foo();
    }
 }

In the anonymous inner class defined by new Asdf we call foobar(). If you invoked the function using this.foobar() it only looks for the class inside the anonymous inner class. If you don’t use ‘this’ the scope will start locally and then be expanded until the function is found.

Motorola Droid Bionic [pics] – Unlock Hidden Functionality

The Motorola Droid Bionic. The latest feature to be added to the Motorola Droid Bionic, the company’s new flagship smart phone, is the ability to fuck you in the ass. I know some of you may be thinking: “Finally! Smart phones have finally reached the pinnacle of human technology!” The truth is this is nothing new. This feature has been included in many of Motorola’s older products including the original Motorola Droid, the great-great-grandfather of Motorola Droid Bionic. It’s not common knowledge, but this feature can be unlocked on nearly all of Motorola’s mobile products, including the soon-to-be-released Motorola Droid Bionic.

The best part about accessing this functionality is that you don’t have to root your phone, you don’t have to download an app. It already comes standard with the phone and will DEFINITELY be included in the Motorola Droid Bionic.

You may be wondering how you can do this on your phone. Well, I was one of the first people to get hold of and become a proud owner of the original Motorola Droid. I’ve been really happy with it. I shouted its praises at anyone willing to listen. Imagine my joy in finding new abilities on an old piece of hardware that I already thought was amazing.

Anyways enough teasing. In then next few paragraphs I will explain to you how to unlock this functionality so that your own Motorola phone can fuck you in the ass. So without further ado:

Unlock the ability to get fucked in the ass with the Motorola Droid Bionic

Motorola Droid Bionic - The fuck machine
  • Step 1: Use your phone as normal.
  • Step 2: Wait for a fault that you yourself are unable to fix.
  • Step 3: Send it to the repair centre listed on Motorola’s own website.
  • Step 4: Hear nothing. Wait a week.
  • Step 5: Phone the customer centre. Listen to them tell you they have no idea where your phone is… even though it was tracked and you can see that someone has signed for it.
  • Step 6: Send a few emails, wait a week.
  • Step 7: They find your phone and email you to tell you they will send you a quote.
  • Step 8: Wait for the quote, receive nothing.
  • Step 9: Call them up. Get told you’ve already been sent a quote and they have been waiting on you all this time.

That’s it! You’ve been fucked in the ass. As you can see it comes standard with every Motorola phone.

The best part is the feature has lasting effect and with the last few steps probably being:

  • Step 10: Pay through you teeth for this shitty service.
  • Step 11: Maybe get your phone back.

SBE Ltd UK, the company behind Motorola’s customer service, is shit. LG uses them too as does T-Mobile. If you can, avoid these companies at all costs. This is NOT an isolated incident. Support is a big part of the product. If you don’t have good support, you don’t have a good product.

Fuck you, a lot.

Comment Spam

I have been seeing an evolution of comment spam on here. It’s become really interesting watching it. At first it started off as gibberish: “Buy neat watches” with a URL included. Then over the years the content has been increasing in sophistication.

Hmmm… I forgot what I was saying… anyways… so yeah… some of it’s been getting really sophfisty. It’s been really well written with next to no spelling errors and almost even coherent. Something like this: “As a internet resource for organizations and technology enthusiasts to stick to the newest and greatest developments in Unified Communications, IP Telephony, Hosted Communications and VoIP” and of course a URL is included. So stuff like this, if it’s not caught by the spam filter I would spam anyway. I might let it pass if the comment was on topic which in most cases would mean the person was real.

The most recent type I have been getting is this: “It appears that you’ve put a lot of effort and hard work into your article and I require more of these using the net currently. I sincerely got a kick from your post. I don’t really have much to speak about in response, I only wished to comment to reply wonderful work.” A URL is also included. How am I supposed to Spam that? It’s validating my ideas, telling me I’m worth my salt, the spelling and grammar is impeccable (if it’s not, it’s much better than mine). The meaning is not fully there but I understand what they are trying to say. My ego wants me to approve it, it wants me to show you all: “Look, look! Someone thinks I am awesome. Look at my badge of awesomeness given to me by a unknown third party… which makes it more valid than when my mom tells me that I am cool… or when I look at myself in the mirror and say: ‘you are awesome’.”

I spammed it. The URL they included was to a halitosis clinic in Germany.

Question Mark inside Angled Brackets in Java?

Edit: Thanks to Jon Ellis for some clarification.

Edit 2: Added more context to the code.

Edit 3: Thanks again to Jon for more clarification.

I came across something like this while following an android tutorial:

import android.widget.AdapterView.OnItemClickListener;

public class HelloLinear extends Activity
{
  public void onCreate(Bundle savedInstanceState)
  {
    ...
    gridview.setOnItemClickListener(
      new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
          Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
        }
      }
    );
  }
}

If you look at the line with the colours, what the hell does that mean?

A quick Google search led me to a tutorial on Generics in Java.  Turns out the question mark is called a wild card. I am not entirely sure on the full meaning of that line as my goal is to get just enough information to carry on with the tutorial. So having said that, what I think it is saying is: The onItemClick() takes as it’s first parameter a construct of AdapterView of an unspecified type. The collection can referenced using the variable name parent.

The reason I added more context because I kept staring at this code as there was something else that was not sitting correctly with me. Look at this my original understanding (because I was applying dynamic type rules from JavaScript) was It was a class definition (HelloLinear) containing a function definition, containing a function call which instantiates and maybe even possibly defines an OnItemClickListner class, which then defines a function.

Turns out I was way off. What is actually happening is we are defining a HelloLinear class which defines the onCreate() function which calls the gridview member function which takes as a parameter, I think, any object that implements the ALREADY defined OnItemClickListener interface (which I should have seen from the imports) which is required to implement the onItemClick function. I guess what I was struggling with is that I was not aware you could firstly, instantiate an interface… or secondly instantiate an interface AND define a function inline. Or was it you could instantiate interfaces and it’s the abstract class you can’t instantiate? Or is that just a java thing?

Turns out the new keyword is used slightly differently to what I am used to. The new keyword here is defining an “Anonymous Inner Class” that implements the OnItemClickListener interface.