Showing posts with label API design. Show all posts
Showing posts with label API design. Show all posts

Thursday, October 22, 2015

Good API video watching and notes taken

Oct. 22, 2015

  Spent time to look into the note through the video, and then study more later:


How To Design A Good API and Why it Matters (Julia's rating: A+)
https://www.youtube.com/watch?v=aAb7hSCtvGw


1. Watched again on 10/21/2015, notes taken to share:
54:40/1:00:18
Use Appropriate Parameter and Return Types
. Favor interface types over classes for input
- provides flexibility, performance
. Use most specific possible input parameter type
- Moves error from runtime to compile time (Julia's comment: Great tip, reduce time on debugging, fix things in compiling time!)
. Don't use string if a better type exists
- Strings are cumbersome, error-prone, and slow
. Don't use floating point for monetary values
- Binary floating point causes inexact results!
- Use double (64 bits) rather than float (32bits)
-Precision loss is real, performance loss negligible

2. watched again on 10/21/2015, notes taken to share:
49:19/1:00:18
Don't violate the Principle of Least Astonishment

Read more on this article:
http://programmers.stackexchange.com/questions/187457/what-is-the-principle-of-least-astonishment

3. watched again on 10/21/2015, notes taken to share:
42:31/1:00:18

Subclass only where it Makes Sense
. Subclassing implies substitutability (Liskov)
-- Subclass only when is-a relationship exists
-- Otherwise, use composition 

. Public classes should not subclass other public classes for ease of implementation
Bad: Properties extends Hashtable 
        Stack extends Vector 

Good: Set extends Collection 




Thursday, June 25, 2015

Cache design, dynamic programming - matrix region sum

June 25, 2015

Introduction

It is my firs time to read the algorithm and I am so surprised to learn the algorithm. I love the learning and also very happy to read the blog with good and very clear explanation of the algorithm.

Problem statement:
Given the integer matrix, top left and bottom right coordinates of the rectangular region, calculate the region sum.
Here is one of blogs I like to read and share. 

Make it more time efficient


Naive solution, O(n x m) calculation of addition to get the sum. How to get it as O(1) using cache, how big the cache space?
Naive way to design the cache, it takes O( n2 x m2) space. The efficient way is O(n x m), using dynamic programming.
Share the practice C# code, here is the link.