Tuesday, November 17, 2009
gaining confidence...
Sunday, September 27, 2009
Simplication via Polyglot
Radical Simplification Through Polyglot and Poly-paradigm Programming
*less code
*biz logic and impl separation (DSL)
imutable
nothing to sync
no locks semaphores mutexes
data stable, but a lot of functions use list, map, filter, fold/reduce (cloud computing)
adding types, few functions, use OO inheritances
declarative vs imperative
erlang
no mutable variables & side effect
IPC optimised msg passing (actor model)
lightweight & fast process
*less code
*model domain as close as possible
*declarative concise bug free
*no mutable variables & side effect
-mocking dependency
Wednesday, September 16, 2009
“FIRST class” test cases
Make “FIRST class” test cases (Fast, Independent, Repeatable, Small and Transparent)
Fast. Your test cases should be very fast to execute, every time you want to run all of them it shouldn’t take more than a few seconds for an small application.
Independent. You should be able to run your test cases in any order.
Repeatable. The result of the test case should be always the same, no matter how many times you have executed it before.
Small. Small test cases are easy to understand and change, are also likely to be faster.
Transparent. It should be clear what the purpose of each test case is.
from How to write a good test case: 5 tips to write better test cases
Wednesday, August 26, 2009
inverse vandals
"Basically, inverse vandals dont care about their work and its impact on the lives of users and the many others affected by their work, which is a pity. Software has a sort of magic in itself, and interactive software provides a concrete, vivid example of such a magic. Whether you are a teenager playing a video game or an old guy fiddling with an early computer in your garage, there was probably a moment in your life when you were totally amazed by a piece of software - otherwise you would probably have chosen another career."
Wiley Professional Java User Interfaces p. xxiiv
Tuesday, June 23, 2009
sql to_date() to_char() removal for java
select db_fieldname from db_table where db_timestamp_field = to_date(?, 'dd-mm-yyyy');
replace the to_date(?, 'dd-mm-yyyy') function with a ?
select db_fieldname from db_table where db_timestamp_field = ?;
then using
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Timestamp result = new Timestamp(sdf.parse(inputdate,new ParsePosition(0)).getTime());
prepareStatement.setTimeStamp(1,result);
Oracle to_char()
select * from table where to_char(db_timestamp_field, 'dd-mm-yyyy') = ?;
replace to_char(db_timestamp_field,'dd-mm-yyyy') with trunc(db_timestamp_field)
select * from table where trunc(db_timestamp_field) = ?;
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date javaDate = sdf.parse(inputdate);
java.sql.Date sqlDate = new java.sql.Date(javaDate.getTime());
prepareStatement.setDate(1,sqlDate);
Tuesday, June 9, 2009
accumulator
file size is long
count is int
so i have one array to keep track of file size
another array to keep the int count
so once i have a file size, i would check through the array of file size, to see if it is the same, if yes, i remember the index and take the value from the count array plus one and put back in. The data structure which i used initially was 2 arraylist.
for sizeArray
if sizeArray[i] is filesize
take countArray[i]+1
addedFlag to false
if addedFlag
sizeArray[max] is filesize
countArray[max] is 1
it looks awfully complicated, so i changed the 2 array into a hashtable
the long value will be converted to a string object.
if hashtable has fileSizeString
currentCount is hashtable get fileSize
hashtable put fileSizeString, currentCount+1
hence making the code a lot more shorter.
Conditional Complexity
public function validateObject(object:Object):void {
if (conditionA || conditionB) {
throw new ObjectValidationError(object);
}
if (conditionC || conditionD) {
throw new ObjectValidationError(object);
}
if (conditionE || conditionF) {
throw new ObjectValidationError(object);
}
// and many more if-statements
}
public function validateObject(object:Object):void {
if (conditionA || conditionB) {
invalid(object);
}
if (conditionC || conditionD) {
invalid(object);
}
if (conditionE || conditionF) {
invalid(object);
}
}
protected function invalid(object:Object):void {
throw new ObjectValidationError(object);
}
public function validateObject(object:Object):void {
validate(conditionA && conditionB, object)
validate(conditionC && conditionD, object)
validate(conditionE && conditionF, object)
}
protected function validate(isValid:Boolean, object:Object):void {
if (!isValid) {
throw new ObjectValidationError(object);
}
}
Tuesday, June 2, 2009
Vector to HashMap pattern
Some Action
Vector v = new Vector();
v.add(request.getParameter("name"));
v.add(request.getParameter("address"));
v.add(request.getParameter("telephone"));
Some Manager
v.get(0);
v.get(1);
v.get(2);
can be replaced with
HashMap hm = new HashMap();
hm.add("name",request.getParameter("name"));
hm.add("address",request.getParameter("address"));
hm.add("telephone", request.getParameter("telephone"));
later on
hm.get("name");
hm.get("address");
hm.get("telephone");
this is much less error prone then refering via vector indexes. you can add new parameters without affecting the orders of the parameters also. String should be extracted out into a constants class to obey the principles of DRY.
Monday, May 25, 2009
Ternary operator pattern (aka inline conditions)
String id = request.getParameter("aaa")==null? "" : request.getParameter("aaa");
can be refactored to
String id = request.getParameter("aaa");
if(id==null) id ="";
which can be furthered reduce to
String id = Utility.isNull(request.getParameter("aaa"));
public String isNull(String input){
if(input==null) return "";
return input;
}
Saturday, May 9, 2009
becoming a better coder...
[Dont repeat yourself][1]
[Command-query separation (CQS)][2]
[Defensive programming][3]
[S.O.L.I.D.][4]
[Code Smell][5]
[Smells to Refactorings][6]
Patterns & Anti-Patterns
[Software Craftsmanship][7]
[Testable code drags OOP into Functional Programming][8]
[Writing Testable Code][9]
[How to Write 3v1L, Untestable Code][10]
[Design by Contract][11]
[1]: http://en.wikipedia.org/wiki/Don't_repeat_yourself
[2]: http://en.wikipedia.org/wiki/Command-query_separation
[3]: http://en.wikipedia.org/wiki/Defensive_programming
[4]: http://mmiika.wordpress.com/oo-design-principles/
[5]: http://en.wikipedia.org/wiki/Code_smell
[6]: http://www.industriallogic.com/papers/smellstorefactorings.pdf
[7]: http://en.wikipedia.org/wiki/Software_Craftsmanship
[8]: http://noss.github.com/2009/02/21/testable-code-drags-oop-into-functional-programming.html
[9]: http://googletesting.blogspot.com/2008/08/by-miko-hevery-so-you-decided-to.html
[10]: http://googletesting.blogspot.com/2008/07/how-to-write-3v1l-untestable-code.html
[11]: http://en.wikipedia.org/wiki/Design_by_Contract
Tuesday, February 24, 2009
little thoughts
you can have the only documentation as the codes...
or you can do fast iterations, so that we (software engineers) help the user visualise what they want. Show them immediately quick and dirty prototype. Be ready to throw them away. This helps to converge to a commonality point.
Tuesday, February 10, 2009
quotes
but if i looked good, i am sure you will also looked good.
if the team dont look good, i dont looked good.
if the team looked good, we will look good too...
stakeholder...
decision maker...
middle man...
my client...
my team mates aka internal customer ...
Saturday, February 7, 2009
environmental ideas
throttle server fans
increases air con temperature
a pot that reduces heat wastes. (invented in taiwan)
| |
| |
| |----| |
+---|fire|---+
encapsulate and fully cover the flame...
random words
if I dont look good, you probably wouldnt looked very good too...
codes should be free...
Scolding generates bad karma. explain why not, what is the implications. 1st time let it off, subsequently then take discplinary actions.
the more you restrict, the more precious it becomes.
the more you give, the less it becomes a critical issue.
improper handover is sad, it means 2 person messed up as a professional.
Tuesday, February 3, 2009
a little quote
agility and software engineering is 2 different process for different kind of constraints projects. Cheap, fast, quality triangle? cheap but heavy design doc with long turn around time doesnt go togother with fast. quality, writing JUnit codes will turn up 50% of the project time.
know who are the stake holders... are they the decision maker?
Friday, January 23, 2009
Tuesday, January 20, 2009
how to find a keyword within an entire project
usage:
mfind "String title"
====mfind.bat====
@echo off
for /f "tokens=*" %%a in ('dir /b /s *.java') do find %1 "%%a"
Sunday, January 18, 2009
Wednesday, January 7, 2009
Thursday, January 1, 2009
Ada
check out wikibooks.org natural science, social science, computing, humanities, arts books.





