SlideShare a Scribd company logo
1 of 13
The programming philosophy of jRQL

Frank Leja, May 2012
My goals
You wanna …
• be flexible and agile for changing customer demands?
• develop faster in the long run without reducing quality?
• don‘t invent the wheel again and again?

• write reliable code?
• write errorless code?
• write highly reusable code?


… check out this guide, if you want to improve your style!



                                                             take the chance
… follow these small steps to improve yourself …
You write services!
Think of every class and method
as a service you provide
for users not having your knowledge of the domain.                                   unmistakable

Means
• your classes and methods forms an API

• tell your users with your code what they can do (public)
• how you do it (implementation) is private (encapsulation), could be changed!

• public method and parameter names focus on what not how
• take 10s to think on good names!
                                                                                          reliable
• all possible usage scenarios should work! (formBean setter problem)
• or force user for only one usage possibility (method calling order)

• caches has to be maintained transparently (for the user) (e.g. in instance variables)

• full javadoc with all parameters and possible return values described
• handle every problem, even it „could not happen“ (prevent NullPointerExceptions)
think on options: see this
ProjectDetailsFormBean    public void saveProjectDetails(ProjectDetailsFormBean formBean) {
.setBpm(String)
.setDescription(String)       // write the data into CRX
                              this.setProperty(ProjectConstants.DESCRIPTION, formBean.getDescription());
.setEndDate(Calendar)         this.setProperty(ProjectConstants.OWNER, formBean.getBpm());
.setItm(String)               this.setProperty(ProjectConstants.OWNER2, formBean.getItm());
.setName(String)              this.setProperty(ProjectConstants.START_DATE, formBean.getStartDate());
.setStartDate(Calendar)       this.setProperty(ProjectConstants.END_DATE, formBean.getEndDate());
.setStatus(String)            this.setProperty(ProjectConstants.STATUS, formBean.getStatus());


If not all set* methods used, the save method will go wrong.

How can this problem be solved?


  1. with FormBean?                  my option:
  2. without FormBean?               • no form bean at all, bc only used once for all attributes
                                     • direct usage of parameter values in method
  What do you prefer and why?
Think on all options and decide wisely and
  consious
there are always options how to solve a problem or implement a task

1. think on all possible options you could imagine

2. for every option think on the pros and cons

3. choose the option which best matches the goals given in this guide
Dry
Never break this rule!
                                                                                Easy to
Don‘t repeat yourself! or Once and Only Once (see wikipedia)                    change

public method1() {
if (getOwnerProfile() != null) {
                                            public boolean hasOwnerProfile() {
…
                                                     return getOwnerProfile() != null;
public method2() {
                                            }
if (getOwnerProfile() != null) {
…                                                                               Safe to
                                                                                change
StringBuilder sb = …                        StringBuilder sb = …
If (sb.toString().length() >5) {            String currentName = sb.toString();
  node.getNode(sb.toString());              If (currentName.length() >) {
                                              node.getNode(currentName);
                                                                                     reusable
• every check should go into a new check method (is*, has*, exists*)
• every repetition within a method should use a local variable or new method
• find the right class for the new method to re-use it from everywhere you need it
One method = one task!
Every method should solve only ONE task!
                                                                             flexible
One method = one task

This will result typically into many short methods with only some lines of code (<10 w/o
catches), often <5 lines

• check methods return boolean (is*, has*, exists*)
• very short attribute methods (get*, set*)                                reusable
• every conversion as gettter too (date formatting)
• new types of method parameters supported with new method
• action methods with other verbs

                                                                           easy to
Benefits?                                                                understand
• better possibility for reusing a task
• easy to assemble into new tasks with more power (more abstract)

• even the main program code could be only 1 page long!
naming convention for getter
private Entity getEntity() {
…
}
                                                                   keep
public String getEntityName() {                                   control
  return getEntity().getName();
}

public String getEntityDescription() {
  return getEntity ().getDescription();
}

public String getEntityEmail() {
  return getEntity ().getEmail();
}

prevent exposing an entity, because you break encapsulation
if you do it, think carefully on the consequences!
no conversion possible (show blank, if entity could not found)
no lazy initialisation possible
How I implement a method
1. visibility of method
    (public, private)
2. name of method
    (think on WHAT not how; the kind of implementation is never stated in the name!)
3. how many input parameters?
4. type of input parameters?
    (prefer an object over primitive types like String to keep signature stable)
5. return value
    (reduce void, return what makes sense, even you don‘t need it yet)
6. now write the method‘s signature
7. write the methods javadoc explanation
    (sometimes a better method name comes into my mind, than adjust)
8. implement functionality
9. sit back and check the method‘s implementation
    (all possible return values of used methods handled?)
10. sit back and think on the big picture
    (can this method be used at any time and all circumstances?)
Monitor cheat sheet                                                   hang on your
                                                                          monitor


Issues                                    Recommended action

method name tell about how implemented?   rename to tell what it does, not how
long method?                              refactor | extract methods to shorten it

exposing entity?                          implement getter for all needed attributes
first thought implemented?                think on other options and decide wisely

method called twice for return value      refactor | extract local variable

all (instance var) caches maintained?     update when set, or set to null

checkstyle complaints?                    fix them all!

unused or unwanted methods still there?   remove first thought not needed anymore
You are free!
there is no limitation for the number

• of methods of a class
• of method parameters

A class represents an item from your domain, regardless how many methods it
needs.

A class should not be splitted only because of the number of methods!


By the way, prevent static helper methods, because you will never get them in the
code completion feature of your IDE.

Instead implement methods on your API classes you can re-use!
forget about complains
The most often complain I heard for this programming style is:

too many methods on a class are not maintainable

This comes, because you try to understand all code of a class at the same time.

I think on a method as a service I offer to the users of my class.

For implementing a new service (method) I only have to understand how to achieve this.

I can concentrate of implementing this one service (method) right,
without a need to understand all the other methods available.

Of course, I can call other methods to provide the new service (method).


(This might be a Java specific problem, because Java handle a whole classes source into 1 file.
In Smalltalk a file for class doesn‘t exists, only a list of methods you have to check one-by-one.)
Conclusion
If you want to

• be agile and flexible
• write safe and reliable code and
• develop fast at still high quality,

you have to re-use your code as much as you can!

In the long term you would be faster as a programmer doing the same stuff again and again.


Only because of the consequent usage of these principles jRQL

• can offer functions from such a wide range
• is reliable and stable
• and still easy to enhance!

More Related Content

What's hot

Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Nuzhat Memon
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptFu Cheng
 
The Ring programming language version 1.5.1 book - Part 70 of 180
The Ring programming language version 1.5.1 book - Part 70 of 180The Ring programming language version 1.5.1 book - Part 70 of 180
The Ring programming language version 1.5.1 book - Part 70 of 180Mahmoud Samir Fayed
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Ruby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyRuby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyTushar Pal
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized军 沈
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with pythonArslan Arshad
 
25 java tough interview questions
25 java tough interview questions25 java tough interview questions
25 java tough interview questionsArun Banotra
 
The Ring programming language version 1.3 book - Part 55 of 88
The Ring programming language version 1.3 book - Part 55 of 88The Ring programming language version 1.3 book - Part 55 of 88
The Ring programming language version 1.3 book - Part 55 of 88Mahmoud Samir Fayed
 

What's hot (20)

Generics in java
Generics in javaGenerics in java
Generics in java
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
Prototype
PrototypePrototype
Prototype
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Code smells and remedies
Code smells and remediesCode smells and remedies
Code smells and remedies
 
The Ring programming language version 1.5.1 book - Part 70 of 180
The Ring programming language version 1.5.1 book - Part 70 of 180The Ring programming language version 1.5.1 book - Part 70 of 180
The Ring programming language version 1.5.1 book - Part 70 of 180
 
Only oop
Only oopOnly oop
Only oop
 
JavsScript OOP
JavsScript OOPJavsScript OOP
JavsScript OOP
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Ruby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyRuby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for ruby
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
 
25 java tough interview questions
25 java tough interview questions25 java tough interview questions
25 java tough interview questions
 
The Ring programming language version 1.3 book - Part 55 of 88
The Ring programming language version 1.3 book - Part 55 of 88The Ring programming language version 1.3 book - Part 55 of 88
The Ring programming language version 1.3 book - Part 55 of 88
 

Viewers also liked

Security Systems of The Future
Security Systems of The FutureSecurity Systems of The Future
Security Systems of The FutureDAVID ISSA
 
Phantom Runner Project
Phantom Runner ProjectPhantom Runner Project
Phantom Runner ProjectDAVID ISSA
 
Practical information and agenda berlin
Practical information and agenda berlinPractical information and agenda berlin
Practical information and agenda berlinChon Keon
 
Final presentation
Final presentationFinal presentation
Final presentationraylian
 
Future of the remote
Future of the remoteFuture of the remote
Future of the remoteDAVID ISSA
 
A Circular Story
A Circular StoryA Circular Story
A Circular StoryDAVID ISSA
 
Nouveau présentation microsoft power point (1)
Nouveau présentation microsoft power point (1)Nouveau présentation microsoft power point (1)
Nouveau présentation microsoft power point (1)eftis
 
Billaud camille m1_eftis_spider_silk_2nd_passage
Billaud camille m1_eftis_spider_silk_2nd_passageBillaud camille m1_eftis_spider_silk_2nd_passage
Billaud camille m1_eftis_spider_silk_2nd_passageeftis
 
Starbucks: A Story of Growth - case study presentation for EBS/DBS
Starbucks: A Story of Growth - case study presentation for EBS/DBSStarbucks: A Story of Growth - case study presentation for EBS/DBS
Starbucks: A Story of Growth - case study presentation for EBS/DBSBrandon J. Murray, PMP
 

Viewers also liked (12)

Security Systems of The Future
Security Systems of The FutureSecurity Systems of The Future
Security Systems of The Future
 
Phantom Runner Project
Phantom Runner ProjectPhantom Runner Project
Phantom Runner Project
 
Practical information and agenda berlin
Practical information and agenda berlinPractical information and agenda berlin
Practical information and agenda berlin
 
Final presentation
Final presentationFinal presentation
Final presentation
 
Future of the remote
Future of the remoteFuture of the remote
Future of the remote
 
A Circular Story
A Circular StoryA Circular Story
A Circular Story
 
Mulookk
MulookkMulookk
Mulookk
 
Nouveau présentation microsoft power point (1)
Nouveau présentation microsoft power point (1)Nouveau présentation microsoft power point (1)
Nouveau présentation microsoft power point (1)
 
Parameciul
ParameciulParameciul
Parameciul
 
Billaud camille m1_eftis_spider_silk_2nd_passage
Billaud camille m1_eftis_spider_silk_2nd_passageBillaud camille m1_eftis_spider_silk_2nd_passage
Billaud camille m1_eftis_spider_silk_2nd_passage
 
Starbucks: A Story of Growth - case study presentation for EBS/DBS
Starbucks: A Story of Growth - case study presentation for EBS/DBSStarbucks: A Story of Growth - case study presentation for EBS/DBS
Starbucks: A Story of Growth - case study presentation for EBS/DBS
 
NAVIDAD PARA TOIDOS
NAVIDAD PARA TOIDOSNAVIDAD PARA TOIDOS
NAVIDAD PARA TOIDOS
 

Similar to The programming philosophy of jrql

The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185Mahmoud Samir Fayed
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartGabriele Lana
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design PatternsPham Huy Tung
 
The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196Mahmoud Samir Fayed
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerIgor Crvenov
 
The Ring programming language version 1.10 book - Part 86 of 212
The Ring programming language version 1.10 book - Part 86 of 212The Ring programming language version 1.10 book - Part 86 of 212
The Ring programming language version 1.10 book - Part 86 of 212Mahmoud Samir Fayed
 
33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmodwalkmod
 
The Ring programming language version 1.2 book - Part 53 of 84
The Ring programming language version 1.2 book - Part 53 of 84The Ring programming language version 1.2 book - Part 53 of 84
The Ring programming language version 1.2 book - Part 53 of 84Mahmoud Samir Fayed
 
Software Engineering Best Practices @ Nylas
Software Engineering Best Practices @ NylasSoftware Engineering Best Practices @ Nylas
Software Engineering Best Practices @ NylasBen Gotow
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsRasan Samarasinghe
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objectsmcollison
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in RubyVolodymyr Byno
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming RailsJustus Eapen
 
Test in action – week 1
Test in action – week 1Test in action – week 1
Test in action – week 1Yi-Huan Chan
 

Similar to The programming philosophy of jrql (20)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns
 
The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196The Ring programming language version 1.7 book - Part 78 of 196
The Ring programming language version 1.7 book - Part 78 of 196
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
 
The Ring programming language version 1.10 book - Part 86 of 212
The Ring programming language version 1.10 book - Part 86 of 212The Ring programming language version 1.10 book - Part 86 of 212
The Ring programming language version 1.10 book - Part 86 of 212
 
33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod
 
The Ring programming language version 1.2 book - Part 53 of 84
The Ring programming language version 1.2 book - Part 53 of 84The Ring programming language version 1.2 book - Part 53 of 84
The Ring programming language version 1.2 book - Part 53 of 84
 
Software Engineering Best Practices @ Nylas
Software Engineering Best Practices @ NylasSoftware Engineering Best Practices @ Nylas
Software Engineering Best Practices @ Nylas
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
core_java.ppt
core_java.pptcore_java.ppt
core_java.ppt
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - Modifiers
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming Rails
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
Test in action – week 1
Test in action – week 1Test in action – week 1
Test in action – week 1
 

Recently uploaded

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

The programming philosophy of jrql

  • 1. The programming philosophy of jRQL Frank Leja, May 2012
  • 2. My goals You wanna … • be flexible and agile for changing customer demands? • develop faster in the long run without reducing quality? • don‘t invent the wheel again and again? • write reliable code? • write errorless code? • write highly reusable code? … check out this guide, if you want to improve your style! take the chance … follow these small steps to improve yourself …
  • 3. You write services! Think of every class and method as a service you provide for users not having your knowledge of the domain. unmistakable Means • your classes and methods forms an API • tell your users with your code what they can do (public) • how you do it (implementation) is private (encapsulation), could be changed! • public method and parameter names focus on what not how • take 10s to think on good names! reliable • all possible usage scenarios should work! (formBean setter problem) • or force user for only one usage possibility (method calling order) • caches has to be maintained transparently (for the user) (e.g. in instance variables) • full javadoc with all parameters and possible return values described • handle every problem, even it „could not happen“ (prevent NullPointerExceptions)
  • 4. think on options: see this ProjectDetailsFormBean public void saveProjectDetails(ProjectDetailsFormBean formBean) { .setBpm(String) .setDescription(String) // write the data into CRX this.setProperty(ProjectConstants.DESCRIPTION, formBean.getDescription()); .setEndDate(Calendar) this.setProperty(ProjectConstants.OWNER, formBean.getBpm()); .setItm(String) this.setProperty(ProjectConstants.OWNER2, formBean.getItm()); .setName(String) this.setProperty(ProjectConstants.START_DATE, formBean.getStartDate()); .setStartDate(Calendar) this.setProperty(ProjectConstants.END_DATE, formBean.getEndDate()); .setStatus(String) this.setProperty(ProjectConstants.STATUS, formBean.getStatus()); If not all set* methods used, the save method will go wrong. How can this problem be solved? 1. with FormBean? my option: 2. without FormBean? • no form bean at all, bc only used once for all attributes • direct usage of parameter values in method What do you prefer and why?
  • 5. Think on all options and decide wisely and consious there are always options how to solve a problem or implement a task 1. think on all possible options you could imagine 2. for every option think on the pros and cons 3. choose the option which best matches the goals given in this guide
  • 6. Dry Never break this rule! Easy to Don‘t repeat yourself! or Once and Only Once (see wikipedia) change public method1() { if (getOwnerProfile() != null) { public boolean hasOwnerProfile() { … return getOwnerProfile() != null; public method2() { } if (getOwnerProfile() != null) { … Safe to change StringBuilder sb = … StringBuilder sb = … If (sb.toString().length() >5) { String currentName = sb.toString(); node.getNode(sb.toString()); If (currentName.length() >) { node.getNode(currentName); reusable • every check should go into a new check method (is*, has*, exists*) • every repetition within a method should use a local variable or new method • find the right class for the new method to re-use it from everywhere you need it
  • 7. One method = one task! Every method should solve only ONE task! flexible One method = one task This will result typically into many short methods with only some lines of code (<10 w/o catches), often <5 lines • check methods return boolean (is*, has*, exists*) • very short attribute methods (get*, set*) reusable • every conversion as gettter too (date formatting) • new types of method parameters supported with new method • action methods with other verbs easy to Benefits? understand • better possibility for reusing a task • easy to assemble into new tasks with more power (more abstract) • even the main program code could be only 1 page long!
  • 8. naming convention for getter private Entity getEntity() { … } keep public String getEntityName() { control return getEntity().getName(); } public String getEntityDescription() { return getEntity ().getDescription(); } public String getEntityEmail() { return getEntity ().getEmail(); } prevent exposing an entity, because you break encapsulation if you do it, think carefully on the consequences! no conversion possible (show blank, if entity could not found) no lazy initialisation possible
  • 9. How I implement a method 1. visibility of method (public, private) 2. name of method (think on WHAT not how; the kind of implementation is never stated in the name!) 3. how many input parameters? 4. type of input parameters? (prefer an object over primitive types like String to keep signature stable) 5. return value (reduce void, return what makes sense, even you don‘t need it yet) 6. now write the method‘s signature 7. write the methods javadoc explanation (sometimes a better method name comes into my mind, than adjust) 8. implement functionality 9. sit back and check the method‘s implementation (all possible return values of used methods handled?) 10. sit back and think on the big picture (can this method be used at any time and all circumstances?)
  • 10. Monitor cheat sheet hang on your monitor Issues Recommended action method name tell about how implemented? rename to tell what it does, not how long method? refactor | extract methods to shorten it exposing entity? implement getter for all needed attributes first thought implemented? think on other options and decide wisely method called twice for return value refactor | extract local variable all (instance var) caches maintained? update when set, or set to null checkstyle complaints? fix them all! unused or unwanted methods still there? remove first thought not needed anymore
  • 11. You are free! there is no limitation for the number • of methods of a class • of method parameters A class represents an item from your domain, regardless how many methods it needs. A class should not be splitted only because of the number of methods! By the way, prevent static helper methods, because you will never get them in the code completion feature of your IDE. Instead implement methods on your API classes you can re-use!
  • 12. forget about complains The most often complain I heard for this programming style is: too many methods on a class are not maintainable This comes, because you try to understand all code of a class at the same time. I think on a method as a service I offer to the users of my class. For implementing a new service (method) I only have to understand how to achieve this. I can concentrate of implementing this one service (method) right, without a need to understand all the other methods available. Of course, I can call other methods to provide the new service (method). (This might be a Java specific problem, because Java handle a whole classes source into 1 file. In Smalltalk a file for class doesn‘t exists, only a list of methods you have to check one-by-one.)
  • 13. Conclusion If you want to • be agile and flexible • write safe and reliable code and • develop fast at still high quality, you have to re-use your code as much as you can! In the long term you would be faster as a programmer doing the same stuff again and again. Only because of the consequent usage of these principles jRQL • can offer functions from such a wide range • is reliable and stable • and still easy to enhance!