00 Guide How to Build High Quality Applications

00 Guide How to Build High-Quality Applications #

At the beginning of this year, I went to Shanghai to attend a mobile technology conference and asked many developers what they have been busy with recently. I was surprised to find that the most talked-about topics were user experience and application quality. Especially for those developers targeting Southeast Asia, they faced the challenge of dealing with devices with only 512MB of memory and the frustration of weak network conditions.

Building a high-quality application is not just about memory optimization and weak network optimization. On one hand, the environment we face is becoming increasingly complex. iOS developers in the past could never have imagined that they would need to adapt to different screen sizes and dual SIM cards now, not to mention the countless models, manufacturers, and operating systems on Android. If your application also has to go international, you will need to face the diverse languages and environments of dozens of countries.

On the other hand, our code and business have also become increasingly complex. Not to mention the large amount of “legacy code” that has not been maintained for a long time, the business itself is becoming more and more complicated. How can we manage dozens or even hundreds of modules effectively? Additionally, there are situations where various languages and frameworks such as React Native, Flutter, and TensorFlow are all piled together, along with complex environments and massive systems. Just the thought of building a high-quality application makes us realize how challenging it really is.

Starting from the Application Delivery Process #

Since building a high-quality application is so difficult, where can we start and what can we do? My approach is to treat the application as a product. Imagine the production process of a product on an assembly line. So, how can we ensure “quality control” at each step? This brings us to the topic of the application delivery process.

In my opinion, an application would generally go through several stages: development, CI compilation, testing, gray release, and deployment. What issues should we pay attention to at each stage?

  1. Development stage. During interviews, people often claim to be proficient in various development tools. But do we really understand them? Taking the time-consuming analysis tool Traceview as an example, what is its underlying implementation principle? Can we create a Traceview that has zero performance impact? Or how can we migrate it for use in production?

  2. CI compilation stage. How do we prevent the code from continuously deteriorating? How can we further optimize performance? What magical techniques do d8 and ReDex have? How can we make good use of static analysis tools like Coverity and Infer? This part may require some knowledge of compilation principles, and you will find that mobile development has many things worth exploring in depth.

  3. Testing stage. We often talk about agile development, with users being the best testers. It is painful for both ourselves and the users to repeatedly try and error online when encountering problems. We hope to achieve “left-shifting testing” and discover problems as early as possible. However, many times we don’t test not because we don’t want to, but because we can’t find any problems. So, how can we enhance our ability to identify issues in the lab? How can we simulate user interaction paths as much as possible? Testing is not easy, but combining automated testing with AI may help us solve some pain points.

  4. Gray release and deployment stage. After dynamic deployment became popular, many developers became lax. When there is a problem, they patch it. If one doesn’t work, they try two. If two don’t work, they try ten. How can we ensure product quality? Many online issues have very low probabilities and are generally difficult to reproduce. For example, for a user in India, we hope to have a remote stethoscope, rather than having to bring the user to our operating table.

In alignment with the application delivery process, let me introduce the learning methodology of this column. The “High-Quality Development” module corresponds mainly to the development stage, and you can study various skills required for development with the confusion encountered in practical processes. The “Efficient Development” module corresponds mainly to the CI compilation, testing, gray release, and deployment stages. By combining practical work, you can enhance the efficiency of the entire application delivery process. In addition, I believe that a good architecture can reduce or even prevent team errors, which is also a crucial aspect of building a high-quality application. Therefore, in the final “Architectural Evolution” module, I will discuss how to design a good architecture and how to select an appropriate architecture.

Image

Mobile APM Quality Platform #

Let’s consider whether our goals and approaches to achieving high quality are the same in each stage of application delivery. During the development stage, developers may want to collect as much data as possible. During the testing stage, testers may focus more on laboratory environments or comparing with competitors. During the grey and release stages, dedicated operations personnel may take a more conservative approach. It’s clear that our goals and methods for achieving high quality may vary across different stages.

It is common for companies to have multiple quality systems. We hope to have a unified platform that integrates application personnel and development processes, which is what we commonly refer to as the APM quality platform.

APM stands for “Application Performance Management.” I understand that domestic companies like Alibaba, Tencent, Meituan-Dianping, Ele.me, and iQiyi are investing heavily in this area. Google has also made efforts this year in Android Vitals monitoring, adding modules for power consumption and permissions management. So, what are the charms of an APM quality platform?

1. Unified management: Student A develops a time-consuming monitoring tool, while student B develops a memory monitoring tool. These tools are located in different repositories with different reporting formats, each having their own simple interface. If we want to evaluate the quality of an application, we always have to go to several systems to gather data. It can be quite cumbersome.

2. Unified across the three platforms: A company may have multiple applications, each with H5, iOS, and Android versions. We hope these platforms only differ in terms of data collection methods, while reporting, backend analysis, display, and alerting are all unified. With the advancement of technology, we may add monitoring for new modules like React Native and Flutter, so this platform should evolve in a unified manner. Of course, we also hope that the industry has an open-source solution that we can all optimize together.

APM Quality Platform

So what issues should this quality platform pay attention to? It depends on what matters to our users. Some issues may be critical, such as crashes, freezes, or blank screens. Another major category of issues is performance-related, including package size, startup time, latency, memory usage, power consumption, and network traffic. In this column, I won’t teach you how to build an APM platform from scratch. I hope that you will master the knowledge behind it, which mainly includes:

Knowledge

Due to the fragmentation of the Android versions and the chaotic nature of the Android ecosystem in China, or in other words, “Android developers are suffering, and Chinese Android developers are suffering even more.” At the Android Green Alliance Developers Conference held in November, application experience standards were introduced, which provided detailed definitions for compatibility, stability, performance, functionality, and security. I’ll share an image for you to see.

Application Experience Standards

While pursuing extreme performance, we also hope to further develop “green applications.” In this process, a comprehensive and powerful APM quality platform can be our solid support. Of course, for most small and medium-sized developers, we suggest choosing mature third-party services. However, understanding the principles behind them will be helpful in selecting suitable services and in our daily development work. After learning the above content, you will find that “performance optimization” is not as “unattainable” as it seems. We can gradually move towards becoming “performance optimization experts.”

However, we need to be clear that although a mobile APM quality platform can help us quickly identify and locate issues, monitoring cannot guarantee high quality. The key always lies with humans, not the system. Why is that? Let me give you two small examples.

In your work, you often encounter a scenario that I call the “feedback problem triple hit:” “Is it my fault?” “Can you reproduce it?” “Are your test results reliable?” Although an APM quality platform can reduce blame-shifting, some people’s approach is usually to add a null check when a null pointer exception is found or to add a lock when a concurrency issue is found. What is the real cause of the null pointer exception? Will the logic run correctly after the null check? Are there better methods or architectures to avoid this issue? These are the three questions we should really ask, deeply ingraining the “quality mindset” and genuinely striving for personal growth by digging into the underlying reasons.

The second example is that I noticed many people only start various optimization efforts when the problems become intolerable or when their bosses can’t tolerate it anymore, but then they drop them later on. We often use tactical diligence to cover up strategic laziness. The key to performance optimization lies in how to solve existing problems while quickly identifying new incremental problems. An APM quality platform can only assist us and cannot solve internal organizational mindset issues.

Summary #

At this point, you may have a question: How can we learn all these things in a small company? Indeed, it’s true that personal growth along with the company is the fastest and most precious opportunity, but not everyone will necessarily have such a chance. From my own experience, I encountered various difficult problems at Sogou and WeChat, and had plenty of time to research, which allowed me to grow while solving these problems.

Fortunately, nowadays people are more willing to share. In columns and technical conferences, we can see a lot of mature experiences and ideas for solving problems. On GitHub, we can find many excellent source codes. In this environment, we need to be patient, pay attention to details, conduct in-depth research, and take time to summarize.

Let me share my story. In early 2013, I went for an interview at WeChat. The previous part of the interview didn’t go too well, but I ultimately passed. Later, during a casual conversation with the interviewer, they mentioned that there was one thing that impressed them. In 2012, before LeakCanary was open source, I felt dissatisfied with using MAT for memory leak analysis. Why couldn’t it be automated? Why couldn’t I see the pictures in the Bitmap? At that time, I delved into the memory file Hprof format and made a few small innovations:

  1. Implemented automated testing for memory. After automated testing, I returned to the home page and obtained a memory snapshot of the application at that moment. I automatically analyzed the Activity instances in memory, and in a normal situation, there should only be one, so the rest were considered leaks. In order to support official packages, I also implemented the function of deobfuscating the Hprof file through the mapping file.

  2. Viewed pictures. Automatically converted repetitive and relatively large pictures in memory to PNG format and output them to files.

Nowadays, these functionalities may not seem too difficult, but if we look back six years ago, there weren’t many people who could think of and accomplish this. I shared this story hoping that you can take more time to think and conduct in-depth research in your work and practice. Many seemingly casual thoughts and innovations may have greater value in the future.

Homework #

“Though one may have learned much, if one has not put it into practice, one has learned little.” Only through practice, by applying what you have learned to your own projects, will you have a deeper understanding of the knowledge.

I have specially designed samples for you to practice in the “Homework” section of the column. I have also created a group for the column on GitHub called Group. I will gradually upload these samples to the group. The homework is mainly based on these samples. You need to understand the implementation principles and submit your learning summary and thoughts in the comments section below the column articles on the Geektime App. I, along with Geektime, have prepared generous learning encouragement gift packages for students who submit their homework seriously. The packages include classic books I recommend, Geektime weekly calendar, column code reading, and other gifts. I will also select students who persist in learning and sharing their experiences. At the end of Module 1 and Module 3, I will give away 2 tickets to the 2019 GMTC conference.

To better answer questions for students, I have invited my friend Sun Pengfei as the “Study Committee” for the course, and he will occasionally explain the implementation principles of our samples. Pengfei is a senior Android development engineer and is currently responsible for business development and performance optimization for a well-known online ride-hailing platform’s driver app. Our Study Committee has a deep understanding of system frameworks, virtual machines, performance optimization, and has rich practical experience. I believe that Pengfei’s participation can better help you master the key points of the course and solve problems encountered in practice.

Today is the course introduction, which officially begins our journey of learning for the next three months. Therefore, I especially invite you to introduce yourself in the comments section. Tell us about yourself, your current work, study situation, or specific problems and confusions you have encountered. You can also write about your expectations for this course, allowing us to understand each other better.

I hope you can actively participate and let us learn from each other and progress together.

You are welcome to click “Share with friends” to share today’s content with your friends and invite them to study together.