【转载】http://www.crazyjiang.cn/2017/08/06/android-best-practices/
摘录自How to become a better Android developer: 30+ bite-sized pro tips
觉得写得挺好,摘录下来,经常看看,激励自己
Becoming an Android developer is easy, but becoming a successful Android developer and standing out from the rest is not. It takes a lot of hard work, passion, dedication, and perseverance to become great at this job.
I can't show you any shortcuts, but if you are willing to put in the effort, you will surely get all the success you deserve.
To aid you on your quest to become a better Android developer, I compiled some bite-size pro tips from my experience. So whether you have just decided to jump into Android development or have been working as an Android developer for a while now, these tips will be relevant to you.
1. Get more familiar with the Android framework internals
(不要害怕去深入学习Android框架内核)
I am not talking about the documentation but the actual framework code. I have seen many developers who were afraid to dive deep into the Android framework internals. Don't be one of them. It's amazing how much you can discover when you see how things actually work and how the different pieces fit together properly.
If you need to up your Android game, stop shying away from the inner workings of the Android SDK and start befriending it.
2. Get over your fear of missing out (FOMO)
(学习是个循序渐进的过程)
Android is big, very big. You cannot learn it completely end to end in a month or three. And the more you learn, the more you will understand how much you don't know. As a beginner, it’s perfectly normal to be afraid that you're missing out on learning crucial information by trying to build things while still in a state of great ignorance, but try to get over it.
Learn the things that you really need to get started with the app you are currently working on and then slowly expand your horizon.
3. Start reading a lot more code
(经常去学习一些好的开源代码)
Most developers don’t take time to read what other developers are writing. And they spend most of their time writing what they already know.
But that will not help you grow as a complete Android developer. The only way to truly become a better developer is to read the excellent code of more experienced developers. You should start looking at other open-source apps and libraries, where you'll discover a lot of coding techniques and feature implementations that you had no idea about before.
Tip: Here is an excellent resource of some of the best open-source apps to help you get started.
4. Consider learning more languages
(学习一下其他语言:Javascript、Kotlin等)
I am not telling you to learn Spanish or Chinese, obviously. I'm saying you should learn new programming languages. You need to keep yourself updated with what is happening in the industry rather than confining your thinking to the Android space.
This will open up your perspective, inspire new ideas, and help you improve your Android development skills significantly. Make up your mind to learn one new programming language every year.
Tip: JavaScript is a good place to start if you don’t know it already.*
5. It’s time to learn Java design patterns
(设计模式)
I can’t stress enough how important this can be in your Android development career. Whenever you are stuck in trying to solve a critical programming problem, design patterns can be a lifesaver.
You also need to be on the same page with other developers, so that when they are talking about using a Factory, Decorator, or Facade pattern, you instantly know what they mean.
Make a promise to yourself to learn one new design pattern every week until you know most of them.
6. Start contributing to open source
(开源共享你的代码,其他人也能帮助你去优化)
If you have developed a library, plugin, or other useful piece of code and you're using it in your own app, consider open-sourcing it. There's much to learn in the process of contributing to open-source projects or maintaining your own. It's an excellent crash course in open-source development that will exponentially increase your value as a developer.
If you don’t have anything to open-source, consider checking out other open-source projects that interest you, and fix some bugs, improve the documentation, or write a few tests there.
Even the smallest bit of contribution (such as fixing some grammatical errors in the docs) will be helpful for the project maintainer to keep the project running.
Tip: Here is an awesome guide for you to get started in open-source development.
7. Make your IDE work for you
(熟悉IDE的使用:Live Templates)
Start spending more time in understanding the IDE you are using: Android Studio. It can do much more than you probably think it can. There are many cool features and shortcuts hidden in the IDE that most developers don’t even try to discover.
Make it a habit to discover new and better ways of making your tools work for you, thereby improving your workflow and productivity.
Tip: Here is an amazing article to help you master Android Studio.
8. It’s time to architect your app properly
(代码架构)
Most of the time we end up dumping all our code in the Activities or Fragments (I've committed this sin as well), turning them into gigantic God objects that are nearly impossible to maintain and test.
It is very important to adopt a good architecture for your app, such as MVP or MVVM. Separate your app’s business logic, view interactions, and data interactions into different layers so that they're easy to manage and test.
Tip: Check out these useful blueprints from Google to make your life easier with Android app architecture designs.
9. Learn clean coding guidelines for Android
(编码规范)
You can’t ignore this either, because it's really difficult to maintain the standard coding guidelines of Android development when working with developers who don’t write clean code.
It’s not rocket science, and it shouldn't take you more than a few hours to learn most of the fundamental Android coding guidelines.
Tip: Here is an excellent resource for you to start learning.
10. Spend some time learning about Android best practices
To give yourself an edge over other developers and build apps that look good and work well, you need to start learning some of the best practices of Android development.
Learn the dos and don’ts that will help you become a better developer and help your app stand out from the rest.
Tip: Here is a compilation of some of the best practices for you to make better apps.
11. Use your free time effectively by listening to podcasts
(可以花点时间去学习视频教程,比自己看代码更容易记住。视频教程也可能会提到很多自己不知道的小知识)
Try to use your time properly and effectively. When you are commuting, working out at the gym, driving, or cooking, your genius brain is not doing too much.
You can multitask at such times by listening to some Android podcasts.
Tip: Fragmented Podcasts and Android Developers Backstage are two excellent podcasts to start with.
12. Don’t over-engineer things. Be realistic.
I have seen this happen not only with me but with several fellow developers as well. Thinking about something before starting to work on it is good (very good, actually), but overthinking and overanalyzing lead to unnecessary confusion, delay, and anxiety.
Do what seems good for the project right now, and you can always adjust to the changing situations in the future as required.
13. Try to learn about design
(学习一点UI设计相关知识)
I can understand that as a developer your primary focus is on learning to write better code. But if you want to be a complete developer, you should start spending some time on learning and understanding user interface (UI) and user experience (UX) design as well.
This will change the way you look at the apps you have been coding. Try to talk and interact more with the UI and UX designers in your team to get better insight into app design.
Tip: Give this great book a read if you are interested in understanding how design works.
14. Start being a perfectionist
(没有最好,只有更好。保持激情)
"Perfect" is a subjective term, but as a rule of thumb, try to achieve the best possible version of the product that you are required to deliver, all the time.
Never settle for less. Don’t work on something just for the sake of it. Be passionate about the work you are doing, and do it better than the best. This will help you constantly grow and become a more successful developer in the long run.
15. Consistency is the key to success
(持之以恒)
If you want to be successful as a developer (or anything else in life), you need to be consistent.
Doing something for a few days or weeks and then quitting won’t take you anywhere. Don’t be fickle. Try to visualize where you want to be as an Android developer in the next few years and stick to your goal, whatever challenges come your way.
It is very easy to start doing something but very difficult to continue doing it with the same passion and dedication for a long time.
16. Start small. Expand slowly.
(任务细分)
As a developer, you should always try to break down any complex problem or feature you are working on into small, simple, and independent components that can be understood and solved easily and quickly.
Don’t get overwhelmed with the initial size or complexity of a project. Everything can be solved once you are on the right track. Start small, take baby steps, and then expand slowly.
17. Always have a playground project in hand
(读代码时,也需要自己动手写代码)
Having a playground project in progress can completely change the way you learn things. If you come across something new in Android somewhere, make it a habit to immediately give it a try in your playground project.
Suppose you come across an interesting Android library somewhere. Instead of just skimming the docs and the APIs, you should test it out in your playground project. This will give you a much better and deeper understanding of the library.
18. Start writing more tests
(动手写单元测试代码)
I can’t stress enough how important this is. You can’t consider a feature to be complete until you have written exhaustive test cases for it. Tests will help you build confidence walls across your code.
Don’t make the mistake of neglecting testing or considering it optional and making your life more painful with regression bugs later.
19. Consider adopting TDD
When you are developing an app, consider making the choice of building it in a robust and efficient way so that it can survive the test of time.
Consider following the “red-green-refactor” cycle of test-driven development (TDD). First, write the test case that will fail (red), then write the actual code to make the test pass (green), and finally, clean and optimize it (refactor).
“Test-driven development is a way of managing fear during programming. Fear makes you tentative. Fear makes you want to communicate less. Fear makes you shy away from feedback. Fear makes you grumpy. ”— TDD by Example
20. Set up a proper automated release mechanism
As a developer, try to spend as little time as possible on things that should be automated, such as app quality checking and release.
You should automate the quality-checking mechanism with tools such as CheckStyle, PMD, Lint, and FindBugs. Running all the unit and instrumentation tests before merging any major change is a must as well.
When all of these checks pass, you get the green signal to publish the APK to the Play Store or distribute it in any other way you want.
Tip: Consider automating the Play Store publishing process by using open-source tools such as this.
21. Embrace the reactive programming approach
If you want to up your skills as an Android developer, you should definitely consider embracing the reactive approach. This will force you to think in a completely different way when building your apps.
Going the reactive way will surely help you write interactive apps faster and make your development life easier and fun again.
Tip: Here is an excellent series to learn RxJava for Android.
22. Learn to use Kotlin for Android development
Since Google announced first-class support for the Kotlin programming language at Google I/O 2017, interest in the language has skyrocketed. This easygoing language brings a breath of fresh air to the world of Android development.
This is great news for Android developers who are bored working on the same old, verbose, and error-prone Java apps. Give it a try and see if it lights a fire of new inspiration in you.
Tip: Check out this awesome tutorial to get started with Kotlin.
23. Attend meet-ups, and be more social with other developers
(加入一些技术讨论组)
We developers tend to be quite introverted and like to sit in a corner with our computer, in our own world.
Try to move out of your comfort zone and interact more with other developers. There are lots of things to learn when you attend dev meet-ups and social gatherings or when you just talk to other developers who share interests similar to yours.
Tip: Visit meetup.com to find meet-ups that you are interested in.
24. Get familiar with keyboard shortcuts
(实用的硬技巧)
There are keyboard shortcuts for almost every action you want to perform in Android Studio. Learning these shortcuts will significantly reduce your development time and improve your workflow. Memorizing keyboard shortcuts might take some time, but in the long run, it will help you move toward a truly mouse-less workflow.
Tip: If you don’t want to memorize keyboard shortcuts in the old-fashioned way, here is an excellent Android Studio plugin to help you do it.
25. Try learning at least one new thing in Android every week
(循序渐进。逆水行舟,不进则退)
In the vast world of Android, there are lots of things to learn and understand, enough to overwhelm you when you initially step into it. But things will get easier if you make a commitment to learn one new thing in Android every week.
Make a list of all the things you don’t know, assign priorities to them, and start each of them one by one every week. After a few months, you will find yourself way ahead of where you started.
26. Automate anything that eats your time
(怎么省掉重复性工作: Live Template;沉淀自己所学,抽出公共模块)
We engineers are lazy by birth and always try to find an easy way to do a boring job.
So if you need to do something repetitive and boring several times a day, consider automating it. It will cumulatively save you a lot of time every week, which you can spend on doing other, more productive and useful things.
Tip: Have a look at Zapier, an awesome tool that can help you connect and automate several tools you use almost every day.
27. Consider running two versions of Android Studio
Always keep a stable version of Android Studio to do all the important things you need to do daily. But also consider keeping a canary, or beta, version of the latest Android Studio installed as well.
Sometimes there are lots of new and exciting features that make their way to these early builds that you'll want to try as early as possible.
28. Audit all your third-party libraries once in a while
We all love using libraries, and that’s perfectly fine when we need them, but make a habit once in a while of auditing all the third-party libraries you have added and removing the ones that you don’t need anymore.
If you are using only a small part of a particular library, consider extracting that part instead of retaining the entire library. An occasional audit will also help you update the libraries that urgently need it.
29. Learn better ways of refactoring legacy codebases
Do not make the mistake of refactoring a huge legacy codebase all at once. Doing so will put you in a trap from which there is no escape.
Instead, consider refactoring parts of the codebase that you need to work on right now and then slowly expand to other parts when necessary. Also, consider writing test cases for the screen you want to refactor before touching any code that you suspect might break existing functionality.
Tip: This book completely changed the way I work with legacy code. You should definitely give it a read.
30. Always develop and test on low-end devices
If you want to develop apps like a pro, never, ever make the mistake of developing and testing apps on high-end devices. Generally, we developers own high-end flagships and use them for developing apps as well. But this is something you should absolutely refrain from.
Try to get your hands on the cheapest, lowest-end devices you can find on the market, and make it a habit to develop apps only on those. You will start seeing a lot of flaws in your apps that you had no clue about before. This way you can prepare your apps for the larger segments of the world's population that don't have the best Android devices.
31. Buy the best work machine you can afford
(不要让设备影响到你的学习或工作)
Don’t make the mistake of buying a low-end work machine and ruin your development experience every day with it.
Consider using a Mac (over Windows) for development. You will fall in love with its simplicity and stability over anything else.
If you are purchasing a MacBook, consider getting the one with the best specs you can. You will thank yourself forever for making this decision.
Share your tips
Now that you have read and understood these tips, it’s time for you to convert them into action. I hope these tips will help you become a better Android developer.
If you have found this article useful, please consider recommending it to your friends, colleagues, enemies, or anybody you want via social media. And share your own Android development tips in the comments.