Updates from September, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • Tomás Augusto Müller 1:55 pm on September 30, 2011 Permalink | Reply
    Tags: javascript,   

    Javascript Console Tips 

    Take a Javascript console rundown with Paul Irish from the Chrome team.

     
  • Tomás Augusto Müller 4:29 pm on September 7, 2010 Permalink | Reply
    Tags: ,   

    Error installing sqlite3-ruby 

    “make sure you have the libsqlite3-dev package installed on (ubuntu|debian), or the sqlite gem won’t compile”

    This solved to me the following error:

    $ gem install sqlite3-ruby
    Building native extensions. This could take a while…
    ERROR: Error installing sqlite3-ruby:
    ERROR: Failed to build gem native extension.
    .
    .
    .
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers. Check the mkmf.log file for more
    details. You may need configuration options.
    .
    .
    .

    Using ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-linux], MBARI 0×8770, Ruby Enterprise Edition 2010.02

     
  • Tomás Augusto Müller 1:18 am on May 28, 2009 Permalink | Reply
    Tags: ,   

    Adding visual to your voice 

    Last year I started to develop an hotel booking application called Voice Hotel. The word Voice was used in the name because the user interface with all features offered by the system is through the voice. It was missing an interface for viewing the reservations made, and the situation of each one (confirmed or canceled).

    This year I decided to study JavaFX language for developing an initial prototype for this interface, where it should at least allows visualizing existing reservations and the new reservations in real time.

    To start this development, it was necessary to go back to Voice Hotel project and make some modifications and improvements in the system architecture, as follows the list below:

    • Added Jersery support to implement RESTful Web Services, offering a interface to communicate and exchange information with JavaFX application.
    • Jersey Spring contribution to use Spring Framework beans through dependency injection using annotations in the RESTful services.
    • Updated Spring Framework to 2.5.6. Now using annotations to configure Spring beans and cut xml code when possible. Added DelegatingVariableResolver in faces-config.xml variable-resolver configuration, to use Spring beans as JavaServer Faces managed-beans.
    • JavaServer Faces, RichFaces and Facelets to develop a rich user interface, where the JavaFX application will be available. Other reason to use RichFaces is to demonstrate one possibility of integration between JavaServer Faces and JavaFX, through Java LiveConnect and Ajax.

    The Application

    My JavaFX application consists in a data table, with all reservations information. All data is retrieved from the database used by Voice Hotel application, through a RESTful web service.
    To display data, it was used a Swing JTable component, one PullParser implementation to interpret returned data from the web service and a bi-directional bind to update data in the table component.

    If you want a little more information about this powerful JavaFX language feature – data-binding and triggers – I recommend reading these slides.

    For asynchronous communication between JavaFX and the Web service, it was implemented a class that defines a task to update the data and that must be run on a fixed interval of time. This way any user interaction with the Voice Hotel system appears automatically after the end of the respective transaction.

    JavaServer Faces integration

    The intention here is just to show up a way to integrate this two view technologies in a efficiently and interesting manner, using Java LiveConnect, available only in JavaSE 6u12 and above, and Ajax request, sending an attribute from the managed-bean for the JavaFX application.

    Using RichFaces component library, we have access to a4j:jsFunction and a4j:commandButton components.
    Let’s see:

    With the a4j:commandButton component we set in the action attribute a method of the managed-bean that should be performed in the Ajax request. This method can perform any processing on the server, databases, and so on, and update the objects that you want to send to the JavaFX application. For this demonstration, the method executed only assigns a value for the string object “testParameter”.

    The trick is done through the use of oncomplete attribute that performs a call, when the Ajax request is completed, to the javascript function defined with a4j:jsFunction component as explained below.

    a4j:commandButton value=”Reset grid data”
    action=”#{reservationList.searchParameter}”
    oncomplete=”searchParameter();”

    We define a javascript function with the a4j:jsFunction component, indicating in the data attribute which managed-bean attribute will be sent by parameter to the JavaFX application.

    a4j:jsFunction name=”searchParameter”
    data=”#{reservationList.testParameter}”
    oncomplete=”sendParameterToJavaFX(data);”

    Continuing, the sendParameterToJavaFX function is performed, getting the JavaFX application by id (“app”), and sending the value of the managed-bean object as a parameter value to the JavaFX function (“resetGridData” in this case).


    function sendParameterToJavaFX(parameter) {
    try {
    var dataGrid = document.getElementById(“app”);
    dataGrid.script.resetGridData(parameter);
    } catch (e) {
    reportException(e);
    }
    }


    JavaFX application at JSF page:

    javafx(
    {
    archive: “javafx/VoiceHotelFXViewer.jar”,
    draggable: true,
    width: 800,
    height: 240,
    code: “net.java.dev.voicehotel.viewer.Main”,
    name: “VoiceHotelFXViewer”,
    id: “app”
    }
    );

    This sequence is performed by clicking the “Reset grid data” button (the a4j:commandButton). Looking at the java webstart console the following message appears: “parameter received from ajax request: parameter returned from server by ajax request” where “parameter returned from server by ajax request” is the value of the String object of the managed-bean used for this demonstration.

    With this demo we can think, for example in a rich JavaFX component library for JavaServer Faces applications. Why not? For more information about Java LiveConnect see:

    https://jdk6.dev.java.net/plugin2/liveconnect/
    http://java.sun.com/products/plugin/1.3/docs/jsobject.html
    https://developer.mozilla.org/en/LiveConnect
    https://developer.mozilla.org/En/Core_JavaScript_1.5_Guide:LiveConnect_Overview

    Conclusion

    JavaFX is a powerful scripting language that can be used to develop and deploy rich user experiences, where the same application can be used in different environments, from cell phones to desktops. The integration between JavaFX and JRE in desktop applications and between JavaME in mobile devices, offers a great advantage by reducing the learning curve and reusing existing knowledge over these platforms.

    You can check the final JavaFX application here:
    http://inf.unisc.br/tmuller/view/home.jsf

    The VoiceHotel project is available here:
    https://voicehotel.dev.java.net/

    To test the application make a free call using Skype Voip to the following number: +99000936 9996079911, and make a reservation. When the reservation process finish you will see the new reservation on top of the JavaFX data table automatically.

    If you want, follow the instructions to deploy locally the VoiceHotel project, and change the URL for the RESTful web service in Main.fx file, to localhost.

    The instructions for deploying VoiceHotel can be found here:
    https://voicehotel.dev.java.net/source/browse/voicehotel/trunk/artifacts/

     
  • Tomás Augusto Müller 12:09 am on May 4, 2009 Permalink | Reply
    Tags: ,   

    Conclusion – Nine Steps to Better Software Design Today Exercise 

    We have reached the end of the exercise – Nine Steps to Better Software Design, presented at chapter Object Calisthenics by Jeff Bay in The ThoughtWorks Anthology book from the Pragmatic Programmers.

    Eight of these nine rules are simply ways to visualize and implement the Holy Grail of object-oriented programming—the encapsulation of data. In addition, another drives the appropriate use of polymorphism (not using else and minimizing all conditional logic), and another is a naming strategy that encourages concise and straightforward naming standards, without inconsistently applied and hard-to-pronounce abbreviations.

    Tip from the author:

    In the long run, you will inevitably find that these rules contradict each other in some situations or that applying the rules leads to degenerate results. For the purpose of the exercise, however, spend 20 hours and 1,000 lines writing code that conforms 100% to these rules. You will find yourself having to break old habits and change rules that you may have lived with for your whole programming life. Each of the rules has been chosen such that if you follow it, you will encounter situations that would typically have an obvious (but perhaps incorrect) answer that is not available to you.

    Following these rules with discipline will force you to come up with the harder answers that lead to a much richer understanding of objectoriented programming. If you write 1,000 lines that follow all these rules, you will find that you have created something completely different from what you expected. Follow the rules, and see where you end up. If you keep working at it, the code you are writing might conform to these rules without any conscious effort on your part.

    If you have missed some part of this series, check out the list below with all related posts.

    1. Use only one level of indentation per method.
    2. Don’t use the else keyword.
    3. Wrap all primitives and strings.
    4. Use only one dot per line.
    5. Don’t abbreviate.
    6. Keep all entities small.
    7. Don’t use any classes with more than two instance variables.
    8. Use first-class collections.
    9. Don’t use any getters/setters/properties.

    Happy coding! ; )

     
  • Tomás Augusto Müller 12:07 am on May 4, 2009 Permalink | Reply
    Tags: ,   

    Rule 9: Don’t Use Any Getters/Setters/Properties 

    From the series about the rules of thumb, presented at chapter Object Calisthenics by Jeff Bay in The ThoughtWorks Anthology book from the Pragmatic Programmers (click here to see the the previous rules).

    The rule

    The last sentence of the previous rule leads almost directly to this rule.
    If your objects are now encapsulating the appropriate set of instance variables but the design is still awkward, it is time to examine some more direct violations of encapsulation. The behavior will not follow the instance variable if it can simply ask for the value in its current location.

    The idea behind strong encapsulation boundaries is to force programmers working on the code after you leave it to look for and place behavior into a single place in the object model. This has many beneficial downstream effects, such as a dramatic reduction in duplication errors and a better localization of changes to implement new features. This rule is commonly stated as “Tell, don’t ask.”

     
  • Tomás Augusto Müller 12:05 am on May 4, 2009 Permalink | Reply
    Tags: ,   

    Rule 8: Use First-Class Collections 

    From the series about the rules of thumb, presented at chapter Object Calisthenics by Jeff Bay in The ThoughtWorks Anthology book from the Pragmatic Programmers (click here to see the the previous rules).

    The rule

    The application of this rule is simple: any class that contains a collection should contain no other member variables. Each collection gets wrapped in its own class, so now behaviors related to the collection have a home. You may find that filters become part of this new class.

    Filters may also become function objects in their own right. Also, your new class can handle activities such as joining two groups together or applying a rule to each element of the group. This is an obvious extension of the rule about instance variables but is important for its own sake as well. A collection is really a type of very useful primitive. It has many behaviors but little semantic intent or clues for either the next programmer or the maintainer.

     
  • Tomás Augusto Müller 12:00 am on April 18, 2009 Permalink | Reply
    Tags: ,   

    Rule 7: Don’t Use Any Classes with More Than Two Instance Variables 

    From the series about the rules of thumb, presented at chapter Object Calisthenics by Jeff Bay in The ThoughtWorks Anthology book from the Pragmatic Programmers (click here to see the the previous rules).

    The rule

    Most classes should simply be responsible for handling a single state variable, but a few will require two. Adding a new instance variable to a class immediately decreases the cohesion of that class. In general, while programming under these rules, you’ll find that there are two kinds of classes, those that maintain the state of a single instance variable and those that coordinate two separate variables. In general, don’t mix the two kinds of responsibilities. 

    Now, go back and read the rule number three again. You probably notice that there are few cases where a cohesive single job description can be created for a class with many instance variables.


    Example:

        String first;
        String middle;
        String last;
    }

    The previous code could be decomposed into two classes like this:

    class Name {
        Surname family;
        GivenNames given;
    }

    class Surname {
        String family;
    }

    class GivenNames {
        List names;
    }

    Note that in thinking about how to do the decomposition, the opportunity to separate the concerns of a family name (used for many legal entity restrictions) could be separated from an essentially different kind of name. The GivenName object here contains a list of names, allowing the new model to absorb people with first, middle, and other given names. Frequently, the decomposition of instance variables leads to an understanding of commonality of several related instance variables. Sometimes several related instance variables actually have a related life in a first-class collection.

    Decomposing objects from a set of attributes into a hierarchy of collaborating objects leads much more directly to an effective object model. The recursive application of this rule has led to a very quick decomposition of complex large objects into much simpler models. Behavior naturally follows the instance variables into the appropriate place. If you get stuck, work downward by splitting objects into related halves or upward by picking any two instance variables and making an object out of them.

     
  • Tomás Augusto Müller 12:49 am on March 30, 2009 Permalink | Reply
    Tags: ,   

    Rule 6: Keep All Entities Small 

    From the series about the rules of thumb, presented at chapter Object Calisthenics by Jeff Bay in The ThoughtWorks Anthology book from the Pragmatic Programmers (click here to see the the previous rules).

    Keeping All Entities Small

    This means no class that’s more than fifty lines and no package that’s more than ten files.
    Classes of more than fifty lines usually do more than one thing, which makes them harder to understand and harder to reuse. Fifty-line classes have the added benefit of being visible on one screen without scrolling, which makes them easier to grasp quickly.

    What’s challenging about creating such small classes is that there are often groups of behaviors that make logical sense together. This is where you need to leverage packages. As your classes become smaller and have fewer responsibilities and as you limit package size, you’ll start to see that packages represent clusters of related classes that work together to achieve a goal. Packages, like classes, should be cohesive and have a purpose. Keeping those packages small forces them to have a real identity.

     
  • Tomás Augusto Müller 12:05 am on March 23, 2009 Permalink | Reply
    Tags: ,   

    Rule 5: Don’t Abbreviate 

    From the series about the rules of thumb, presented at chapter Object Calisthenics by Jeff Bay in The ThoughtWorks Anthology book from the Pragmatic Programmers (click here to see the the previous rules).

    It’s often tempting to abbreviate in the names of classes, methods, or variables. Resist the temptation. Abbreviations can be confusing, and they tend to hide larger problems.

    Think about why you want to abbreviate. Is it because you’re typing the same word over and over again? If that’s the case, perhaps your method is used too heavily, and you are missing opportunities to remove duplication.
    Is it because your method names are getting long? This might be a sign of a misplaced responsibility or a missing class.

    Try to keep class and method names to one to two words, and avoid names that duplicate the context. If the class is an Order, the method doesn’t need to be called shipOrder(). Simply name the method ship() so that clients call order.ship() — a simple and clear representation of what’s happening.

    For this exercise, all entities should have a name that is one or two words, with no abbreviations.

     
  • Tomás Augusto Müller 9:10 pm on February 23, 2009 Permalink | Reply
    Tags: classical, music,   

    Gustavo Dudamel and the Teresa Carreño Youth Orchestra 

    The 2009 TED Prize winner, Maestro Jose Antonio Abreu, founded El Sistema (“the system”) in 1975 to help Venezuelan kids take part in classical music. After 30 years (and 10 political administrations), El Sistema is a nationwide organization of 102 youth orchestras, 55 children’s orchestras, and 270 music centers — and close to 250,000 young musicians.

    There is a simple concept behind Abreu’s work: for him an orchestra is first and foremost about together­ness, a place where children learn to listen to each other and to respect one another.

    “Music has to be recognized as an … agent of social development in the highest sense, because it transmits the highest values — solidarity, harmony, mutual compassion. And it has the ability to unite an entire community and to express sublime feelings.”
    José Antonio Abreu

    Several El Sistema students have gone on to major international careers, including Gustavo Dudamel, soon to be the music director of the Los Angeles Philharmonic, and the bassist Edicson Ruiz, who at 17 became the youngest musician ever to join the Berlin Philharmonic. The Teresa Carreño Youth Orchestra (Sinfónica Juvenil Teresa Carreño) is the national high school age youth orchestra of El Sistema.

    Take 17 minutes of your life and look at this outstanding video with the presentation of Gustavo Dudamel and the Teresa Carreño Youth Orchestra.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel
Follow

Get every new post delivered to your Inbox.