Dear
Software Developers,
This CPTTM Software Developer newsletter is to bring useful news to
you, software developers in Macau, for references without obligations,
so that you can do your jobs easier and better! Hope you like it. if
you'd like to unsubscribe or recommend your friends to subscribe, just
email me at kent@cpttm.org.mo.
Old issues are available here.
Topics in this issue:
Dealing with hierarchical data in a DB
easily
For
example, in the DB, each employee record stores both his own ID and that of his
superior. Now, how can you find out all the superiors (direct
or
indirect) of a given employee? You could try:
select e1.superior, e2.superior, ... from employees e1 join employees e2 on e1.superior=e2.id left join employees e3 on e2.superior=e3.id left join employees e4 on e3.superior=e4.id ...
But
this requires joining the table to an uncertain times (the
max depth of the tree). Now, there is an easy way to do that: The idea
is that you first create a temperary table containing the
records the direct superior relationship like:
(id, superior) ============== (b, a) (c, a) (d, b) (e, b)
Then you join this temperary table with itself to
expand it:
(b, a) (c, a) (d, b) (e, b) (d, a) (e, a)
You
can continue to expand it, but in this case it will return no
new
record, so it should stop. To implement this idea, if you DB server
supports Common
Table Expression, then you can create this temperary file as:
with superiors as ( -- initial records select id, superior from employees union all -- expansion select s1.id, s2.superior from superiors s1 join superiors s2 on s1.superior=s2.id )
Then you can use it in a query:
select * from superiors
by
Kent Tong
FREE Cheat Sheets for
Developers
We
are not talking about cheating during exams :p. I have a limit memory
in my brain, so I always fogtets a syntax for a particialar language.
Those cheat sheets really help me remind, and you could print them as
reference cards. It also help us learn something new and apply our
knownledge from one lanugage to another language. Those cheat sheets
are quite good quality, since the authors have already published a book
for those topics. If you think those cheat sheets are good, you
properly consider to buy theirs book.
Save time and stay well-informed:
- Written by bestselling authors and leading
experts
- Reliable information on major developer topics
- Filled with useful tips and source code examples
- PDF looks great on-screen or printed from your
printer
Download them once you have registered dzone.com:
by Tim Ma
Creating
UI mock-ups with this free tool  
When planning
the features with customers, sketching the proposed
UI on
a whiteboard is the most effective way. However, if the
customer
is not in the same location, and if it is just an additional little
feature or a minor revision, then an alternative is to mock-up the UI
on a computer and email the picture to him. This can be done with a
free tool like the Pencil
Project. It allows you to quickly mock-up a web-based UI or a
desktop client GUI. I've used it and it worked very well. Highly
recommended.
There are also extensions
allowing it to mock-up Dojo or ExtJs widgets.
by
Kent Tong
Scala:
successor to Java?
Scala is a new
language that is believed by some to be the successor to Java. It has
received endorsements
from James Gosling (the creator of Java) and James Strachan (the
creator of Groovy).
The latter even said that if he had known about Scala, he
wouldn't have created Groovy!
Below are the
features of Scala:
- It is statically typed.
- It
compiles to standard Java byte code (so a Scala class can access a
Java class/library and vice versa and as a result, investments
in
existing code base are not thrown away).
- It supports closures
(just a piece of code that can be pass around to be executed later,
like an anonymous inner class instance).
- It supports mixins (like multiple
inheritance if the base classes only contain methods but not data).
- It supports functional progamming
which suits the upcoming trend of distributed, parallel, multi-core
computing.
- It supports type inference (it can guess the
data type of variables so you don't repeat yourself).
Who is using
Scala? Not many for the moment, but Twitter
is one of them. There are even seven books
written for it.
If you have time, you may try it out and introduce to your colleagues.
You might become the new technology super-star in your company in a
couple of years :-) There are Scala IDE plugins
for Eclipse, Netbeans and IDEA. They aren't that mature but
should be usable.
by
Kent Tong
Never write getters and setters again
If you use Java, you must have written countless
getters and setters
by now! But now by adding a jar file to your classpath, you can have
the JVM add the getters and setters for you automatically using an
annotation like:
@Data class Foo { private Long id; private String name; }
How could this be done? This is implemented by a Java
agent (in a jar file) which can dynamically modify the
classes in the JVM. To get this agent, get the open source Lombok project.
by
Kent Tong
Upcoming courses for software
developers
Feedbacks
Any questions, ideas or experiences to share? Contact me at 28781313
or kent@cpttm.org.mo. We also
have two other newsletters: CIO newsletter
and Network
administrator newsletter,
your friends may like to subscribe.
Until next time,
Kent Tong |