SlideShare una empresa de Scribd logo
1 de 67
Groovy: Efficiency Oriented Programming
Lecture 6
Master Proteomics & Bioinformatics - University of Geneva
Alexandre Masselot - summer 2011
Contents

‣ Eclipse tips
‣ Productive tip
‣ Two thoughts on code design
‣ Running a script standalone
‣ test case: build all isoforms & extract proteotypic peptides
The book of the day

                      ‣ by Neal Ford
                      ‣ Do’s and Don’t for programmer, from the
                        rookies to ol’timers...
Go productive: clipboard history

‣ Working with a computer induces a lot of cut/past (<ctrl>-C / <ctrl>-V)
Go productive: clipboard history

‣ Working with a computer induces a lot of cut/past (<ctrl>-C / <ctrl>-V)
‣ In practice, you often refer (or intent to refer) to a piece of text you cut a
  few minutes ago
Go productive: clipboard history

‣ Working with a computer induces a lot of cut/past (<ctrl>-C / <ctrl>-V)
‣ In practice, you often refer (or intent to refer) to a piece of text you cut a
  few minutes ago
‣ It is possible to use clipboard history (and <ctrl>-V’ offers to visit
  history)
   - mac OS: jumpcut
   - ubuntu: parcellite
   - windows: CLCL
Go productive: clipboard history

‣ Working with a computer induces a lot of cut/past (<ctrl>-C / <ctrl>-V)
‣ In practice, you often refer (or intent to refer) to a piece of text you cut a
  few minutes ago
‣ It is possible to use clipboard history (and <ctrl>-V’ offers to visit
  history)
   - mac OS: jumpcut
   - ubuntu: parcellite
   - windows: CLCL
‣ What a big deal?
   - such functionalities has been present in editors such as vi or x?emacs
     for decades...
Eclipse tips
Eclipse tips


‣ create documentation for a method (filled with method parameters)
  - place the cursor on the method name
  - right button > source > generate comment
  - or <ctrl>-<alt>-J
  - documentation is ready to be exported in a html javadoc
Eclipse tips
Eclipse tips




‣ How to know where a method is called?
  - place the cursor on the method declaration
  - right button > open call hierarchy
  - or <ctrl>-<alt>-H
DRY: Don’t Repeat Yourself




                             7
Code design: DRY




‣ <ctrl>-C / <ctrl>-V is the most common shortcut        appealing to
 duplicate a piece of “working” code into another part of the software
Code design: DRY




‣ Problems:
Code design: DRY




‣ Problems:
  - harder to understand where a given action is coded,
Code design: DRY




‣ Problems:
  - harder to understand where a given action is coded,
  - hard to maintain bug.
Code design: DRY



‣ Fight against DRY:
Code design: DRY



‣ Fight against DRY:
  - refactor your code continuously (test are there to ensure stability).
Code design: DRY



‣ Fight against DRY:
  - refactor your code continuously (test are there to ensure stability).
  - tackle duplication in your process at any level
Code design: DRY



‣ Fight against DRY:
  - refactor your code continuously (test are there to ensure stability).
  - tackle duplication in your process at any level
  - time spent for factorizing process or code is almost never a waste
YAGNI: You Ain’t Gonna Need It




                                 11
Code design: YAGNI



‣ A very common pitfall when writing code it to follow some enthusiasm and
  imagine features that are (on the instant you imagine them):
Code design: YAGNI



‣ A very common pitfall when writing code it to follow some enthusiasm and
  imagine features that are (on the instant you imagine them):
  - very cool,
Code design: YAGNI



‣ A very common pitfall when writing code it to follow some enthusiasm and
  imagine features that are (on the instant you imagine them):
  - very cool,
  - you have a bright idea on how to implement them,
Code design: YAGNI



‣ A very common pitfall when writing code it to follow some enthusiasm and
  imagine features that are (on the instant you imagine them):
  - very cool,
  - you have a bright idea on how to implement them,
  - even though they don’t answer a particular need at that time, you “feel”
    they would be “cool to have in the future”
Code design: YAGNI




‣ Problems:
Code design: YAGNI




‣ Problems:
  - the code get more complex, harder to maintain,
Code design: YAGNI




‣ Problems:
  - the code get more complex, harder to maintain,
  - in a few weeks of time, this feature won’t be of any use (but other will!)
Code design: YAGNI



‣ Fight YAGNI:
Code design: YAGNI



‣ Fight YAGNI:
  - stick to your customer practical needs
Code design: YAGNI



‣ Fight YAGNI:
  - stick to your customer practical needs
  - pair programming is the most efficient way to tackle such situations
Groovy: running a script (outside the IDE)

‣ Programming goal is (often) to have a runnable program, outside the IDE
Groovy: running a script (outside the IDE)

‣ Programming goal is (often) to have a runnable program, outside the IDE
‣ Be able to deploy the program on another machine
Groovy: running a script (outside the IDE)

‣ Programming goal is (often) to have a runnable program, outside the IDE
‣ Be able to deploy the program on another machine
‣ First: install Groovy on the machine (apt-get install groovy etc.)
Groovy: running a script (outside the IDE)

‣ Programming goal is (often) to have a runnable program, outside the IDE
‣ Be able to deploy the program on another machine
‣ First: install Groovy on the machine (apt-get install groovy etc.)

‣ Let’s consider a simple script hw.groovy, stored in directory /some/path
 println “hello, world”
Groovy: running a script (outside the IDE)

‣ Programming goal is (often) to have a runnable program, outside the IDE
‣ Be able to deploy the program on another machine
‣ First: install Groovy on the machine (apt-get install groovy etc.)

‣ Let’s consider a simple script hw.groovy, stored in directory /some/path
 println “hello, world”
‣ launch the script from command line
 groovy hw.groovy
Parsing command line arguments

‣ Runtime arguments are passed on the command line
Parsing command line arguments

‣ Runtime arguments are passed on the command line
‣ Defining the possible arguments
 def cli = new CliBuilder(usage:'myscript.groovy [options]')

 //binary argument -h or --help and usage text
 cli.h(longOpt:'help', 'usage information')

 //compulsory argument for -n or --name=<user name>
 cli.n(longOpt:'name', argName:'user name', args:1,
       required: true, 'some user to salute')

 //facultative argument --int-value=<int>
 cli.i(longOpt:'int-value', argName:'int', args:1,
       'some integer value')
Parsing command line arguments   (cont’d)

‣ Parsing the command line
 def options = cli.parse(args)
 if (!options) return
Parsing command line arguments   (cont’d)

‣ Parsing the command line
 def options = cli.parse(args)
 if (!options) return
‣ Check --help
 if (options.help) cli.usage()
Parsing command line arguments                   (cont’d)

‣ Parsing the command line
 def options = cli.parse(args)
 if (!options) return
‣ Check --help
 if (options.help) cli.usage()
‣ Arguments usage:
 println "Hello $options.name (${options['int-value']})"
Parsing command line arguments                 (cont’d)

‣ groovy myscript.groovy --help
usage: myscript.groovy [options]
 -h,--help               usage information
 -i,--int-value <int>    some integer value
 -n,--name <user name>   some user to salute
Parsing command line arguments                      (cont’d)

‣ groovy myscript.groovy --help
usage: myscript.groovy [options]
 -h,--help               usage information
 -i,--int-value <int>    some integer value
 -n,--name <user name>   some user to salute
‣ groovy myscript.groovy   --name=alice   --int-value=234
Hello alice (234)
Parsing command line arguments                                 (cont’d)

‣ groovy myscript.groovy --help
 usage: myscript.groovy [options]
  -h,--help               usage information
  -i,--int-value <int>    some integer value
  -n,--name <user name>   some user to salute
‣ groovy myscript.groovy        --name=alice      --int-value=234
 Hello alice (234)
‣ More doc on http://groovy.codehaus.org/gapi/groovy/util/CliBuilder.html
Parsing command line arguments                    (cont’d)

‣ The whole script:
 def cli = new CliBuilder(usage:'myscript.groovy [options]')

 cli.h(longOpt:'help', 'usage information')
 cli.n(longOpt:'name', argName:'user name', args:1,
       required: true, 'some user to salute')
 cli.i(longOpt:'int-value', argName:'int', args:1,
       'some integer value')

 def options = cli.parse(args)
 if (!options) return

 if (options.help) cli.usage()

 println "Hello $options.name (${options['int-value']}) "
Running a script with a packaged library

‣ A script by itself is soon meaningless, it is often backed by a library of
  packaged classes for doing the actual business
Running a script with a packaged library

‣ A script by itself is soon meaningless, it is often backed by a library of
  packaged classes for doing the actual business
‣ The script is often the last assembly of coded (and tested) functionalities
Running a script with a packaged library

‣ A script by itself is soon meaningless, it is often backed by a library of
  packaged classes for doing the actual business
‣ The script is often the last assembly of coded (and tested) functionalities
‣ Library is packaged as a jar (Java Archive) and the script is written on the
  side, making calls to the archive
Running a script with a packaged library

‣ A script by itself is soon meaningless, it is often backed by a library of
  packaged classes for doing the actual business
‣ The script is often the last assembly of coded (and tested) functionalities
‣ Library is packaged as a jar (Java Archive) and the script is written on the
  side, making calls to the archive
‣ The jar if often the distributed part of a code
Running a script with a packaged library

‣ A script by itself is soon meaningless, it is often backed by a library of
  packaged classes for doing the actual business
‣ The script is often the last assembly of coded (and tested) functionalities
‣ Library is packaged as a jar (Java Archive) and the script is written on the
  side, making calls to the archive
‣ The jar if often the distributed part of a code

‣ The script varsplic.groovy uses the jar
 import unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer
 ...
 def xml=new XmlSlurper()
     .parseText("http://pir.uniprot.org/uniprot/${ac}.xml"
                .toURL().text)
     .entry
 UniprotEntrySplicer splicer=[entryXml:xml]
 splicer.buildAllIsoforms().values().each{print it}
Eclipse: exporting a jar from the IDE

‣ A jar is an archive that contains at least the compiled classes
Eclipse: exporting a jar from the IDE

‣ A jar is an archive that contains at least the compiled classes
‣ Test classes are usually not exported
Eclipse: exporting a jar from the IDE

‣ A jar is an archive that contains at least the compiled classes
‣ Test classes are usually not exported
‣ Exporting from eclipse
  - project > right button > export > java > jar
Eclipse: exporting a jar from the IDE

‣ A jar is an archive that contains at least the compiled classes
‣ Test classes are usually not exported
‣ Exporting from eclipse
  - project > right button > export > java > jar
‣ A myfile.jar file is created
Eclipse: exporting a jar from the IDE

‣ A jar is an archive that contains at least the compiled classes
‣ Test classes are usually not exported
‣ Exporting from eclipse
  - project > right button > export > java > jar
‣ A myfile.jar file is created
Eclipse: exporting a jar from ant

‣ Apache ant is a versatile tool for automatic software build process
Eclipse: exporting a jar from ant

‣ Apache ant is a versatile tool for automatic software build process

‣ It can be used to build a task: the build.xml (at project home directory)
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <project default="create_run_jar" name="Create Runnable Jar for Project
 eop.lec6">
     <targetname="create_run_jar">
         <jar destfile="eop6.jar">
            <fileset dir="bin">
            
 <exclude name="**/*Test.class"/>
             
 <exclude name="src/practicals/groovy/scripts/*"/>
            
   </fileset>
         </jar>
     </target>
 </project>
Eclipse: exporting a jar from ant

‣ Apache ant is a versatile tool for automatic software build process

‣ It can be used to build a task: the build.xml (at project home directory)
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <project default="create_run_jar" name="Create Runnable Jar for Project
 eop.lec6">
     <targetname="create_run_jar">
         <jar destfile="eop6.jar">
            <fileset dir="bin">
            
 <exclude name="**/*Test.class"/>
             
 <exclude name="src/practicals/groovy/scripts/*"/>
            
   </fileset>
         </jar>
     </target>
 </project>

‣ right button > run as > ant build
Eclipse: exporting a jar from ant

‣ Apache ant is a versatile tool for automatic software build process

‣ It can be used to build a task: the build.xml (at project home directory)
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <project default="create_run_jar" name="Create Runnable Jar for Project
 eop.lec6">
     <targetname="create_run_jar">
         <jar destfile="eop6.jar">
            <fileset dir="bin">
            
 <exclude name="**/*Test.class"/>
             
 <exclude name="src/practicals/groovy/scripts/*"/>
            
   </fileset>
         </jar>
     </target>
 </project>

‣ right button > run as > ant build
‣ <ctrl>-<alt>-X-Q
Eclipse: exporting a jar from ant

‣ Apache ant is a versatile tool for automatic software build process

‣ It can be used to build a task: the build.xml (at project home directory)
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <project default="create_run_jar" name="Create Runnable Jar for Project
 eop.lec6">
     <targetname="create_run_jar">
         <jar destfile="eop6.jar">
            <fileset dir="bin">
            
 <exclude name="**/*Test.class"/>
             
 <exclude name="src/practicals/groovy/scripts/*"/>
            
   </fileset>
         </jar>
     </target>
 </project>

‣ right button > run as > ant build
‣ <ctrl>-<alt>-X-Q
‣ http://ant.apache.org/manual/tasksoverview.html
Executing a script with a jar library

‣ The script varsplic.groovy can reside anywhere
 groovy -cp eop6.jar /path/to/varsplic.groovy      --ac=Q70Z44
Executing a script with a jar library

‣ The script varsplic.groovy can reside anywhere
 groovy -cp eop6.jar /path/to/varsplic.groovy                --ac=Q70Z44
‣ Arguments following the script will be passed to the script args
Executing a script with a jar library

‣ The script varsplic.groovy can reside anywhere
 groovy -cp eop6.jar /path/to/varsplic.groovy                --ac=Q70Z44
‣ Arguments following the script will be passed to the script args
‣ Remember: put the least possible “business intelligence” into the script
Test case: isoforms & proteotypic peptides

‣ Proteotypic peptide: given a list of proteins and cleavage enzyme, a
  proteotypic peptide is a peptide that can be produced only by one of those
  proteins
Test case: isoforms & proteotypic peptides

‣ Proteotypic peptide: given a list of proteins and cleavage enzyme, a
  proteotypic peptide is a peptide that can be produced only by one of those
  proteins
‣ Customer of the day: “I want to give you one uniprot AC, you print me all the
  isoforms in a fasta format and the list list of proteotypic peptide (+ the isoform
  they are referring to). Please.”
Test case: isoforms & proteotypic peptides

‣ Proteotypic peptide: given a list of proteins and cleavage enzyme, a
  proteotypic peptide is a peptide that can be produced only by one of those
  proteins
‣ Customer of the day: “I want to give you one uniprot AC, you print me all the
  isoforms in a fasta format and the list list of proteotypic peptide (+ the isoform
  they are referring to). Please.”
‣ Hopefully enough, you already have a toolkit to build, from a uniprot entry,
  a map isoform name -> isoform Protein
Test case: isoforms & proteotypic peptides

‣ Proteotypic peptide: given a list of proteins and cleavage enzyme, a
  proteotypic peptide is a peptide that can be produced only by one of those
  proteins
‣ Customer of the day: “I want to give you one uniprot AC, you print me all the
  isoforms in a fasta format and the list list of proteotypic peptide (+ the isoform
  they are referring to). Please.”
‣ Hopefully enough, you already have a toolkit to build, from a uniprot entry,
  a map isoform name -> isoform Protein
‣ Your turn to play....

Más contenido relacionado

La actualidad más candente

Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Daniele Pallastrelli
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGuillaume Laforge
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot WorldSchalk Cronjé
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?Nick Belhomme
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHPNick Belhomme
 
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionCool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionSchalk Cronjé
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golangTing-Li Chou
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyAerospike
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
React mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche EheReact mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche Eheinovex GmbH
 
Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Andrea Francia
 
Information security programming in ruby
Information security programming in rubyInformation security programming in ruby
Information security programming in rubyHiroshi Nakamura
 
Developer Android Tools
Developer Android ToolsDeveloper Android Tools
Developer Android ToolsMacha DA COSTA
 
SymfonyCon Berlin 2016 Jenkins Deployment Pipelines
SymfonyCon Berlin 2016 Jenkins Deployment PipelinesSymfonyCon Berlin 2016 Jenkins Deployment Pipelines
SymfonyCon Berlin 2016 Jenkins Deployment Pipelinescpsitgmbh
 

La actualidad más candente (20)

Smoking docker
Smoking dockerSmoking docker
Smoking docker
 
Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
Testing con spock
Testing con spockTesting con spock
Testing con spock
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot World
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionCool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
React mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche EheReact mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche Ehe
 
Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008Google C++ Testing Framework in Visual Studio 2008
Google C++ Testing Framework in Visual Studio 2008
 
Node.js cluster
Node.js clusterNode.js cluster
Node.js cluster
 
Information security programming in ruby
Information security programming in rubyInformation security programming in ruby
Information security programming in ruby
 
Developer Android Tools
Developer Android ToolsDeveloper Android Tools
Developer Android Tools
 
SymfonyCon Berlin 2016 Jenkins Deployment Pipelines
SymfonyCon Berlin 2016 Jenkins Deployment PipelinesSymfonyCon Berlin 2016 Jenkins Deployment Pipelines
SymfonyCon Berlin 2016 Jenkins Deployment Pipelines
 

Similar a groovy & grails - lecture 6

MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScriptOffirmo
 
Pipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodePipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodeKris Buytaert
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projectsMpho Mphego
 
Grokking Techtalk #38: Escape Analysis in Go compiler
 Grokking Techtalk #38: Escape Analysis in Go compiler Grokking Techtalk #38: Escape Analysis in Go compiler
Grokking Techtalk #38: Escape Analysis in Go compilerGrokking VN
 
Containerized IDEs.pdf
Containerized IDEs.pdfContainerized IDEs.pdf
Containerized IDEs.pdfLibbySchulze
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
 
Computational practices for reproducible science
Computational practices for reproducible scienceComputational practices for reproducible science
Computational practices for reproducible scienceGael Varoquaux
 
Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Libraryjeresig
 
JavaScript All The Things
JavaScript All The ThingsJavaScript All The Things
JavaScript All The ThingsJordan Yaker
 
How does one learn to program?
How does one learn to program?How does one learn to program?
How does one learn to program?Olmo F. Maldonado
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-wayRobert Lujo
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidVlatko Kosturjak
 
The genesis of clusterlib - An open source library to tame your favourite sup...
The genesis of clusterlib - An open source library to tame your favourite sup...The genesis of clusterlib - An open source library to tame your favourite sup...
The genesis of clusterlib - An open source library to tame your favourite sup...Arnaud Joly
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAndrii Soldatenko
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...Sang Don Kim
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Writing Rust Command Line Applications
Writing Rust Command Line ApplicationsWriting Rust Command Line Applications
Writing Rust Command Line ApplicationsAll Things Open
 

Similar a groovy & grails - lecture 6 (20)

MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
Pipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodePipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as Code
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
Grokking Techtalk #38: Escape Analysis in Go compiler
 Grokking Techtalk #38: Escape Analysis in Go compiler Grokking Techtalk #38: Escape Analysis in Go compiler
Grokking Techtalk #38: Escape Analysis in Go compiler
 
Containerized IDEs.pdf
Containerized IDEs.pdfContainerized IDEs.pdf
Containerized IDEs.pdf
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
 
Computational practices for reproducible science
Computational practices for reproducible scienceComputational practices for reproducible science
Computational practices for reproducible science
 
Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
 
JavaScript All The Things
JavaScript All The ThingsJavaScript All The Things
JavaScript All The Things
 
How does one learn to program?
How does one learn to program?How does one learn to program?
How does one learn to program?
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
 
The genesis of clusterlib - An open source library to tame your favourite sup...
The genesis of clusterlib - An open source library to tame your favourite sup...The genesis of clusterlib - An open source library to tame your favourite sup...
The genesis of clusterlib - An open source library to tame your favourite sup...
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Writing Rust Command Line Applications
Writing Rust Command Line ApplicationsWriting Rust Command Line Applications
Writing Rust Command Line Applications
 

Más de Alexandre Masselot

Offshoring software development in Switzerland: You can do it
Offshoring software development in Switzerland: You can do itOffshoring software development in Switzerland: You can do it
Offshoring software development in Switzerland: You can do itAlexandre Masselot
 
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data StackDev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data StackAlexandre Masselot
 
Swiss Transport in Real Time: Tribulations in the Big Data Stack
Swiss Transport in Real Time: Tribulations in the Big Data StackSwiss Transport in Real Time: Tribulations in the Big Data Stack
Swiss Transport in Real Time: Tribulations in the Big Data StackAlexandre Masselot
 

Más de Alexandre Masselot (9)

Offshoring software development in Switzerland: You can do it
Offshoring software development in Switzerland: You can do itOffshoring software development in Switzerland: You can do it
Offshoring software development in Switzerland: You can do it
 
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data StackDev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
 
Swiss Transport in Real Time: Tribulations in the Big Data Stack
Swiss Transport in Real Time: Tribulations in the Big Data StackSwiss Transport in Real Time: Tribulations in the Big Data Stack
Swiss Transport in Real Time: Tribulations in the Big Data Stack
 
groovy & grails - lecture 8
groovy & grails - lecture 8groovy & grails - lecture 8
groovy & grails - lecture 8
 
groovy & grails - lecture 1
groovy & grails - lecture 1groovy & grails - lecture 1
groovy & grails - lecture 1
 
groovy & grails - lecture 11
groovy & grails - lecture 11groovy & grails - lecture 11
groovy & grails - lecture 11
 
groovy & grails - lecture 12
groovy & grails - lecture 12groovy & grails - lecture 12
groovy & grails - lecture 12
 
groovy & grails - lecture 7
groovy & grails - lecture 7groovy & grails - lecture 7
groovy & grails - lecture 7
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 

Último

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

groovy & grails - lecture 6

  • 1. Groovy: Efficiency Oriented Programming Lecture 6 Master Proteomics & Bioinformatics - University of Geneva Alexandre Masselot - summer 2011
  • 2. Contents ‣ Eclipse tips ‣ Productive tip ‣ Two thoughts on code design ‣ Running a script standalone ‣ test case: build all isoforms & extract proteotypic peptides
  • 3. The book of the day ‣ by Neal Ford ‣ Do’s and Don’t for programmer, from the rookies to ol’timers...
  • 4. Go productive: clipboard history ‣ Working with a computer induces a lot of cut/past (<ctrl>-C / <ctrl>-V)
  • 5. Go productive: clipboard history ‣ Working with a computer induces a lot of cut/past (<ctrl>-C / <ctrl>-V) ‣ In practice, you often refer (or intent to refer) to a piece of text you cut a few minutes ago
  • 6. Go productive: clipboard history ‣ Working with a computer induces a lot of cut/past (<ctrl>-C / <ctrl>-V) ‣ In practice, you often refer (or intent to refer) to a piece of text you cut a few minutes ago ‣ It is possible to use clipboard history (and <ctrl>-V’ offers to visit history) - mac OS: jumpcut - ubuntu: parcellite - windows: CLCL
  • 7. Go productive: clipboard history ‣ Working with a computer induces a lot of cut/past (<ctrl>-C / <ctrl>-V) ‣ In practice, you often refer (or intent to refer) to a piece of text you cut a few minutes ago ‣ It is possible to use clipboard history (and <ctrl>-V’ offers to visit history) - mac OS: jumpcut - ubuntu: parcellite - windows: CLCL ‣ What a big deal? - such functionalities has been present in editors such as vi or x?emacs for decades...
  • 9. Eclipse tips ‣ create documentation for a method (filled with method parameters) - place the cursor on the method name - right button > source > generate comment - or <ctrl>-<alt>-J - documentation is ready to be exported in a html javadoc
  • 11. Eclipse tips ‣ How to know where a method is called? - place the cursor on the method declaration - right button > open call hierarchy - or <ctrl>-<alt>-H
  • 12. DRY: Don’t Repeat Yourself 7
  • 13. Code design: DRY ‣ <ctrl>-C / <ctrl>-V is the most common shortcut appealing to duplicate a piece of “working” code into another part of the software
  • 14. Code design: DRY ‣ Problems:
  • 15. Code design: DRY ‣ Problems: - harder to understand where a given action is coded,
  • 16. Code design: DRY ‣ Problems: - harder to understand where a given action is coded, - hard to maintain bug.
  • 17. Code design: DRY ‣ Fight against DRY:
  • 18. Code design: DRY ‣ Fight against DRY: - refactor your code continuously (test are there to ensure stability).
  • 19. Code design: DRY ‣ Fight against DRY: - refactor your code continuously (test are there to ensure stability). - tackle duplication in your process at any level
  • 20. Code design: DRY ‣ Fight against DRY: - refactor your code continuously (test are there to ensure stability). - tackle duplication in your process at any level - time spent for factorizing process or code is almost never a waste
  • 21. YAGNI: You Ain’t Gonna Need It 11
  • 22. Code design: YAGNI ‣ A very common pitfall when writing code it to follow some enthusiasm and imagine features that are (on the instant you imagine them):
  • 23. Code design: YAGNI ‣ A very common pitfall when writing code it to follow some enthusiasm and imagine features that are (on the instant you imagine them): - very cool,
  • 24. Code design: YAGNI ‣ A very common pitfall when writing code it to follow some enthusiasm and imagine features that are (on the instant you imagine them): - very cool, - you have a bright idea on how to implement them,
  • 25. Code design: YAGNI ‣ A very common pitfall when writing code it to follow some enthusiasm and imagine features that are (on the instant you imagine them): - very cool, - you have a bright idea on how to implement them, - even though they don’t answer a particular need at that time, you “feel” they would be “cool to have in the future”
  • 27. Code design: YAGNI ‣ Problems: - the code get more complex, harder to maintain,
  • 28. Code design: YAGNI ‣ Problems: - the code get more complex, harder to maintain, - in a few weeks of time, this feature won’t be of any use (but other will!)
  • 29. Code design: YAGNI ‣ Fight YAGNI:
  • 30. Code design: YAGNI ‣ Fight YAGNI: - stick to your customer practical needs
  • 31. Code design: YAGNI ‣ Fight YAGNI: - stick to your customer practical needs - pair programming is the most efficient way to tackle such situations
  • 32. Groovy: running a script (outside the IDE) ‣ Programming goal is (often) to have a runnable program, outside the IDE
  • 33. Groovy: running a script (outside the IDE) ‣ Programming goal is (often) to have a runnable program, outside the IDE ‣ Be able to deploy the program on another machine
  • 34. Groovy: running a script (outside the IDE) ‣ Programming goal is (often) to have a runnable program, outside the IDE ‣ Be able to deploy the program on another machine ‣ First: install Groovy on the machine (apt-get install groovy etc.)
  • 35. Groovy: running a script (outside the IDE) ‣ Programming goal is (often) to have a runnable program, outside the IDE ‣ Be able to deploy the program on another machine ‣ First: install Groovy on the machine (apt-get install groovy etc.) ‣ Let’s consider a simple script hw.groovy, stored in directory /some/path println “hello, world”
  • 36. Groovy: running a script (outside the IDE) ‣ Programming goal is (often) to have a runnable program, outside the IDE ‣ Be able to deploy the program on another machine ‣ First: install Groovy on the machine (apt-get install groovy etc.) ‣ Let’s consider a simple script hw.groovy, stored in directory /some/path println “hello, world” ‣ launch the script from command line groovy hw.groovy
  • 37. Parsing command line arguments ‣ Runtime arguments are passed on the command line
  • 38. Parsing command line arguments ‣ Runtime arguments are passed on the command line ‣ Defining the possible arguments def cli = new CliBuilder(usage:'myscript.groovy [options]') //binary argument -h or --help and usage text cli.h(longOpt:'help', 'usage information') //compulsory argument for -n or --name=<user name> cli.n(longOpt:'name', argName:'user name', args:1, required: true, 'some user to salute') //facultative argument --int-value=<int> cli.i(longOpt:'int-value', argName:'int', args:1, 'some integer value')
  • 39. Parsing command line arguments (cont’d) ‣ Parsing the command line def options = cli.parse(args) if (!options) return
  • 40. Parsing command line arguments (cont’d) ‣ Parsing the command line def options = cli.parse(args) if (!options) return ‣ Check --help if (options.help) cli.usage()
  • 41. Parsing command line arguments (cont’d) ‣ Parsing the command line def options = cli.parse(args) if (!options) return ‣ Check --help if (options.help) cli.usage() ‣ Arguments usage: println "Hello $options.name (${options['int-value']})"
  • 42. Parsing command line arguments (cont’d) ‣ groovy myscript.groovy --help usage: myscript.groovy [options] -h,--help usage information -i,--int-value <int> some integer value -n,--name <user name> some user to salute
  • 43. Parsing command line arguments (cont’d) ‣ groovy myscript.groovy --help usage: myscript.groovy [options] -h,--help usage information -i,--int-value <int> some integer value -n,--name <user name> some user to salute ‣ groovy myscript.groovy --name=alice --int-value=234 Hello alice (234)
  • 44. Parsing command line arguments (cont’d) ‣ groovy myscript.groovy --help usage: myscript.groovy [options] -h,--help usage information -i,--int-value <int> some integer value -n,--name <user name> some user to salute ‣ groovy myscript.groovy --name=alice --int-value=234 Hello alice (234) ‣ More doc on http://groovy.codehaus.org/gapi/groovy/util/CliBuilder.html
  • 45. Parsing command line arguments (cont’d) ‣ The whole script: def cli = new CliBuilder(usage:'myscript.groovy [options]') cli.h(longOpt:'help', 'usage information') cli.n(longOpt:'name', argName:'user name', args:1, required: true, 'some user to salute') cli.i(longOpt:'int-value', argName:'int', args:1, 'some integer value') def options = cli.parse(args) if (!options) return if (options.help) cli.usage() println "Hello $options.name (${options['int-value']}) "
  • 46. Running a script with a packaged library ‣ A script by itself is soon meaningless, it is often backed by a library of packaged classes for doing the actual business
  • 47. Running a script with a packaged library ‣ A script by itself is soon meaningless, it is often backed by a library of packaged classes for doing the actual business ‣ The script is often the last assembly of coded (and tested) functionalities
  • 48. Running a script with a packaged library ‣ A script by itself is soon meaningless, it is often backed by a library of packaged classes for doing the actual business ‣ The script is often the last assembly of coded (and tested) functionalities ‣ Library is packaged as a jar (Java Archive) and the script is written on the side, making calls to the archive
  • 49. Running a script with a packaged library ‣ A script by itself is soon meaningless, it is often backed by a library of packaged classes for doing the actual business ‣ The script is often the last assembly of coded (and tested) functionalities ‣ Library is packaged as a jar (Java Archive) and the script is written on the side, making calls to the archive ‣ The jar if often the distributed part of a code
  • 50. Running a script with a packaged library ‣ A script by itself is soon meaningless, it is often backed by a library of packaged classes for doing the actual business ‣ The script is often the last assembly of coded (and tested) functionalities ‣ Library is packaged as a jar (Java Archive) and the script is written on the side, making calls to the archive ‣ The jar if often the distributed part of a code ‣ The script varsplic.groovy uses the jar import unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer ... def xml=new XmlSlurper() .parseText("http://pir.uniprot.org/uniprot/${ac}.xml" .toURL().text) .entry UniprotEntrySplicer splicer=[entryXml:xml] splicer.buildAllIsoforms().values().each{print it}
  • 51. Eclipse: exporting a jar from the IDE ‣ A jar is an archive that contains at least the compiled classes
  • 52. Eclipse: exporting a jar from the IDE ‣ A jar is an archive that contains at least the compiled classes ‣ Test classes are usually not exported
  • 53. Eclipse: exporting a jar from the IDE ‣ A jar is an archive that contains at least the compiled classes ‣ Test classes are usually not exported ‣ Exporting from eclipse - project > right button > export > java > jar
  • 54. Eclipse: exporting a jar from the IDE ‣ A jar is an archive that contains at least the compiled classes ‣ Test classes are usually not exported ‣ Exporting from eclipse - project > right button > export > java > jar ‣ A myfile.jar file is created
  • 55. Eclipse: exporting a jar from the IDE ‣ A jar is an archive that contains at least the compiled classes ‣ Test classes are usually not exported ‣ Exporting from eclipse - project > right button > export > java > jar ‣ A myfile.jar file is created
  • 56. Eclipse: exporting a jar from ant ‣ Apache ant is a versatile tool for automatic software build process
  • 57. Eclipse: exporting a jar from ant ‣ Apache ant is a versatile tool for automatic software build process ‣ It can be used to build a task: the build.xml (at project home directory) <?xml version="1.0" encoding="UTF-8" standalone="no"?> <project default="create_run_jar" name="Create Runnable Jar for Project eop.lec6"> <targetname="create_run_jar"> <jar destfile="eop6.jar"> <fileset dir="bin"> <exclude name="**/*Test.class"/> <exclude name="src/practicals/groovy/scripts/*"/> </fileset> </jar> </target> </project>
  • 58. Eclipse: exporting a jar from ant ‣ Apache ant is a versatile tool for automatic software build process ‣ It can be used to build a task: the build.xml (at project home directory) <?xml version="1.0" encoding="UTF-8" standalone="no"?> <project default="create_run_jar" name="Create Runnable Jar for Project eop.lec6"> <targetname="create_run_jar"> <jar destfile="eop6.jar"> <fileset dir="bin"> <exclude name="**/*Test.class"/> <exclude name="src/practicals/groovy/scripts/*"/> </fileset> </jar> </target> </project> ‣ right button > run as > ant build
  • 59. Eclipse: exporting a jar from ant ‣ Apache ant is a versatile tool for automatic software build process ‣ It can be used to build a task: the build.xml (at project home directory) <?xml version="1.0" encoding="UTF-8" standalone="no"?> <project default="create_run_jar" name="Create Runnable Jar for Project eop.lec6"> <targetname="create_run_jar"> <jar destfile="eop6.jar"> <fileset dir="bin"> <exclude name="**/*Test.class"/> <exclude name="src/practicals/groovy/scripts/*"/> </fileset> </jar> </target> </project> ‣ right button > run as > ant build ‣ <ctrl>-<alt>-X-Q
  • 60. Eclipse: exporting a jar from ant ‣ Apache ant is a versatile tool for automatic software build process ‣ It can be used to build a task: the build.xml (at project home directory) <?xml version="1.0" encoding="UTF-8" standalone="no"?> <project default="create_run_jar" name="Create Runnable Jar for Project eop.lec6"> <targetname="create_run_jar"> <jar destfile="eop6.jar"> <fileset dir="bin"> <exclude name="**/*Test.class"/> <exclude name="src/practicals/groovy/scripts/*"/> </fileset> </jar> </target> </project> ‣ right button > run as > ant build ‣ <ctrl>-<alt>-X-Q ‣ http://ant.apache.org/manual/tasksoverview.html
  • 61. Executing a script with a jar library ‣ The script varsplic.groovy can reside anywhere groovy -cp eop6.jar /path/to/varsplic.groovy --ac=Q70Z44
  • 62. Executing a script with a jar library ‣ The script varsplic.groovy can reside anywhere groovy -cp eop6.jar /path/to/varsplic.groovy --ac=Q70Z44 ‣ Arguments following the script will be passed to the script args
  • 63. Executing a script with a jar library ‣ The script varsplic.groovy can reside anywhere groovy -cp eop6.jar /path/to/varsplic.groovy --ac=Q70Z44 ‣ Arguments following the script will be passed to the script args ‣ Remember: put the least possible “business intelligence” into the script
  • 64. Test case: isoforms & proteotypic peptides ‣ Proteotypic peptide: given a list of proteins and cleavage enzyme, a proteotypic peptide is a peptide that can be produced only by one of those proteins
  • 65. Test case: isoforms & proteotypic peptides ‣ Proteotypic peptide: given a list of proteins and cleavage enzyme, a proteotypic peptide is a peptide that can be produced only by one of those proteins ‣ Customer of the day: “I want to give you one uniprot AC, you print me all the isoforms in a fasta format and the list list of proteotypic peptide (+ the isoform they are referring to). Please.”
  • 66. Test case: isoforms & proteotypic peptides ‣ Proteotypic peptide: given a list of proteins and cleavage enzyme, a proteotypic peptide is a peptide that can be produced only by one of those proteins ‣ Customer of the day: “I want to give you one uniprot AC, you print me all the isoforms in a fasta format and the list list of proteotypic peptide (+ the isoform they are referring to). Please.” ‣ Hopefully enough, you already have a toolkit to build, from a uniprot entry, a map isoform name -> isoform Protein
  • 67. Test case: isoforms & proteotypic peptides ‣ Proteotypic peptide: given a list of proteins and cleavage enzyme, a proteotypic peptide is a peptide that can be produced only by one of those proteins ‣ Customer of the day: “I want to give you one uniprot AC, you print me all the isoforms in a fasta format and the list list of proteotypic peptide (+ the isoform they are referring to). Please.” ‣ Hopefully enough, you already have a toolkit to build, from a uniprot entry, a map isoform name -> isoform Protein ‣ Your turn to play....

Notas del editor

  1. today end of a cycle\nnext week: genetic algorithm\nthen web programming\nend of the year exam: bring in your ideas\nplay customer + coder\ncustomer phase with me, then iterative development.\n
  2. parsing command line arguments, packaging a project into a library\nIn practice, we will often use web application for end usage\n\n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  11. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  12. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  13. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  14. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  15. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  16. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  17. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  18. Agile: refactor your code show you do not fear it! think of how to deal with a wild animal\n
  19. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  20. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  21. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  22. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  23. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  24. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  25. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  26. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  27. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  28. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  29. &quot;You ain&apos;t gonna need it&quot; (or YAGNI for short) is the principle in extreme programming that programmers should not add functionality until it is necessary.[1] Ron Jeffries writes, &quot;Always implement things when you actually need them, never when you just foresee that you need them.&quot;[2]\n\n
  30. not only for fun...\nit is also possible to run a script/project packaging a jar and only with java\n
  31. not only for fun...\nit is also possible to run a script/project packaging a jar and only with java\n
  32. not only for fun...\nit is also possible to run a script/project packaging a jar and only with java\n
  33. not only for fun...\nit is also possible to run a script/project packaging a jar and only with java\n
  34. not only for fun...\nit is also possible to run a script/project packaging a jar and only with java\n
  35. in real life, you don&amp;#x2019;t edit a script, save and rerun\nan option is to parse argument from a property file\n
  36. in real life, you don&amp;#x2019;t edit a script, save and rerun\nan option is to parse argument from a property file\n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. classes code for action, for re-use, test etc....\n
  45. classes code for action, for re-use, test etc....\n
  46. classes code for action, for re-use, test etc....\n
  47. classes code for action, for re-use, test etc....\n
  48. classes code for action, for re-use, test etc....\n
  49. can also contains source code (more voluminous but easier for third parties to debug), javadoc...\n
  50. can also contains source code (more voluminous but easier for third parties to debug), javadoc...\n
  51. can also contains source code (more voluminous but easier for third parties to debug), javadoc...\n
  52. can also contains source code (more voluminous but easier for third parties to debug), javadoc...\n
  53. can also contains source code (more voluminous but easier for third parties to debug), javadoc...\n
  54. in fact, ant can be used for countless tasks, as soon as you needed for automated, dependency oriented process\nan ant file can contained multiple targets (as possibly a default one)\n
  55. in fact, ant can be used for countless tasks, as soon as you needed for automated, dependency oriented process\nan ant file can contained multiple targets (as possibly a default one)\n
  56. in fact, ant can be used for countless tasks, as soon as you needed for automated, dependency oriented process\nan ant file can contained multiple targets (as possibly a default one)\n
  57. in fact, ant can be used for countless tasks, as soon as you needed for automated, dependency oriented process\nan ant file can contained multiple targets (as possibly a default one)\n
  58. in fact, ant can be used for countless tasks, as soon as you needed for automated, dependency oriented process\nan ant file can contained multiple targets (as possibly a default one)\n
  59. \n
  60. \n
  61. \n
  62. first questions : you build be some example to validate the program\n
  63. first questions : you build be some example to validate the program\n
  64. first questions : you build be some example to validate the program\n
  65. first questions : you build be some example to validate the program\n