r/androiddev • u/[deleted] • Jan 26 '17
Casual Found this comment deep inside the code of ProgressBar
11
Jan 26 '17
Don't they at google use taskboard/todo list instead of writing them inside the code :D o
70
u/alanviverette Android Jan 26 '17
Oh there's an internal bug filed for this, too. It's just so awful that it deserved complaints in multiple places.
3
Jan 26 '17 edited Jan 26 '17
This comment has been there for a very long time along with other bugs I have filed/reportet. But they never seem to fix them why?
And another one is the method
context.obtainStyledAttributeswhich is either very bad documented or has a bug with the array attributes that it need in its parameter. I have two times reported a bug and both times nothing has happend6
u/alanviverette Android Jan 26 '17
The array has to be sorted. Create a styleable resource and pass that instead. In practice, you should never be constructing an array of more than one item and passing that to the method.
6
Jan 26 '17
I know that. But it is just not any where on the documentation of the obtainStyledAttributes. Its just an example.
9
u/bradbananaboat Jan 27 '17
Because no one gets a promotion by fixing old bugs that aren't a big deal.
12
u/sonnytron Jan 27 '17
Correction: nobody's boss gets promoted by having old bugs fixed.
You can definitely get promoted for having the diligence and technical capacity to find and fix complex bugs. The problem is your boss will never ask you to or have it added to any of your sprints.
And fixing shit that's not in your sprint is a fast way to get shitty performance reviews.4
u/LoneWulfXIII Jan 27 '17
If they're real issues affecting the stability of your product your management should be happy you found it and fixed it. Not saying a sprint should be full of fixing old code, but having a couple tasks for known issues each sprint should be part of maintaining a product.
All I'm saying is if you're working at a place that shames fixing old bugs just because they're not new features, find a new job.
4
u/prlmike Friendly Mike Jan 27 '17
You ever work at a big company? While there did you work on an app that's been around for 7 years? Now think about this app, I'm assuming it had a bug tracker, it's also safe to assume it had a backlog. Believe it or not Android is the same, just a big application that is not 100% bug free. I think I've reported a few dozen bugs in my companies bug tracker that have not been fixed it. It happens ☺️
1
u/pulse1989 Jan 26 '17
funny thing is on the Backstage podcast, they said they've just finished with an annotation processor that is supposed to help with these types of things.
1
8
u/kreempuff Jan 27 '17
Relatively new Android dev here, what's makes this bad code?
3
u/gabbo3 Jan 27 '17
This code makes a lot of assumptions about the object being operated on. Hence the comment; any descendant of LayerDrawable which doesn't satisfy the assumptions being made here could cause shit to proverbially explode.
This is why using
instanceofis usually (but not always) a design smell. It means generally that some object needs to know implementation details about another, which breaks encapsulation.-32
u/ajbiz11 Jan 27 '17 edited Jan 27 '17
Oh, you have much to learn
One, the to-do is what's funny
Two, what's bad is partially not shown, but the damage is mostly done. Whatever your object is gets stripped down pretty quickly if you tried making a custom progress bay.
22
u/ReggieJ Jan 27 '17
What?
9
Jan 27 '17
The same here. wtf
2
u/solaceinsleep Jan 27 '17
Can you actually answer his comment about what makes it so bad?
2
Jan 27 '17
I was replying to the comment that didn't give much sense by ajbiz11. But no. I havn't analyzed what is wrong the code.
-2
u/ajbiz11 Jan 27 '17
I was trying to say that this basically destroys any custom class. It'll nuke custom drawables and stuff
1
17
u/Mr-X89 Jan 26 '17
"We really need to remove this... At some point I guess"
37
Jan 26 '17
Every TODO ever
3
u/Iron_Maiden_666 CM11 Jan 27 '17
I've started putting dates for Todos. Let's see if it works.
3
Jan 27 '17
Why don't just add this TODO to your task manager instead.
1
u/Iron_Maiden_666 CM11 Jan 27 '17
Task manager like jira? I don't want management hounding me for adding tasks.
2
Jan 27 '17
You can have your own todo list. This list can even be shared with all developers in the team. Just a text file in a cloud will do.
2
2
u/CodyOdi Jan 27 '17
If you type
todointo Android Studio and hit enter it will automatically add the date for you.11
4
u/meyerjaw Jan 27 '17
It was either in Pragmatic Programmer or Refactoring but the best quote was something like, "Soon means never"
4
u/apallocarry Jan 27 '17
Why not type out full words with variables. It is not much harder to type out original.
0
Jan 26 '17
[deleted]
10
Jan 27 '17
In what situation should you create a descendant of LayerDrawable which is not a valid LayerDrawable?
2
u/Arkanta Jan 27 '17
And you shouldn't alter the platform's LayerDrawable for that method. What the hell is that isLayerDrawable() function?
0
Jan 27 '17
[deleted]
0
u/Arkanta Jan 27 '17
There's not only the layer case. Refactoring a isLayered property to the drawable base class doesn't make any sense, since LayerDrawable is a specialized Drawable, and can't be another kind of Drawable (like BitmapDrawable, so isLayered would only return true for LayerDrawable, and in my opinion that's bad design too)
The real issue is that Drawables (and many android classes) suck at cloning themselves. Many copy constructors are missing, or you can't properly clone a subclass of a drawable to another instance of itself. That's why the code checks for the type and tries to copy the drawable.
0
Jan 27 '17
[deleted]
1
u/Arkanta Jan 27 '17
We both agree that there are design issues, but disagree on the solution.
I don't think it does, because the base class should not be aware of every subclass there is. LayeredDrawable is just one special case, and only this instance (and its subclasses) can be layered: A drawable is layered because of this subclass, but is not a property of all drawables: it's just a special case, but the naming makes it kinda confusing.
You wouldn't add "isSQL()" to a database driver implementation base class/interface, as it shouldn't even know these implementations exist.There also are a lot of time where we have to do that because we can't alter the base class, and this happens a lot with the framework classes. It's not optimal but heh.
I'd also argue that making a ProgressBar widget shouldn't require an alteration of the Drawable class. What's really missing here is a proper .clone() on drawables.
0
Jan 27 '17
[deleted]
1
u/Arkanta Jan 27 '17
I am not assuming that: it is one kind of specialized drawable (it's even more obvious in XML since it has a really different syntax than regular drawables): https://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html
Any drawable that needs to be layered should build upon LayerDrawable. Most drawables don't need what would essentially be bloat to them.
I'd argue that there is no need for the lightweight base Drawable class to know this, especially since LayerDrawable is kind of a meta-drawable.
0
35
u/daroltidan Jan 26 '17
I've seen so much bad code in Google repositories that this doesn't surprise me...