archive-cr.com » CR » I » INFORMATECH.CR

Total: 292

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • method references | Informatech CR Blog
    the static method references was more succinct Constructor Method References Let s consider now the existence of a functional interface named Function as follows public interface Function T R public R apply T t Based on it we could define a method map that converts the elements from a source list from certain value T to certain value R as follows static T R List R map Function T R function List T source List R destiny new ArrayList for T item source R value function apply item destiny add value return destiny Now imagine that we had a list of strings containing numbers that we would like to transform to integer values We could do it using a lambda expression to provide an implementation for the Function interface more or less like this List String digits asList 1 2 3 4 5 List Integer numbers map s new Integer s digits However we can clearly infer that the constructor Integer String has the same signature as the apply method in the Function reference required here namely it receives a string as argument and returns an integer So in this case we simplify the implementation of the functional interface by means of using a constructor reference as follows List String digits asList 1 2 3 4 5 List Integer numbers map Integer new digits This conveys the same meaning take a string and make me an integer out of it It is the perfect task for our Integer String constructor Instance Method Reference to Arbitrary Objects Consider now the existence of a class named Jedi defined as follows public class Jedi private String name private int power public Jedi String name int power this name name this power power public String getName return name public int getPower return power equals hashCode toString Now consider that we had a list of jedis and we would like to use our previous function map to extract the name from every jedi and generate a list of names out of the list of jedis Somewhat like this using lambda expressions List Jedi jedis asList new Jedi Obi wan 80 new Jedi Anakin 25 new Jedi Yoda 500 List String names map jedi jedi getName jedis The interesting observation here is that the parameter jedi is the argument for the apply method in the Function reference And we use that reference to a jedi to invoke on it the method getName In other words we invoke a method on the reference we receive as argument So we could simplify this implementation by using an instance method reference as follows List Jedi jedi asList new Jedi Obi wan 80 new Jedi Anakin 25 new Jedi Yoda 500 List String names map Jedi getName jedi Again the interesting aspect of this type of method reference is that the method getName is an instance method Therefore the target of its invocation must be an instance which in this case is an arbitrary object being provided as the argument

    Original URL path: http://blog.informatech.cr/tag/method-references/ (2015-08-19)
    Open archived version from archive


  • JSApps 101: AngularJS In A Nutshell | Informatech CR Blog
    interface Create and include a JavaScript file where we are going to create our application object wait for it and define some controllers Add scope almost there variables and functions that will be bound to the view through special AngularJS HTML attributes Basic View Markup Let s start this in a natural way let s create the user interface first We will create a file called todolist html and we will add the following HTML to it Now nothing fancy right there we just included the AngularJS library at line 8 and another file at line 9 which we will create in a moment However just notice the structure of the document We have an UL element which will represent our list of to do items and then a couple input controls so we can add new items to the list It does not have any information on it for now but eventually it will And it will be awesome Let s leave this code as it is for now let s move to the app js file which has all the fun going on Adding Logic The Controller Just by looking at the previous HTML document you will realize that there are two things we need regarding to view state data An array to store the to do items to be displayed in the UL element at line 13 A function to add new items when I click the Add button at line 15 Simple right Well let s create a new file called app js and add the following code I ll explain it later First things first let s take a look at line 1 Before we start building controllers that handle UI logic we need to create what is known as an AngularJS application module this is done by calling the angular module function and passing it the module name which returns the created module This object will later be used as a container where you will store all of the controllers belonging to this particular JS App The variable angular is available after we included the AngularJS library in our HTML document at line 8 After we create the application object we can start creating controllers being done in line 3 through the controller function which is now callable from the application module we created in line 1 This function takes two arguments the name of the controller and a callback function that will be responsible of initializing the controller and which will be called each time a controller is instantiated by AngularJS AngularJS also passes a special variable to that function called scope everything that is added to the scope variable during controller initialization will be accessible to the view for data binding better said it represents what the view can see The rest of the lines are quite self explanatory Lines 7 to 11 adds a pre initialized array of to do items to the scope that will be used as storage for new items It represents the items that will be displayed in the empty UL element we have right now Line 13 declares a variable that will hold the description of new items to be added after the Add button is clicked Lines 17 to 21 define a function that will add new items to the to do items array this should be called each time the Add button is clicked Binding The View Now that we have AngularJS the application module and the to do list controller we are ready to start binding HTML elements in the view to the scope But before that we need to change our html tag a little and add some special AngularJS attributes Notice the ng app attribute we added to the html tag this is your first contact with one of the several directives that are part of the AngularJS data binding framework Directives are simply HTML element markers that are to be processed by the data binding engine What does ng app do Well it tells AngularJS which application module it should use for this HTML document you might notice we specified ToDoListApp which is the one we created in out app js file at line 1 After we associate our HTML document with the ToDoListApp second step is to specify a controller for our view this is done through the ng controller directive The ng controller directive assigns a controller to a section of the HTML document in other words this is how we tell Angular where a view starts and when it ends Anyways modify the body tag so it looks like this Same with the ng app directive the previous code tells AngularJS that everything inside the body tag will be governed by the ToDoListController which we created in our app js file at line 3 Now we are ready to start binding elements to members added to the scope variable during the ToDoListController controller initialization The ng repeat Directive Let s start with the empty UL list element In this case we want to create a new child LI element per item that is contained in the to do items array Let s use the ng repeat directive for this matter add the following code inside the UL tags OK hold on tight The ng repeat directive will repeat an element per item in an array used as data source the quoted value represents the iterator expression which defines the array to be iterated and an alias used to refer the current item being iterated In this case we specified that it should repeat the LI element for all of the items in the items array defined in the scope variable from line 7 through 11 in the app js file Lastly inside the LI tags we define an Angular template which is an expression enclosed in double curly braces that will be compiled dynamically during run time In this case the template is extracting a member named

    Original URL path: http://blog.informatech.cr/2014/04/15/jsapps-101-angular-js/?shared=email&msg=fail&replytocom=2461 (2015-08-19)
    Open archived version from archive

  • Improving Code With Fluent Interfaces | Informatech CR Blog
    in the main method without having to reference the Task class at all on it making our fluent interface totally unobtrusive What a good boy Now our main method looks a little something like this package com codenough demos fluentthreads import static com codenough demos fluentthreads threading Task import com codenough demos fluentthreads threading public class Main public static void main String args throws Exception System out println Creating task Task task createTaskFor new Action Override public void onExecute try Thread sleep 5000 System out println Task internal action execution finished catch InterruptedException exception throw new Error Thread sleep was interrupted exception onErrorUse new ErrorHandler Override public void onErrorCaught Exception exception System out println An error ocurred while executing task internal action thenExecute System out println Task created Now running while true Thread sleep 1000 if task isRunning System out println Still waiting for task else break System out println Task execution completed Benefits Fluent interfaces leverage existing language features which are not that user friendly to improve code readability This allows us to produce awesome code with superior quality since is a lot easier to read understand and maintain QAs will be grateful which is good Of course additional code and effort is required to implement fluent interfaces but in the end it all pays when we for example have to implement additional features or modify existing code in a codebase we might have last touched ages ago You ll save thousands of dollars on aspirin tablets Example FluentThreads Example Further Reading FluentInterface by Martin Fowler Share this Email Facebook Twitter Like this Like Loading Related March 22 2013 by Luis Aguilar Categories Java Programming Tags fluent interfaces good practices java 4 Comments Post navigation Programmer Jokes Java Streams Preview vs Net High Order Programming with LINQ 4 thoughts on Improving Code With Fluent Interfaces Edwin Dalorzo says March 22 2013 at 3 27 pm Quite interesting above all because I was not familiar with the name I was familiar with the concept of method chaining and I have seen it many times when we use a Builder pattern where this is very common but I was not familiar with Martin Fowler s coined name Do you have a reference for this I would be great to read Martin s article as well I have to say that I personally would have preferred an example that had nothing to do with threads because the multithreading may deviate the attention from the actual beauty of the post which is the power of fluent interfaces and I think that if us the readers wouldn t have to consider the multithreading side of the story the examples would be simpler and more enlightening For example I have several comments about threading issues in the examples that have nothing to do with the main idea of the post My comments do not undermine the power of fluent interfaces but they do question some unconsidered multithreading scenarios in the examples For instance I believe

    Original URL path: http://blog.informatech.cr/2013/03/22/improving-code-with-fluent-interfaces/?replytocom=457 (2015-08-19)
    Open archived version from archive

  • Improving Code With Fluent Interfaces | Informatech CR Blog
    call the createTaskFor method in the main method without having to reference the Task class at all on it making our fluent interface totally unobtrusive What a good boy Now our main method looks a little something like this package com codenough demos fluentthreads import static com codenough demos fluentthreads threading Task import com codenough demos fluentthreads threading public class Main public static void main String args throws Exception System out println Creating task Task task createTaskFor new Action Override public void onExecute try Thread sleep 5000 System out println Task internal action execution finished catch InterruptedException exception throw new Error Thread sleep was interrupted exception onErrorUse new ErrorHandler Override public void onErrorCaught Exception exception System out println An error ocurred while executing task internal action thenExecute System out println Task created Now running while true Thread sleep 1000 if task isRunning System out println Still waiting for task else break System out println Task execution completed Benefits Fluent interfaces leverage existing language features which are not that user friendly to improve code readability This allows us to produce awesome code with superior quality since is a lot easier to read understand and maintain QAs will be grateful which is good Of course additional code and effort is required to implement fluent interfaces but in the end it all pays when we for example have to implement additional features or modify existing code in a codebase we might have last touched ages ago You ll save thousands of dollars on aspirin tablets Example FluentThreads Example Further Reading FluentInterface by Martin Fowler Share this Email Facebook Twitter Like this Like Loading Related March 22 2013 by Luis Aguilar Categories Java Programming Tags fluent interfaces good practices java 4 Comments Post navigation Programmer Jokes Java Streams Preview vs Net High Order Programming with LINQ 4 thoughts on Improving Code With Fluent Interfaces Edwin Dalorzo says March 22 2013 at 3 27 pm Quite interesting above all because I was not familiar with the name I was familiar with the concept of method chaining and I have seen it many times when we use a Builder pattern where this is very common but I was not familiar with Martin Fowler s coined name Do you have a reference for this I would be great to read Martin s article as well I have to say that I personally would have preferred an example that had nothing to do with threads because the multithreading may deviate the attention from the actual beauty of the post which is the power of fluent interfaces and I think that if us the readers wouldn t have to consider the multithreading side of the story the examples would be simpler and more enlightening For example I have several comments about threading issues in the examples that have nothing to do with the main idea of the post My comments do not undermine the power of fluent interfaces but they do question some unconsidered multithreading scenarios in the examples

    Original URL path: http://blog.informatech.cr/2013/03/22/improving-code-with-fluent-interfaces/?shared=email&msg=fail (2015-08-19)
    Open archived version from archive

  • A Fable For Management: The Ill-Informed Walrus | Informatech CR Blog
    with the shortage of herring the invasion could be dangerous No one wanted to tell the Boss though only he could take the steps necessary to meet the new competition Basil approached the Old Man After some small talk he said Oh by the way Boss a new herd seems to have moved into our territory The Old Man s eyes snapped open and he filled his great lungs in preparation for a mighty bellow But Basil added quickly Of course we don t expect any trouble They don t look like herring eaters to me More likely interested in minnows And as you know we don t bother with minnows ourselves The Old Man let out the air with a long sigh Good good he said No point in our getting excited over nothing then is there Things didn t get any better in the weeks that followed One day peering down from his rock the Old Man noticed that part of the herd seemed to be missing Summoning the XO he grunted peevishly What s going on Basil Where is everyone Poor Basil didn t have the courage to tell the Old Man that many of the younger walruses were leaving to join the new herd Clearing his throat nervously he said Well Boss we ve been tightening up things a bit You know getting rid of some of the dead wood After all a herd is only as good as the walruses in it Run a tight ship I always say the Old Man grunted Glad to hear that all is going so well Before long everyone but Basil had left to join the new herd and Basil realized that the time had come to tell the Old Man the facts Terrified but determined he flopped up to the large rock Chief he said I have bad news The rest of the herd has left you The Old Walrus was so astonished that he couldn t even work up a good bellow Left me he cried All of them But why How could this happen Basil didn t have the heart to tell him so he merely shrugged helplessly I can t understand it the old Walrus said And just when everything was going so well MORAL What the Boss likes to hear isn t always what he needs to know Share this Email Facebook Twitter Like this Like Loading Related December 19 2011 by pjpalm801 Categories Collaboration 2 Comments Post navigation CONCACAF Semi Finals New Hackathon Challenge Desarrollando América 2012 2 thoughts on A Fable For Management The Ill Informed Walrus pjpalm801 says December 19 2011 at 12 55 pm This is the story I tried to re tell last week in one of our discussions It was something that my boss at the University sent out to all his managers Very timely and appropriate I believe Reply Edwin Dalorzo says March 27 2013 at 11 22 am It was an interesting and fun read The

    Original URL path: http://blog.informatech.cr/2011/12/19/a-fable-for-management-the-ill-informed-walrus/?shared=email&msg=fail&replytocom=51 (2015-08-19)
    Open archived version from archive

  • pjpalm801 | Informatech CR Blog | Page 3
    issues is not fun All that is good and true but don t desktop apps on the Mac Linux and Windows also access the hardware fully Don t some of them have nice UIs What s the catalyst for all this interest The answer in my opinion is convenience KISS Yep what users of apt get have known for years relatively easy installation of native applications via the Internet is very desirable I think all of us might ve moved to webapps for email news etc because the administration and acquiring of desktop apps was just inconvenient another good point would be feature creep but that s another post altogether Consider Windows and buying downloading software later installing configuring it ain t pretty It s more convenient just to access a webpage no dealing with configs or anything at the cost of reduced expectations If Microsoft and the rest of the packaged software industry had embraced Internet distribution we might be somewhere else now but they did not and thus a lot of PC software moved to the Web So now you go click on a store and you app download and install Once you see it in action you shouldn t be surprised people like it even when ceding control and maybe even freedom Hopefully one day a desktop OS could have such an option The Web is dead Long live the Web So is the Web dead Not by a long shot as some would point out and likely to remain very profitable given Google s latest earnings The Web remains a vital information resource both of text and now of richer context like video and that s not going away anytime soon Also there are many millions of PCs out in the world that now exist for the sole purpose of Web browsing consider all those machines with WinXP that are just not upgrading But will the notion that everything must run in a browser prevail At this point clearly not That said there are concerns of bypassing the Web and walled gardens that shouldn t be discarded hastily but I think a new balance is emerging The new old world will have extremely media rich apps delivered and coexisting with information and webapps via the Cloud A perfect example of this is the killer Flipboard application that turns your social network and Internet feeds into a readable magazine Where magazine apps have been nothing more than glorified versions of the interative CDROMs of the 90s without the linking that made the Web what it is Flipboard integrates the feeds and gives you a way to see Web content from the app Brilliant 9 933333 84 083333 Share this Email Facebook Twitter Like this Like Loading October 21 2010 by pjpalm801 Categories Web Tags android app store apple flipboard iphone market 2 Comments A New Week A New Blog Well so far I am the only blogger on our website hint hint That s okay I am

    Original URL path: http://blog.informatech.cr/author/pjpalm801/page/3/ (2015-08-19)
    Open archived version from archive

  • The Web is Dead | Informatech CR Blog
    respond faster and be launchable easier Visual appeal Buttons images tabs they all look nice and respond quickly Development of rich interfaces is easier For all I love the Web dealing with browser incompatibilities and CSS rendering issues is not fun All that is good and true but don t desktop apps on the Mac Linux and Windows also access the hardware fully Don t some of them have nice UIs What s the catalyst for all this interest The answer in my opinion is convenience KISS Yep what users of apt get have known for years relatively easy installation of native applications via the Internet is very desirable I think all of us might ve moved to webapps for email news etc because the administration and acquiring of desktop apps was just inconvenient another good point would be feature creep but that s another post altogether Consider Windows and buying downloading software later installing configuring it ain t pretty It s more convenient just to access a webpage no dealing with configs or anything at the cost of reduced expectations If Microsoft and the rest of the packaged software industry had embraced Internet distribution we might be somewhere else now but they did not and thus a lot of PC software moved to the Web So now you go click on a store and you app download and install Once you see it in action you shouldn t be surprised people like it even when ceding control and maybe even freedom Hopefully one day a desktop OS could have such an option The Web is dead Long live the Web So is the Web dead Not by a long shot as some would point out and likely to remain very profitable given Google s latest earnings The Web remains a vital information resource both of text and now of richer context like video and that s not going away anytime soon Also there are many millions of PCs out in the world that now exist for the sole purpose of Web browsing consider all those machines with WinXP that are just not upgrading But will the notion that everything must run in a browser prevail At this point clearly not That said there are concerns of bypassing the Web and walled gardens that shouldn t be discarded hastily but I think a new balance is emerging The new old world will have extremely media rich apps delivered and coexisting with information and webapps via the Cloud A perfect example of this is the killer Flipboard application that turns your social network and Internet feeds into a readable magazine Where magazine apps have been nothing more than glorified versions of the interative CDROMs of the 90s without the linking that made the Web what it is Flipboard integrates the feeds and gives you a way to see Web content from the app Brilliant 9 933333 84 083333 Share this Email Facebook Twitter Like this Like Loading Related October 21 2010

    Original URL path: http://blog.informatech.cr/2010/10/21/the-web-is-dead/?shared=email&msg=fail (2015-08-19)
    Open archived version from archive

  • Hello world! | Informatech CR Blog
    we could speak volumes on our expectations for this blog we don t want to get ahead of ourselves and for the moment simply say hello world 9 933333 84 083333 Share this Email Facebook Twitter Like this Like Loading Related October 6 2010 by pjpalm801 Categories Informatech Tags welcome 4 Comments Post navigation Thanksgiving in Costa Rica 4 thoughts on Hello world Phil says October 6 2010 at 3 01 pm Hello right back at ya Reply slamdunk says October 6 2010 at 9 58 pm Good luck with the new blog Reply Alvaro says October 7 2010 at 9 08 am Great guys Reply Pingback 2010 in review Informatech CR Blog Leave a Reply Cancel reply Enter your comment here Please log in using one of these methods to post your comment Email required Address never made public Name required Website You are commenting using your WordPress com account Log Out Change You are commenting using your Twitter account Log Out Change You are commenting using your Facebook account Log Out Change You are commenting using your Google account Log Out Change Cancel Connecting to s Notify me of new comments via email Notify me of new posts

    Original URL path: http://blog.informatech.cr/2010/10/06/hello-world/?shared=email&msg=fail (2015-08-19)
    Open archived version from archive