android10 源代码_您想要(不要)在旧版Android代码中看到的10件事

android10 源代码

Android is a highly customizable platform, it’s free, and it evolves quickly. Furthermore, it’s available everywhere around us — on phones and tablets, smartwatches, TVs and in cars too. What’s not to like? Every day brings some innovation to Android and to its users, making Android a very dynamic environment. I will not talk about technical details; you can find a lot of articles on the Web on those topics, so I would rather share personal experience.

被A ndroid是一个高度可定制的平台,它是免费的,并Swift演变。 此外,它在我们周围的任何地方都可用-在手机和平​​板电脑,智能手表,电视以及汽车上也是如此。 不喜欢什么 每天都会为Android及其用户带来一些创新,使Android成为一个非常动态的环境。 我不会谈论技术细节; 您可以在网上找到许多关于这些主题的文章,因此,我宁愿分享个人经验。

It started when I joined a cool company, focused on its own products, with a team of highly experienced developers, and a codebase which had well-organized architecture for projects.

它始于我加入一家很酷的公司时,该公司专注于自己的产品,拥有一批经验丰富的开发人员,以及一个代码库,该代码库具有组织良好的项目架构。

That was what I thought.

那就是我的想法。

I was curious, full of enthusiasm and excitement to find out how will my work look like over the next couple of months. The disappointment came when I learned that one of the older projects finished two or three years ago was never touched again, not even maintained. I found out that the client was happy with it, used it daily and never asked for any changes. That was until they came up with a new list, some “easy fixes” from the user’s perspective. As you might imagine, these were not as easy as they thought — it required a lot of development and going deeper into details.

我很好奇,充满热情和兴奋,想知道我的工作在接下来的几个月中会是什么样子。 令我失望的是,当我得知两三年前完成的一个较旧的项目再也没有被触及,甚至没有得到维护时,也是如此。 我发现客户对此感到满意,每天都使用它,从未要求任何更改。 直到他们提出了一个新列表,从用户的角度来看,这是一些“简单的修补程序”。 就像您想象的那样,这些操作并不像他们想象的那么容易-它需要大量的开发并深入细节。

Guess who got assigned to this project!

猜猜谁被分配了这个项目!

At first, I thought: “Oh no, seriously, I came here for some Kotlin coding, to do some new stuff, do I really have to work on that thing?!”. The project was developed by an elder colleague some time ago, and a great thing was that he’s great developer and still at the company (I was very lucky, otherwise I would have had to do research by myself which would take at least 50% more time). One look at the project, and I knew I will have to work in legacy code.

一开始,我想:“哦,不,是的,我来这里是为了进行Kotlin编码,要做一些新的东西,我真的必须从事那件事吗?!”。 该项目是由一位年长的同事开发的,很高兴的是他是一位出色的开发人员,并且还在公司工作(我很幸运,否则我将不得不自己进行研究,这至少需要花费50%的时间)时间)。 一看这个项目,我知道我将不得不使用遗留代码。

Long story short, they wrote the code in Java (Kotliners know what I mean 😁), some design patterns were very recognizable, but some parts (as always when you need to hurry) were so messy. I accepted the challenge and got hands dirty. After I reviewed the code, the colleague answered many of my questions, explained some concepts and ideas behind the code. I was ready to start grinding.

长话短说,他们用Java编写了代码(Kotliners知道我的意思😁),一些设计模式非常容易辨认,但是某些部分(像往常一样急着需要)非常混乱。 我接受了挑战,弄脏了双手。 在检查了代码之后,同事回答了我的许多问题,并解释了代码背后的一些概念和想法。 我准备开始磨削。

Having a good project overview and understanding it is crucial to provide accurate time estimations which in turn allows preventing complications in the future.

拥有良好的项目概述和理解,至关重要的是提供准确的时间估计,从而可以防止将来出现复杂情况。

Working on someone else’s code can be frustrating, that is why you should always try to understand why was the code written in such a manner. Something which seems unclear at first can be understood by diving deeply into it. There is always a way to understand it if you are creative enough.

处理其他人的代码可能会令人沮丧,这就是为什么您应该始终尝试理解为什么以这种方式编写代码的原因。 一开始似乎不清楚的事情可以通过深入研究来理解。 如果您有足够的创造力,总有一种了解它的方法。

But even if the code is written in Java, like in my case, you do not have to drop-off Kotlin’s fancy features. As Kotlin language creators say, the language is interoperable with Java. This means that you can implement new stuff in Kotlin, which will be much more concise if written in Java.

但是,即使像我这样用Java编写代码,也不必放弃Kotlin的精美功能。 正如Kotlin语言创建者所说,该语言可与Java互操作。 这意味着您可以在Kotlin中实现新的东西,如果使用Java编写,则将更加简洁。

Also, that’s the best practice for Android, which I follow when refactoring or getting deeper into legacy code. Furthermore, Kotlin helps a lot in the case of re-factorization. It can take much more time to rewrite some code from scratch by using Java. So consider extracting some code to new Kotlin class, simplify it and use it in Java code.

另外,这是Android的最佳做法,在重构或深入了解遗留代码时,我将遵循该最佳做法。 此外,在重构过程中,Kotlin的帮助很大。 使用Java从头重写一些代码可能会花费更多时间。 因此,请考虑将一些代码提取到新的Kotlin类中,对其进行简化并在Java代码中使用它。

So, you got an Android project codebase and you are about to work on it but you don’t know what to expect.

因此,您有了一个Android项目代码库,并且您将要对其进行操作,但是您不知道会发生什么

👉查看Gradle文件 (👉 Look at a Gradle file)

Gradle files are sometimes ubiquitous for Android developers, yet they’re often treated as a necessary evil, or at least as a magic black box that does things but can always be a good point to discover your project. Before you start, check build configuration script with a bunch of useful information giving you a good project overview.

对于Android开发人员而言,Gradle文件有时无处不在,但它们通常被视为必不可少的东西,或者至少被视为可以做事的魔术黑匣子,但始终可以成为发现您的项目的好地方。 在开始之前,请检查构建配置脚本以及许多有用的信息,从而使您获得良好的项目概述。

👉外部依赖 (👉 External dependencies)

Dependencies will help you understand why the code is written the way it is. Also, allows you to include an external library or local jar files or other library modules in our Android project. It is worth to look at external dependencies along with the versions they are using. They will tell you what technological stack was used and familiarize you with concepts used in the code you will work on.

依赖关系将帮助您理解为什么以这种方式编写代码。 另外,允许您在我们的Android项目中包括外部库或本地jar文件或其他库模块。 值得一看的是外部依赖项及其使用的版本。 他们将告诉您使用了什么技术堆栈,并使您熟悉将要使用的代码中使用的概念。

https://infinum.com/the-capsized-eight/top-10-android-libraries-every-android-developer-should-know-about

https://infinum.com/the-capsized-eight/top-10-android-libraries-every-android-developer-should-know-about

👉API级别要求 (👉 API level requirement)

Google Play requires that apps target at least Android 8.0. Sometimes this and different Gradle upgrades are mandatory changes before the next release.

Google Play要求应用至少针对Android 8.0。 有时,此和不同的Gradle升级是下一个版本之前的强制更改。

👉支持库 (👉 Support Library)

The next potential source of issues can be the Support Library used in the app which can be outdated. For that, Support Library Revisions can be helpful.

下一个潜在的问题源可能是应用程序中使用的支持库,该库可能已过时。 为此, 支持库修订可能会有所帮助。

👉检查清单文件 (👉 Check a Manifest file)

It is worth to look at the Manifest file and analyze the important information.

值得查看清单文件并分析重要信息。

Architecture检查架构并尝试识别设计模式 (👉 Check Architecture and try to recognize Design pattern)

All clear here. :)

这里都清楚。 :)

👉检查深度视图层次结构的使用 (👉 Check Using of Deep View Hierarchy)

If a layout has been inflated once, the system reuses it. But even so, inflating the layout must happen at some point.

如果布局一次膨胀,则系统会重新使用它。 但是即使这样,也必须在某个时候扩大布局。

👉检查片段/活动的使用 (👉 Check Using of Fragments/Activities)

Android introduced the concept of fragments in Honeycomb. In many apps, we can simply use Fragments instead of Activities, depending on background work, and as separate building blocks with their own life cycles can exist inside an Activity.

Android在Honeycomb中引入了片段的概念。 在许多应用程序中,根据后台工作,我们可以简单地使用片段而不是活动,因为活动内部可以存在具有各自生命周期的单独构建基块。

👉检查意图的使用和实施 (👉 Check usage and implementation of Intents)

Intents are one of Android’s key components. It’s a way of passing data between different parts of the app, but sometimes can be implemented in the wrong way.

意图是Android的关键组件之一。 这是在应用程序不同部分之间传递数据的一种方式,但有时可能以错误的方式实现。

ull空指针异常- 十亿 美元的错误 (👉 Null Pointer Exceptions — The billion-dollar mistake)

One of the most common types of crashes are in the wild while you develop, is caused by trying to run methods on objects that are not instantiated (a.k.a. NullPointerException).

崩溃的最常见类型之一是在开发过程中出现的,它是由试图在未实例化的对象上运行方法引起的(又名NullPointerException)。

👉代码重用 (👉 Code Reuse)

We are developers and because of that, we love creating new pieces of code. It is also common to think writing a new code will be easier to understand, implement, and many other things. The truth is that by reusing code we contribute to keep the app’s code simpler and avoid having new crashes on production.

我们是开发人员,因此,我们喜欢创建新的代码段。 人们通常认为编写新代码会更容易理解,实现以及许多其他事情。 事实是,通过重用代码,我们致力于使应用程序的代码更简单,并避免在生产中出现新的崩溃。

Layout简化布局 (👉 Simplified Layout)

One of the trickiest parts of Android development is to keep simplified layouts and stick to what the design team has designed. It is important to pay attention to the number of views and nested views used to keep the layout simple without compromising what was designed.

Android 开发中最棘手的部分之一是保持简化的布局并坚持设计团队的设计。 重要的是要注意用于保持布局简单而不损害设计的视图和嵌套视图的数量。

结语… (Wrapping Up…)

I can’t say that working with legacy code is trivial. Of course, it is much nicer to work with Android Jetpack, write the entire code in Kotlin, without the need to support very old Android System versions. But after some time, and many issues resolved, keep in mind that’s just something that makes you a better developer.

我不能说使用遗留代码很简单。 当然,使用Android Jetpack更好,用Kotlin编写整个代码,而无需支持非常旧的Android System版本,这会更好。 但是一段时间后,许多问题都解决了,请记住,这仅仅是使您成为更好的开发人员的原因。

翻译自: https://medium.com/swlh/10-things-you-dont-want-to-see-in-legacy-android-code-b76d8ff57b3

android10 源代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值