Showing posts sorted by date for query TextMate. Sort by relevance Show all posts
Showing posts sorted by date for query TextMate. Sort by relevance Show all posts

Monday, 6 July 2009

Scala as the long term replacement for java/javac?

Don't get me wrong - I've written tons of Java over the last decade or so & think its been a great evolutionary step from C++ and Smalltalk (lots of other languages have helped too like JavaScript, Ruby, Groovy, Python etc). However I've long wanted a long term replacement to javac. I even created a language to scratch this itch.

Java is a surprisingly complex language (the spec is 600 pages and does anyone really grok generics in Java?), with its autoboxing (and lovely NPE's hiding in there), primitive types, icky arrays which are not collections & general lack of polymorphism across strings/text/buffers/collections/arrays along with extremely verbose syntax for working with any kind of data structure & bean properties and still no closures (even in JDK7) which leads to tons of icky try/catch/finally crapola unless you use frameworks with new custom APIs & yet more complexity. Java even has type inference, it just refuses to use it to let us save any typing/reading.

This issue becomes even more pressing with there being no Java7 (which is even more relevant after Snorcle - I wonder if javac is gonna be replaced with jdkc? :). So I guess javac has kinda reached its pinacle; closures look unlikely as does any kind of simplification or progression.

So whats gonna be the long term replacement for javac? Certainly the dynamic languages like Ruby, Groovy, Python, JavaScript have been getting very popular the last few years - lots of folks like them.

Though my tip though for the long term replacement of javac is Scala. I'm very impressed with it! I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy.

So why Scala? Scala is statically typed and compiles down to the same fast bytecode as Java so its usually about as fast as Java (sometimes a little faster sometimes a little slower). e.g. compare how well Scala does in some benchmarks with groovy or jruby. Or this. Note speed isn't everything - there are times when you might want to trade code thats 10x slower for more productivity and conciseness; but for a long term replacement for javac speed is important.

Yet Scala has type inference - so its typically as concise as Ruby/Groovy but that everything has static types. This is a good thing; it makes code comprehension, navigation & documentation much simpler. Any token/method/symbol you can click on to navigate to the actual implementation code & documentation. No wacky monkey patching involved, or doubting of who added a method, when and how - which is great for large projects with lots of folks working on the same code over long periods of time. Scala seems to hit the perfect sweet spot between the consise feel of a dynamic language, while actually being completely statically typed. So I never have to remember the magic methods that are available - or run a script in a shell then inspect the object to see what it really looks like - the IDE/compiler just knows while you edit.

Scala has high order functions and closure support along with sequence comprehensions so you can write beautifully concise code. Scala also unifies functional and OO paradigms beautifully together into a language thats considerably simpler than Java (though the type system is of a similar order to truly understand than generics - but then thats usually an issue for framework creators rather than application code developers). It also lets folks gradually migrate from a traiditional OO/Java way of coding to a more functional way - which is particularly relevant for folks writing concurrent or asynchronous code (which due to the GHz of chips no longer going up but instead we're getting more cores is becoming more necessary). You can start the OO way and migrate to using immutable state if/when you need its benefits. Increasingly functional programming is becoming more and more important as we try and make things more concise and higher level (e.g. closures, higher order functions, pattern matching, monads etc) as well as dealing with concurrency and asynchrony via immutable state etc.

Scala also has proper mixins (traits) so you don't have to muck about with AOP wackiness to get nice modular code. There's even structural types in case you really do need some duck typing.

The thing which most impresses me is the core language syntax is pretty small and simple (the spec is about a quarter the size of Java's); but its way more powerful and flexible and is very easy to extend in libraries to add new semantics and features. For example see the Scala Actors. So its ideal for creating either embedded DSLs or external DSLs. There's really no need to have Java , XPath, XSLT, XQuery, JSP, JSTL, EL and SQL - you can just use Scala with some DSLs here and there (examples of this later...).

Scala does take a little bit of getting used to - I confess the first few times I looked at Scala it wasn't that pleasing on the eye - with Java you're kinda used to dumb verbose code which doesn't do very much - it can be quite a shock to see quite a few symbols at first. (It took me a while to get over the use of _ in scala which is the 'wildcard' symbol since * is an identifier/method).

If you've been doing lots of Java then Scala does feel quite different at first - (e.g. the order of types & identifiers in method/variable/parameter declarations - though the reason for that is to make it easy to miss out redundant type information).

e.g. in Java
List<String> list = new ArrayList<String>()
in Scala
val list = new List[String]
or if you want to specify exact typing
val list : List[String] = new List[String]
However if you keep at it, the beauty of Scala soon becomes apparent; its simplified so many of the gremlins in the Java language, allows you to write very concise code describing the intent behind the code rather than the implementation cruft - together with providing a nice migration path to elegant functional programming which is awesome for building concurrent or distributed software.

I highly recommend you take a look at Scala - with an open mind - and see if (once you're brain adjusts) you can see its beauty too.

Some scala links and online presentations
If you have a spare hour or so these video talks are great to watch
Handy Scala frameworks and libraries
  • liftweb the rails of scala
  • specs and ScalaTest for BDD and more literate testing showing how a typesafe DSL can help you write more consise and expressive code that is very IDE friendly
  • scalaz a handy library of utilities
  • dispatch for working with HTTP/JSON services
BTW for those like me who love JAXRS you can now use lift templates with Jersey via the new jersey-lift module.

As an example of this in action you can check out RestMQ which is an open source project I've been working on lately to provide a RESTful API and web console to message orientated middleware which is built on JAXRS (Jersey), Scala and Lift.

From a tooling perspective there's Ant/Maven plugins, an interactive Scala console (REPL) and IDE plugins for IDEA, Eclipse, NetBeans along with the usual editors (TextMate/Emacs etc). The IDE plugins are not yet up to the Java grade, but they are very useful with good code navigation & completion.

I've tried the plugins for NetBeans, Eclipse and IDEA they all have strengths and weaknesses; it seems Scala folks are split between them all. For code navigation and completion along with maven support I've found IDEA to be quite good. When you open a Maven pom.xml it seems to grok the code nicely, finding the scala source so you can navigate through any type/method to see its documentation/source etc. (You do typically have to manually add the Scala facet to run/debug stuff). Though IDEA is not always the best at highlighting syntax errors as you type. They could all use some work to bring them up to line with their Java counterparts though - try them out and see which you prefer.

Scala nits
With any language there's gonna be bits you love and bits you're not so keen on. Early impressions of Scala do seem like there's a bit of an attempt to use a few too many symbols :-; but you don't have to use them all - you can stick to the Java-ish OO side of the fence if you like. But then I guess longer term its probably better to use symbols for the 'special stuff' to avoid clashing with identifiers etc.

I'm not a massive fan of the nested import statement, using _root_.java.util.List to differentiate a 'global' import from a relative import. I'd have preferred a child prefix. e.g. if you have imported com.acme.cheese.model.Foo then to import model.impl.FooImpl i'd prefer an explicit relative prefix, say: import _.impl.FooImpl which would simplify things a little and more in keeping with Scala's attempt at simplifying things and removing cruft (being polymorphic to import java.util._).

However compared to all the massive hairy warts in Java, these downsides of Scala are tiny compared to the beauty, simplicity and power of Scala.

Conclusion
Given that MrJava, MrJRuby and MrGroovy are all tipping Scala as javac's long term replacement, there might be something in it. So what are you waiting for; get the Programming in Scala book or the O'Reilly Scala book and start having fun :)

Monday, 21 January 2008

[LazyWeb] using Subversion as a front end to Confluence?

I hack a lot of Confluence spaces as part of my job. I've been working on the UFace project at Google Code so I've been getting used to the Google way.

One of the great things about google code is that the wiki is in subversion as *.wiki files; so you can edit them in any text editor (and TextMate comes with great MoinMoin syntax support, you just have to install the bundle...). So you can grab your wiki content, jump on a plane, hack it with your favourite editor then check in your changes when you're next online.

I wonder how hard it'd be to sync Confluence content with a subversion repo; so folks could still use the online Confluence site to edit content, which would get mirrored to an svn repo as *.wiki files - then folks could commit to the svn repo to update the confluence database? Anyone ever tried?

Monday, 3 September 2007

Got a Mac? Use TextMate? Try GetBundle

If you've a Mac then do try TextMate; its an awesome editor and part of my favourite OS X software. Its not a replacement for your Java IDE; but is very handy for editing everything else :). I often type this into the command line...
mate someFolderName
To browse a Java project quickly, without doing the whole Java IDE create project thing; which can sometimes take a while...

Today I stumbled on the GetBundle bundle which is a really nice way of adding new bundles. Also the Groovy/Grails bundle looks good!

Tuesday, 10 July 2007

My favourite OS X software

It seems more and more fellow geeks are switching to Macs all the time so I thought I'd revamp my old post on recommended OS X software.

Incidentally while writing this post I ended up stumbling on my switching thoughts from 2003, so I guess I've been a very happy Mac user for over 4 years now (which also explains why that first generation 1Ghz G4 that I'm still using while on the road is so sloooowww - I can't wait for my new MacBook Pro to arrive...).

The one big change from my previous recommendations is that I don't use so many rich applications; as I can use the online versions on the move, on my desktop, laptop or phone. So I use Gmail for almost all mail - unfortunately I'm stuck with Mac.Mail for corporate email :(. I use Google Reader instead of NetNewsWire for reading blogs etc.

Since switching to gmail for email; I no longer feel the huge need for a virtual desktop anymore; I've gotten out of the habit. Expose is enough for me, especially on a 30" screen.

So here's my current list of recommended OS X software, excluding Java IDE (which I'm using IDEA but eclipse is good too on the Mac).
  • QuickSilver. I love it; though only really use it for starting up applications & tend to use it instead of the Dock
  • text editor: TextMate
  • for terminal stuff iTerm rocks. I love tabbed shells (though maybe Leopard might have this too in Terminal)
  • for creating diagrams OmniGraffle is awesome. It can even open DOT files. Also if you have some open source which creates visualisations in DOT files, then the OS X version of GraphViz rocks - as it monitors the DOT file in real time and re-renders the graph in a surprisingly flicker-free way. I've used this with some customers to watch ActiveMQ clients startup visually as they deploy their applications.
  • irc: X-ChatAqua
  • xmpp: iChat
  • MenuMeters for neat monitors of CPU, disk, network etc on the menu bar (I'm quite fond of the graph view for CPU usage)
  • VoodooPad is a WYSIWYG editor for wiki-ish things which I'm hooked on. I just wish it auto-sync'd with GDrive :)
  • ByteController for a nice little iTunes controller on the menu bar; so you don't have to switch windows when the phone goes or you wanna forward to the next track etc
  • RadioLover for recording internet radio & installing it into your iTunes library; though if you're not careful you'll end up with a monster library :)
  • Clutter is cool to play with your new monster iTunes library :)
  • Growl for notifications of things (like IRC posts etc)
  • Google Notifier for easy access to your calendar etc
  • I tend to use gCal for calendering but sync it with iCal
Thats all I can think of right now. Other advice for new switchers; give it a couple of weeks to get used to being on the light side; things are a bit different but after 2 weeks you'll hopefully feel at home.

To other OS X users out there, whats your favourite software?

Update: here's Charles Millers list - thanks! I particularly like the look of Chax (certainly until Leopard with tabbed iChat).

Tuesday, 3 July 2007

using TextMate to edit text in any Cocoa application

Many thanks to noodl for commenting on my previous post; turns out you can use TextMate to edit any Cocoa application. As noodl said...
for editting text in TextMate from any cocoa application, see:

http://macromates.com/blog/2006/textmate-tricks/

"As noted on the blog, you need to install the Edit in TextMate input manager, which is done by clicking the gear menu in the status bar (inside TextMate), navigating to the TextMate submenu and selecting Install “Edit in TextMate”…"

And for firefox:
http://macromates.com/blog/2007/edit-in-textmate-from-firefox/

Great stuff!

Sunday, 1 July 2007

useful firefox plugin: Its all text!

For editing large wiki pages or big emails in gmail I find this fireFox plugin amazingly useful. Its all Text! Then just use your favourite editor; such as TextMate on OS X to edit text areas in any web page whenever you like. Neat!

Wednesday, 18 April 2007

Sharing code snippets online with TextMate

TextMate is an awesome text editor for OS X. I just learnt of a nice plugin from proyal on #codehaus IRC...

When you want to share a code snippet in your editor with others, highlight a bit of code then hit ctrl-command-t and select Paste Selection Online and you can post a link to the code either to a URL or iChat etc. Very cool! :)