澳门百家乐网址

首页 > 正文

Java程序员应该如何学习框架源码?

www.diyarbakirpvc.com2019-07-16
百家乐导航

1d25cffa365e4d5eaee5285fc42ada82

无论程序员哪个部分,阅读源代码都是一件非常好的事情,特别是对于初学者来说,这可以快速吸收优秀的框架本质代码营养,并迅速成长。不幸的是,难以理解的源代码很容易让人感到舒服。今天,分享阅读源代码的方法。

首先,了解框架解决了什么问题

这不仅有助于阅读源代码,而且有助于整个研究。想一个问题:你学习Vue \ React的原因,除了在一天中,如果你不学习,你也很难找到工作。您是否也考虑过一些可以带来一些好处的优秀功能?

与以前的技术系统相比,新框架,开发人员需要也应该理解,这个框架解决了哪些问题,优势在哪里,学习的目的不要混淆。例如,Vue \ React的最大优势是什么?组件化,以及如何解决这个问题来学习的框架,将能够用更少的资源做更多的事情。

其次,了解框架的设计思路

我们不了解源代码(或者看起来很难),不是因为我们不理解某种语法,而是因为我们不理解作者的想法。举一个简单的例子:

//这个方法可以获得point2顶角的弧度

functiongetAngle(point1,point2,point3){

Var bb=(point2.y - point1.y)*(point2.y - point1.y)+(point2.x - point1.x)*(point2.x - point1.x);

Var aa=(point3.y - point1.y)*(point3.y - point1.y)+(point3.x - point1.x)*(point3.x - point1.x);

Var cc=(point3.y - point2.y)*(point3.y - point2.y)+(point3.x - point2.x)*(point3.x - point2.x);

Var cosa=(bb + cc - aa)/(2 * Math.sqrt(bb)* Math.sqrt(cc));

返回Math.acos(cosa);

}

getAngle方法接收三个坐标参数,并可以计算point2的点角度的弧度。如果你没有告诉你它使用了三角形的余弦定理,恐怕你看不出它是如何长期计算的。

了解框架设计思路的方法:

1.转到框架的官方网站查看文档。开源框架,细节不详细,这绝对是第一手权威数据

2.在互联网上搜索其他人的分析和摘要(源代码分析不会少)。在大多数情况下,会有大神已经研究过,站在巨人的肩膀上,可以拯救很多东西

此外,设计理念是在框架层面。对于每个实现细节,使用了许多设计模式,例如函数编程(在Js中最常用),单例模式,代理模式,工厂模式等,这需要通常累积。在累积了一定数量的代码后,建议您阅读一些有关设计模式的书籍,这对您自己的代码设计和阅读其他人的源代码很有帮助。

Third, set up the debugging environment, find out the main thread of execution

Subdivided into each module, we must have an overall grasp of the module function, how to do this "hold"? In addition to the official documentation and online access to information, the best way is to write a simple demo, build a test environment, add some debugging information, naturally clear the life cycle of the framework, each step needs to call that module (for the directory structure Very clear and excellent framework, sometimes you can guess by intuition, print log confirmation)

Fourth, distinguish the primary and secondary

The source code of the framework is a towering tree, and what you have to do is climb from the roots. The tree has so many branches, the time is so expensive, and the reading strategy is very important. Our reading path should be based on the main process (that is, the main drive of the tree, so that we can reach the vertices as quickly as possible), and for some details, then slowly and slowly (or when necessary).

For example, to read Vue's source code, there is a directory that parses the template and generates the syntax tree AST to finally generate the Render Function. In fact, the most important part of this step is the result of the Render Function, how to parse the template and generate the syntax tree. You can put it first, and look back when you need it. Otherwise, you can easily get stuck at a certain point, and you will have the idea of giving up.

Fifth, insist on not giving up

The technical strategy is right, and it is normal to encounter difficult problems. At this time, the test is perseverance. Continue to debug, search for information, or find a big god to ask questions, as long as you don't give up.

6. Learn to ask for help

xx无论你的自学能力有多强,无论你是P4还是P7,总会有遇到困难的时候。普通人遇到瓶颈只能自己默默的去一次次冲击,如果冲击成功还好,是另一片天地;倘若冲击失败,轻则灰心丧气迷失一阵子,重则一蹶不振。

如果有人领路呢?看过小说的都知道,冲关的时候如果有人指导,借鉴前人的经验,可以少走很多弯路。人生不过数十载,何不把时间节省出来去多学点东西,多做点有意义的事情。

为了帮大家尽快的提升自己,更有效率的进阶,我精心准备了框架源码系列资料,希望能帮你早日突破自己!

51fc27d3816745708626d24a3eded9fa

领取方式点击下方了解更多!验证:源码分析

xxxx
热门浏览
热门排行榜
热门标签
日期归档