JFinal 4.2 release, a jar package wander

    JFinal had only third-party dependencies are introduced when adding business layer AOP, this version 4.2 is the only third party to get rid of this dependence, from a jar package wander

    JFinal 4.2 new proxy module 628 only lines of code to get rid of the 19,505 code amount cglib-nodep. Cglib kill code amount is 31 times the JFinal proxy. code amount cglib-node:

    JFinal proxy amount of code:

 

    At this point, a third party without dependent MVC + ORM + AOP + Proxy + Template Engine, the modules are extremely lightweight application development framework was born, unprecedented

    JFinal after eight years of innovation and iteration, to what extent lightweight terrible, the data speak:

1、JFinal VS Spring

    Spring is one of the most popular open source frameworks, code size is striking:

    Spring over 320,000 lines of code amount is then clearly no longer perceived lightweight framework

    JFinal amount of code:

    Spring 324816 lines of code, is 11.59 times JFinal 28024 lines of code

    NOTE: To ensure fairness, the code has been deleted Spring in all test directory, or the amount of 632 096 lines of code spring, will be about twice the amount of code above 320,000

2、JFinal VS Spring Boot

    Spring Spring construct depends on the Boot, which is merely a sleeve housing on the basis of the Spring Spring cumbersome to simplify development, which code amount is as follows:

    Although Spring Boot package only made two points facilitate the development of convenience on Spring, but the amount is still a lot of code, to 29,583 lines

    注意:为确保公平,上面截图仅仅统计 spring boot 中的一个子项目(注意上图中左侧箭头指向的子项目名),并去掉了 test 代码,否则代码量将是惊人的 275527 行,截图如下:

    spring boot 作为简化 Spring 开发的 "壳" 的存在,所以基于它开发的项目,必有大量的 jar 包依赖,以它官方最简单的 hello world demo 为例(demo代码送门),其打包出来的 jar 包数量十分惊人:

    一个啥正事也没干的 demo 居然需要 33 个 jar 包依赖,19 M 的体积,如果要添加 AOP、ORM、Template Engine 等常用功能,jar 量还将大量增加

    而其同等功能的 jfinal 项目则大为不同:

    同等 demo 之下,spring boot 打包后依赖 33 个 jar 包,而 JFinal 只有一个 jar 包。Spring Boot 的 jar 包依赖数是 JFinal 的 33 倍

    jar 包体积的对比,先上 Spring Boot 的:

     再上 jfinal 的:

      Spring Boot 的 jar 包体积是 19MB,是 JFinal 716KB 的 27 倍。更少 jar 包意味着运行时更低的内存占用,更轻量级。

3、JFinal Template Engine VS FreeMarker

    FreeMarker 是应用最广泛的 java 模板引擎之一,其代码量如下:

    仅模板引擎一个功能,代码量就超过 5 万行之巨,不得不说代码量非常之高

    而 JFinal 模板引擎仅作为其 template 的一个子模块存在,代码量如下:

    FreeMarker 55018 行代码,是 JFinal Template Engine 8858 行代码的 6.21 倍

4、JFinal ORM VS Hibernate

    Hibernate 是老牌的 Java ORM 框架,应用十分广泛,其代码量如下:

    为确保公平,只统计其 hibernate-core 模块的代码量,其代码量为 263530 行,作为 ORM 的 core,其超过 26 万行的代码量,令人震惊

    以下是 JFinal ORM 的代码量:

    hibernate-core 模块 263530 行代码,是 JFinal ORM 6849 行代码的 38.47 倍

5、轻量级的意义

    为什么 JFinal 迭代八年,一直如此严苛地坚持轻量级,坚持小而精?在保障代码简洁、清晰的前提下,代码量少的好处非常多,为节省时间,在此仅简单提几点:

  • 完全掌控

    整体才 28024 行代码,使得用户完全掌控变得十分容易。完全掌握意味着你可以随心所欲地扩展、定制,在碰到问题时可迅速定位解决

    相比 Spring 的几十万行代码量,再加上其很多组件都是六七层的类层次关系,要读懂源码都会十分困难,更别提完全掌控

  • 降低 bug 率

      好比言多必失,代码量越大,出错的概率必然越大。代码量少,意味着 bug 概率的降低

  • 提升可维护性

      在保障可读性的前提下,代码量越少,在添加、修改功能时,所花成本必然越少

  • 低成本、高效率

      代码简洁、量少,学习成本下降,开发效率提升,运行效率也将提升。为自由开发者和创业公司提升竞争力,降低成本

6、JFinal 4.2 重要新功能

    以上是干掉最后一个第三方依赖后的轻量级方面的总结与对比,4.2 新版本还添加了很多好用的新功能:

6.1、新增 proxy 模块

    proxy 首要目标是实现动态代理,从而实现 AOP。 JDK 的动态代理机制必须要实现接口,显然该 pass 掉。另外常见的代理方案是使用 cglib、asm 等字节码增强方案,这类方案需要依赖第三方,并且操作字节码的代码可读性极差,也被 pass 掉

    JFinal 的 proxy 采用任何地方都不可能见到的全新设计:Enjoy、Class Loader、Dynamic Compile 美妙结合,628 行代码打完收工(源码传送门)

    proxy 模块处于 jfinal AOP 的底层,对开发者完全透明,无学习成本

6.2、Db 新增 template 系方法

    JFinal 4.2 还针对 sql 模板功能添加了 template 系列 API,可减少此类用法 50% 的代码量,sql 模板功能在这之前是这么用的:

SqlPara sqlPara = Db.getSqlPara(sqlKey, 123);
Db.find(sqlPara);

    使用新增 template 系的方法以后可以这么来用:

Db.template(sqlKey, 123).find();

6.3、model 新增 template 系方法

    同理 model 也添加了 template 方法: 

dao.template(sqlKey, 123).find();

    本次 JFinal 4.2 自上次新版本发布以来,共有 39 项增强与改进,限于篇幅在此不再赘述,可以在官网下载最新版本的 jfinal-4.2-changelog.txt

    极速升级到 4.2 的文档也准备妥当,十分平滑,传送门:https://www.jfinal.com/doc/14-1

 

ONE MORE THING:

    值此 JFinal 4.2 新版发布之际,jfinal.com 官方网站也已全新改版。改版后的整站源代码作为 jfinal 俱乐部的专享福利已经可以下载,下载传送门:https://www.jfinal.com/club

 

 

 

Guess you like

Origin www.oschina.net/news/107259/jfinal-4-2-released