Playing with Scala 3: OO, Traits, and Views
OO Look at graph classes my previous post: class Node (val label:String) { var transitions: List[Arc] = Nil var previous: Node = _ var weight= Float.PositiveInfinity var visited = false... and class Arc(var start: Node, var end: Node) { var weight: Float = _... Don't you feel that something doesn't really fit? What are previous, visited, and weight are doing in Node? And weight in Arc?Those properties doesn't really belong to a generic Node or Arc, they're specific for our algorithm. So, why having them there? Let's put those attributes on special cases of Node and Arc: DfsNode and DfsArc. But wait! Putting weight in both doesn't seem right either... we're defining the same thing twice! Weight is some kind of "cross-cutting" attribute. Traits Luckily modern OO languages had a very elegant way of solving this kind of problems by means of traits (usually are described as "interfaces with implementation" but a very powerful concept)......
Playing with SCALA 2: Dijkstra’s shortest path (Dsp) algorithm
As I continue to play with Scala, I wanted to do something non-trivial, so I decided to to implement Dijstra’s shortest path algorithm As background, my experience is mostly object oriented OOAD and programming in Java (I use it at work). The first challenge was getting the algorithm right (the first attempt ended in a beautiful recursive algorithm that just traversed the graph greedily selecting the shortest arc), but wikipedia’s page helped Just in case, be aware that I’m no Scala expert and no functional programming expert… (I’m no expert on anything at all) I’m just trying to share what I found, I’m sure there’s a better way, feel free to suggest it. So far, I’ve enjoyed the experience: programming in Scala is easy and fun (at least compared to Java or C++, … yes, yes, it doesn’t require much, I can think many jokes, leave your in the comments ;-)). Sure, I spend a while on seemingly trivial stuff, but that happens when you learn any language (......
Playing with SCALA: interoperation with Java
I'm toying with the Scala language and it looks like what the future Java could be (or a great candidate at least).It feels like at the sweet spot between OO and functional paradigms.It has first order functions, closures, comprehensions, type inference, mixing composition, Erlang-style concurrency, pattern matching, and more interesting stuff that makes coding easier and concise.And the best thing is it compiles to .class files so it integrates seamlessly with Java: you have all your Java libraries when programming in Scala and you can call your Scala classes from your Java code as just another java class.Of course, I'm not aware of anybody using it in a production environment, but looks VERY promising.Having this kind of language makes less necessary to "bolt-in" those features in the core Java language.So I installed the eclipse plugin and started to play with it.I knew you could use Java libraries in Scala (even you can use Hibernate !) , so I was interested in the opposite way:......
Quote of the month
"Object-oriented programming is like money, as the old joke has it: It's not everything, but it's way ahead of whatever's in second place."Objects have not failed - Guy L. Steele Jr....
Javascript, the underdog
I'm back working on some JavaScript, just like the old times, adding client-side UI dynamics. In spite of still being hard to work and debug (at least in IE), it allows me to play with a different language. I realized the worst thing you can do with JavaScript is use it like Java, it works but you'll miss the interesting features like prototyping and higher order functions.This week I found that Mozilla JavaScript implements useful iteration methods were you can pass functions to operate on the collection:filter, forEach, every, map, and some: filterSelects the elements of the collection that satisfy the function forEachApplies a function to all the elements of the array everyReturns true if every element of the array satisfies the function someReturns true if at least one element satisfies the function mapCreates a new array with the results of calling a provided function on every element in this array. As an example, you can easily write: funtion doSomethig(element){ /*wha......
OOPSLA keynotes podcasts
Very interesting software engineering pioneers's podcasts from the OOPSLA 2007 conference:David ParnasJohn McCarthyFrederick BrooksI couldn't recommend them more!...
IT Architect skills library
I’ve been in IASA’s IT Architects Regional Conference (ITARC) in Atlanta. Great event, with very interesting events with the topics which the architects want. Some of the presentations were very good, others not that good, but I got many good ideas from all of them. I’ll post on the topics later.Meanwhile, I want to share IASA’s project of creating an IT Architect skills library: http://www.iasahome.org/web/home/skillset. Is an ongoing project, but is worthwhile to take a look at it....
Quote of the month
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." Martin Fowler, "Refactoring: Improving the Design of Existing Code"...
Language "wars"
I'ts me or we are at "war" again? As the old history goes, in the nineties, OO Warlocks fought each other from their towers, everyone claiming to have The Methodology, until some of they settled for the "Unified Philosopher Stone" or something like that... (I always thought it was strange that the outcome of a methodology war as a notation, but I digress)After that, came the agile jihad, trying to burn the non-believers in the stake, all in the name of the eXtremellyPurity religion, causing great havoc in the process world (and every process guru claimed "I'm agile too!", probably to satisfy the angry mob... but agile waterfall got burned anyway). Is funny now how many experts now say "XP is very good, but if you do , is even better!" And now, the languages!Well, is not really a war, I guess is more like in the OO-java-roman.net empire, encounters with the Rubyites or the functional programming tribes and similars(the Haskells, Lisperers, or Schemitas) are getting more common.........
JSF code snippet: integrating JSF pages into a plain old JSP
A simple way to include a JSF page into a bigger JSP (sure there's other ways, but this one is easy):the JSF page must be a subview:<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:subview>.....</f:subview>The tricky part is how to include it in the JSP, in a way that is independent of the main JSP. But you just need to include like this:<% pageContext.include("myJSFpage.jsf"); %>...
Comentarios

