Yesod Web Framework
Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).
The content has been bookmarked!
There was an error bookmarking this content! Please retry.
Posted by Floyd Marinescu on May 31, 2006
Elliotte concludes his entry criticizing the over-use of Interfaces:make preconditions, postconditions, and class invariants language level constructs. Then make them automatically inherited by all subclasses. This would allow subclasses to override methods from the superclass, but would not allow them to change the superclass’s defined behavior. They could only change things the superclass did not explicitly promise.
They’re a lot of other benefits to this scheme as well. First of all it would mean more people would use design by contract, and thus write better code. For those of us who already use design by contract, it would make our code much simpler. But what interests me for the moment is that it would dramatically reduce the need for
final.finalis really overkill for 90% of the uses to which it’s put.
They’re a lot of high-powered theorists who just love interfaces and abstract factories; and it’s not a coincidence that these are the same people who hate final. They’re wrong about this too, and for the same reason. Java interfaces have no ability to enforce preconditions, postconditions, and invariants. This means they’re appropriate only when a type really doesn’t have any of those, which is rare.
Monitor your Production Java App - includes JMX! Low Overhead - Free download
Using Drools? See what you're missing! Get the Power of Drools with the Assurance of Red Hat
18 agile and lean practices for effective software development governance
Improve Java Garbage Collection, Runtime Execution, and JVM visibility with Zing
I agree that the final keyword is a powerful mechanism for maintaining class invariants, and is under-used in many codebases.
Hand-in-hand with that is the fact that (in my experience, anyway) subclassing and overriding methods is not the right way to extend functionality in most cases. Composition is usually better than inheritance, and patterns such as the Strategy pattern usually offer much better extensibility without the need to risk class invariants.
Hmmm... wanted to make a point here, but I can't find a code formatter that makes Java look legible in the message text.
I don't agree. When overusing the final keyword you force developers who use your codebase to reinvent the wheel or copy your classes to slightly extend them.
When used with delegation/composition the same fact applies to the delegate used. Mostly it is a implementing class of an interface or a subclass of an abstract or default implementation. When only allowing the methods you think of being worth to be overridden you restrict the possibilities.
Just today I had to copy the code of NameMatchTransactionAttributeSource as there were no protected methods to be overridden that allow the modification of the matching algorithm (i.e. the access of the map set as property).
I fully agree when using the final keyword on method parameters, local and global variables that should be fixed and reduce the possibility of coding errors. (Trade semantic errors for compiler errors - see Hardcore Java by Robert Simmons).
Michael
The point that the author missed was the fact some of the problems of making classes/methods finals is they tend to be very hard to test.
Obviously, I agree with the author's points of invariants, etc. But the way I usually enforce invariants are through unit testings. And nothing makes me happier than to have a well designed class resulting from unit testings. TDD anyone?
I agree with you, but I think that both proposals -- deprecating the final keyword, or making it a default setting -- are just trying to cover up symptoms, instead of solving the real problem.
The real problem as I perceive it is education. Many Java developers simply don't know when to use the keywords final, volatile or even synchronized and transient. Hell, I even keep seeing completely abstract classes where an interface would have done the job nicely.
The final keyword is definitely a good thing in the Java language. But if a programmer is unable to master that features, only a fool would blame the feature...
Just my 2 cents, Lars
I guess nobody is seriously questioning that the overuse of anything is dangerous. Same can be said for food, for instance. Or for the private keyword, for that matter -- as I always have to acknowledge grudgingly when programming Swing.
The funny thing, though, is that you never notice the "overuse" of private or final in your own software, but only in third party frameworks... ;-)
Cheers, Lars
final is the most undervalued keyword in java. I can only fully agree to Elliot here. When certain people say it should be deprecated, i wonder how they develop programs at all.
Not using final means taking the risk of inproper API usage, resulting in various problems when using APIs in general.
Marc Logemann
I've always believed that the best written software is used (successfully) for purposes that the author did not intend. For instance the original browser and html were not intended for e-commerce. I think the same should hold true for libraries. I think using final by default makes this hard unless you have been able to predict every possible extension point and use. People here seem to worry about someone creating a subclass that breaks some contract and makes the code behave erratically. That is that coders problem not the original author. They need to write correct code and it isn't my job to make sure that they do it.
Lars I agree with you, but I think that both proposals -- deprecating the final keyword, or making it a default setting -- are just trying to cover up symptoms, instead of solving the real problem.
Both proposals are quite extreme. The language presently offers a good tool that developers can choose to use.The real problem as I perceive it is education.
Exactly. The problem is not the language, it's lack of knowledge of some very important features.
Rgds
Rod
Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).
Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.
Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.
One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.
InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.
Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.
John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.
Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.
10 comments
Watch Thread Reply