Sunday, December 23, 2012

[gpu/cuda] NSight needs to be started from command line

otherwise, you'll get

/bin/sh: nvcc: command not found

apparently it is bug in CUDA's installation script, I found it is still not fixed in Nsight 5.0.0


see

http://stackoverflow.com/questions/11672515/nsight-eclipse-edition-not-finding-nvcc

Monday, June 11, 2012

3 tier, 3 layer, MVC, a more 'thorough' comparison

Many comparison of the 3-xxx v.s. MVC on the web, I am trying to make a more thorough summary here:

1. 3-tier (physical architecture) is different from 3-layer (logical architecture) as Martin Fowler (PEAA, Chap1 "The Evolution of Layers in Enterprise Applications") and many others pointed out. 


2. So it is really the comparison between 3-layer (principally, Presentation, Domain Logic and Data Source layers (PEAA Chap1 "The Three Principal Layers") ) and the MVC

- Presentation Layer is similar to View, most would agree

- Model and Control is bit more ambiguous to map to Domain Logic and Data Source layers.

----- Not the actual data source (such as the actual DB or JMS) but data accessing 'sub-layer' (such as DAO) of the 'Data Source' layer can be mapped to part of 'Model' in a small system. In a large system, 'Data Source' layer could be separated from the entire 'MVC' and the Model of the 'MVC' will only contain logic for 'internal representation of data' that the 'View' can understand (e.g, similar to a 'Data Transfer Object' (PEAA, "Core J2EE Pattern'))*.


----- So therefore most things in Domain Logic belong 'Model' and 'Control', doesn't it?  Not necessarily, here is the trickier part: 


--------- We don't seem to agree on where the core part of 'Domain Logic' - the so-called 'Business Logic' should be, 
----------------A. Some say in Model (http://forums.asp.net/post/1380219.aspx
----------------B. Some say in Control (http://stackoverflow.com/a/698250)
----------------C. Some say in neither but a separately logical location (http://stackoverflow.com/a/9749694, http://stackoverflow.com/a/4577672) and leave the Control skinny and dumb (e.g. only for http request processing and parameter extracting)** -> this is perhaps the more common practice, especially in the large enterprise system, where 'Application Services' encapsulating business logic and can be called remotely through 'Service Facade' and 'Business Delegate' ("Core J2EE Patterns");


- You also hear people say that MVC could be an architecture for just the Presentation Layer of larger systems. Well it's probably true if you consider * and **; 

- Another well quoted explanation to the difference, rather a little too superficial and misleading to me, is that

"
Conceptually the three-tier architecture is linear. However, the MVC architecture is triangular: the view sends updates to the controller, the controller updates the model, and the view gets updated directly from the model.
"
(http://en.wikipedia.org/wiki/3-tier_architecture#Comparison_with_the_MVC_architecture)

I found it is a bit misleading as it sounds like if you do an Update operation, it has to go through the Control, but if you do a Retrieval operation, you don't. 

Nevertheless, if you have a 'Front Controller' (PEAA, "Core J2EE Patterns") as part of your control as your frontline to all requests, which most business systems that are open to web request do nowadays, either Update or Retrieval operation, you will need to go through the Control. 
 It probably better to say that 'The view sends update to controller (e.g. press the Buy button), the controller update the model (e.g. remove the item from the stocked item list) correspondingly and send it back to the view to display updated information (e.g. bring up the new stocked item list on the web page)'.
And if that is the case, it does not constitute a really legit difference from '3 Layer' as we can easily have a 'Transfer Object' (PEAA, "Core J2EE Pattern') that goes through all the layers, which will be used in quite similar capacity as the 'Model' in 'MVC'.

Sunday, June 3, 2012

URL, URI, URN, ... the 'official' difference

URI:

Internet standard STD 66 (also RFC 3986) defines the generic syntax to be used in all URI schemes.

Syntax:
<scheme name> : <hierarchical part> [ ? <query> ] [ # <fragment> ]

Both URN and the obsolete notion of URL therefore are URIs, and a URI does not have to be classified just URN or just URL.

"
URIs can be classified as locators (URLs), as names (URNs), or as both. A uniform resource name (URN) functions like a person's name, while a uniform resource locator (URL) resembles that person's street address. In other words: the URN defines an item's identity, while the URL provides a method for finding it
"

URN:

http://en.wikipedia.org/wiki/Uniform_Resource_Name

Syntax (RFC 2141):
<URN> ::= "urn:" <NID> ":" <NSS>

Example:
urn:isbn:0451450523 -  The URN for The Last Unicorn (1968 book), identified by its book number.
urn:isan:0000-0000-9E59-0000-O-0000-0000-2 - The URN for Spider-Man (2002 film) identified by its audiovisual number.
urn:issn:0167-6423 - The URN for the Science of Computer Programming (scientific journal), identified by its serial number.
urn:ietf:rfc:2648 - The URN for the IETF's RFC 2648.
urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66 - A URN using a version 1 UUID.


URL:

http://en.wikipedia.org/wiki/Uniform_resource_locator

(Informal) Syntax (RFC 1738 - Obsolete):
scheme://domain:port/path?query_string#fragment_id

Example:
http://<host>:<port>/<path>?<searchpart>
mailto:<rfc822-addr-spec>
news:<newsgroup-name>
news:<message-id>
telnet://<user>:<password>@<host>:<port>/

URI, URN and URL Clarification and Recommendation in RFCs:

RFC3986 - http://tools.ietf.org/html/rfc3986#section-1.1.3

"
An individual scheme does not have to be classified as being just one
   of "name" or "locator".  Instances of URIs from any given scheme may
   have the characteristics of names or locators or both, often
   depending on the persistence and care in the assignment of
   identifiers by the naming authority, rather than on any quality of
   the scheme.  Future specifications and related documentation should
   use the general term "URI" rather than the more restrictive terms
   "URL" and "URN" [RFC3305].
"

RFC3305: http://tools.ietf.org/html/rfc3305 - The general idea is that usage of the term 'URL' should be replace by the more generic term 'URI'





Wednesday, May 9, 2012

SOAP, REST, RPC

 http://stackoverflow.com/questions/409338/examples-of-the-best-soap-rest-rpc-web-apis-and-why-do-you-like-them-and-what

http://geeknizer.com/rest-vs-soap-using-http-choosing-the-right-webservice-protocol/

 REST web services are:
  • Lightweight – not a lot of extra xml markup
  • Human Readable Results
  • Easy to build – no toolkits required
SOAP also has some advantages:
  • Easy to consume – sometimes
  • Rigid – type checking, adheres to a contract
  • Development tools

(OReilly.RESTful.Web.Services.May.2007)

SOAP
a typical SOAP service keeps its method information in the entity-body
and in a HTTP header.

Example Request Message:

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header>
  </soap:Header>
  <soap:Body>
    <m:GetStockPrice xmlns:m="http://www.example.org/stock">
      <m:StockName>IBM</m:StockName>
    </m:GetStockPrice>
  </soap:Body>
</soap:Envelope>

Example Response Message:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPriceResponse>
    <m:Price>34.5</m:Price>
  </m:GetStockPriceResponse>
</soap:Body>

</soap:Envelope> 

RESTful
In RESTful architectures, the method information goes into the HTTP method. In Resource-
Oriented Architectures, the scoping information goes into the URI. The combination
is powerful

If the HTTP method doesn't match the method information, the service isn’t RESTful. If the scoping information
isn’t in the URI, the service isn’t resource-oriented. These aren't the only requirements,
but they're good rules of thumb.

RPC
An RPC-style web service accepts an envelope full of data from its client, and sends a
similar envelope back. The method and the scoping information are kept inside the
envelope, or on stickers applied to the envelope.

Simply put, an XML-RPC service ignores most features of HTTP. It exposes
only one URI (the “endpoint”), and supports only one method on that URI (POST). e.g. No matter what you do with the UPC database service,
the URI is always http://www.upcdatabase.com/rpc and the HTTP method is always
POST.

A few well-known examples of RPC-style web services:
• All services that use XML-RPC
• Just about every SOAP service (see the “Technologies on the Programmable
Web” section later in this chapter for a defense of this controversial statement)
• A few web applications (generally poorly designed ones)

REST-RPC hybrid
The Flickr web API asks clients to use HTTP GET even when they
want to modify the data set. To delete a photo you make a GET request to a URI that
includes method=flickr.photos.delete. That’s just not what GET is for, as I’ll show in
“Split the Data Set into Resources [115]. The Flickr web API is a REST-RPC hybrid:
RESTful when the client is retrieving data through GET, RPC-style when the client is
modifying the data set.

A few well-known examples of REST-RPC hybrid services include:
• The del.icio.us API
• The “REST” Flickr web API
• Many other allegedly RESTful web services
• Most web applications

Tuesday, May 8, 2012

Why singleton is bad

- Against the OO spirit and increase coupling which usually becomes hidden

- Classic Singleton approach is hard to unit test

- Classic Singleton Class is hard to be inherited

http://code.google.com/p/google-singleton-detector/wiki/WhySingletonsAreControversial

http://stackoverflow.com/questions/1020312/are-singletons-really-that-bad

http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/

http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/

http://sites.google.com/site/steveyegge2/singleton-considered-stupid

J2SE v.s. J2EE

http://www.velocityreviews.com/forums/t141428-j2ee-vs-j2se-vs-jdk.html

J2SE - Java 2 Standard Edition. This is what most people need for a
Servlet/Beans/JSP/XML/JDBC web application or Swing desktop application.

J2EE - Java 2 Enterprise Edition. This is J2SE plus RMI tools, EJB, an
EJB server, and other distributed computing tools. There's a high
development overhead to using J2EE features so don't bother unless you
need them.

http://stackoverflow.com/questions/402056/should-i-do-more-javase-before-jumping-to-javaee

Why stateless utility class with static methods is bad?

- Violation of the OO design principle:
---- Theoretically, if such a static method takes in arg1, arg2, ... and change their 'state', then either:
--------1. arg1, arg2, should be members of a separate class Class1 and assigned through constructor 
--------2. the operation carried out by this static method should be part of classes of arg1, arg2 ....

- Hard to mock and Unit Test

Practically, however, most people don't ban it in entirety.

+ Could potentially save memory in multithread operation (the Utility object itself is read-only by the thread as it contains no state, hence no race or deadlock) - e.g. Stateless session bean pool in J2EE?

+ Examples of existing implementation:
JAVA 
java.lang.Math
java.util.Collection

C#
System.Collections.Specialized.CollectionsUtil 
System.Net.WebUtility
 
 
http://stackoverflow.com/questions/3339929/if-a-utilities-class-is-evil-where-do-i-put-my-generic-code
http://stackoverflow.com/questions/3340032/utility-classes-are-evil
http://stackoverflow.com/questions/1942903/java-class-with-only-static-fields-and-methods-bad-or-good-practice 
 

How To Design A Good API and Why it Matters

http://www.youtube.com/watch?v=aAb7hSCtvGw 
 

Thursday, April 19, 2012

"Cannot reduce the visibility of the inherited method from ..." - inteface are implicitly public

http://stackoverflow.com/questions/8584802/reducing-visibility-of-the-java-interface-when-implementing-it-in-an-abstract-cl

interface CFL extends PowerSaver, LightingDevice{
    void showLifeTime();
    void getBrand();
}

interface PowerSaver {
    void showEcoRate();
}

interface LightingDevice {
    void doLight();
}
 
 
public abstract class Philips implements CFL{
    void showLifeTime(){}; // ! => Cannot reduce the visibility of the inherited method from CFL.
    void showEcoRate(){};  // ! => Cannot reduce the visibility of the inherited method from CFL.
}
 
 
Interface implementations must be public.
To understand the error, see the spec:
Every method declaration in the body of an interface is implicitly public.
Therefore, you're actually overriding (or, in this case, implementing) public methods.
 

Monday, April 9, 2012

JDK v. JRE v. JVM

http://www.javabeat.net/qna/67-wat-is-the-difference-between-jrejvm-and-jdk/

JDK (Java Development Kit)

Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc…
Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method.
You need JDK, if at all you want to write your own programs, and to compile the m. For running java programs, JRE is sufficient.
JRE is targeted for execution of Java files
i.e. JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.
JDK is mainly targeted for java development. I.e. You can create a Java file (with the help of Java packages), compile a Java file and run a java file

JRE (Java Runtime Environment)

Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system
The Java Virtual Machine provides a platform-independent way of executing code; programmers can concentrate on writing software, without having to be concerned with how or where it will run.
If u just want to run applets (ex: Online Yahoo games or puzzles), JRE needs to be installed on the machine.

JVM (Java Virtual Machine)

As we all aware when we compile a Java file, output is not an 'exe' but it's a '.class' file. '.class' file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… JVM is platform dependent.
The JVM is called "virtual" because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs.
There are different JVM implementations are there. These may differ in things like performance, reliability, speed, etc. These implementations will differ in those areas where Java specification doesn’t mention how to implement the features, like how the garbage collection process works is JVM dependent, Java spec doesn’t define any specific way to do this.