rubysdl vs. ruby-sdl-ffi - ruby

Could anyone here tell me the difference between the Ruby gems rubysdl and ruby-sdl-ffi, like speed variances? If so, which would you prefer? I'm wondering for the sake of my gem that I'm writing, Rubydraw (located here).
Thanks in advance!

I am the author of ruby-sdl-ffi. This question was brought to my attention today, so I am answering for the benefit of anyone who is still curious.
The main difference is that ruby-sdl-ffi is pure Ruby code that accesses SDL (and related libraries) via FFI (foreign function interface), whereas rubysdl is an extension written in C that links to SDL (and related libraries). There are pros and cons to each approach. (Obviously, I feel that FFI is the better approach, or I would not have bothered to write ruby-sdl-ffi.)
Both libraries offer similar feature sets, although there are some differences (noted below). They can both do 2D games with images, sounds/music, and user input from keyboard, mouse, and/or joystick/gamepad. They can also both be used with OpenGL (via ruby-opengl or ffi-opengl) to create hardware-accelerated 3D games. They can both be used on Windows, MacOS X, and Linux (and perhaps other platforms), although rubysdl only works on MacOS X if you use a special Ruby interpreter wrapper called "rsdl".
I have not run any serious benchmarks, so I can't provide any definitive data about raw performance. My general impression is that rubysdl might have a slight performance advantage, but they are close enough that performance isn't the main factor when deciding between the two libraries.
Here is how I would summarize the pros and cons of the two libraries:
ruby-sdl-ffi
Easier for users to install the gem. It does not need to be compiled, so users don't need to install a C compiler or toolchain.
Works with MRI (the "usual" Ruby interpreter), JRuby, and probably Rubinius.
No special interpreter is required on MacOS X. However, the MacOS X support may need to be updated to get it working totally right on the latest versions of MacOS X. (Apple keeps changing things.)
Lower-level API, more closely mirrors the C libraries. This may be good or bad depending on your perspective.
Currently has bindings for SDL, SDL_gfx, SDL_image, SDL_mixer, and SDL_ttf libraries. (Compared to rubysdl, it adds SDL_gfx but lacks SGE and SMPEG.) Adding bindings for other libraries is quite easy.
Not actively developed or maintained anymore. I don't have the time or interest anymore, but someone is welcome to take over, and I can provide guidance.
Somewhat experimental, and has some rough edges.
rubysdl
More mature and polished, has withstood the test of time.
Better support for Japanese text input and rendering.
Higher-level, more abstract API.
Binds SDL, SGE, SMPEG, SDL_image, SDL_mixer, and SDL_ttf libraries.
Requires users to have a C compiler to install the gem. This can be quite a headache on Windows and MacOS X.
Requires MacOS X users to run your game using the special "rsdl" Ruby interpreter. Thus, to my knowledge, it will not work with JRuby or Rubinius on MacOS X.
Does not seem to be actively developed or maintained anymore either.

Related

Can the Ruby language be used to build operating systems?

Can the Ruby language be used to create an entire new mobile operating system or desktop operating system i.e. can it be used in system programming?
Well there are a few operating systems out there right now which use higher-level languages than C. Basically the ruby interpreter itself would need to be written in something low-level, and there would need to be some boot-loading code that loaded a fully-functional ruby interpreter into memory as a standalone kernel. Once the ruby interpreter is bootstrapped and running in kernel-mode (or one of the inner rings), there would be nothing stopping you from builing a whole OS on top of it.
Unfortunately, it would likely be very slow. Garbage collection for every OS function would probably be rather noticeable. The ruby interpreter would be responsible for basic things like task scheduling and the network stack, which using a garbage-collecting framework would slow things down considerably. To work around this, odds are good that the "performance critical" pieces would still be written in C.
So yes, technically speaking this is possible. But no one in their right mind would try it (queue crazy person in 3... 2...)
For all practical purposes: No.
While the language itself is not suited for such a task, it is imaginable (in some other universe ;-) that there a Ruby run-time developed with such a goal in mind.
The only "high level" -- yes, the quotes are there for a reason, I don't consider C very "high level" these days -- language I know of designed for Systems Programming is BitC. (Which is quite unlike Ruby.)
Happy coding.
Edit: Here is a list of "Lisp-based OSes". While not Ruby, the dynamically-typed/garbage-collected nature of (many) Lisp implementations makes for a favorable comparison: if those crazy Lispers can do/attempt it, then so can some Ruby fanatic ... or at least they can wish for it ;-) There is even a link to an OCaml OS on the list...
No, not directly
In the same way that Rails is built on top of Ruby, Ruby is built on top of the services that lower layers .. the real OS .. provide.
I suppose one could subset Ruby until it functionally resembled C and then build an OS out of that, but it wouldn't be worth it. Sure, it would have a nice if .. end but C syntax is perfectly usable and we already have C language systems. Also, operating systems don't handle character data very much, so all of the Ruby features to manipulate it wouldn't be as valuable in a kernel.
If we were starting from scratch today we might actually try (as various experimental projects have) to use garbage collected memory allocation in a kernel but we already have OS kernels.
People are making investments at the higher layers rather than redoing work already done. After all, with all the upper level software to run these days, a new kernel would need to present a compatible interface and the question would then be asked "why not just run the nice kernels we already have?".
Now, the application API for a mobile OS could indeed be done for Ruby. So, just as Android apps are written in Java, RubyPhone apps could be written in Ruby. But Ruby might not be the best possible starting point for a rich application platform. Its development so far has been oriented to server-side problems. There exist various graphical interface gems but I don't think they are widely used.
basically yes, but with a big disclamer .. which is basically Chris' answer but a different spin on it. Since for kernel performance it would kinda suck to use ruby, you'd probably want to build around a linux-ish kernel and just not load any of the rest of the operating system. This is basically what Android does: the kernel is a fork from Linux (and is maintained close to linux), the console is a webkit screen, and the interpreter is Java with some Android specific libraries. IE, Android is Java masquerading as an OS, .. you could do about the same thing with Ruby instead of Java and only a smallish hit to performance from java
While building a whole OS from scratch in Ruby seems like
a multi-billion project (think of all the drivers), a
linux kernel module that runs simple ruby scripts does
make sense for me - even it was only for prototyping
new linux drivers.

Rich and widely used Ruby GUI framework for Windows?

I read about wxRuby and Shoes but never used them. I want to learn ruby by developing a real-world serious Windows application. Among the available frameworks, which one is widely used and acceptable, rich in libraries and comes bundled with .exe builder?
There aren't a great deal of sensible choices for client/desktop applications in Ruby right now, however I believe one of your best options is to take advantage of mature JVM libraries via JRuby.
The Redcar text editor is written in Ruby and runs on the JVM, and you can view the source on Github here https://github.com/danlucraft/redcar
There is also a development company called Atomic Object that made a neat Ruby desktop app using JRuby with a fairly sophisticated GUI and you can view that here.
I've been thinking about the exact same problem as you and keeping and eye on my the options, these last few months :-)
I've also been using JRuby on the server-side and it's solid and reliable.
Finally, if it's Windows-only as you say, then you could consider using a .NET GUI Framework like WPF and build it using IronRuby, however IronRuby is not yet as mature as JRuby, so you could be exposing yourself to some risk there in terms of compatibility, bugs and performance (and for the record, I like IronRuby!).
However, the potential issues of using IronRuby might be balanced out by the gains you'd make using a GUI framework that's designed and optimised for Windows and is nicer than Swing. WPF is about as rich as it gets for GUI frameworks on Windows.
There are bindings for Qt on GitHub. I believe it's a fork from the Korundum bindings from KDE. However, I haven't tried it on Windows yet.
You might consider using RubyTk. Tk is a toolkit that works with many languages including ruby. For more information see tkdocs.com
disclaimer: I have no idea how widely used it is, though Tk in general is used in many places for both commercial, internal and open source projects.
http://en.wikibooks.org/wiki/Ruby_Programming/GUI_Toolkit_Modules will help
In terms of popularity, in 2008 shooes was most popular, but that has probably dropped.
http://www.pressure.to/ruby_gui_survey/
Since RubyInstaller project bundles now complete modern Tk distribution and bindings eliminating Windows installation woes- Tk seems the way to go.
With RubyGems I believe it is now possible to install GTK+ for this. So says this in Gems. This is a widely used framework, both in open source and industry. It is used in GIMP and, I think, presents a good windows system that is close to native and easily useable.

Haskell UI framework?

Is there, by chance, an emerging Haskell UI framework for Windows?
I recently took up looking over the language, and from what I see, it would be for great little "one-off" applications (elaborate scripts).
However, without a good UI framework I can't see it getting in under the smoke and mirrors of the more obvious contenders.
I've read that there are many frameworks, but none are full-featured.
I'm just wondering if this is something that's on the rise, or is it simply too difficult to get enough developers going in the same direction with one?
The two main frameworks are wxHaskell and Gtk2Hs. Both of these have been used for real work. From what I know my preference would be Gtk2Hs because it handles resources properly (i.e. uses the GC). wxHaskell requires the programmer to release widgets once they are no longer required, so you can get all the classic memory leaks and stale pointer screws with it.
The problem with both is that everything is in the IO monad. This reflects the fact that they are comparatively thin wrappers around existing GUI libraries for imperative languages. Of course this means you are no worse off than you would be writing a GUI in an imperative language, but you are hardly much better off either.
There are some interesting experimental libraries to be found on Hackage, including Grapefruit and Conal Elliott's "Tangible Values" ideas in GuiTV. Both of these try for a more declarative approach.
(Disclaimer: I am the wxHaskell maintainer)
Both wxHaskell and Gtk2Hs are more or less complete. That's to say, both wrap a great deal of the functionality provided by their underlying libraries. They also both, as mentioned earlier, require a rather 'imperative' style of programming in the IO monad.
There have been many discussions on the relative merits of each. I would say that wxHaskell is the easier of the two to get working, especially on Windows, as it can be installed via cabal (see http://www.haskell.org/haskellwiki/WxHaskell/Install#On_Windows)
The FRP frameworks (Grapefruit and others) provide a more 'functional' style of programming, at the cost of having much reduced widget coverage. I have the feeling that this is still an open research area, and not really ready for 'prime time'.
In practice, I've never had resource management issues with wxHaskell, although I agree that it's possible, and is an area handled better by Gtk2Hs, which uses reference counting in the underlying library.
For completeness, I should also mention that a Qt binding (QtHaskell?) also exists - it is relatively young, but apparently reasonably complete.
I rather feel that the Haskell community, small as it is, would do well to fix on one GUI framework, but accept the difficulty of this (e.g. licensing, support for all OS platforms etc.).
Also you can use wxWidgets (i mean C++ library) with Haskell. Here is an example: https://bitbucket.org/afiskon/hs-a-star-gui/src Such approach has some advantages over wxHaskell: 1. You can use UI generators (Code::Blocks, wxFormBuilder) 2. Your application takes less disk space 3. You can use all features of wxWidgets.
It should also be noted, that last version of wxHaskell uses wxWidgets 2.9, which probably will never be ported to Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=16;bug=613431

Is Smalltalk a viable development language for Mac OS X?

Every time I see a discussion on software development, always someone suggests or exalts the qualities of Smalltalk, be it the beautiful language constructs or the better implementation of basically everything.
So I was curious, is anybody developing in Smalltalk? can Smalltalk actually be used to develop software on the Mac? Or what is the target platform for Smalltalk? What is the poster child for this apparently fantastic but unpopular language?
Smalltalk isn't really used for GUI application development on the Mac in any major way. The only distribution that could produce native apps was Ambrai Smalltalk, and that died in beta AFAIK. Squeak is the most popular Smalltalk variant nowadays, but you will be torn limb from limb if you release a Mac OS X app that looks like Squeak. It's worth checking out if you're interested in learning the language (which is still unique in a lot of ways), but you're probably not going to be developing OS X apps with it.
If you would like something similar, check out MacRuby. Ruby is as close as you can get to Smalltalk without actually being Smalltalk — total object orientation, dynamic, 100% message-based, heavy use of blocks, etc. MacRuby is an implementation being developed by Apple specifically for making OS X applications.
Mac OS X's native Objective-C is also heavily Smalltalk-inspired (it's basically a big chunk of Smalltalk's object system and syntax bolted onto C), but owing to its extreme C compatibility, it falls a little further from the tree.
Take a look at fscript, which is essentially a smalltalk-like language for Objective C.
Luis: do you want to do desktop application for Mac ? or you want to program in Mac? If you want to do a web application for example, you can perfectly use Squeak or Pharo. If you want to do native mac applications, you should see the Mars project for Squeak:
http://smallworks.com.ar/productos/Mars
As an example, most of the Pharo users and developers are under Mac.
http://www.pharo-project.org/home
download and try it at least for a couple of hours!
I still believe that Squeak is well worth investigating, if only to broaden your mind a little. As for the poster child for Smalltalk, it's probably Seaside.
Squeak isn't its UI. You can configure Morphic heavily (look at how similar Pharo's is to OSX, for instance). Or you can just use native widgets with wxSqueak.
This deserves some attention:
"Objective-Smalltalk was created specifically to solve practical problems that have been encountered in 25 years of Objective-C and Smalltalk use, but with a theoretical framework that solves many of these problems elegantly and minimally, rather than by bolting on special feature after special feature."
http://objective.st/

What are the relative merits of wxHaskell and Gtk2HS?

Which is better for developing GUI applications with Haskell, wxWidgets (via wxHaskell) or GTK (via Gtk2HS)?
What are the pros and cons of each? Does it vary depending on which platform you are targeting (I would primarily be working on OS X but would like my programs to work on Linux and Windows too)?
[Disclaimer: I am a wxHaskell maintainer]
Both are stable and fairly complete GUI bindings, and you could choose either for most projects with confidence. Both have some degree of 'higher-level' Haskell bindings, but in both cases you will need to drop into rather imperative 'C' style coding to get things done. My impression is that wxHaskell allows you to spend a little more time in the higher-level bindings, but I've not done much GTK2HS, and in any event, you definitely find yourself working on the thin end of the wrapper for both libraries - and I think the overall programming 'complexity' is similar in both cases.
Therefore, let's take the basic functionality as a given and concentrate on the differences. Please note that I genuinely believe that GTK2HS is an excellent piece of work, and that you will be happy if you choose it. Most of what I say below is a personal take on the differences, and why I choose to work on and with wxHaskell myself.
GTK2HS has a larger team working on it, and is released more regularly. wxHaskell is not updated as frequently, but the core team is active, and there are regular bugfixes, but with major new functionality being added rather more slowly than we would like (we all have day jobs).
wxHaskell gives true native application appearance on all supported platforms out of the box. GTK2HS is, of course, native on Linux and has a pretty good native theme on Windows (i.e. good enough to satisfy all but pedants...), but has GTK look and feel on OSX, and depends on having X11 installed. I believe that an OSX 'native' GTK library is under development, but is considered relatively immature. Once this is stable, GTK2HS should be able to easily benefit from the same 'partially native' look and feel (e.g. GTK OSX screenshot).
wxHaskell is probably a little easier to build if you are not on Linux (GTK2HS is likely easier if you are Linux hosted), but both are pretty complex to build, to be honest, as there are a significant number of dependencies in both cases.
It is slightly easier (IMHO) to distribute applications based on wxHaskell, simply because it has fewer library dependencies. I distribute applications using mainly InnoSetup on Windows, and as App bundles on OSX. I would admit that with only a small amount of extra work, the same could be done with GTK2HS, so this is probably the weakest argument in favour of wxHaskell.
It is my personal opinion that wxHaskell is friendlier to closed source (e.g. commercial) developments. This is, of course, the subject of interminable flame wars, so I will only say that wxHaskell is under the wxWidgets license which unambiguously allows for closed source development. GTK2HS is LGPL, so you'll need to ask your lawyer - although I must make it clear that many people and companies have concluded that LGPL is compatible with commercial development; the lawyers at the company I work for have concluded that it is inappropriate for our projects.
I think that if Linux was my main development and delivery platform, I'd probably use GTK2HS. It isn't, however: I deliver mainly to Windows with occasional OSX, and I think wxHaskell is a better match to these platforms, although both options support all three platforms.
I hope this will help you with your choice.
A consideration is that currently it is slightly easier to get wxHaskell to work natively on Mac OS X. GTK2HS depends on GTK, which does have an implementation using native widgets on Mac OS X, but that implementation is not as easily built as the wxWidgets implementation for Mac OS X is.
Therefore, if you want to develop code to run without X11.app, currently you are slightly better off with wxHaskell.
Note however that this is quickly changing:
http://www.haskell.org/haskellwiki/Gtk2Hs#Using_the_GTK.2B_OS_X_Framework
shows how to use GTK2HS with native GTK+ on Mac OS X.
One advantage of GTK2HS is its GLADE support, making the development of simple UI very quick. The higher level combinators in wxHaskell mitigate most of that advantage, but they do require a deeper understanding of how you want your interface to look and behave, and therefore are harder to use in an exploratory fashion.
I have pretty incomplete information, but since you have no answers yet, maybe incomplete information is better than none.
The question to ask is this: is the toolkit just a wrapper around C-like functionality, or is there an additional layer that gives the toolkit a more "native Haskell-like" API? When wxHaskell was first announced at the Haskell workshop, the development of the native Haskell API looked extremely promising, but was still incomplete. It looks as if the "Haskellized" API for wxHaskell is still being worked on, whereas the Gtk2Hs project doesn't mention this issue at all. For that reason I'd recommend wxHaskell.
Personally I would look into some sort of Reactive package/extension. It seems to sit with the paradigm much much closer. Instead of specifying your graphical stuff imperatively, you can do it declaratively. Example (not representative of any particular language or implementation):
x, y, z :: Int
click, buttonclicked :: Bool
x = <X coordinate of mouse>
y = <Y coordinate of mouse>
click = <Whether mouse button is currently being pressed>
z = x + y
buttonclicked = (x == 10 && y == 10 && click)
Buttonclicked and z will be automatically updated every time x and y change.
You could then have some logic somewhere that looks something like this:
if buttonclicked then <do something> else <do something else>
This is all very fuzzy though. Just look into some real reactive interfaces

Resources