- Vaadin 7 UI Design By Example:Beginner’s Guide
- Alejandro Duarte
- 335字
- 2021-08-13 16:17:39
The Time It application
A couple of years ago I was working with some friends on a personal Java project. We used to meet every Saturday to review what we had done before building the entire system. Let me introduce you to my friends: Susan Obstinate and Mark Nowsitall (weird last names, aren't they?).
"I've spent the entire week writing this code, but it's ready now," said Susan with an embittered tone.
"Let me see how you handled that," replied Mark suspiciously. Though they didn't seem to be, they were a couple.
So Susan proudly showed us her piece of code:
// some nasty code was here (censored for respect of the reader)
public String getUglyUrl(long total) {
String url = "http://localhost/app/someservice?code=";
for(long i = 0; i < total; i++) {
url += someTrickyMath(i);
}
return url;
}
public String someTrickyMath(long i) {
// (censored)
}
"We can use an int
object type instead of long
for the loop in your getUglyUrl
method," instantly affirmed Mark.
"I don't think we need that," said Susan.
"You could also use a StringBuilder
class to..." I started to say, but suddenly got interrupted by Mark.
"An int
object type would improve performance a lot. The int
comparisons and manipulations are faster than long
ones," Mark explained.
"What if the total gets too big? We'd need a long
object type then," Susan argued.
"Total has never gone beyond 10,000 and I highly doubt it will in the near future," Mark replied.
We (actually it was Mark) finally managed to convince Susan to change her code.
There are lots of situations similar to this one, more complicated, and with tons of external factors that make it hard to be 100 percent sure about which of two code strategies will work faster. Let's take advantage of this story and develop a nice Vaadin application for timing code.
Note: please read the following sentence using a flamboyant and jazzy voice.
Introducing: Time It! The application that will show some facts to Susan.

- MySQL數(shù)據(jù)庫管理實戰(zhàn)
- Java入門經(jīng)典(第6版)
- Visual FoxPro程序設(shè)計教程(第3版)
- Learning Informatica PowerCenter 10.x(Second Edition)
- C語言程序設(shè)計案例精粹
- SQL基礎(chǔ)教程(視頻教學(xué)版)
- 從零開始學(xué)C語言
- 區(qū)塊鏈底層設(shè)計Java實戰(zhàn)
- Java Web從入門到精通(第3版)
- 代替VBA!用Python輕松實現(xiàn)Excel編程
- STM8實戰(zhàn)
- 軟硬件綜合系統(tǒng)軟件需求建模及可靠性綜合試驗、分析、評價技術(shù)
- Java 7 Concurrency Cookbook
- VMware vSphere Design Essentials
- Java面試一戰(zhàn)到底(基礎(chǔ)卷)