Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
User Journal

Journal Chacham's Journal: Rant: Android namespaces and ids 3

I hate Java, i hate Android development, but i repeat myself. And that's exactly what i hate about them.

In Android, objects have their own namespaces, under R. There's R.class, R.mipmap, R.layout, R.color, R.integer, and many more. So, the namespace of the layout (where you usually add objects) is under R.layout, the image on a button can be under R.mipmap. Nice.

However, if you want to refer to an object, you need its id. The way to add an id is to add the android:id attribute to the layout, or via the object's setId() method. In either case, the id is kept under R.id. This makes for a common line of code Button button = (Button) findViewById(R.id.id_of_button);

The reason is, in order to get a reference to the button, you have to find it first, and that is done via the button's id. Of course, since everything is stuffed under R.id, it must be cast to the appropriate type. (Ultimately, it's just an int.) This makes sense, as long as you are braindead.

First of all, there ought to be a way to directly reference an object by its container, if not an array of all similar objects. At the very least, this would provide a sensible naming scheme, for the object or container would be the parent. By shoving everything into R.id, people add the object type to the object name. A certifiable scheme by the Department of Redundancy Department. Furthermore, if i'm adding an id, i shouldn't need a method to find it, i should be able to refer to R.id.id_of_button directly. Instead, R.id.id_of_button is just a pointer, and findViewById() turns that pointer into a value. Really?! What morons come up with this stuff? Instead of the name being a reference to the object, it is a reference to a reference to the object.

But a reference to a reference isn't convoluted enough. We're going to put them all in the same namespace, so you have to add the type to the name, and even after that, cast it to make sure you have the right type.

It hurts when i see tables Customer.CustomerId. Even if the name is to avoid naming the table in each reference, at most you saved a period, and in many cases, you have to put it back in anyway, if only for clarity (so you know that it's from a table of the same name, and not just an attribute in another table) or when there are more than one column of the same name (much as they try to avoid it). Why do they do this? The solution creates the problem.

I'm beginning to think you have to be braindead before coding for Android.

This discussion has been archived. No new comments can be posted.

Rant: Android namespaces and ids

Comments Filter:

"Experience has proved that some people indeed know everything." -- Russell Baker

Working...