给变量和函数起个不啰嗦的名字
写代码就像写作文,所以Joshua Bloch在Coder at Work的采访中推荐了一本写作书,The Elements of Style,和 一本词典,Merriam-Webster’s Collegiate Dictionary, 11th Edition。
强烈推荐“Long Names Are Long”这篇文章,可以帮助我们给函数或者变量命名时更加简洁。 下面是文章中给出的一些例子(例子的上下文见文章),
// Bad:
String nameString;
DockableModelessWindow dockableModelessWindow;
// Better:
String name;
DockableModelessWindow window;
// Bad:
List<DateTime> holidayDateList;
Map<Employee, Role> employeeRoleHashMap;
// Better:
List<DateTime> holidays;
Map<Employee, Role> employeeRoles;
// Bad:
mergeTableCells(List<TableCell> cells)
sortEventsUsingComparator(List<Event> events,
Comparator<Event> comparator)
// Better:
merge(List<TableCell> cells)
sort(List<Event> events, Comparator<Event> comparator)
Hash Join
Hash join是数据库实现join操作的一种算法。
- First prepare a hash table of the smaller relation. The hash table entries consist of the join attribute and its row.
- Once the hash table is built, scan the larger relation and find the relevant rows from the smaller relation by looking in the hash table.
有3种基本的join实现算法:
Three fundamental algorithms for performing a join operation exist: nested loop join, sort-merge join and hash join.
Nested loop join就是两个简单粗暴的for loop。
Javascript Engine in Java
A colleague recently asked me to extract some information/text from a json file in a Docker container. This Docker container has no things like Python or Perl included, and it’s dedicated to Java application only. Parsing json with grep/awk seems a bit intimidating. At last, I recalled that Java is shipped with a Javascript engine and after simply googling found the jjs. We used Javascript as the script language and jjs as the script interpreter to solve the problem.
Java SE 8 will instead ship with a new engine called Oracle Nashorn, which is based on JSR 292 and invokedynamic. It provides better compliance with the ECMA normalized JavaScript specification …
To do so, builds of Oracle’s JDK or OpenJDK include a command-line tool called jjs. It can be found in the bin/ folder of a JDK installation along with the well-known java, javac, or jar tools.
More details in this doc
Increase Number in Vim
How do you increase a number directly under the cursor?
光标放在数字上,按Ctrl+A
原数值加1;按Ctrl+X
减1。
10Ctrl+A
,在原数值上加10.