IntensiTris

I had a bet running with a guy: Can I implement a Tetris game within one day for J2ME while sitting in the cafe? (I’m usally sitting in the cafe. Working.)

I failed.

Took me two days to have the game complete. I’ve spent the rest of the weekend adding a Java Web Start wrapper to make it playable on the desktop.

Check it out here: IntensiTris Project Page

The J2ME builds are tested on a 6630 and K750.

Here’s a screenshot from the WebStart version:

IntensiTris

Update: Intelli/J IDEA SimpleSyntax Highlighter Plugin

I’ve made available the plugin through the IDEA Plugin Manager. It’s still at an early alpha stage. Basically still a prototype. But I find it quite useful already. Apart from Ruby highlighting I use it to highlight its own configuration file syntax as well as property files and some other work-related file types.

Just before uploading the latest version a few minutes ago I’ve spent some time on improving the performance. Probably the major problem of the plugin right now. If you’ve followed my recent posts on the IDEA plugin topic you may recall that I explicitly decided not to use a system like jflex. Well, by now I realize that this has certain implications. Mainly performance related.. :)

What I’m now thinking about is providing an alternative configuration syntax that can be used with jflex, but doesn’t use the complicated jflex syntax. And I’m thinking about compiling it at runtime using Groovy. Well, it’s still just a thought.

More importantly: I’m still waiting for the project to be approved at Tigris. I tried SourceForge first, but no response after five days.. For now the plugin sources are available at my IntensiCode site.

If you’re interested, check out the included TODO.txt to get an idea of what I have planned and/or what I’m dealing with.

And if you want to see some really awful stuff, have a look at my ConfigurableLanguage hack (in the src/net/intensicode/idea/core folder). Who’s to blame? Me because I’m trying to abuse the API? Or the JetBrain guys because they are trying to protect their application? (I’m guessing here.. I don’t really know why they choose to use global registries all over.. To be honest I probably would never use something like a global registry.. Just because global itself has such a bad smell.. together with registry it stinks..)

tfdj

Intelli/J IDEA SimpleSyntax Highlighter Plugin

Alright, this pet project became quite serious now and is consuming more and more evenings..

I’m now thinking about making it officially available. It’s become quite useful. It probably needs a small UI to make configuration easier. Apart from that it’s really nice to have proper highlighting for Ruby, etc.

Well, for now I simply attached the latest version of the plugin. If you should stumble upon this blog, please give this plugin a try and give me your feedback!

Extract the IDEA SimpleSyntax Plugin zip file into your IDEA config/plugins/ folder. After (re)starting IDEA, you should see two new entries in your Tools menu. Use the “Init SimpleSyntax” to install the default Ruby configuration in your IDEA settings. You can then use ‘Reload SimpleSyntax’ to activate Ruby syntax highlighting.

Update: Gizmo of kodierer.de fame pointed me to the syntax configuration of Adie. The functionality offered by the ‘configuration language’ is actually quite similiar. Very interesting to see their more formal approach using a configuration grammar..

Anyway, the really interesting question is this: Should IDEA provide a simpler way of configuring syntax highlighting? The XML filetypes based approach doesn’t work properly. (Or does it? And I’m just to stupid.. :) Implementing a full IDEA plugin just to get highlighting for a small (and/or own) little language seems to be overkill..

Update: I’ve made the plugin available through the IDEA Plugin Manager. Of course I found quite a few annoying problems after uploading it.. :) I’m working on fixes right now.. The important part is this: You should now be able to download the latest version of the plugin from inside IDEA.

tfdj

Update 3: Ruby Plugin for IDEA

Alright. Took me nearly three whole evenings to conquer IDEA. I’ve seen lots of little things I really dislike.. Globals and other BS.. Horrible..

Well. I got an initial configurable version of the “SimpleSyntax” highlighter plugin done. It’s available here as binary and source. These files will probably go away soon, after I created an official project somewhere. But some heavy cleaning up has to happen first..

Anyway, some of the nice bits of this plugin. Have a look at a configuration as it is supported right now:

[SimpleSyntax:V1.0]

Name: Ruby
Icon: simplesyntax_ruby.png
Description: Ruby Script File
ExampleCode: simplesyntax_ruby.rb

# Braces Configuration
Braces.Pairs: (),[]
Braces.Structural: {}

# Commenter Configuration
Comment.Line: #
Comment.BlockPrefix:
Comment.BlockSuffix:

# FileType Configuration
FileType.Icon: simplesyntax_ruby.png
FileType.Extensions: rb, ruby
FileType.DefaultExtension: rb

# Syntax Configuration
regex BLOCK_COMMENT                 => (?m)^(?:\s*#.*$){2,}
regex LINE_COMMENT                  => (?m)#.*$
(...)
regex SPECIAL_QUOTED_STRING         => %[qQ](.).*\1
regex SINGLE_QUOTED_STRING          => \'(?:[^\']|\\')*\'
regex DOUBLE_QUOTED_STRING          => \"(?:[^\"]|\\")*\"
(...)

# Element Descriptions
descriptions[ BLOCK_COMMENT ] = Block comment
descriptions[ LINE_COMMENT ] = Line comment
descriptions[ DOC_COMMENT ] = Documentation
(...)

# Element Default Attributes
attributes[ BLOCK_COMMENT ] = #303030,BOLD,ITALIC
attributes[ LINE_COMMENT ] = #305030,BOLD,ITALIC
attributes[ DOC_COMMENT ] = #503030,BOLD,ITALIC
(...)

I removed the dirty/incomplete parts.. :) Support for easier keyword specification, etc is still missing. For now only the “regex” rules are supported. Which is pretty clumsy for specifiying keywords..

Another “nice” thing I want to add are “ruby” and “groovy” rules in which some script code is executed to recognize tokens – instead of RegEx matching. We’ll see..

That’s it for today.. BF2 is waiting.. :)

tfdj

Update 2: Ruby Plugin for IDEA

I’ve been pretty busy with work all day. Now I got back to the IDEA Ruby plugin and after only a few minutes of thinking about what I was going to do, I said to myself “Wait a minute.. that’s BS..”. There’s a much simpler solution..

Alright, here’s the context: Yesterday I spent a few hours trying to use a ‘search-replace’ approach for turning the JavaScript IDEA example plugin into a Ruby plugin. Didn’t work.. :) And after a few minutes playing around with JFlex.. well, it really was enough JFlexing for a lifetime.. I then started implementing the Lexer interface offered by IDEA again, keeping in mind that at some point I’d have JRuby doing the ‘tokenizing’.

But while doing that, I ‘stumbled’ across a simpler idea. How about a concept called ‘RecognizedToken’, offering a simple API like this:


interface RecognizedToken
{
    boolean isFoundIn( CharSequence, StartOffset, EndOffset );
    int getTokenStart();
    int getTokenEnd();
    IElementType getTokenType();
}

Then it should be possible to implement a very simple Lexer checking all registered tokens on every ‘advance’ call. This Lexer could read a simple config file consisting of lines such as:


LINE_COMMENT => "#.*"
DOUBLE_QUOTED_STRING => "\"(?:[^\"]|\\\")*\""
(...)

Of course, the next problem is the complexity of the regular expressions. And performance could be an issue, if IDEA doesn’t properly cache the Lexer output. But judging from the ‘start’ method signatures, my guess is they will cache everything..

Anyway, the Lexer now becomes a simple “10″ liner. Well, apart from the 100 LOC used to implement the generic API..


private final void updateTokenType( final int aStartOffset )
{
    myTokenStart = aStartOffset;
    myTokenEnd = myEndOffset;
    myTokenType = null;

    final RecognizedToken recognizedToken = myTokenFinder.findClosest
        ( myCharSequence, aStartOffset, myEndOffset );
    if ( recognizedToken == null ) return;

    myTokenType = recognizedToken.getTokenType();
    myTokenStart = recognizedToken.getTokenStart();
    myTokenEnd = recognizedToken.getTokenEnd();
}

The basic Lexer is working now. I’ll add configuration file support and then try some Ruby coding in IDEA with this plugin’s syntax highlighting enabled.

tfdj

Update 1: Ruby Plugin for IDEA

It’s been a busy week. Not much time for my fun projects.. Only today I started looking back into the Ruby plugin for IDEA. I see two ways that I’m willing to follow:

1. Embed JRuby into the Plugin and offer a Ruby-bases configuration file for the syntax definitions.

2. Clone the JavaScript example plugin and do a string-replace “JavaScript” to “Ruby”.

I actually like the first idea a lot more. And it’s much closer to my current solution, which is basically a hack using hardcoded lexer, keywords, etc.. I like the idea of having a simple config syntax to define the keywords and other parts of the languages that I want to hilight. Obviously there may be some performance issues..

The second idea, cloning the JavaScript thing, well.. it’s huge! And using JFelx for the lexer is nearly overkill.. imho.. :) I simply don’t like these ‘theoretically correct’ but not too pragmatic/usable solutions..

tfdj

Update: IDEA Plugin Development

I’ve spent most part of this easter monday working on basic Ruby syntax hilighting for IDEA. (See the previous posts for some more context..) I’ve got a simple lexer and the “surrounding” classes finished in a “proof-of-concept” way.

The funny thing, however, is,that “surrounding” means about 10 classes.. Anyway, I’ll check out some more of the JavaScript example code provided by JetBrains. Quite useful to get you started in the world of “We don’t need no useful APIs”.. :)

What becomes quite apparent quickly is that you should probably use something like “flex” to generate your lexer code. But I wonder how IDEA handles the XML filetypes stuff.. I never worked with anything remotely compiler-related (I mean yacc, etc, not the compiler itself.. :). So I have to check out flex next..

tfdj

IDEA (Not a) Rant Part 2

Here’s a quote from The Basics of Plugin Development for IntelliJ IDEA:

A more complex example for getting a container inside the event handler is presented below. In this example, the DataContext class is used for passing context references for the considered action. This class deserves special attention, and we will consider it in detail in another article devoted to actions and passing context parameters principles.

And here’s some following example code from this article:


    public class MyAction extends AnAction {
        public void actionPerformed(AnActionEvent e) {
            DataContext dataContext = e.getDataContext();
            Project project = (Project)dataContext.getData(DataConstants.PROJECT);
            Module module = (Module)dataContext.getData(DataConstants.MODULE);
        }
    }

In context of my previous post, this is just another example of what I mean when I ask for more declarative APIs. Sure, I understand certain reasons for using “identifiers” to retrieve Objects from some kind of object container. And it may very well make absolute sense for the JetBrains guys to do it this way. But expose such an API? To a potential external plugin developer? Smells strange, doesn’t it?

And what would the problems be when offering an alternative API using a more declarative style like for example this:


... {
project = dataContext.getProject();
module = dataContext.getModule();
...
}

Of course, you can’t have a million getThis, getThat, etc methods in the DataContext API. But is this a valid argument against a more declarative API? Or an argument for an ID-based “query-API”? I don’t think so. All it means is, that something is not they way it should be.

The question should probably be more like: How can I separate the DataContext thing into sub contexts? Or can I provide specialized contexts depending on the kind of “plugin component part” I’m currently working on.

Enough of this..

There’s something above all that.. It has to do with arguments “Why Ruby is better?” and the like. It runs along these lines:

If you’re used to coding in a more dynamic language, you probably come to like how you can implement a lot of things with very little code. (Let’s leave all strong-typing related matters aside for now. They don’t matter here.) In this context I kind of hate Jave. Obviously.. :)

BUT: I still think arguments like “Java + IDEA” vs “Ruby + ???” saying basically that with Ruby you’re pretty much stuck with typing everything yourself are.. well.. valid in a way. Not so much as to count number of key strokes and compare them. But like.. with a nice Java API and a nice Java IDE, the IDE can actually “guide” you through what you want to acomplish.

In Ruby (for example) you’re pretty much stuck with reading docs (remember the days of JDK1.1 and 1.2? I do.. :) and/or trusting your guts. Of course things are not as bad for Ruby as they may sound here. Writing Ruby is a lot of fun, and you’re guts are right a lot of times. And a test-driven approach helps a lot to keep a nice development speed in Ruby.

But Java, with the right APIs and the right IDE, can make 90% of the coding work a real breeze. You still write a lot more code than in Ruby, no doubt about that. But you proabably have to, because of some limitation that’s still present in the Ruby world, or some legacy argument forcing you to use Java. But with appropriate APIs that help the IDE to guide you, Java coding isn’t that bad.

This is my problem with looking at the pluging development stuff offered by IDEA.. You know what I mean?

tfdj

IDEA Plugin Development

Subtitle: PicoContainers, Decoupling and other things I don’t know anything about.

Alright, in a really weird way this post is a perfect candidate for this ‘In a world gone mad’ blog. Here’s why..

Besides other, probably more important things, frameworks like PicoContainer try to make decoupling easier. Maybe a too simplistic description. But let’s focus on the resulting “APIs”..

You try to avoid too tight coupling. You rely on alternative mechanisms like for example singleton objects like “ApplicationManager” etc. You access the objects you need – when you need them – through the associated singleton classes.

Which probably is fine under certain circumstances. But does it really make things easier? It surely makes the ‘top level interfaces’ easier. Have a look at for example the “ApplicationComponent” interface provided by IDEAs OpenAPI:


public interface ApplicationComponent
{
    String getComponentName();
    void initComponent();
    void disposeComponent();
}

Easy enough. But what does it tell you?

Here’s what I mean: Why is there no “anchor” object part of method signatures? Why is it better to have to read the (quite extensive) documentation to find examples on how (and reasons why) to use for example the ApplicationManager class. Looking at a somewhat more sophisticated plugin like GroovyJ you are faced with all the beauty of this “system”.

Don’t get me wrong.. I don’t mean to sound too negative here. I think taking everything into account the JetBrains guys did a great job! And of course it’s quite a hard problem itself to figure out what this before mentioned “anchor” object would look like.

What I really mean to say is this: If a system gets complex (complicated?) enough to make you long for a “dependency injection thing”, wouldn’t it then be a good time to stop for a minute, and try to look at your problem from a different point of view? Maybe looking for alternative solutions? Shouldn’t there be an easier solution? A more expressive, maybe more “declarative” API possible? An API that guides you through the development?

OK. Sorry for this – not really! – rant. I don’t know too much about component containers, dependency injection, etc. And I only looked at IDEA plugin development for a few hours. And I haven’t worked on projects as big as IDEA must be.

It’s just that sometimes.. you know.. I feel lost.. uncomfortable.. you know.. In a world gone mad.. :)

tfdj

Thoughts on JRuby

Just stumbled upon a – slightly weird – mentioning of JRuby on Lambda. It’s weird because JRuby has been around for a long time..

Anyway, I’m just thinking, maybe this could be a nice answer to my recent ‘performance’ problems mentioned here. Using the Java NIO memory-mapped files stuff in (J)Ruby..

Overall a very cool project.. imho..

tfdj

« Previous PageNext Page »