Date post: | 05-Dec-2014 |
Category: |
Technology |
Upload: | dhananjay-nene |
View: | 6,679 times |
Download: | 2 times |
Contrasting Java and Dynamic Languages
Dhananjay NeneSessions @ Java Pune Java Group
July 5, 2008
(c) : Dhananjay Nene blog : http://blog.dhananjaynene.com contact / mail : link available on blog
What are Dynamic Languages
”Dynamic programming language is a term used broadly in computer science to describe a class of high level programming languages that execute at runtime many common behaviors that other languages might perform during compilation” Wikipedia
Characteristics of dynamism
eval – ability to execute any text or nonmachine code data
runtime data structure alteration – ability to modify the type system at runtime altering the way existing types behave
functional characteristics closures and continuations
reflection
Popular Dynamic Languages
Python Ruby PHP Perl Note: Not all have the same capabilities or
characteristics (Python / Ruby are much more dynamic, PHP is much easier to get started off with)
Scripting languages ?
A highlevel programming language that is interpreted by another program at runtime rather than compiled by the computer’s processor
Most dynamic languages meet the above definition of scripting languages
Scripting languages ? (2)
A scripting language, is a programming language that controls a software application. Wikipedia Most languages will not meet the above definition.
In context of Java these mean languages that can control or be controlled by Java code (and are JVM based)
Scripting Languages using Java
Groovy Scala Beanshell Javascript (Rhino) Jython JRuby
Dimensions of comparisons Developer Productivity
Brevity Impact of Build & Deploy Cycle Capability
Maintainability Readability, Refactorability, Verbosity
Framework Support Performance Enterprise / Library API Support
Brevity
public class HelloWorld{ public static void main (String[] args) { System.out.println("Hello, world!"); }}
BufferedReader myFile = new BufferedReader(new FileReader(”a.txt”));
print 'Hello World'
myFile = open(”a.txt”)
Brevity .. 2
What helps brevity No variable declarations Simpler Object Models Lesser Cruft (white space / braces) Compact structures (eg. code blocks, closures, functors) No getters / setters (properties are supported) Classes / Modules / Global code (not classes alone)
Our brain implements paging algorithms. Putting more logic on one page helps our brain deal with more logic at a time.
Build and Deploy Cycle
Dependency management is much simpler No compile cycle. No build cycle during development Hot deploy means no startup / shutdown of web
apps This is a huge huge time saver for development
times
Maintainability
In general system APIs are much simpler Code is much more readable / understandable Generally training required is much lower Compact code makes for easier maintenance I have found refactoring much tougher Dynamic typing takes away many of the checks
(possibility of more errors)
Framework Support
All languages have decent framework support Ruby – Ruby on Rails, Merb Python – Django, Pylons, TurboGears, WebOb PHP – Zend, CodeIgniter, CakePHP etc
It is much easier to use frameworks Lesser code to write. Lesser places to write it in
Performance
Java is likely to be much much faster than these languages especially if if you are focused on writing performant code if you have sufficiently CPU intensive code (ie. your
code isn't doing db or network access all the time) Raw code performance is often at least 10x.
Effective application performance may be 3x5x (gut feel not specifically benchmarked)
Enterprise API / libraries support
Many years ago I believed this to be a major strength of Java. This competitive advantage is coming down with each passing year. API coverage of dynamic languages is now nearly close to that of Java.
Characteristic strengths DLs
Code the same features faster ... sometimes much much much faster.
No compile / build / deploy downtime Get developers up the curve much faster One developer can more easily understand other's code Fewer options to evaluate may mean faster development Defect recording to Fix release time (not MTBF) can be cut
down
Characteristic strengths Java Complex algorithms : Can be developed and maintained
much faster in DLs, will run much faster under Java Java is much better at handling high speed pipelines (eg.
messaging), highly concurrent applications and ability to leverage multicores (no GIL), has more architectural and deployment flexibility (vertical and horizontal scaling), strong multilingual capabilities
DLs are cost efficient at lower end. JEE is likely to be more efficient as you scale up.
JEE has more flexibilities at scaling. eg. jgroups, memcached, app server based session configurations etc.
Internet full of DL based apps
DL based architectures may be more expensive at higher scales, but provide much much better risk management
If you are the architect and if it is your own money on the line .. what would you choose ?
For internet startups, the architect and entrepreneur role is often much closer or even merged .. one's own money on the line
This to me is the most compelling argument for DLs (rapid development + lower initial cost + agility + risk management)
Analogies
Java
Developer Productivity Car Ferrari Runtime Performance Ferrari Truck Code Size Truck Enterprise Support Truck LCV Complex Handling Car
Dynamic Langs
Nano
Nano* Nano : An extremely compact low cost Indian car (US$ 2500) meeting all regulatory and emission standards likely to offer very efficient and nimble handling through crowded Indian roads* Truck : In Indian contexts a truck is a really large sized vehicle meant for hauling cargo. LCV is a light truck
Candidate aplications for DLs Simple : Blogs, Wikis, Task Management Moderate : Issue Tracking, Project
Management, Network Monitoring, Social Networking, Content Management
Complex Algorithms: Metadata / DSL based processing, Complex algorithms (eg. operations research) not requiring extreme performance
Typical web based form processing apps riding on a relational database
Candidate applications for Java Airline Ticketing Core Banking Telecom Switching Messaging Infrastructures Intrusion Detection Department level databases Any applications requiring extreme performance, or scaling
under modest budgets (especially those with high write %) Note : As hardware performance improves, more of these will
start becoming candidates for DL based development
When Java
Requirements somewhat stable More predictable customer availability High Performance Required Developer Availability Existing Architecture Standards Initial Hardware and Hosting costs are not an
issue
When Java Scripting Languages Want to use Groovy / Scala in standalone mode Java based development environment. May want to do say
20% outside java Java based hosting environment Architectural decision to make JVM the standard runtime Script around Java based software DO NOT BELIEVE because these are on the JVM or since
they compile to java bytecode, they are likely to be as fast as Java. They often arent.
When Dynamic Languages Rapid Development is essential High Agility required in meeting changing requirements Customer (revenue) availability is less predictable Performance requirements are not extreme Low budgets for deployment / hosting Budgets not an issue for internet level scaling Prototyping Simple / moderate scale or high algorithmic complexity or
high risk applications
Thank You for your patience !
Questions ??