The Traps of Frameworks

When I interview a Java developer, if I see Spring Boot or Spring on the candidate’s resume, I may start with a simple question: “What is the default scope for a Spring bean”? Most people would get it right. I would then follow with a tricky question: “Does Spring make sure a Singleton bean thread-safe?” or “Does developer need to do anything to make sure a Singleton bean thread-safe?”.

When I say “tricky”, not because it’s tricky technically, but because half interviewees have no idea. The other half who correctly answered don’t always demonstrate solid understanding of Singleton and thread-safety. It’s okay to guess at an interview I guess.

Spring Boot is one of those popular frameworks for Java developers. Like most other Java frameworks, it provides proven reusable libraries and increases productivity. Some developers can probably make a living by simply being good at it.

However, because it encapsulates the interpretation of various Java Specifications, hides the complexity of design and implementation, often the framework itself imposes a serious impediment for developers to understand the underlining fundamentals.

Many Spring Boot developers don’t know Spring Boot is just a framework on top of another popular framework Spring Framework, which was initially a framework for Java Servlet applications. Most freshly-minted Spring Boot developers never heard of Servlet, not to mention web.xml. They only know their Spring Boot applications, “just run”. They never know why and how it runs.

Because of that, they never think of what the underlining Servlet Container is, what the default configurations (like Max Concurrent Requests) are, and how to fine tune those configurations. Imagine asking them to write a Java Web Application without Spring Boot?

Frameworks tend to wrap a lot of default features and behaviors under the hood, just to name a few: default Encryption Algorithm, default Socket Timeout, default Retry Strategy.

In the past, Frameworks might have configuration property for each “feature”, but this has changed in the recent years. Nowadays, Framework authors tend to favor “Convention over configuration”. Old configuration files are replaced by annotations with “sensible defaults”. Moreover, many of the features and behaviors are “discovered” automatically based on your running environments, like system properties, environment variables and what is in the class-path.

Several years back, I led a framework team. We built a Framework as the foundation for a slew of web applications that support multi-million $ business. We worked very hard to support all major features by default, and still allow each application to extend and override each feature by configuration and automatic discovery. I learned first hand, it’s even harder for application developers to fully understand how each feature worked and how to extend or override them.

Naturally, due to the lack of visibility and transparency of frameworks, people makes a lot of assumptions about frameworks, such as Singleton bean thread-safety. Some of the assumptions will definitely haunt the team down the road if the technical leads on the team didn’t review the design and code carefully.

Overtime, frameworks will evolve or die. If you ever worked with Struts 1.x framework, and if you didn’t understand Java Servlet, you would have a difficult time to migrate your applications to Struts 2.x or Spring.

Frameworks are your tools, not your crutches. If you don’t think out of the box of Spring Boot, you can’t professionally outgrow Spring Boot. Simple. Period.

That is true to other frameworks too.

Frameworks can help you get started quickly, but understanding the underlining principles will help you in the long run.

一些鲜为人知的编程真相

2016-04-08 Python开发者

英文:Rational Mind

译文:外刊IT评论

链接:http://www.aqee.net/2010/09/05/some-lesser-known-truths-about-programming/

做程序员的经历让我知道了一些关于软件编程的事情。下面的这些事情可能会让朋友们对软件开发感到惊讶:

1. 一个程序员用在写程序上的时间大概占他的工作时间的10-20%,大部分的程序员每天大约能写出10-12行的能进入最终的产品的代码 — —不管他的技术水平有多高。 好的程序员花去90%的时间在思考、研究和实验,来找出最优方案。差的程序员花去90%的时间在调试问题程序、盲目的修改程序,期望某种写法能可行。“一个卓越的车床工可以要求比一个一般的车床工多拿数倍高的工资,但一个卓越的软件写手的价值会10000倍于一个普通的写手。”——比尔 盖茨

2. 一个优秀的程序员的效率会是一个普通的程序员的十倍之上。一个卓越的程序员的效率会是一个普通程序员的20-100倍。这不是夸张 — — 1960年以来的无数研究都一致的证明了这一点。一个差的程序员不仅仅是没效率 — — 他不仅不能完成任务,写出的大量代码也让别人头痛的没法维护。

3. 卓越的程序员只花很少的时间去写代码——至少指那些最终形成产品的代码。那些要花掉大量时间写代码的程序员都是太懒惰,太自大,太傲慢,不屑用现有的方案去解决老问题。卓越的程序员的精明之处在于懂得欣赏和重复利用通用模式。好的程序员并不害怕经常的重构(重写)他们的代码以求达到最好效果。差的程序员写的代码缺乏整体概念,冗余,没有层次,没 有模式,导致很难重构。把这些代码扔掉重做也比修改起来容易。

4. 软件遵循熵的定律,跟其它所有东西一样。持续的变更会导致软件腐烂,腐蚀掉对原始设计的完整性概念。软件的腐烂是不可避免的,但程序员在开发软件时 没有考虑完整性,将会使软件腐烂的如此之快,以至于软件在还没有完成之前就已经毫无价值了。软件完整性上的熵变可能是软件项目失败最常见的原因。(第二大 常见失败原因是做出的不是客户想要的东西。)软件腐烂使开发进度呈指数级速度放缓,大量的软件在失败之前都是面对着突增的时间要求和资金预算。

5. 2004年的一项研究表明大多数的软件项目(51%)会在关键功能上失败,其中15%是完全的失败。这比1994年前有很大的改进,当时是31%。

6. 尽管大多数软件都是团体开发的,但这并不是一项民/主的活动。通常,一个人负责设计,其他人负责实现细节。

7. 编程是个很难的工作。是一种剧烈的脑力劳动。好的程序员7×24小时的思考他们的工作。他们最重要的程序都是在淋浴时、睡梦中写成的。因为这最重要的工作都是在远离键盘的情况下完成的,所以软件工程不可能通过增加在办公室的工作时间或增加人手来加快进度。