Monday, February 15, 2010

implicit conversions, more errata

Getting used to writing Plasmoids in Javascript takes a bit for me, and apparently at least some others out there. One things I'm used to from C++ is being able to watch one object of one class "turn into" another using implicit conversion. For instance, when something expects a QEasingCurve it's second nature for me to use the QEasingCurve::Type enumeration directly (animation->setEasingCurve(QEasingCurve::OutBounce)) and rely on the compiler to figure out what I really meant (animation->setEasingCurve(QEasingCurve(OutBounce))). With the Javascript Plasmoids we have to be a bit more eplicit about these things.

So this doesn't work:


animation.easingCurve = QEasingCurve.OutBounce


but this does:


animation.easingCurve = new QEasingCurve(QEasingCurve.OutBounce)


The Smoke bindings are capable of doing implicit conversions, though, as Richard Dale pointed out in a recent blog post. So there is hope in the long run. :)

Two more pieces of errata:


  • If you are using Kubuntu and you are getting errors about not being able to create a Javascript ScriptEngine, that's because of a packaging mistake on Kubuntu. The Javascript ScriptEngine is part of kdebase-runtime, which means we are supposed to be able to be rely on it being there. It used to be in kdebase-workspace which doesn't have these guarantees, however, which I assume is why things got dropped here. The solution is simple, though: sudo apt-get install plasma-scriptengine-javascript. I'm told that future updates will have make kdebase-runtime depend on plasma-scriptengine-javascript which will fix this issue.

  • The MovementDirection enumeration for Animations was not being created in 4.4.0; this has been fixed and in 4.4.1 and beyond one can indeed write things like "animation.movementDirection = animation.MoveLeft". Until then you need to use the literal values of the enumeration.



I'm really happy with all the testing the Javascript Plasmoid system is getting, and not just because it's working out but also because it is highlighting problems in the process. I'm fixing the problems as they arise in #plasma, plasma-devel@kde.org or on bugs.kde.org. It (once again :) highlights the value of having users of an API, and the need for a larger number of test Plasmoids (which also tends to help KDE Examples grow) as well as setting up an automated system around those tests to catch regressions ($DEITY forbid! :) between releases.

14 comments:

Tom said...

OK, this will be off topic:

But all this talk about JS and C++ made me realize that there is no really new and modern language for Qt. There is no Vala or Genie like for Gnome. There is no Scala or Groovy like for Java.(Scala and Groovy only have a few of the properties I want.)
What I want is a language that will give me native binaries without VM-bloat, but also has very concise syntax and small memory footprint and great speed.

Maybe someone (me) should start making good bindings for PHP and use Facebooks Hiphop compiler or something.
All the languages Qt currently has compile really badly I think.

Or is there anything that has modern syntax(high level) and nearly the speed of C++?

rdale said...

Maybe someone (me) should start making good bindings for PHP and use Facebooks Hiphop compiler or something

@Tom: we have PHPQt language bindings in kdebindings, but unfortunately we have lost the maintainers. I've recently made a start in bringing them up to date to be in line with the other Smoke based language bindings. In fact the next step is to add the overloaded method resolution code from the JSmoke bindings that Aaron is discussing. There is some great work being done on KDevelop support for PHP. So by combining that with the PHPQt/KDE bindings we could have a really nice KDE development environment.

Naproxeno said...

@Tom: Perhaps this could be of your interest: QtD. D is supposed to be a modern, compiled language without many of the annoyances of C++.

Disclaimer: I've never programmed anything in D but I'm following its development.

Tom said...

Thanks guys.

@rdale: That sounds really interesting. Do you think PHP+Qt will work with Hiphop? (But I guess why wouldn't it, right?)

@Naproxeno: Cool, but D is still too lowlevel and I am not convinced it is the way forward. The gains over C++ are not that big and it had its time to gain traction and it didn't. If I wanted improved C++ I would use Go I guess. But my goal is way less typing and more high level language features.

Aaron J. Seigo said...

@Tom: "there is no really new and modern language for Qt"

and i really hope we never have one "for Qt"; building a whole new language just for one toolkit is a great way to build a dead-end language imho. the odds of success are miniscule next to the odds of raising the barrier to entry (having to learn a new language) and creating a language that lags significantly in capabilities due to the # of people willing to invest time and energy into the language itself.

then there's all the IDE support and what not .. erf.. no, i think a language is such a huge task that instead of creating one from scratch, something that already has a life of its own (and people with transferable knowledge using it) should be selected.

as a general concept, a higher level language that does compile down to native code could be very nice for certain use cases. maybe that will happen; you mentioned PHP + Hiphop and that could be a nice potential answer.

Parker said...

@Tom, Maybe the Qt bindings for Haskell would interest you. (http://qthaskell.berlios.de)

Tom said...

@Parker: Thanks, that is an option (for people who like pure functional .. )

@Aaron: For once I don't agree. I think for instance what the Vala guys did is really smart. Gnome needs a new low level language. Mono is not really a solution. They don't like C++. That limits the solution space massively. What they did is take the the C# syntax and build a Vala2C converter for it. Maybe not the most elegant solution, but it seems to get the job done. They are nearing 1.0. And they have IDE support (Valide, Monodevelop, VIM, Emacs) and some apps have already been programmed in Vala.
I think in the long run including Vala in the platform will be a smart move by the Gnome guys.
There are a lot of coders out there that love and know C# and Java and don't want to deal with C++. It would be cool if Qt and KDE would offer them a platform (especially now that Qt is gaining so much traction thanks to Meego)

But compiled PHP might even be the better solution. With awesome Kdevelop that could really take app development on KDE to a whole new level.

milianw said...

PHP? Seriously? I mean you ask for something new and good and you suggest.... PHP???

I'm one of the KDevelop PHP developers and a longtime PHP webdeveloper, and in my eyes (and those of many others) PHP has serious problems with it's overcrowded, unintuitive API. It's all but modern. And stuff like the namespace syntax really gets me laughing and crying at the same time...

But really: C++ is such an awesome language, esp. when you combine it with a framework like Qt. Of course for a quick plasmoid, editor plugin or similar, a binded language is the way to go since speed is not of importance then. Any language suffices there.

Tom said...

@milianw

If I could just make my wishes come true I would ask for something like Scala. Problem is reality has some limitations and I have to be realistic about this. I have just written a few tiny things in PHP and I don't even like it, but it is good for rapid development and it is newer and more modern than C++. It kinda looks like what I am looking for (with a lot of squinting)
Telling people how great C++ is is not really a solution to the problem that a lot of people won't use it IMO.
I personally would even prefer Ruby or Python, but I don't get to choose and PHP just got a nifty compiler that works for big applications (facebook is big, right?)

maninalift said...

@Aaron

I get your point about a new language but there is a great deal to learn with a new toolkit and Qt and glib do provide language-like functionalities. A "new" language might be little more than syntactic sugar on top which could make learning easier not harder. Not that I'm completely convinced by this argument, on balance you are probably be right.

@everyone: php is great for web development and handy for making simple tools but it surely isn't how you'd design a modern system programming language?

David said...

If you (Aaron or others) have the time, could you please make a tutorial for creating a plasmoid like this (in JS)?
step 1: download some web page at time intervals.
step 2: parse with a regex to extract data
step 3: show the data in a pretty way

IMHO this would cover most of the plasmoids that people want to do, e.g. plasmoids that show TV schedule, weather, bicycle/bus/car disponibility, etc. In general any service that is published at the web and updated at intervals.
Then for the user it would be a matter of changing the source web page, the regex and the item layout to make a new plasmoid.

jadrian said...

@Tom

GJC compiles Java to native code. Doesn't that get rid of the VM bloat? And once you got Java it should be easy to get Scala.

Juan Manuel said...

@David

Look into kdeexamples. There you have what you want.

momesana said...

I really wonder why so many people whine about C++ not being modern/new. Being newer doesn't necessarily mean that it's better.

C++ is a good general purpose language well suited for a wide range of tasks due it's support for many different programming paradigms. There is a reason why it has been around for so many years. It is also experiencing a good overhaul with C++0x.

Now if you really don't like C++, there are really pleasant languages like Python out there that have excellent Qt bindings. Anyways, there are more important things than the choice of the language (the quality of the code for example).

If you are still looking for a better language, you may really just be looking for an excuse not to start programming.