Hey Brian, how are you so fast at implementation?

Hey everyone,

I just recently got this question from a colleague of mine. He’s also programming in Xamarin, but on the iOS side.

Anyway, back to the question. How do you get to the finish line first?

The first and foremost is to know about your health condition. I’ve seen people who were much lazier than others and come up with something just a tad sloppier than what could be better. Now about health, the healthier you are, the better you can think. That’s the main part of the journey.

The next parts are to learn and grow along with what you have. If something doesn’t work in the first 15 to 30 minutes, try something else.

Now for planning out solutions to something larger, I’d first ask myself what is needed. I’ll even draw it out if need be. The implementation part comes later.

Keep finding obstacles as well as what you know that exists in the code base. By the way, if you don’t know the code base enough, I’d recommend ReSharper by JetBrains. They assist me a lot when it comes to finding stuff quickly.

Also, here’s another important thing which is not to worry too much about details during this time. You can study this part on your own later, if you wanted.

Then once I know something works, I’d make the solution more elegant. Make it readable. Make it maintainable. Make it reusable.

I also learned about making passes before coming to the finalization stage. This means to have something in a working state, and then refactor when it comes time.

So those are some ideas that come from me. Go ahead and use this as a base, and then try it yourself. You’ll be amazed at how much better you’ll be doing your job!

Until next time!

Brian.

How to take the company’s pros and none of its cons

Hey everyone,

Today, I’m going to delve into the goods and bads of what is provided via the company. But, I think we should first ask ourselves what’s good and what’s bad? We have options like holidays, gym memberships, snacks, insurance, etc….

Is it a company’s holiday? Take it! It’s just one of those things that are given free to you, and plus if you are working on a salary basis it’s what you are owed via work standardization. Otherwise, if you don’t use it, then it’s gone. That time cannot be taken back.

If the company provides gym memberships for free, take it and use it! If not, then I’d first compare rates and the different offerings with other contracts to find the best deal for you. Health is an important aspect of life, but at the same time, you can also have a small gym with the activities you like at home.

Snacks? Depends. What I usually do is look through the ingredients before consuming stuff. We as developers have a problem which is sitting and staring at the screen all day already. Therefore, we need to watch our sodium, cholesterol, and sugar intake. All of this counts towards productivity. Unfortunately, there are those who would be eating chips all day; I stay as far as possible from that as I am not willing to risk my health for such junk. Think about what is best for you, and stick with that.

Insurance? This is necessary by law living in America at this time of writing, at least for medical. In fact, I opted in for an HSA this year since this is a smart way to save your money. So look at the best option for you, and then make a decision. Everything else is voluntary, but it will be worthwhile only if it’s going to be used.

And all other factors? Again, you decide what is best for you before doing anything, because before considering everything else around you, you must love yourself.

Until next time!

Brian.

Getting a solution that is simpler than what another person has posted, an example…

Hey everyone,

A little bit before, I had posted on getting to a better solution. If you haven’t read it yet, you can find it here: http://improvisedcode.com/2018/08/29/getting-a-solution-that-is-simpler-than-what-another-person-has-posted/

Today, I am going to focus on an example of that. I came across this problem: https://stackoverflow.com/questions/3554377/handling-click-events-on-a-drawable-within-an-edittext

The answer by aristo_sh works, sure. What I see that isn’t pretty however, is that this touch event will trigger anywhere, and it will be ignored outside of the drawable. And although the check will handle the job well, there’s another problem to deal with: justification!

And what we mean by justification is how your layout draws depending on the region and language. In the solution posted above, there is no justification. aristo_sh’s solution is just checking on the right side when touched. The edge case is, what will happen with Hebrew? The event will be triggered probably within the EditText instead of the drawable! Not good…

I’ve learned that dealing with justification by using start and end instead of left and right will absolutely work for every language. However, typing up “GetEnd” or “End” didn’t come up with any result. Therefore, I knew this solution wouldn’t work for me.

So what I did instead was programmatically setup a transparent view, with twice the dimensions of the drawable that gravitates towards the end of my TextInputLayout (and in case you didn’t know, TextInputLayout is a child of LinearLayout), then set the top gravity to the negative of twice the drawable’s height before adding the view. This was great since I didn’t have to wire up any events I didn’t need for my EditText. Instead, I just had my click event for the transparent view that sits on top of the drawable.

It worked, and it was a lot simpler than the original solution. Therefore, it is assured that across all languages, this solution will also work.

Now, why is this better?

First of all, there is no checking involved. Secondly, it is just wiring up a view, and not any weird or extra EditText events. Third, it’s just another view that gets added onto a ViewGroup. Lastly, it is much easier to understand, and the next developer will certainly be happier of this choice.

Now it’s known that Google will rewrite their APIs quite soon. From now, we’ll have to see how much simpler they’ll be doing things versus the codebase that we will have to work with now, but I’m sure that there are always improvements to be made.

Anyway, I just wanted to share my two cents of what can be better. Therefore, just keep trying to find out the right way to do certain things!

Until next time!

Brian.

What do you gain going from Android to Xamarin.Android?

Hi everyone,

I’m betting many of you are asking about the benefits of going from Android to Xamarin.Android. In order to get here, the first question I’m almost always going to ask would be “why”?

The next question to ask is “is the project ‘new'”? In terms of “new”, this could be whether it’s new new, or this is scrapping the old codebase that there was once before, which is still being used, but replacing it with something that is to the point of a shareable workspace.

Because a couple of years before, it used to be that in order to use Xamarin alone, there was a fee. Therefore, it made more sense to just develop in a couple of platforms (mainly iOS and Android) because although iOS has always been $99 annually for renewing the developer’s license, in either case it was better to use the specific IDE that the device’s apps to build were designed for. For performance, this made the most sense. The drawback was that in business logic, there would be some that would have to be written twice both in Objective-C/Swift and Java/Kotlin.

Having said that however, Xamarin one of these days decided to become free. Therefore, in using Xamarin, the business logic can be written once and then run everywhere. The team doesn’t have to be as big either. Also, object-oriented programming principles still apply, along with learning curves of functional programming (but for old-timers, this isn’t a big deal). If you’re a learner, this is a big gain.

Let’s say that there’s a team of at least 3 in Android alone. This means having to split the cost for each person’s time, so then each developer will do certain tasks for the app alone. Copy this idea within iOS and now you have at least 6 people, which can get quite expensive fast. This is one reason why some startups don’t survive.

The next question to ask is whether or not the same app for both iOS and Android will have the same types of functionality, and also the formatting. It’s highly unlikely that the apps will have very different functionality, but if there is, then Xamarin will not be the ideal choice. But again, this is going to cost more for the logic, the backend development, and the mess that will be created. Therefore, I’d call this a loss, so the smarter choices will give better results.

Using Xamarin, one person can work on one platform. Then with any changes needed in shared code, multiple people can work on them. This makes the team smaller, and each person will learn about the different platforms of how they function. Questions will have to be asked. This is another gain for each developer using Xamarin.

Then, if the timing of design and development is done right, then the productivity should be a lot faster. This is for the company’s gain, but it also means your iterations will also look fast as well.

Finally, you’ll be sure that you’ll learn about your platform very well almost independently, and without having to rely on others. The only thing to rely on is Xamarin and its libraries that get maintained quite often.

But if you are just doing Android at this current time, I’d recommend trying Xamarin.Android for about 2 months and see how you like it.

Until next time!

Brian.

Getting a solution that is simpler than what another person has posted

Hey everyone,

I’m sure that the majority of us have looked over on StackOverflow for solutions to a certain problem. I’m also sure that we’ve done a copy and paste at one point or another. I’m sure that there are those situations where we take the source and then try it, and the test works!

So, as anything in life, there are some good, and there are also some bad. So, the question is how do we understand that it is bad?

First of all, I want you to think for yourself in terms of sitting there, looking at the code to get a general idea of what it does, then looking deeper into the source level, and then see if it fits what you’re trying to achieve.

Do you see any potential problems aside of the solution posted on StackOverflow?

If you see a red flag, then I’d think of another solution that’ll be the “same”, but “better”.

In fact, I saw one today and thought to myself the solution wasn’t worth implementing since there seems like some potential side effects that I couldn’t fathom with. Moreover, it was also complicated, and there was also an edge-case that I know wouldn’t work with that. And because I already knew that I’m unable to use the solution, I started looking into making one that I’m much more sure of which will work.

It is all about analysis before getting something done. Whether it’s writing whatever you need down in chicken-scratch, looking deeper on the internet for more answers, or asking another person about a problem, this is all going to give your application good performance, and ensuring that you did it right!

I’ll give out an example, but that’ll wait until next time!

Brian.

I’m stuck in a problem for quite a long time

Hey everyone,

So today, I was actually stuck on a problem for a long time. I’ve tried so many solutions that didn’t really help out. It was from looking at my own code where I wasn’t able to see anything wrong with it, towards listening to a task, down to rebuilding my view model again and disposing my listeners, down towards recreating my activity.

The last two options work pretty much the same way, with the exception of recreating all of your views and adapters (if any) which can be a much more expensive operation if you had to deal with many objects, versus dealing with maybe 4 or 5 items. Unless it’s better to do a recreation of an activity without worrying too much just as a page refresh, and if it takes at most 3 seconds to load the page, then that’s worth the change.

Anyhow, this post was more about being stuck on a problem. It turns out that the problem was laying under the shared code, and it was a boolean that was missing there that just didn’t provide the results for me on time!

Wow, now that’s not so easy to find. I had a second pair of eyes to take a look as well. And yes, although he had told me what I should try, I have already done most everything and it’s better just to say so. Therefore, it’s always better to know what you have done and then explain it as simplified as possible.

So that’s where the problem lies. Okay, I’m probably not too much of a genius, but I do know what I’ve tried. I also don’t want code that seems too complicated, or even spaghetti, otherwise it just seems like too much time and even trying to find out what each segment does.

However, that’s most of what our code looks like. But since I’ve learned to always try and simplify the code, it’s serving me quite well.

Therefore, remember that quality of work is always important. Otherwise, watch out and don’t let bad code pile up to a mess.

That’s all I have for thoughts, and until next time!

Brian.

Update as of… two weeks later, literally

Hello everyone!

Just as an update to say that I’ve been doing fine along with my ankle as of late. All that I haven’t done was follow up with the doctors.

Sure, the nurse practitioner might have said to me that I shouldn’t have been walking. However, I was already walking the next three days. Of course, the healing progression was slower, but even some of my colleagues told me not to worry about it, especially if I can handle it.

Granted that there are still some swollen places around the ankle, everything is walk-able and I’ll be expecting another two weeks until the ankle heals up fully. It is good that since we all work in the office using our keyboards, the foot doesn’t affect us as much! 🙂

Either way, I’m feeling great as things are turning out, so no worries there 🙂

Let’s get to the why I’ve got here. It’s all about the failure. Yes, failing is always going to be a part of life, and you need to do this in order to become better. Especially in programming since it takes around 6 months of continuous development to make something great. Specializing in one thing will also get you to dig down deeper into the why of something happening.

Therefore, if you’re failing at something, then just pick yourself up again and keep thinking about it. Draw it out if you need to. The key is “don’t give up”, and keep walking.

Until next time!

Brian.

How not to make the same mistakes

Hey everyone,

Have you found yourself seeing that you are doing something right, in which the end result turned out to be wrong?

Human error happens all the time; we don’t live in a perfect world.

This doesn’t only happen in the programming world, it even happens to the best of us.

I’ll give you an example of myself… I was inspecting my roof at my own home without using any ladders, and it was yesterday as a matter of fact. Climbing up the roof was fine. Why I did it was because repairs were required. By the way, I don’t have a ladder yet.

Now then, going down the roof, it seemed too scary for me to jump off a slanted surface, although the distance was a lot shorter to make the jump.

Therefore, instead, I did what seemed fine for me as a child. I used to jump off around 8 feet off the playground without any problems at all.

I did exactly just that, and then gravity hit my left ankle really hard. The end result? It got sprained.

And that was the error on my part.

As for myself, I’m turning 31 next month. It is not the same as 10 years ago; aging every couple of years will make you a little weaker than you think you can handle.

And guys, it may be better to have some money well spent in the now that will last for the next coming years. If I did invest in a ladder which costed not as much, then I would have been able to enjoy my weekend a lot more.

Now, I will have to make a trip to the doctor, which is a little more of a bummer.

Anyway, you maybe asking, where am I getting at with this?

The time to invest in your own self. That is like loving yourself first. After that, you can find yourself assured that you’ll do things a lot better.

Now as for my situation, I know what I shouldn’t have done, and I’m going to make it different the next time. So a high-risk, low-reward type of situation is very bad.

Anyway, that’s all I have. Today is a day’s visit to the doctor to see if there is anything wrong with my ankle.

However, until next time, for sure!

Brian.

For large objects, should I use WeakReferences or dispose until I’m done?

Hey everyone,

Short post today. I’m just giving some food for thought.

This post has come up since I’ve just done something that might be interesting for those of you. Especially, those of us who are dealing with high resolution images.

So, I’ve come across a very similar problem today along with what I’ve done before. Except before, I was always recycling and/or disposing my images. Now with what I had done before, these have worked quite well for me, though sometimes I can get unpredictable results like app crashes.

Even in RecyclerView, depending on the image being loaded, you can end up with a race condition. Hey guys, I get it; your image loaded is different than what you chose, so in this case I’d record the position under OnViewAttachedToWindow.

Now for the big question! Dispose my image, or use a WeakReference? The answer I’ll give you is, it really depends on your situation.

Let’s say I have a ViewHolder that also includes a bitmap that my ImageView will reference. In this case, I must keep track of the bitmap mainly in OnBindViewHolder and OnViewRecycled. Sure, this is more maintenance, but it helps me learn the inner workings of how a RecyclerView and its adapter works. Granted, this solution is good if you’re loading multiple images in your RecyclerView.

Now then, let’s revisit our RecyclerView that has a SnapHelper that loads one image (so like a full-page screen) per swipe. In this case, I am able to make a static bitmap which is under a WeakReference, and then therefore it’ll just load when I need it, or throw the bitmap away some time later when the system knows I’m really done with it. I played with this, and the Android Profiler provided good results with ram, along with my emulator that had a RAM threshold of 256MB! If the image nulled out for some odd reason, hey, I didn’t do it. Now having one image per page, one bitmap makes sense. If there were multiple images, I’d already be able to tell that this wouldn’t work so well.

So there you have it! Take your pick, and make it efficient 🙂

Until next time!

Brian.

What is that perfect amount of time for a vacation?

Hey everyone,

Just a question. When was the last time you had a vacation? Was it a week ago? Months ago? Years ago?

Whatever it was, maybe you’ve thought about getting another vacation, and some time soon.

If it’s the earlier option, you’ll probably want to hold off on it for the next couple of months. However, let’s talk about those who just had one at least some months before.

Maybe you are found that project quite boring, and that it’s time to maybe step up your game.

Vacation time is to recharge your batteries. You probably want to find that spark again, I’m guessing? If so, taking a long weekend vacation will be good (between 3 to 5 days). I’ve just done it as a matter of fact, and I think I have more charge for more capacity.

Maybe you’re looking into spending some time with family? I would say around 10 days is enough. Too much longer than that, and you’ll feel out of it like the cosmos has hit you to Pluto.

Unless you really feel out of it, and you’re ready for something new, then take that next challenging project and keep churning after a much longer vacation. Maybe you’re on hiatus, but this one is a long one. However, you can spark up a business idea and then implement that. It gives you some time to think through your life goals as well. It also will give you an opportunity to ask yourself what you’d like to do.

However, life can take us to many interesting places. Towards those travels, we can also navigate through our professions as well, however long it takes to solve a problem.

So the main thing to do would be to love yourself first. This way, you’ll be able to perform on anything that you’d like to do. This also enables you to keep rocking, rockstar 😉

Until next time!

Brian.