RSS feed [root] /




login:

password:

title search:




 


Wed Jun 09 10:03:42 AEST 2021



(google search) (amazon search)
second
download zip of files only

Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

DTO


http://mrpmorris.blogspot.com/2009/01/data-transfer-objects.html

(google search) (amazon search)



Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

Event


How to build an event store - http://cqrsinfo.com/documents/building-event-storage/

A event base web backend - http://kasparov.skife.org[..]live/src/erlang/yaws-for-comet.writeback

Example code of domain events - http://www.udidahan.com/2009/06/14/domain-events-salvation/

Benefit of CQRS - http://blog.fohjin.com/blog/2009/11/12/CQRS_a_la_Greg_Young

(google search) (amazon search)



Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

Handle exception at event


To prevent no one notice there is problem

What the code is trying to do is make sure is that any exception thrown is brought to the attention of the user. I’ve been looking at a few approaches to help catch and handle these exceptions without the developer having to explicitly catch them at the UI level.
You can create your own EventQueue, and have it catch uncaught exceptions when dispatching methods

http://www.magpiebrain.com[..]2004/07/21/catching-uncaught-exceptions/

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

High level software design discussion


A nice table:
Do Don't
1. Focus on interfaces. 2. Be worried about the implementation.
3. Mention semantic contract using interfaces. 4. Let subtypes break this semantic contract of their parent types.
5. Service decoupling using interfaces. 6. Be coupled with specific concrete implementation.
7. Family extension using interfaces. 8. Break the family relationship using concrete implementation.
9. Establish a family rule by abstract classes. 10. Impose your own rule through concrete classes.
11. Let interfaces answer all "what" about the system. 12. Forget to mention "how" are you answering all "what" from interfaces.
Also a good introduction of Strategy pattern

http://today.java.net[..]/03/28/testing-java-object-oriented.html How to determine the levels of abstraction - http://programmers.stackexchange.com[..]w-to-determine-the-levels-of-abstraction
(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

How to format parameter


Some will think boolean is ugly as parameter, I think if there is more than one boolean in parameter list - http://silkandspinach.net/blog/2004/07/hexagonal_soup.html

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

Using stacktrace to know call hierarchy


Sometime it useful to know call hierarchy even if it is not exception case

http://jroller.com/page/henribenoit?entry=where_am_i_called_from

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

Why use exception instead of error code


A detailed explanation

http://gamearchitect.net/Articles/ExceptionsAndErrorCodes.html

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

anti-pattern of exception


Mostly agree, however, why do we need NoSuchMethodException? Why we don't just don't implement that method? If this is required by the interface, why we implement an interface but not complete the contact?

http://today.java.net[..]/06/exception-handling-antipatterns.html http://softarc.blogspot.com[..]06/exception-handling-anti-patterns.html

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

check or uncheck


Checked or unchecked? Not sure, seen all exception is unchecked are ok for me

To summarize Java orthodoxy: checked exceptions should be the norm. Runtime exceptions indicateprogramming errors.
I used to subscribe to this view. However, after writing and working with thousands of catch blocks, I've come to the conclusion that this appealing theory doesn't always work in practice. I'm not alone. Since developing my own ideas on the subject, I've noticed that Bruce Eckel, author of the classic book Thinking in Java, has also changed his mind. Eckel now advocates the use of runtime exceptions as the norm, and wonders whether checked exceptions should be dropped from Java as a failed experiment

http://www.mindview.net/Etc/Discussions/CheckedExceptions

Other discussion of checked or unchecked - http://www.theserverside.com/news/thread.tss?thread_id=35586 http://www.infoq.com[..]2007/05/removing-java-checked-exceptions

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

cool exception message


From a very good jpeg meta data extractor - http://drewnoakes.com/code/exif/ mention the solution at exception message
com.drew.metadata.MetadataException: Tag Image Width has not been set -- check using containsTag() first
        at com.drew.metadata.Directory.getInt(Unknown Source)

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

dsl


A paper show the evolution of a DSL - http://www.mockobjects.com/files/evolving_an_edsl.ooplsa2006.pdf

A stock trading order example of DSL - http://debasishg.blogspot.com[..]05/designing-internal-dsls-in-scala.html

What is the difference between API / DSL if we don't write a parser for our language? From Martin Fowler's blog - http://martinfowler.com/bliki/DslReadings.html , it is mentioned:
Piers Cawley makes the point that a key characteristic of DSLs is their narrow focus on a domain.
I think this is a very good summary, usually if most of the APIs are getXXX() , setXXX(), loadXXX() , createXXX() ........ Then we mostly design APIs that expose low level detail to the API user to work on, which, is work but user probably work nicer if we can come up with language like API that allow users to do their work in more descriptive level.

I think if API design like that usually it will reduce the code duplication, what ever real duplication or conceptual duplication. It probably already apply "Tell, don't ask" style - http://c2.com/cgi/wiki?TellDontAsk

A discussion about applying "Tell, don't ask" which lead to message passing architecture - http://beautifulcode.oreillynet.com[..]07/10/do_messages_want_to_be_asynchr.php

And other discussion about "Tell, don't ask"
http://sriramnarayan.blogspot.com[..]/2008/11/demeters-law-tell-dont-ask.html
http://sriramnarayan.blogspot.com[..]part-two-demeters-law-tell-dont-ask.html
http://sriramnarayan.blogspot.com[..]rt-three-demeters-law-tell-dont-ask.html

One good sample with explaination -
http://hamletdarcy.blogspot.com[..]-it-really-domain-specific-language.html
http://nat.truemesh.com/archives/000727.html

Few links - http://dreamhead.blogbus.com/logs/17667876.html

From CRUD to DDD - http://www.udidahan.com[..]2/15/from-crud-to-domain-driven-fluency/

I like this: "XML abuse reduction (conducting an “XML Intervention”)" - http://www.lostechies.com[..]ps-internal-dsl-draft-outline-notes.aspx

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

ease of use gone wrong



(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

failfast


Have read this article long time before: http://www.martinfowler.com/ieeeSoftware/failFast.pdf However, the more I work on programming the more I find that reasonable default (may be with logging) work better in some cases, but really need to beware about the cost of debugging if there is problem....

Another discussion about failfast vs. failsafe - http://www.certpal.com[..]009/09/iterators-fail-fast-vs-fail-safe/

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

flow condition


i wonder if it makes sense to refactor from this:

public void someMethod(SomeClass someObject) {
if(someObject != null){
do something ...
}
}
to this:
public void someMethod(SomeClass someObject) {
if(someObject == null) return;
do something ...
}

http://groups.yahoo.com/group/refactoring/message/3385

The other discussion about flow control presentation - http://www.artima.com/forums/flat.jsp?forum=106&thread=211172

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

functional


Having functional program in java? http://codemonkeyism.com/functional-programming/

Functional Programming For The Rest of Us - http://www.defmacro.org/ramblings/fp.html?

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

handle exception in finally


This blog discuss the code at finally can affect code at catch block - http://mult.ifario.us/articles/2006/07/26/java-brain-teaser


ExternalResource resource = resourceManager.open();
Throwable e1 = null;
try {
// Use the resource (stream, db connection, ...)
} catch (Throwable e) {
e1 = e;
} finally {
try {
resource.close();
if (e1 != null) throw e1;
} catch (Throwable e2) {
// Pretend e2 doesn't already have a cause...
if (e1 != null) e2.initCause(e1);
throw e2;
}
}

http://bagotricks.com[..]06/02/06/dropping-the-ball-er-exception/

or this, can be better looking


try {
InputStream is = new FileOutputStream("hello.txt");
try {
is.write("hello");
finally {
is.close();
}
} catch (IOException e) {
e.printStrackTrace();
}

http://jroller.com/page/davinci?entry=finally_in_catch

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

hashing


http://computinglife.wordpress.com[..]why-do-hash-functions-use-prime-numbers/
http://www.azillionmonkeys.com/qed/hash.html

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

html generation


This approach, as far as I know, is the nicest one, please tell me if you have better choice:
http://www-128.ibm.com/developerworks/java/library/j-pg04125/
http://www-128.ibm.com/developerworks/cn/java/j-pg04125/
http://groovy.codehaus.org/GroovyMarkup
http://redhanded.hobix.com/inspect/markabyForRails.html

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design

immutability


Java Immutability - http://www.theserverside.com[..]_id=50161&asrc=EM_NLN_4133229&uid=703565

"A similar pattern is that with objects that you need to open before usage and make sure that they are closed on usage completion."

http://digerati-illuminatus.blogspot.com[..]2/initialize-pattern-and-open-close.html

Discussion of various approach that implement immutable class - http://discuss.joelonsoftware.com/default.asp?design.4.601499

How to create immutable class, and why it is better? - http://www.infoq.com/presentations/Immutable-Object

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

problem of using exception for control flow


Other than harder to read, this approach is easier to have side effect, consider the following case:

// Code which fail
public String service() {
try {
// a lot of other code....
return getRecord();
} catch (SQLException re) {
return "defaultRecord";
}
}

private String getRecord() throws SQLException {
PreparedStatement ps = getConnection().prepareStatement("select something from sometable");
try {
final ResultSet rs = ps.executeQuery();
try {
if (rs.next())
return rs.getString(1);
else
throw new NotFoundException();
} finally {
rs.close();
}
} finally {
ps.close();
}

// definition of NotFoundException, analog to IOException and FileNotFoundException
public final class NotFoundException extends SQLException {....}


The idea is, for any database problem, just return default value. However, if someone change the interface of NotFoundException to

public final class NotFoundException extends RuntimeException {....}

Then it break service() silencely :-/ Some to it is better to have


// Code which fail
public String service() {
try {
// a lot of other code....
return getRecord() == null ? "defaultRecord" : getRecord();
} catch (SQLException re) {
// proper exception handling
}
}

private String getRecord() throws SQLException {
PreparedStatement ps = getConnection().prepareStatement("select something from sometable");
try {
final ResultSet rs = ps.executeQuery();
try {
if (rs.next())
return rs.getString(1);
else
return null;
} finally {
rs.close();
}
} finally {
ps.close();
}



(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/distribute

scalability


There are two key primary ways of scaling web applications which is in practice today.
1) “Vertical Scalability” - Adding resource within the same logical unit to increase capacity. An example of this would be to add CPUs to an existing server, or expanding storage by adding hard drive on an existing RAID/SAN storage.
2) “Horizontal Scalability” - Adding multiple logical units of resources and making them work as a single unit. Most clustering solutions, distributed file systems, load-balancers help you with horizontal scalability.

Scalability can be further sub-classified based on the “scalability factor”.
1) If the scalability factor stays constant as you scale. This is called “linear scalability“.
2) But chances are that some components may not scale as well as others. A scalability factor below 1.0 is called “sub-linear scalability“.
3) Though rare, its possible to get better performance (scalability factor) just by adding more components (i/o across multiple disk spindles in a RAID gets better with more spindles). This is called “supra-linear scalability“.
4) If the application is not designed for scalability, its possible that things can actually get worse as it scales. This is called “negative scalability“.

http://www.royans.net/arch/2007/09/22/what-is-scalability/

Report of building web application with 55k pageload with rail - http://shanti.railsblog.com[..]mongrels-handled-a-550k-pageview-digging

XMPP a IM protocol about scalability - http://www.process-one.net[..]icle/the_aol_xmpp_scalability_challenge/

Presentation and resources of making you website more scalable - http://www.scribd.com[..]9/Real-World-Web-Performance-Scalability http://www.theserverside.com[..]lications&asrc=EM_NLN_3990118&uid=703565 http://www.theserverside.com[..]ionsPart2&asrc=EM_NLN_3990119&uid=703565

Brian Zimmer, architect at travel startup Yapta, highlights some worst practices jeopardizing the growth and scalability of a system:
* The Golden Hammer. Forcing a particular technology to work in ways it was not intended is sometimes counter-productive. Using a database to store key-value pairs is one example. Another example is using threads to program for concurrency.
* Resource Abuse. Manage the availability of shared resources because when they fail, by definition, their failure is experienced pervasively rather than in isolation. For example, connection management to the database through a thread pool.
* Big Ball of Mud. Failure to manage dependencies inhibits agility and scalability.
* Everything or Something. In both code and application dependency management, the worst practice is not understanding the relationships and formulating a model to facilitate their management. Failure to enforce diligent control is a contributing scalability inhibiter.
* Forgetting to check the time. To properly scale a system it is imperative to manage the time alloted for requests to be handled.
* Hero Pattern. One popular solution to the operation issue is a Hero who can and often will manage the bulk of the operational needs. For a large system of many components this approach does not scale, yet it is one of the most frequently-deployed solutions.
* Not automating. A system too dependent on human intervention, frequently the result of having a Hero, is dangerously exposed to issues of reproducibility and hit-by-a-bus syndrome.
* Monitoring. Monitoring, like testing, is often one of the first items sacrificed when time is tight.

http://highscalability.com/scalability-worst-practices

Useful Corporate Blogs that Talk About Scalability - http://highscalability.com[..]l-corporate-blogs-talk-about-scalability

Overview of mapreduce and how it compare with other distributed programming model -http://natishalom.typepad.com[..]0/is-mapreduce-going-to-main-stream.html

Paper of data store at amazon http://www.allthingsdistributed.com/2007/10/amazons_dynamo.html

Discuss how haven't sync can cause performance issue - http://www.theserverside.com[..]lications&asrc=EM_NLN_6273194&uid=703565 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6423457

Discussion about Cloud Based Memory Architectures - http://highscalability.com[..]ased-memory-architectures-next-big-thing

http://highscalability.com[..]alability-and-performance-best-practices

Interview with google engineer - http://www.zdnet.co.uk[..]gle-at-scale-everything-breaks-40093061/

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/distribute

storage


How facbook manage photo storage - http://www.facebook.com/note.php?note_id=76191543919&ref=mf

(google search) (amazon search)


Fri Dec 30 19:39:56 AEDT 2011 From /weblog/design/exception

suggestion


With nice examples - http://www.javaspecialists.eu/archive/Issue162.html

Try to do better working than log and quit - http://blog.objectmentor.com[..]9/01/05/abstracting-away-from-exceptions

http://www.makinggoodsoftware.com[..]ceptions-in-java-4-basic-considerations/

Exception Patterns - http://c2.com/cgi/wiki?ExceptionPatterns

(google search) (amazon search)