ios开源_开源iOS应用分析

ios开源

We analysed 273 open source iOS apps written in swift for 33 object oriented and 2 iOS specific code smells. We also looked at how well tested these apps were.

我们分析了273个快速编写的开源iOS应用程序,以了解33种面向对象和2种iOS特定代码的味道。 我们还研究了这些应用程序的测试情况。

我们在哪里找到开源应用程序? (Where did we find open source apps?)

Open source apps are not as common in iOS as in Android, but there is a collaborative list of open source iOS apps on GitHub. Some of the apps are in the app store, but not all of them.

开源应用程序在iOS中不像Android中那样常见,但是在GitHub上有协作的开源iOS应用程序列表。 有些应用程序位于应用程序商店中,但并非全部。

Some stats

一些统计

  • 568 apps written in swift

    快速编写568个应用
  • 273 apps successfully analysed

    273个应用程序成功分析
  • of which 68 apps also in app store

    应用商店中也有68个应用
  • Smallest app has 2 classes

    最小的应用程序有2个课程
  • Largest app has 1112 classes

    最大的应用程序具有1112个课程
  • 10569 classes in total

    共10569堂
  • 45867 methods in total

    总共45867种方法
  • 2993 tests in total

    总共2993个测试

什么是代码气味,我们如何检测到它们? (What are code smells and how do we detect them?)

Code smells are patterns in code that indicate possible issues that can lead to less maintainable and harder to understand code. Smelly code is not necessarily incorrect but might indicate an issue.

代码气味是代码中的模式,指示可能导致无法维护和难以理解的代码的问题。 有臭味的代码不一定正确,但是可能表明存在问题。

This article gives a good overview of object oriented code smells and covers most of the code smells defined by Fowler:

本文对面向对象的代码气味进行了很好的概述,并涵盖了Fowler定义的大多数代码气味:

We implemented a tool that analyses swift code and detects code smells. It uses the sourcekitten framework and stores information about analysed apps in a neo4j graph database. Code smells are defined as queries. This makes it possible to analyse a lot of applications at once.

我们实现了一个工具 ,用于分析SWIFT代码和检测代码味道。 它使用sourcekitten框架并将有关已分析应用程序的信息存储在neo4j图形数据库中。 代码气味被定义为查询。 这样就可以一次分析很多应用程序。

那么,这些应用程序有多臭? (So, how smelly are these apps?)

Our tool is able to detect 35 code smells. The following figure shows the percentage of apps including a code smell.

我们的工具能够检测35种代码气味。 下图显示了包含代码气味的应用程序百分比。

Image for post

Most apps are affected by lazy classes, long methods, message chains. But it is important to note that already one long method or one lazy class lands an application in this statistic. More interesting is that only around 20% of the applications are plagued by massive view controllers.

大多数应用会受到懒惰类,长方法和消息链的影响。 但是必须注意,已经有一个长方法或一个惰性类在该统计信息中找到了应用。 更有趣的是,只有大约20%的应用程序受到大型视图控制器的困扰。

The following figure shows the distribution of code smells:

下图显示了代码气味的分布:

Image for post

Most commonly occurring code smell is internal duplication, accounting for more than 14% of all code smells. Followed by lazy classes and long methods.

最常见的代码气味是内部重复,占所有代码气味的14%以上。 其次是惰性类和长方法。

It would be interesting to know if there are any differences to not-open source apps. Unfortunately right now we need the source code to perform the analysis. But we did look into if there are any differences between apps that are released on the app store vs. the ones that are not.

知道与非开源应用程序是否有差异,这将很有趣。 不幸的是,现在我们需要源代码来执行分析。 但是我们确实调查了在应用商店上发布的应用与未在应用商店上发布的应用之间是否存在差异。

Image for post

The distribution of smells is very similar. There is slightly less internal duplication which might indicate more quality control.

气味的分布非常相似。 内部重复较少,这可能表示质量控制要加强。

这些应用程序的测试情况如何? (How well are these apps tested?)

Tests are important right? We counted the number of asserts in test files for each app. The median number of tests? …. 1

测试重要吗? 我们计算了每个应用程序在测试文件中的断言数量。 中位数测试? …。 1个

We were interested in finding out if there is a relationship between how well an application is tested and how smelly its code is. But unfortunately found that open source iOS apps apps are barely tested at all. Is this the norm or are closed source application better tested? Are you writing tests?

我们对找出应用程序的测试程度与代码的气味之间是否存在关联感兴趣。 但不幸的是,发现开源iOS应用程序应用程序几乎没有经过测试。 这是规范还是对开源应用程序进行了更好的测试? 你在写测试吗?

If not, then you might want to read about unit testing iOS apps. This is a pretty nice article:

如果没有,那么您可能想阅读有关iOS应用程序单元测试的信息。 这是一篇非常不错的文章:

那工具呢? (What about the tool?)

The tool (GraphifySwift) used to detect these smells is written in swift and uses SourceKitten to analyse the applications AST. It is open source and available here. The tool was inspired by Paprika that analyses Android apps.

Swift编写用于检测这些气味的工具(GraphifySwift),并使用SourceKitten来分析AST应用程序。 它是开源的,可在此处获得 。 该工具的灵感来自分析Android应用程序的Paprika

Yes, I did run the tool on its own code and yes it is pretty smelly. I do plan to improve on that and hopefully convert it into an XCode extension as well. Any improvement suggestions are welcome.

是的,我确实在自己的代码上运行了该工具,是的,它很臭。 我确实打算对此进行改进,并希望也将其转换为XCode扩展。 欢迎任何改进建议。

一些未来的想法: (Some future ideas:)

  • comparing code smells on iOS and Android

    比较iOS和Android上的代码味道
  • analysing architecture patterns

    分析架构模式
  • including other types of code smells, iOS specific smells, security smells

    包括其他类型的代码气味,iOS特定气味,安全性气味
  • improving the tool, making it useful for developers

    改进工具,使其对开发人员有用

翻译自: https://medium.com/dev-genius/analysis-of-open-source-ios-apps-b7466fb20de3

ios开源

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值