SlideShare a Scribd company logo
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

ODP
Clean code and refactoring
PPTX
Iterative architecture
PDF
Clean coding-practices
PPTX
Introduction to Design Patterns in Javascript
PPT
PDF
Java Programming - 03 java control flow
PDF
Java unit 7
PPTX
Basic concept of class, method , command line-argument
Clean code and refactoring
Iterative architecture
Clean coding-practices
Introduction to Design Patterns in Javascript
Java Programming - 03 java control flow
Java unit 7
Basic concept of class, method , command line-argument

What's hot (20)

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

Viewers also liked (12)

PDF
Security Systems of The Future
PPTX
Phantom Runner Project
PDF
Practical information and agenda berlin
PDF
Final presentation
PDF
Future of the remote
PDF
A Circular Story
DOCX
PPT
Nouveau présentation microsoft power point (1)
PPT
Parameciul
PPT
Billaud camille m1_eftis_spider_silk_2nd_passage
PDF
Starbucks: A Story of Growth - case study presentation for EBS/DBS
PDF
NAVIDAD PARA TOIDOS
Security Systems of The Future
Phantom Runner Project
Practical information and agenda berlin
Final presentation
Future of the remote
A Circular Story
Nouveau présentation microsoft power point (1)
Parameciul
Billaud camille m1_eftis_spider_silk_2nd_passage
Starbucks: A Story of Growth - case study presentation for EBS/DBS
NAVIDAD PARA TOIDOS
Ad

Similar to The programming philosophy of jrql (20)

PDF
Design Patterns
PDF
The Ring programming language version 1.5.4 book - Part 74 of 185
PDF
Refactoring In Tdd The Missing Part
PPTX
Javascript Common Design Patterns
PDF
The Ring programming language version 1.8 book - Part 81 of 202
PPTX
Design p atterns
PDF
The Ring programming language version 1.7 book - Part 78 of 196
PPT
Refactoring Tips by Martin Fowler
PDF
The Ring programming language version 1.10 book - Part 86 of 212
PDF
33rd degree talk: open and automatic coding conventions with walkmod
PDF
The Ring programming language version 1.2 book - Part 53 of 84
PDF
Software Engineering Best Practices @ Nylas
PPSX
Esoft Metro Campus - Certificate in java basics
PPTX
Pi j2.3 objects
PPTX
Metaprogramming in Ruby
PPT
core_java.ppt
PPTX
2CPP18 - Modifiers
PDF
Week 7 Java Programming Methods For I.T students.pdf
PDF
Metaprogramming Rails
PPTX
L03 Software Design
Design Patterns
The Ring programming language version 1.5.4 book - Part 74 of 185
Refactoring In Tdd The Missing Part
Javascript Common Design Patterns
The Ring programming language version 1.8 book - Part 81 of 202
Design p atterns
The Ring programming language version 1.7 book - Part 78 of 196
Refactoring Tips by Martin Fowler
The Ring programming language version 1.10 book - Part 86 of 212
33rd degree talk: open and automatic coding conventions with walkmod
The Ring programming language version 1.2 book - Part 53 of 84
Software Engineering Best Practices @ Nylas
Esoft Metro Campus - Certificate in java basics
Pi j2.3 objects
Metaprogramming in Ruby
core_java.ppt
2CPP18 - Modifiers
Week 7 Java Programming Methods For I.T students.pdf
Metaprogramming Rails
L03 Software Design

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Mobile App Security Testing_ A Comprehensive Guide.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf

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!