Still using java? Lombok can make you more productive
projectlombok.org
projectlombok.org
case class Mountain( val name: String, val latitude: Int, val longtitude: Int, var country: String)
For the above code you get a nice factory like
Mountain('name', 11, 12, 'nowhere')
with hashCode, toString and equals. Plus that you can use this class to decompose it using pattern matching:
mountain match { case Mountain(name, _, _, country) => println(name + ' located in ' + country) }
The future is here - it's just not evenly distributed:
Will other tools find this code? E.g. I think javadoc is source-based, and I don't know if it will invoke such annotations. I would expect the annotation spec to require it, for annotations that can create methods etc, but I'm just not that familiar with the spec.
BTW: great presentation video: showing the problem, showing the solution, showing how to get started. It might seem like overkill, but that's the way to sell stuff (though this one seems to be under the MIT license, ie free).
http://code.google.com/p/lambda4jdt/
It's quite an innovative idea. Just because the text is in java, why does it have to look like blub?
http://en.wikipedia.org/wiki/Outliner
Not a new concept, but could certainly be applied way more often than it is.
(It's not just parsing. We have to write little tools to take the parsed code, then infer relationships within it. Why not just make explicit links?)
Think about what happens. Your IDE parses your source code so that it can do things like highlighting, identifying senders, code folding, etc. It does this so that you as a programmer can use those tools to more easily parse it in your head to understand it. Eventually, your code is interpreted or compiled, which involves another parsing.
Why not just have a direct representation of the program and its interrelationships? Languages where the compiler/interpreter make the AST available go a part of the way there. But too many of the interrelationships are implicit, requiring a program to do some sort of searching/indexing/parsing to make available. Why not just represent those directly, and have source code be a representation?
If we could make such a representation, we might even be able to transcend the tyranny of particular languages. (Multi language VMs are somehow related here.)
I'm also not sure why I'd care that my tool parses the code to do those things for me, nor why having my brain parse the code matters in particular. If you're arguing for Lisp's "code as AST" syntax, well, that's fine by me, but I don't think it's a neccesity. Macros work best with sexps, it's true, but I've never found, say, Ruby's metaprogramming to be wanting for Lisp-style macros.
Also, I'm firmly against the One True Language way of thinking. See, for instance, Python vs. Ruby as a great example of why nobody will ever be happy with One Language to Rule Them All. They're so close to each other, yet their small differences cause so much argument between the two camps.
"Subtext takes the position that both text and diagrams have the same inherent limitation: they are paper-based media. Subtext represents programs as complex data structures that can not be fully printed out in a human-readable form. Text and diagrams are used to interactively present the program, not as a source encoding of it. This is the same approach taken by WYSIWYG applications like word processors and spreadsheets. Subtext is WYSIWYG programming."
Neat tool, but I really don't see this being that much of a time-saver over the built-in tools that Eclipse or Idea has for this.
In addition, using annotations to generate things like "cleanup" blocks around a stream seems dangerous in the long run to me - I don't like having any part of the flow of my code being handled by "magic".
I don't either, but I do agree with his argument that it will make code more readable. And, w.r.t. the auto-finally block thingy, badly implemented exception handling is a common cause of error in "maintenance mode" codebases. [Yes, code reviews SHOULD happen, etc.]
mountain.getLatitude() vs. dataClass.getDataElement("latitude");
It's the same reason I use XMLBeans (a schema-based codegen) for serializing/deserializing XML documents. Rather than writing mountainElement.getAttribute("latitude"), I can say mountain.getLatitude().
mountain.getDouble("latitude")
With at least two advantages: I'm pretty sure what getDouble will do, as opposed to getLatitude which may query google maps for all I know, and it can be processed in abstract ways. You can have operations which work on any structure: serialization, encription, logging, persistence, hash codes, sorting, raporting and a lot more.
Edit: It also makes for easier code reuse. You make something that works with mountains but could work just as well with houses, you don't have to play with class hierarchies to use it on both.
If you program like you are suggesting you lose the only reason to use java, and have to enforce your code using unit tests in a verbose language. No thanks.
The Scala example in the comments demonstrates that you can have your cake and eat it too:
case class Mountain (val name: String, val latitude: Int, val longtitude: Int, var country: String)
It's concise and type-safe, and can readily be used with more powerful aggregate constructs.
mountain.latitudesomething like:
(defdata mountain name :setter :getter latitude :getter etc ...)
might not be too hard to implement on top of clos (or on top of defstruct - but clos has the advantage of already having flexible accessors) not sure about clojure.
(defstruct mountain :name :latitude :longitude :country)
(struct mountain "Zugspitze" 47.416667 10.983333 "Germany")