Posts

Showing posts from 2015

Best programming practice

Today, I was going through the code of someone and found it difficult for myself to read it. And the reason behind that was too many If's and too many switch cases. Each method was written with more then 30 line of code. I wasn't sure that why he has choose Object Oriented Programming when he had to do that. Every developer who is willing to improve his programming skills he must need to keep one rule in his mind before writing code: Someone will read your code someday I think few just leave their code without method level or class level comments; so that no one get to know that who wrote that code. But, those stupids forget that subversion do this too. Anyway few of the things I think should be simple in code: Class level comments Method level comments Method should be well-commented Atomic NO to Conditional Programming I am not going to debate on comments because you can get this information from a lot of blogs. So, I will start this blog from the 4th Poi...

MySQL- Hierarchical Data

Image
No developer ever came into the problem of storing hierarchical data. And we always come up with a solution that store the parentId into the same table. And when we just need to retrieve the data then it becomes a nightmare to optimize the nested-join. The advantage to these systems is that they don't take a lot of space, but the disadvantage is that nearly all the maintenance has to be done in the application. So, in essence, these approaches trade lots of queries at retrieval time, for lots of queries at update and insert/delete time, and often some additional programming complexity. Just imagine a tree and what outcome a user may want: root - son - son#2 - grandson#1 - super grandson - son#3 -grandson#2 and I want to display it like: root -> son root -> son#2 root -> son#2 -> grandson#1 root -> son#2 -> grandson#1 -> super grandson root -> son#3 root -> son#3 -> grandson#2 In order to get the following output we apply the ...

Java 8 - Lambda & Functional Interfaces

Java 8 supposted to be a major release after Java 5 and it brought a lot of new changes and ease for java developers i.e. language,compiler,libraries,tools and runtime (JVM) Lambdas and Functional Interfaces Lambdas allow us to treat functionality as a method argument (passing functions around), or treat a code as data. So, this is must be good news for functional developers and from now on no need for anonymous classes in order to do functional programming with java. Examples (-> lambda): Arrays.asList(“a”,”b”,”c”,”d”).forEach( e -> System.out.println( e ) ); Arrays.asList(“a”,”b”,”c”,”d”).forEach( ( String str ) -> System.out.println( str ) ); Arrays.asList(“a”,”b”,”c”,”d”).forEach( ( String str ) -> {     System.out.println( str ) ;     System.out.println( str + ”,”) ; } ); Obviously lambda expression returns a value to but, it must not need to be declared, if not required. Arrays.asList(“a”,”b”,”c”,”d”).sort( ( ...