SlideShare a Scribd company logo
Tao Showed Me the Way
I Meet the Tao ,[object Object],[object Object],[object Object]
The Problem Write a program that takes the words in its argument list and prints out any duplicate words, the number of distinct words, and a list of the words with duplicates eliminated.
I approached, with winning smile on my face, and the code snippet on my think pad.
import java.util.*; public class FindDups {   public static void main(String args[]) {   new FindDups(args);   }   FindDups(String[] input){   HashSet s = new HashSet();   for (int i=0; i<args.length; i++){ if (!s.add(args[i])){   System.out.println(&quot;Duplicate detected:&quot; + args[i]);   }   }   System.out.println(s.size()+&quot; distinct words detected: &quot;+s);   } }
Out of the program:  % java FindDups i came i saw i left Duplicate detected: i Duplicate detected: i 4 distinct words detected: [came, left, saw, i]
Do Small Change, to Make Big Difference.  Tao had a glance at my great piece of code. There was charismatic smile on his face. I was startled. I knew, I must have done some grave mistake. However, I was eager to learn that fine point of Java programming. I look forward to Tao to enlighten me. Then, to my surprise, Tao made a small correction to my code. I could not see much improvement though.
import java.util.*; public class FindDups {   public static void main(String args[]) {   new FindDups(args);   }   FindDups(String[] input){   Set s = new HashSet();   for (int i=0; i<args.length; i++){ if (!s.add(args[i])){   System.out.println(&quot;Duplicate detected:&quot; + args[i]);   }   }   System.out.println(s.size()+&quot; distinct words detected: &quot;+s);   } }
I could not hide my quizzical expressions on my face. Tao continued to don the same charismatic smile. Then he asked me to ponder over the “small change” and decipher the underlying design principle. Then he left me. I stood there wondering about the design principle.
I struggled through out the day to pin point the design principle. But no gain. Then I wrote down the lines of difference, in hope that I could read between the lines. HashSet s = new HashSet(); …………… My code Set s = new HashSet(); …………… His code  It was beautiful full moon night. I kept staring, at my lap top screen. I do not remember when did I fall a sleep.
Early next morning, I hurried myself to Tao. Tao was not there. But He had left message for me. Design to Interface.
I revisited the lines of difference. HashSet s = new HashSet(); …………… My code Set s = new HashSet(); ……………  His  code  . Now I could see the design principle I was exploring. I got the Aha! Feeling. But I was craving for the Aha! Insight. What is the rationale behind this design mantra. And how it is making the big difference to my Java code. I surrendered myself to Tao. Tao showed mercy on me. I know. When student is ready, Tao appears.
Looking Through the Glass Note that the code should always refer to the collection by its interface type (Set), rather than by its implementation type (HashSet). This is a strongly recommended programming practice, as it gives you the flexibility to change implementations merely by changing the constructor.  If the variables used to store a collection, or the parameters used to pass it around, are declared to be of the collection's implementation type rather than its interface type, then all such variables and parameters must be changed to change the collection's implementation type.
Looking Through the Glass Furthermore, there's no guarantee that the resulting program will work; if the program uses any non-standard operations that are present in the original implementation type but not the new one, the program will fail.  Referring to collections only by their interface keeps you honest, in the sense that it prevents you from using any non-standard operations.
Small Change in Requirement Should Not Result in Big Change in Code The implementation type of the Set in the example above is HashSet, which makes no guarantees as to the order of the elements in the Set.  If you want the program to print the word list in alphabetical order, all you have to do is to change the set's implementation type from HashSet to TreeSet.  Making this trivial one-line change causes the command line in the previous example to generate the following output:
% java FindDups i came i saw i left Duplicate word detected: i Duplicate word detected: i 4 distinct words detected: [came, i, left, saw]
When I emerged from the fundamentals and looked up, Tao had left me long back.  Tao was not there. But He had left message for me. Design to Interface.
Created by ,[object Object],[object Object]

More Related Content

Viewers also liked

Robotics Workshop Overview for School Students
Robotics Workshop Overview for School StudentsRobotics Workshop Overview for School Students
Robotics Workshop Overview for School Students
RootStalk Academy
 
Blessing Equation Series 3 In 1
Blessing Equation Series 3 In 1Blessing Equation Series 3 In 1
Blessing Equation Series 3 In 1
Simon Cooper
 
Why Prefer Flat Roofs?
Why Prefer Flat Roofs? Why Prefer Flat Roofs?
Why Prefer Flat Roofs?
Michale Jazz
 
De va dap an mon tieng anh
De va dap an mon tieng anhDe va dap an mon tieng anh
De va dap an mon tieng anhHườngg Thu
 
Online Assignment
Online AssignmentOnline Assignment
Online Assignment
Arun Murali
 
There is a colored boy at the bottom of the water
There is a colored boy at the bottom of the waterThere is a colored boy at the bottom of the water
There is a colored boy at the bottom of the water
Jaime R. Gutiérrez
 
Propovidi_2010-11_ Final 8x11
Propovidi_2010-11_ Final 8x11Propovidi_2010-11_ Final 8x11
Propovidi_2010-11_ Final 8x11Dr. Vasyl Dmytriv
 
原装进口红酒报价
原装进口红酒报价原装进口红酒报价
原装进口红酒报价
brookedeng
 
Three Ways to Find Your Passion and Act on Purpose
Three Ways to Find Your Passion and Act on PurposeThree Ways to Find Your Passion and Act on Purpose
Three Ways to Find Your Passion and Act on Purpose
Karl Bimshas Consulting
 
Techman Pro show technologies
Techman Pro show technologiesTechman Pro show technologies
Techman Pro show technologiesshirnepes
 
Soong HOMME logo(黑底白字标)-1
Soong HOMME logo(黑底白字标)-1Soong HOMME logo(黑底白字标)-1
Soong HOMME logo(黑底白字标)-1Cindy Song
 
Acuerdo 016 de 2016
Acuerdo 016 de 2016Acuerdo 016 de 2016
Morning at Lohika - Spring Boot Kotlin, a match made in Heaven
Morning at Lohika - Spring Boot Kotlin, a match made in HeavenMorning at Lohika - Spring Boot Kotlin, a match made in Heaven
Morning at Lohika - Spring Boot Kotlin, a match made in Heaven
Nicolas Fränkel
 
Ahkam Janyiz احكام الجنائز
Ahkam Janyiz احكام الجنائزAhkam Janyiz احكام الجنائز
Ahkam Janyiz احكام الجنائز
Mohamed Irshad
 

Viewers also liked (17)

Robotics Workshop Overview for School Students
Robotics Workshop Overview for School StudentsRobotics Workshop Overview for School Students
Robotics Workshop Overview for School Students
 
Blessing Equation Series 3 In 1
Blessing Equation Series 3 In 1Blessing Equation Series 3 In 1
Blessing Equation Series 3 In 1
 
Why Prefer Flat Roofs?
Why Prefer Flat Roofs? Why Prefer Flat Roofs?
Why Prefer Flat Roofs?
 
De va dap an mon tieng anh
De va dap an mon tieng anhDe va dap an mon tieng anh
De va dap an mon tieng anh
 
Online Assignment
Online AssignmentOnline Assignment
Online Assignment
 
There is a colored boy at the bottom of the water
There is a colored boy at the bottom of the waterThere is a colored boy at the bottom of the water
There is a colored boy at the bottom of the water
 
Propovidi_2010-11_ Final 8x11
Propovidi_2010-11_ Final 8x11Propovidi_2010-11_ Final 8x11
Propovidi_2010-11_ Final 8x11
 
原装进口红酒报价
原装进口红酒报价原装进口红酒报价
原装进口红酒报价
 
Three Ways to Find Your Passion and Act on Purpose
Three Ways to Find Your Passion and Act on PurposeThree Ways to Find Your Passion and Act on Purpose
Three Ways to Find Your Passion and Act on Purpose
 
Techman Pro show technologies
Techman Pro show technologiesTechman Pro show technologies
Techman Pro show technologies
 
Soong HOMME logo(黑底白字标)-1
Soong HOMME logo(黑底白字标)-1Soong HOMME logo(黑底白字标)-1
Soong HOMME logo(黑底白字标)-1
 
Acuerdo 016 de 2016
Acuerdo 016 de 2016Acuerdo 016 de 2016
Acuerdo 016 de 2016
 
XM CV 2015
XM CV 2015XM CV 2015
XM CV 2015
 
Morning at Lohika - Spring Boot Kotlin, a match made in Heaven
Morning at Lohika - Spring Boot Kotlin, a match made in HeavenMorning at Lohika - Spring Boot Kotlin, a match made in Heaven
Morning at Lohika - Spring Boot Kotlin, a match made in Heaven
 
D burmistrov
D burmistrovD burmistrov
D burmistrov
 
Ahkam Janyiz احكام الجنائز
Ahkam Janyiz احكام الجنائزAhkam Janyiz احكام الجنائز
Ahkam Janyiz احكام الجنائز
 
KGPP
KGPPKGPP
KGPP
 

Similar to Tao Showed Me The Way

Lab 1 Recursion  Introduction   Tracery (tracery.io.docx
Lab 1 Recursion  Introduction   Tracery (tracery.io.docxLab 1 Recursion  Introduction   Tracery (tracery.io.docx
Lab 1 Recursion  Introduction   Tracery (tracery.io.docx
smile790243
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
Mike Wilcox
 
Wade not in unknown waters. Part two.
Wade not in unknown waters. Part two.Wade not in unknown waters. Part two.
Wade not in unknown waters. Part two.
PVS-Studio
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdf
rd1742
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
Naresh Jain
 
Introduction to Intermediate Java
Introduction to Intermediate JavaIntroduction to Intermediate Java
Introduction to Intermediate JavaPhilip Johnson
 
Ben Agre - Adding Another Level of Hell to Reverse Engineering
Ben Agre - Adding Another Level of Hell to Reverse EngineeringBen Agre - Adding Another Level of Hell to Reverse Engineering
Ben Agre - Adding Another Level of Hell to Reverse EngineeringSource Conference
 
Java interview-questions-and-answers
Java interview-questions-and-answersJava interview-questions-and-answers
Java interview-questions-and-answers
bestonlinetrainers
 
SharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuerySharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuery
Mark Rackley
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4sotlsoc
 
Questioning the status quo
Questioning the status quoQuestioning the status quo
Questioning the status quo
Ivano Pagano
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Krishnaov
 
Software Design
Software DesignSoftware Design
Software Design
Spy Seat
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questions
nicolbiden
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
David Furber
 
PHP Reviewer
PHP ReviewerPHP Reviewer
PHP Reviewer
Cecilia Pamfilo
 
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..Mark Rackley
 
The java server pages
The java server pagesThe java server pages
The java server pages
Atul Saurabh
 
Data weave 2.0 language fundamentals
Data weave 2.0 language fundamentalsData weave 2.0 language fundamentals
Data weave 2.0 language fundamentals
ManjuKumara GH
 

Similar to Tao Showed Me The Way (20)

Lab 1 Recursion  Introduction   Tracery (tracery.io.docx
Lab 1 Recursion  Introduction   Tracery (tracery.io.docxLab 1 Recursion  Introduction   Tracery (tracery.io.docx
Lab 1 Recursion  Introduction   Tracery (tracery.io.docx
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
Wade not in unknown waters. Part two.
Wade not in unknown waters. Part two.Wade not in unknown waters. Part two.
Wade not in unknown waters. Part two.
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdf
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Introduction to Intermediate Java
Introduction to Intermediate JavaIntroduction to Intermediate Java
Introduction to Intermediate Java
 
Ben Agre - Adding Another Level of Hell to Reverse Engineering
Ben Agre - Adding Another Level of Hell to Reverse EngineeringBen Agre - Adding Another Level of Hell to Reverse Engineering
Ben Agre - Adding Another Level of Hell to Reverse Engineering
 
Java interview-questions-and-answers
Java interview-questions-and-answersJava interview-questions-and-answers
Java interview-questions-and-answers
 
SharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuerySharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuery
 
Spsemea j query
Spsemea   j querySpsemea   j query
Spsemea j query
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4
 
Questioning the status quo
Questioning the status quoQuestioning the status quo
Questioning the status quo
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Software Design
Software DesignSoftware Design
Software Design
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questions
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
PHP Reviewer
PHP ReviewerPHP Reviewer
PHP Reviewer
 
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
 
The java server pages
The java server pagesThe java server pages
The java server pages
 
Data weave 2.0 language fundamentals
Data weave 2.0 language fundamentalsData weave 2.0 language fundamentals
Data weave 2.0 language fundamentals
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 

Tao Showed Me The Way

  • 1. Tao Showed Me the Way
  • 2.
  • 3. The Problem Write a program that takes the words in its argument list and prints out any duplicate words, the number of distinct words, and a list of the words with duplicates eliminated.
  • 4. I approached, with winning smile on my face, and the code snippet on my think pad.
  • 5. import java.util.*; public class FindDups { public static void main(String args[]) { new FindDups(args); } FindDups(String[] input){ HashSet s = new HashSet(); for (int i=0; i<args.length; i++){ if (!s.add(args[i])){ System.out.println(&quot;Duplicate detected:&quot; + args[i]); } } System.out.println(s.size()+&quot; distinct words detected: &quot;+s); } }
  • 6. Out of the program: % java FindDups i came i saw i left Duplicate detected: i Duplicate detected: i 4 distinct words detected: [came, left, saw, i]
  • 7. Do Small Change, to Make Big Difference. Tao had a glance at my great piece of code. There was charismatic smile on his face. I was startled. I knew, I must have done some grave mistake. However, I was eager to learn that fine point of Java programming. I look forward to Tao to enlighten me. Then, to my surprise, Tao made a small correction to my code. I could not see much improvement though.
  • 8. import java.util.*; public class FindDups { public static void main(String args[]) { new FindDups(args); } FindDups(String[] input){ Set s = new HashSet(); for (int i=0; i<args.length; i++){ if (!s.add(args[i])){ System.out.println(&quot;Duplicate detected:&quot; + args[i]); } } System.out.println(s.size()+&quot; distinct words detected: &quot;+s); } }
  • 9. I could not hide my quizzical expressions on my face. Tao continued to don the same charismatic smile. Then he asked me to ponder over the “small change” and decipher the underlying design principle. Then he left me. I stood there wondering about the design principle.
  • 10. I struggled through out the day to pin point the design principle. But no gain. Then I wrote down the lines of difference, in hope that I could read between the lines. HashSet s = new HashSet(); …………… My code Set s = new HashSet(); …………… His code It was beautiful full moon night. I kept staring, at my lap top screen. I do not remember when did I fall a sleep.
  • 11. Early next morning, I hurried myself to Tao. Tao was not there. But He had left message for me. Design to Interface.
  • 12. I revisited the lines of difference. HashSet s = new HashSet(); …………… My code Set s = new HashSet(); …………… His code . Now I could see the design principle I was exploring. I got the Aha! Feeling. But I was craving for the Aha! Insight. What is the rationale behind this design mantra. And how it is making the big difference to my Java code. I surrendered myself to Tao. Tao showed mercy on me. I know. When student is ready, Tao appears.
  • 13. Looking Through the Glass Note that the code should always refer to the collection by its interface type (Set), rather than by its implementation type (HashSet). This is a strongly recommended programming practice, as it gives you the flexibility to change implementations merely by changing the constructor. If the variables used to store a collection, or the parameters used to pass it around, are declared to be of the collection's implementation type rather than its interface type, then all such variables and parameters must be changed to change the collection's implementation type.
  • 14. Looking Through the Glass Furthermore, there's no guarantee that the resulting program will work; if the program uses any non-standard operations that are present in the original implementation type but not the new one, the program will fail. Referring to collections only by their interface keeps you honest, in the sense that it prevents you from using any non-standard operations.
  • 15. Small Change in Requirement Should Not Result in Big Change in Code The implementation type of the Set in the example above is HashSet, which makes no guarantees as to the order of the elements in the Set. If you want the program to print the word list in alphabetical order, all you have to do is to change the set's implementation type from HashSet to TreeSet. Making this trivial one-line change causes the command line in the previous example to generate the following output:
  • 16. % java FindDups i came i saw i left Duplicate word detected: i Duplicate word detected: i 4 distinct words detected: [came, i, left, saw]
  • 17. When I emerged from the fundamentals and looked up, Tao had left me long back. Tao was not there. But He had left message for me. Design to Interface.
  • 18.