Groovy: Efficiency Oriented Programming
Lecture 9
Master Proteomics & Bioinformatics - University of Geneva
Alexandre Masselot - summer 2011
Contents
Contents

‣ Eclipse tips: tasks
Contents

‣ Eclipse tips: tasks
‣ Productive developer tips: technical debt
Contents

‣ Eclipse tips: tasks
‣ Productive developer tips: technical debt
‣ Web applications
Contents

‣ Eclipse tips: tasks
‣ Productive developer tips: technical debt
‣ Web applications
‣ Grails
Contents

‣ Eclipse tips: tasks
‣ Productive developer tips: technical debt
‣ Web applications
‣ Grails
‣ Twitter application: step 1
Eclipse tips
Eclipse tips

‣ Annotate code with tasks
Eclipse tips

‣ Annotate code with tasks
‣ TODO / FIXME
Eclipse tips

‣ Annotate code with tasks
‣ TODO / FIXME
‣ Add comments into your code
 
 void mutate(){
      //TODO check that mutation **does** modify position
 
 
 board.piecesPositions[
              randomGenerator.nextInt(board.maxPieces)] =
 
 
 
 [
           randomGenerator.nextInt(board.size),
           randomGenerator.nextInt(board.size)
         ]
 
 }
Eclipse tips   (cont’d)
Eclipse tips                       (cont’d)

‣ Lines is prefixed with an icon
Eclipse tips                       (cont’d)

‣ Lines is prefixed with an icon
‣ The task view
Technical debt
Technical debt

‣ Increasing the debt:
  - poor code
  - repeat in code/process (DRY)
  - postponing refactoring
  - skipping tests
Technical debt

‣ Increasing the debt:
  - poor code
  - repeat in code/process (DRY)
  - postponing refactoring
  - skipping tests

‣ Interest are expensive
Technical debt

‣ Increasing the debt:
  - poor code
  - repeat in code/process (DRY)
  - postponing refactoring
  - skipping tests

‣ Interest are expensive
‣ A common solution: use prototyping
What do you know about www?
A simple (static) web query
protocol
protocol   server host
protocol   server host   resource path
1 find the server (DNS)
1 find the server (DNS)
2 pass the local resource requested
1 find the server (DNS)
2 pass the local resource requested
3 server loads the resource to be served
1 find the server (DNS)
2 pass the local resource requested
3 server loads the resource to be served
4 resource sent back to the browser (client)
1 find the server (DNS)
2 pass the local resource requested
3 server loads the resource to be served
4 resource sent back to the browser (client)
5 browser interprets the response
1 find the server (DNS)
2 pass the local resource requested
3 server loads the resource to be served
4 resource sent back to the browser (client)
5 browser interprets the response
6 browser loads additional resources (+ requests)
1 find the server (DNS)
2 pass the local resource requested
3 server loads the resource to be served
4 resource sent back to the browser (client)
5 browser interprets the response
6 browser loads additional resources (+ requests)
7 browser displays results
Static is not alway enough
   dynamic url queries
An action is performed on the server side
          parameter are passed
action path
action path   parameter(s)
action path         parameter(s)


Instead of a static resource, the results is computed
Master your browser!
Today: firefox (idem for chrome, safari, ~IE)
View page source
(best inspiration is by copying others)
Install firebug & web developer add-ons
display loaded resources
firebug > network
static page
dynamic resource + interactions
More operations can be undertaken within page
But cycle query->server->rendering
             is always respected
More operations can be undertaken within page
But cycle query->server->rendering
             is always respected
Why using/building web based applications?
A script does not suit everyone (unfortunately)
Classic deploy: window based application
A web browser: a powerful GUI
A web transaction
A web transaction

‣ Url request
  - http://host:8080/entry/show?ac=P12345&format=fasta
A web transaction

‣ Url request
  - http://host:8080/entry/show?ac=P12345&format=fasta

‣ Action
  - build the model
A web transaction

‣ Url request
  - http://host:8080/entry/show?ac=P12345&format=fasta

‣ Action
  - build the model

‣ View generation
  - html contents creation
A web transaction

‣ Url request
  - http://host:8080/entry/show?ac=P12345&format=fasta

‣ Action
  - build the model

‣ View generation
  - html contents creation

‣ Rendering
A web transaction

‣ Url request                             [browser]
  - http://host:8080/entry/show?ac=P12345&format=fasta

‣ Action                                    [server]
  - build the model

‣ View generation                           [server]
  - html contents creation

‣ Rendering                               [browser]
Groovy + web = Grails
Grails with STS eclipse
Grails with STS eclipse

‣ Help > dashboard > extensions > Grails
Grails with STS eclipse

‣ Help > dashboard > extensions > Grails
‣ Download Grails
  - http://grails.org/Download
Grails with STS eclipse

‣ Help > dashboard > extensions > Grails
‣ Download Grails
  - http://grails.org/Download

‣ Uncompress in local directory
  - e.g. ~/local/grails-1.3.7
Grails with STS eclipse

‣ Help > dashboard > extensions > Grails
‣ Download Grails
  - http://grails.org/Download

‣ Uncompress in local directory
  - e.g. ~/local/grails-1.3.7

‣ Configure Grails in STS preferences
  - possible to host multiple versions
Grails with STS eclipse

‣ Help > dashboard > extensions > Grails
‣ Download Grails
  - http://grails.org/Download

‣ Uncompress in local directory
  - e.g. ~/local/grails-1.3.7

‣ Configure Grails in STS preferences
  - possible to host multiple versions

‣ Reference
  - http://grails.org/doc/latest/
Grails with STS eclipse                          (cont’d)

‣ Configure shortcut for grails command prompt
Grails with STS eclipse                           (cont’d)

‣ Configure shortcut for grails command prompt
‣ Preference > keys
                     > open grails command prompt
  - <ctrl> <alt> G
  - (maybe need to deactivate another shortcut)
Grails with STS eclipse                           (cont’d)

‣ Configure shortcut for grails command prompt
‣ Preference > keys
                     > open grails command prompt
  - <ctrl> <alt> G
  - (maybe need to deactivate another shortcut)

‣ Calling grails command on selected project
STS: creating a new Grails application
STS: creating a new Grails application

‣ File > new
 > Grails project

groovy & grails - lecture 9

  • 1.
    Groovy: Efficiency OrientedProgramming Lecture 9 Master Proteomics & Bioinformatics - University of Geneva Alexandre Masselot - summer 2011
  • 2.
  • 3.
  • 4.
    Contents ‣ Eclipse tips:tasks ‣ Productive developer tips: technical debt
  • 5.
    Contents ‣ Eclipse tips:tasks ‣ Productive developer tips: technical debt ‣ Web applications
  • 6.
    Contents ‣ Eclipse tips:tasks ‣ Productive developer tips: technical debt ‣ Web applications ‣ Grails
  • 7.
    Contents ‣ Eclipse tips:tasks ‣ Productive developer tips: technical debt ‣ Web applications ‣ Grails ‣ Twitter application: step 1
  • 8.
  • 9.
  • 10.
    Eclipse tips ‣ Annotatecode with tasks ‣ TODO / FIXME
  • 11.
    Eclipse tips ‣ Annotatecode with tasks ‣ TODO / FIXME ‣ Add comments into your code void mutate(){ //TODO check that mutation **does** modify position board.piecesPositions[ randomGenerator.nextInt(board.maxPieces)] = [ randomGenerator.nextInt(board.size), randomGenerator.nextInt(board.size) ] }
  • 12.
    Eclipse tips (cont’d)
  • 13.
    Eclipse tips (cont’d) ‣ Lines is prefixed with an icon
  • 14.
    Eclipse tips (cont’d) ‣ Lines is prefixed with an icon ‣ The task view
  • 15.
  • 16.
    Technical debt ‣ Increasingthe debt: - poor code - repeat in code/process (DRY) - postponing refactoring - skipping tests
  • 17.
    Technical debt ‣ Increasingthe debt: - poor code - repeat in code/process (DRY) - postponing refactoring - skipping tests ‣ Interest are expensive
  • 18.
    Technical debt ‣ Increasingthe debt: - poor code - repeat in code/process (DRY) - postponing refactoring - skipping tests ‣ Interest are expensive ‣ A common solution: use prototyping
  • 19.
    What do youknow about www?
  • 20.
  • 22.
  • 23.
    protocol server host
  • 24.
    protocol server host resource path
  • 26.
    1 find theserver (DNS)
  • 27.
    1 find theserver (DNS) 2 pass the local resource requested
  • 28.
    1 find theserver (DNS) 2 pass the local resource requested 3 server loads the resource to be served
  • 29.
    1 find theserver (DNS) 2 pass the local resource requested 3 server loads the resource to be served 4 resource sent back to the browser (client)
  • 30.
    1 find theserver (DNS) 2 pass the local resource requested 3 server loads the resource to be served 4 resource sent back to the browser (client) 5 browser interprets the response
  • 31.
    1 find theserver (DNS) 2 pass the local resource requested 3 server loads the resource to be served 4 resource sent back to the browser (client) 5 browser interprets the response 6 browser loads additional resources (+ requests)
  • 32.
    1 find theserver (DNS) 2 pass the local resource requested 3 server loads the resource to be served 4 resource sent back to the browser (client) 5 browser interprets the response 6 browser loads additional resources (+ requests) 7 browser displays results
  • 34.
    Static is notalway enough dynamic url queries
  • 35.
    An action isperformed on the server side parameter are passed
  • 37.
  • 38.
    action path parameter(s)
  • 39.
    action path parameter(s) Instead of a static resource, the results is computed
  • 40.
    Master your browser! Today:firefox (idem for chrome, safari, ~IE)
  • 41.
    View page source (bestinspiration is by copying others)
  • 43.
    Install firebug &web developer add-ons
  • 44.
  • 45.
  • 47.
    dynamic resource +interactions
  • 49.
    More operations canbe undertaken within page But cycle query->server->rendering is always respected
  • 50.
    More operations canbe undertaken within page But cycle query->server->rendering is always respected
  • 51.
    Why using/building webbased applications?
  • 52.
    A script doesnot suit everyone (unfortunately)
  • 53.
    Classic deploy: windowbased application
  • 54.
    A web browser:a powerful GUI
  • 55.
  • 56.
    A web transaction ‣Url request - http://host:8080/entry/show?ac=P12345&format=fasta
  • 57.
    A web transaction ‣Url request - http://host:8080/entry/show?ac=P12345&format=fasta ‣ Action - build the model
  • 58.
    A web transaction ‣Url request - http://host:8080/entry/show?ac=P12345&format=fasta ‣ Action - build the model ‣ View generation - html contents creation
  • 59.
    A web transaction ‣Url request - http://host:8080/entry/show?ac=P12345&format=fasta ‣ Action - build the model ‣ View generation - html contents creation ‣ Rendering
  • 60.
    A web transaction ‣Url request [browser] - http://host:8080/entry/show?ac=P12345&format=fasta ‣ Action [server] - build the model ‣ View generation [server] - html contents creation ‣ Rendering [browser]
  • 61.
    Groovy + web= Grails
  • 62.
  • 63.
    Grails with STSeclipse ‣ Help > dashboard > extensions > Grails
  • 64.
    Grails with STSeclipse ‣ Help > dashboard > extensions > Grails ‣ Download Grails - http://grails.org/Download
  • 65.
    Grails with STSeclipse ‣ Help > dashboard > extensions > Grails ‣ Download Grails - http://grails.org/Download ‣ Uncompress in local directory - e.g. ~/local/grails-1.3.7
  • 66.
    Grails with STSeclipse ‣ Help > dashboard > extensions > Grails ‣ Download Grails - http://grails.org/Download ‣ Uncompress in local directory - e.g. ~/local/grails-1.3.7 ‣ Configure Grails in STS preferences - possible to host multiple versions
  • 67.
    Grails with STSeclipse ‣ Help > dashboard > extensions > Grails ‣ Download Grails - http://grails.org/Download ‣ Uncompress in local directory - e.g. ~/local/grails-1.3.7 ‣ Configure Grails in STS preferences - possible to host multiple versions ‣ Reference - http://grails.org/doc/latest/
  • 68.
    Grails with STSeclipse (cont’d) ‣ Configure shortcut for grails command prompt
  • 69.
    Grails with STSeclipse (cont’d) ‣ Configure shortcut for grails command prompt ‣ Preference > keys > open grails command prompt - <ctrl> <alt> G - (maybe need to deactivate another shortcut)
  • 70.
    Grails with STSeclipse (cont’d) ‣ Configure shortcut for grails command prompt ‣ Preference > keys > open grails command prompt - <ctrl> <alt> G - (maybe need to deactivate another shortcut) ‣ Calling grails command on selected project
  • 71.
    STS: creating anew Grails application
  • 72.
    STS: creating anew Grails application ‣ File > new > Grails project

Editor's Notes

  • #2 new round starting web application\nGoal: to build a twitter like application\ntoday is an introduction to web application\n
  • #3 \n
  • #4 \n
  • #5 \n
  • #6 \n
  • #7 \n
  • #8 Pervert use of task to remember what you want to remember\n!!Moderate use of FIXME\n\n
  • #9 Pervert use of task to remember what you want to remember\n!!Moderate use of FIXME\n\n
  • #10 Pervert use of task to remember what you want to remember\n!!Moderate use of FIXME\n\n
  • #11 ctrl F7\nof lower left button to open a view\nclose you projects\nview is just one box, a perspective (upper right corner) is a arrangement of views\nTasks on server: trac, mantis &lt;-&gt; tickets (bug, features etc.)\n
  • #12 ctrl F7\nof lower left button to open a view\nclose you projects\nview is just one box, a perspective (upper right corner) is a arrangement of views\nTasks on server: trac, mantis &lt;-&gt; tickets (bug, features etc.)\n
  • #13 ctrl F7\nof lower left button to open a view\nclose you projects\nview is just one box, a perspective (upper right corner) is a arrangement of views\nTasks on server: trac, mantis &lt;-&gt; tickets (bug, features etc.)\n
  • #14 Example: your parse SwissProt from text format for getting AC and sequence, then, your are asked to read for splicing info =&gt; you text parsing get more and more complex\nJumping to xml parsing is an investment (you loose one day coming back to the same point), but you&amp;#x2019;ll move faster further on.\n
  • #15 Example: your parse SwissProt from text format for getting AC and sequence, then, your are asked to read for splicing info =&gt; you text parsing get more and more complex\nJumping to xml parsing is an investment (you loose one day coming back to the same point), but you&amp;#x2019;ll move faster further on.\n
  • #16 Example: your parse SwissProt from text format for getting AC and sequence, then, your are asked to read for splicing info =&gt; you text parsing get more and more complex\nJumping to xml parsing is an investment (you loose one day coming back to the same point), but you&amp;#x2019;ll move faster further on.\n
  • #17 html javascript css form\nanchor query argument\nGET/POST\nimages\nservlet CGI\najax flash\napache / tomcat\n\n
  • #18 \n
  • #19 \n
  • #20 \n
  • #21 \n
  • #22 \n
  • #23 \n
  • #24 \n
  • #25 \n
  • #26 \n
  • #27 \n
  • #28 \n
  • #29 \n
  • #30 \n
  • #31 \n
  • #32 \n
  • #33 \n
  • #34 \n
  • #35 \n
  • #36 \n
  • #37 \n
  • #38 \n
  • #39 \n
  • #40 \n
  • #41 \n
  • #42 \n
  • #43 \n
  • #44 \n
  • #45 Application is not a weekly TP just enforced by a series of test\nThe application must go public, to be used by the (lab) customer\nFind the easiest way to deploy you app\n
  • #46 Install groovy, copy jars\nCall the scripts =&gt; teach your user\nWindows is catastrophic for command line\nHowever, script can be the solution for high volumes (biologist can learn...)\n
  • #47 Griffon (swing based)\nStill need to install software on customer machine\nSoftware update to take into account (JNLP is a solution)\nFull access to the user&amp;#x2019;s machine\nStandalone solution\n
  • #48 GUI: Graphical User Interface\nEveryone has a browser\nnetwork is fast\nExample: gmail, google map etc.\nJavascript/Ajax turn the browser into a user friendly experience\nFlash: little limits compared to a native GUI (not on the iPhone/iPad family...). Can grant acces to the host computer resources\nEasy to deploy (everyone&amp;#x2019;s connected)\nEasy updates\nCan install a server on the customer machines\n
  • #49 \n
  • #50 \n
  • #51 \n
  • #52 \n
  • #53 \n
  • #54 All the web application architecture is ready\nConfiguration at it simplest level (convention over configuration)\ndomain (database stored beans)\nplugin oriented to enrich the app\nSTS integration\n
  • #55 High changing pace in the versions, keep up to date...\n
  • #56 High changing pace in the versions, keep up to date...\n
  • #57 High changing pace in the versions, keep up to date...\n
  • #58 High changing pace in the versions, keep up to date...\n
  • #59 High changing pace in the versions, keep up to date...\n
  • #60 Version field is set automatically\n
  • #61 a very common command call, so better configure it as a simple shortcut\n
  • #62 a very common command call, so better configure it as a simple shortcut\n
  • #63 a very common command call, so better configure it as a simple shortcut\n
  • #64 equivalent to command line\nexport GRAILS_HOME=/path/to/installed/grails-x.y.z\nexport PATH=$PATH:$GRAILS_HOME/bin\ngrails create-app eop.lec9.demo\n
  • #65 + some optional directories\ntoday : only controller &amp; view\n&amp;#x201C;we&amp;#x2019;ll see that later&amp;#x201D; will be the most commonly used word today...\n\n
  • #66 + some optional directories\ntoday : only controller &amp; view\n&amp;#x201C;we&amp;#x2019;ll see that later&amp;#x201D; will be the most commonly used word today...\n\n
  • #67 Port 80 by default http://localhost\nPort &lt;1024 traditionally reserved to root\nModifying the code (to some extent) does not require to re-start the server (wait 2 seconds)\nIt is not possible to launch twice the application (port conflict). Must kill before relaunching if ever\n
  • #68 Port 80 by default http://localhost\nPort &lt;1024 traditionally reserved to root\nModifying the code (to some extent) does not require to re-start the server (wait 2 seconds)\nIt is not possible to launch twice the application (port conflict). Must kill before relaunching if ever\n
  • #69 Port 80 by default http://localhost\nPort &lt;1024 traditionally reserved to root\nModifying the code (to some extent) does not require to re-start the server (wait 2 seconds)\nIt is not possible to launch twice the application (port conflict). Must kill before relaunching if ever\n
  • #70 Versions are displayed (grails, your application)\nList of plugins used by default (we&amp;#x2019;ll add some more later)\n
  • #71 \n
  • #72 &lt;ctrl&gt;&lt;alt&gt;G create-controller foo.hello \nDo not forget to refresh eclipse after each command line action (F5) or right-button &gt; refresh\n\n
  • #73 \n
  • #74 \n
  • #75 \n
  • #76 \n
  • #77 \n
  • #78 \n
  • #79 \n
  • #80 \n
  • #81 \n
  • #82 \n
  • #83 \n
  • #84 \n
  • #85 \n
  • #86 \n
  • #87 \n
  • #88 \n
  • #89 \n
  • #90 \n
  • #91 \n
  • #92 \n
  • #93 \n
  • #94 \n
  • #95 \n
  • #96 \n
  • #97 Test is ready, but we&amp;#x2019;re not yet there!\n
  • #98 \n
  • #99 Convention is the naming of file, instead of description in configuration files + class inheritance\n
  • #100 Convention is the naming of file, instead of description in configuration files + class inheritance\n
  • #101 Convention is the naming of file, instead of description in configuration files + class inheritance\n
  • #102 Convention is the naming of file, instead of description in configuration files + class inheritance\n
  • #103 index is by default (we&amp;#x2019;ll see the configuration later)\n
  • #104 index is by default (we&amp;#x2019;ll see the configuration later)\n
  • #105 No need to relaunch the application when you add action or controllers\n\n
  • #106 No need to relaunch the application when you add action or controllers\n\n
  • #107 \n
  • #108 \n
  • #109 \n
  • #110 Before going to more complex action (we have not talked about parameters). let&amp;#x2019;s make a tour on view\nText is maybe not always enough\nWhat do you know of html?\n\n
  • #111 \n
  • #112 This is a little bit too simplistic, as we can have in practice one GSP for multiple actions, or an action can be redirected towards one or another view depending on the context\n
  • #113 \n
  • #114 \n
  • #115 \n
  • #116 \n
  • #117 \n
  • #118 \n
  • #119 actions directText &amp; withDate do not have .gsp as they render directly text\n
  • #120 actions directText &amp; withDate do not have .gsp as they render directly text\n
  • #121 \n
  • #122 ${...} extrapolate groovy expression (just as in a println statement)\nNote the link back to home page\nOf course, it is possible to pass more than one variable in the returned map\n
  • #123 ${...} extrapolate groovy expression (just as in a println statement)\nNote the link back to home page\nOf course, it is possible to pass more than one variable in the returned map\n
  • #124 \n
  • #125 \n
  • #126 Parameters are passed as map of string\nNote that we can still access params within the gsp\n
  • #127 Parameters are passed as map of string\nNote that we can still access params within the gsp\n
  • #128 Parameters are passed as map of string\nNote that we can still access params within the gsp\n
  • #129 \n
  • #130 \n
  • #131 \n
  • #132 \n
  • #133 \n
  • #134 \n
  • #135 \n
  • #136 \n
  • #137 One of the most commons software architecture design pattern\nShare responsibility among each components\nModel is far more than just some data exchanged between the controller and the view (we see that later)\n\n