Ruby Book recommendations for how it works under the hood? [closed] - ruby

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm moving from .NET to Ruby, and i'm starting to get a pretty decent grasp on the language. However there's still a lot of things I want to know more about.
In C# one of the best books I read was called CLR via C#. It went into a lot more detail about how the CLR works, how memory works, garbage collection, reflection etc.
Is there an equivalent book for Ruby? Something that explains what the interpreter looks like under the covers?

There is no "the interpreter" in Ruby. Ruby is programming language, a programming language is an abstract mathematical object, a set of logical rules and restrictions.
There is an ISO specification for a subset of Ruby. There used to be a comprehensive set of executable examples written in Ruby, called RubySpec, but unfortunately, it was abandoned by its maintainers because of a lack of buy-in by the language designers of Ruby; however, several implementations still use it internally for their testing, e.g. Rubinius and JRuby. There is also a set of tests that are meant to specify the behavior of the language in the YARV implementation, which is the implementation that most of the language designers are hacking on.
There are several implementations of Ruby, however, none of those implementations is an interpreter, all of them have at least one, some multiple compilers:
Rubinius, a two-stage mixed-mode implementation consisting of a Ruby-to-bytecode-compiler written in Ruby, a kernel and core libraries written in Ruby, and a VM written in C++ with a bytecode interpreter and an LLVM-based JIT compiler.
Topaz, a two-stage mixed-mode implementation built with the PyPy framework consisting of a Ruby-to-bytecode compiler and a VM with bytecode interpreter and JIT compiler written in RPython, and a kernel and core library partially derived from Rubinius.
MagLev, a two-stage mixed-mode implementation built on top of the GemStone/S Smalltalk platform consisting of a Ruby-to-bytecode compiler and a more or less unmodified GemStone/S Smalltalk VM.
IronRuby, a two-stage mixed-mode implementation built on top of Microsoft's Dynamic Language Runtime and Common Language Infrastructure, written in C#.
JRuby+Truffle, a new implementation of Ruby based on JRuby and the Truffle AST interpreter framework.
JRuby, a two-stage mixed-mode implementation built on top of the Java platform, written in Java.
MRuby, a small, lightweight, embeddable implementation of a subset of the ISO Ruby specification. (This is the implementation that the creator of Ruby is working on himself.)
YARV, a two-stage implementation consisting on a Ruby-to-bytecode compiler and a bytecode interpreter, as well as a core library, all written in C.
Opal is a Ruby-to-ECMASCript compiler, which unfortunately does not 100% accurately implement the semantics of the Ruby language.
I have tried to order them from easiest to hardest readable sourcecode, and incidentally also (almost) from most to least interesting. (I think JRuby+Truffle is extremely awesome and should be right up there with Rubinius and Topaz when it comes to interesting ideas about how to make Ruby blazing fast.)
The reason why I ordered them from easiest to hardest readable sourcecode is because, well, there really aren't any books that describe the various implementations. Reading the source is probably your best bet. However, the classic Smalltalk-80: The Language and its Implementation (aka the Blue Book) was a heavy inspiration for the design of Rubinius. JRuby+Truffle, being a research project, has had a fair number of papers published, though.
There's a Ruby Bibliography Page which has some links to papers, mainly about JRuby+Truffle, but also about MagLev and JRuby.

Related

Rubinius in RubySL

I use Ruby from a user level and really don't deal with the internals. I have know Rubinius as 'Ruby in Ruby' which I assumed was a generalization. Recently, I got an error with Rubinius in the RubySL (no, I don't have error msg).
I started looking at RubySL and was a little surprised to see Rubinius everywhere. I really like Ruby and was just curious why Rubinius is in most of the RubySL? It seems to be used with things like locks / unlocks (such as https://github.com/rubysl/rubysl-thread/blob/2.0/lib/rubysl/thread/thread.rb ). Definitely not questioning it, just curious.
RubySL is short for Ruby Standard Library. It is a basic part of the shipped code bundle which forms what is generally known as Ruby. The standards library provides rather basic stuff you often need but which doesn't need to be part of the core language.
For example, the implementation of the Hash or Array, the language keywords, how assignment works, ... are part of the core language. These are often implemented in a language other than Ruby. MRI (the common C-Ruby) implements this mostly in C, JRuby implements this in Java. Rubinius implements this patly in C++ but mostly in Ruby itself. It can do this by bootstrapping itself from a very simple base VM and gradually adding more stuff with Ruby.
The standards library however is mostly implemented in Ruby in all implementations (with some exceptions mostly for performance reasons). Now, all Ruby implementations right now have their own implementation of the Ruby standards library which can thus differ in minor details.
Rubinius' approach to implementing a standards library was to implement it as separate gems. The idea was to one day provide a common standards library which could be used by other implementations (including MRI). This is in line with the efforts of esp. the Rubinius community to drive the RubySpec project in order to provide a common language specification and test suite for all Ruby implementations.
The RubySpec project was eventually abandoned and right now, it doesn't seem as if other Ruby implementations seem to be moving to the RubySL gems for implementing their standards library.
Thus, (and this is the TL;DR), the RubySL gems implement the Ruby Standard Library for the Rubinius project. Thus, it is expected to see the Rubinius project all over the place there: it is their code which is generally not used by other Ruby implementations.

Ruby as a standalone language [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have been messing around with ruby on rails. But my questions is really simple. Is ruby used language used for desktop applications? I mean without Rails? Can it be combined with GUI packages and Graphics Libraries to create a game for example? I have read that ruby is based on C. So it will be fast right?
Is ruby used language used for desktop applications?
Yes it is.
I mean without Rails?
Yes.
Can it be combined with GUI packages and Graphics Libraries to create a game for example?
Yes it can be.
I have read that ruby is based on C. So it will be fast right?
No, it won't be "fast" in the same way C is fast, because that isn't the point of Ruby. Ruby isn't "based on" C in any sense. The interpreter which runs Ruby code may be written in C (there are many interpreters and not all of them are), but that has nothing to do with the language itself. C and Ruby are not really comparable and occupy completely different niches.
I've no experience in programs where speed is critical; however, from my experience, Ruby is fast enough for user applications with GUI, and differences are almost unnoticeable from other similar dynamical languages (Ruby 1.9 is even faster, sometimes).
There is a reason I don't name the "similar languages": I think languages benchmarks aren't useful at all. While the fact that Ruby is fast enough for general purpose programming will probably make you happy, I think it's more important that if you already know and like Ruby you will be more productive using it.
There are some limit cases Ruby will be even faster than C: your implementations in C for functions that are offered as methods in the Ruby core lang and std lib could be slower than the ones in Ruby VM. This is just to say, speed isn't usually a concern, unless you're actually well aware of a particular reason you should be concerned with speed.
Some nice GUI libraries are FXRuby and Shoes, a very easy library used in the Hackety Hack project to teach children to program.
I usually use Tk when programming with Ruby and Python because it's included in the standard library and there is no need to install anything else.
For Gaming, you can try Gosu and Chingu; Gosu is probably the most actively developed Ruby Gaming Library, and Chingu is a nice collection of classes based on the foundations offered by Gosu. They've not got the nice community of other gaming libraries (e.g. Pygame) but you can easily start making little games with them.
Check out the Shoes GUI, it has different implementations, each one has a colorname, the most popular ared Red and Green Shoes, they are often used to make the kind of games you see also in Flash or regular javascript. They are fast enough for that kind of games. Some implementations even work with JRuby.
Red Shoes
Green Shows
Ruby is a language whose common implementation (e.g. ruby-1.9.3-pl94) is an interpreter coded in C. File main.c contains the main function in C which set up the Ruby VM implemented in C in file vm.c.
You could have several implementations of Ruby. I heard that some people wanted to re-implement Ruby above the Parrot VM (itself implemented in C); but that effort is perhaps still in progress. JRuby is a Ruby above the JVM.
Indeed interpreter vs compiler is not a sharp difference. Many interpreters contain a virtual machine with a translator (which you could view as a compiler) to that VM. Some VM implementations have a Just In Time dynamic translator to machine code. The JIT part produces machine code dynamically.
You could code a graphical application using e.g. Ruby-Gnome, a glue to Gnome and Gtk. You could also use Ruby Qt, a glue to KDE and Qt

Which programming languages meet these criteria for GUI app development? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm trying to find a programming language I feel really comfortable learning and using for desktop/GUI application development. I realize it's unlikely that any language meets ALL of these criteria, but I'd like to find one that meets as many as possible. I've listed the following features ROUGHLY in order from most desirable/important to least.
Ideal Language Features:
Code Style: C/Java-like
GUI Development: Easy, elegant, and platform-Native styling
Community: Widely documented, active development, friendly & helpful, unity of focus
Object-oriented
Garbage Collection, no worrying about pointers, etc
Native compilation, NO 3rd-party runtimes like GTK or .NET
Multi-platform (can be compiled on *nix, Windows, Mac)
Reasonably fast
Mixed typing (soft-typed, OR both soft- and strict-typed -- i.e. Pike)
Background:
Most importantly, I need something that is straight foward and reasonably familiar, and something that isn't going to require a deep understanding of platform-specific APIs. I can't afford to spend a lot of time learning to develop Win32 apps in C++ for example. I've used wxWidgets, and liked the basic usage, but I'm really wanting to use a language with garbage collection, dynamic typing, and so on.
My frustration with Java, C#, and others is the need for a 3rd party runtime. I don't want end users to have to worry about installing and maintaining a separate platform.
Now then. Ideas??
Haha, due to the constraints you imposed you are now left with HTML and javascript. Good luck :)
The answer to your question is simply: None.
You excluded all desirable languages and platforms in your question.
I'd suggest you throw away your aversion against .NET and go with Delphi Prism. It's not C#, it is cross-platform compatible (everything is officially supported on Mono) and you can create applications that bring the runtime with them (Mono as part of your application).
I'd suggest Groovy and Griffon. Groovy is a dynamic language (like Ruby / Python) that runs on the JVM and integrates with millions of Java libraries out there easily. Griffon is a high-productivity RAILS-like framework for developing GUIs. Groovy has been around for 5 years and has a robust community and is supported by SpringSource (now division of VMWare). Griffon is a bit younger, but also has a fairly robust community.
These seem to fit your criteria.
I know I switched from Java to Grails (web framework written in Groovy that's similar to Rails), and haven't looked back.
Have you looked at QT? It's a really great GUI library and there are bindings for just about every language in common usage. There is a ton of documentation and a wide community. You mention that you want to do something in a language with garbage collection and dynamic typing, but rule out Python and Ruby, which are the 2 most popular languages that fit this criteria (also, they both have great QT bindings, I use pyQT4 and it is just awesome). They really aren't that far from what you do in Java/C, you just end up writing a lot less.
Wow you really limit your choices. I'm going to jump on the QT bandwagon and recommend C++.
Most of the objects in QT inherit from another object that sort of does it's own garbage collection.
There is incredible documentation out there for it.
QT is extremely powerful and has most of the elements you would like, and is extensible if you want to modify elements yourself.
If you do a static build for your release build the people you give the application to won't need distribute any other libraries as they will all be built into the .exe file.
The next iteration of Delphi is said to be cross-platform (Windows, Mac, Linux). I think it meets all your requirements except garbage collection.
No language meets all of those restrictions. Technically, it sounds like you're asking for something almost identical to Java but then explicitly disallow Java for unstated reasons. Conceptually, it sounds like you're looking for Python or Ruby but disallow them for using slightly different syntax.
Given the order of priorities, I think the closest you'll find in existing languages might be C with the Boehm GC and GTK+ for the GUI (and GLib for the object system). You do say "No GTK" under "No third-party runtime required", but I'm not sure what "runtime" you refer to here, since IIRC it's just a bunch of C libraries.
Given the specificity of the requirements, I think your best bet is to write your own language. Compilers really aren't that hard to write anymore. There are off-the-shelf tools to help with parsing and code generation and math and text processing and GC and so on. Once you get started you'll probably find people willing to help port it. Many existing cross-platform GUI libraries (like wxWidgets) use C/C++ so if you have a decent FFI you can use that, too. You want "support" and "documented" but if you're the primary author you'll understand it better than anybody. The hardest part about a language is design, and it sounds like you have a picture in your head of exactly what the language should be already.
There are a few if you can accept either WxWindows or GTK or QT as a toolkit.
In the order of my personal preference would be:
Eiffel Studio
D with the D-GTK binding
F#
javascript?
might be not the fastest one and doesn't fully address all your needs, but hey... its everywhere and easy to learn
didn't read after the list, but with prism You can probably achieve most your goals.
or You can try Qt and c++ autopointers
Silverlight could actually give you enough cross-platform availability to use C#/.NET, but I am not sure it fits all your requirements.
Sounds like Action Script 3 will make you happy. But it's more web oriented but you could try to make a projector or an Air application. I think it's a good solution because you can do anything with AS3 (image, video, text, sound video text keyboard and mouse input, pear to pear and 3d since flash 10, ...) and it's cross platform and you can use it on the web or your desktop :)
If you are a pure root coder (using vim and only command line for ex) you can make your whole app without using the flash ide, by just writing your as files and compiling them with mxmlc (that comes with the free flex sdk).
I suggest Python. Although it doesn't fit your first requirement of coding style, but it fits all your other requirements!
GUI Development: Easy, elegant, and platform-Native styling --> Yes
I'd suggest that you try wxPython (wxWidgets for Python). This is so "native" on Python that about 90% of all the wxWidgets code examples on the Internet are for Python! I've personally used TkInter, Gtk and wxPython. All of them are well supported on Python. My personal choice is wx.
Community: Widely documented, active development, friendly & helpful, unity of focus --> YES
Object-oriented --> Yes
Garbage Collection, no worrying about pointers, etc --> Yes
Native compilation, NO 3rd-party runtimes like GTK or .NET --> Yes. - You can eiter:
pack a single dll with your code - or
use py2exe which is able to create a single executable out of your project
Multi-platform (can be compiled on *nix, Windows, Mac) --> Yes.
Reasonably fast --> Yes. Well, it's not the fastest out there, but close enough that some serious projects are done in Python only.
Mixed typing (soft-typed, OR both soft- and strict-typed -- i.e. Pike) --> Yes.
Regarding your first requirement I'd say that you should give Python at least a try. It requires very little effort to get started. There is a 2-hour tutorial which gives you a serious introduction. There's a Basic to Advanced tutorial where I'd almost guarantee that you'll be writing your first application on the second day.
I also feel your pain Brian. Most time when I ask questions about desktop GUIs the only answer I get is: "Make it Web". You really nailed it, since your question is still open inspite some really non-constructive answers...
I've been watching closely JavaFX 2, it solves some of Swing problems and seems very promising. This may be the only thing Oracle did right since getting Java from Sun.
UPDATE:
.NET is finally becoming an open-source, cross-platform solution. .NET Core allows native compilation for multiple devices.
The new .NET experience is exactly what I was looking for when I asked this question several years ago.
Original:
Lots of good suggestions, despite being salted with negativity throughout.
I think I'm going to go with C# and Mono. I like C# well enough syntactically (I've been accused often of being shallow, but the syntax of a language is just as important to me as its features, because I spend a lot of time writing in that particular syntax). Although similar to Java, it has a few unique features that I appreciate, and I think the community seems more open-minded.
My biggest complaint about Java besides performance, frankly, is the community. It seems infected with an excess of arrogance, and it also seems to be very fragmented in terms of support for and development on various overlapping libraries, tools, and so on. The community surrounding Mono seems much more organized.
Actually, so does .NET itself, for that matter. Sun is a big enterprise company that seems every bit as confused about what it IS and what it DOES as Microsoft or IBM, yet they seem to be doing an even worse job of leading and organizing their platform than Microsoft, which is pretty tragic.

Is it possible to compile Ruby to byte code as with Python?

In Python, if I want to give out an application without sources I can compile it into bytecode .pyc, is there a way to do something like it in Ruby?
I wrote a much more detailed answer to this question in the question "Can Ruby, PHP, or Perl create a pre-compiled file for the code like Python?"
The answer is: it depends. The Ruby Language has no provisions for compiling to bytecode and/or running bytecode. It also has no specfication of a bytecode format. The reason for this is simple: it would be much too restricting for language implementors if they were forced to use a specific bytecode format, or even bytecodes at all. For example, XRuby and JRuby compile to JVM bytecode, Ruby.NET and IronRuby compile to CIL bytecode, Cardinal compiles to PAST, SmallRuby compiles to Smalltalk/X bytecode, MagLev compiles to GemStone/S bytecode. For all of these implementations it would be plain stupid to use any other bytecode format than the one they currently use, since their whole point is interoperating with other language implementations that use the same bytecode format.
Simlar for MacRuby: it compiles to native code, not bytecode. Again, using bytecode would be stupid, since one of the goals is to run Ruby on the iPhone, which pretty much requires native code.
And of course there is MRI, which is a pure AST-walking script interpreter and thus doesn't have a bytecode format.
That being said, there are some Ruby Implementations which allow compiling to and loading from bytecode. Rubinius allows that, for example. (Indeed, it has to have that functionality since its Ruby compiler is written in Ruby, and thus the compiler must be compiled to Rubinius bytecode first, in order to solve the Catch-22.)
YARV also can save and load bytecode, although the loading functionality is currently disabled until a bytecode verifier is implemented that prevents users from loading manipulated bytecode that could crash or otherwise subvert the interpreter.
But, of course, both of these have their own bytecode formats and don't understand each other's (nor tinyrb's or RubyGoLightly's or ...) Also, neither of those formats is understood by a JVM or a CLR and vice versa.
However, the whole point is irrelevant because, as Mark points out, you can always reverse engineer the byte code anyway, especially in cases like CPython, PyPy, Rubinius, YARV, tinyrb, RubyGoLightly, where the bytecode format was specifically designed to be very close to the source language.
In general it is simply impossible to protect code that way. The reason is simple: you want the machine to be able to execute the code. (Otherwise what's the point in writing it in the first place?) However, in order to execute the code, the machine must understand the code. Since machines are much dumber than humans, it follows that any code that can be understood by a machine can just as well be understood by a human, no matter whether that code happens to be in source form, bytecode, assembly, native code or a deck of punch cards.
There is only one workable technical solution: if you control the entire execution pipeline, i.e. build your own CPU, your own computer, your own operating system, your own compiler, your own interpreter, and so forth and use strong cryptography to protect all of those, then and only then might you be able to protect your code. However, as e.g. Microsoft found out the hard way with the XBox 360, even doing all of that and hiring some of the smartest cryptographers and mathematicians on the planet, doesn't guarantee success.
The only real solution is not a technical but a social one: as soon as you have written your code, it is automatically fully protected by copyright law, without you having to do one single thing. That's it. Your code is protected.
The short answer is "YES",
check rubini.us
It will solve your problem.
Here is how to compile ruby code:
http://rubini.us/2011/03/17/running-ruby-with-no-ruby/
Although Ruby's 1.9 YARV VM is a byte-code compiler I don't believe it can dump the byte-code to disk. You might want to look at the alternative compiler, Rubinius, I believe it has this ability. You should note though that byte-code pyc files (and I imagine the ruby equivalent) can be pretty easily "decompiled".
Not with the MRI interpretter, no.
Some newer VM's are being worked on where this is on the table, but these aren't widely used (or even ready to be used) at this point.
If you use Jruby, you can compile your Ruby code into Java .class files (including your Rails stuff) to execute them with (open)jdk out of the box!
You can even compile your complete stuff into a .war file to deploy it on Apache Tomcat or Jboss with a tool called "warbler"
https://rubygems.org/gems/warbler/
Depends on your ruby.
JRuby - https://github.com/jruby/jruby/wiki/JRubyCompiler
MRuby - http://mruby.org/docs/articles/executing-ruby-code-with-mruby.html
MRI (C)Ruby - https://devtechnica.com/ruby-language/compile-ruby-code-to-binary-and-execute-it

What is the significance for Ruby programmers of SAP's new implementation of Ruby?

SAP announced Blue Ruby, a version of Ruby that runs inside the ABAP Virtual Machine.
This seems to lend additional credibility to the Ruby language but, except for SAP developers, does this have any applicability to the rest of the Ruby community?
I'm just wondering what other significance this may have. Additional job opportunities, perhaps, for Ruby developers to be hired to work on SAP projects?
Any other potential benefits for Ruby programmers?
Also, something I'm not clear about: Besides MRI and JRuby, how many different implementations are there and why do I, as a Ruby programmer, need any implementation except the MRI? I understand I might need JRuby if I want to integrate with Java libraries. Are there any other times I might need to look into an implementation besides the MRI or JRuby?
I notice that Blue Ruby is compiled. Is that a big benefit and would this be the first compiled version of Ruby?
Sorry - maybe too many questions but this is being discussed as a big deal except I'm not sure why/if it really is. Would be grateful to get some feedback from people who understand Ruby (and I.T.) better than I do.
There are actually quite a few alternative implementations. The reason for so many versions is partly because while Ruby itself has a lot of fans, MRI is often considered to be not quite as nice as the language it hosts.
This is a list of all the other Ruby implementations I know of:
MRI
JRuby for Java. Its speed advantage isn't as great now that Ruby 1.9 is out, but it's still a big player for its integration with Java.
IronRuby (still in development) for .NET
MacRuby for making native Mac OS X applications. It's currently based on Ruby 1.9, but they're going to release a new LLVM-based virtual machine for the next version, which looks to offer a major speed boost and will hopefully be portable to other LLVM target platforms.
MagLev (still very much in development) for high-capacity Web apps. It will probably be a commercial product.
Rubinius is a ground-up reimplementation meant as an alternative to MRI with a much cleaner foundation.
I doubt Blue Ruby will have much of an impact on the general software development landscape. It will probably be nice for SAP programmers and allow them to cast a wider net for potential hires since Ruby is somewhat more popular than ABAP.
All of the current Ruby implementations are compiled to bytecode. Contrary to SAP's claims, as of Ruby 1.9, MRI itself includes a bytecode compiler, though the ability to save the compiled bytecode to disk disappeared somewhere in the process of merging the YARV virtual machine. JRuby is compiled into Java .class files. I don't have a lot of details on MagLev, but it seems safe to say it will take that road as well.
Each implementation has its own use cases. JRuby is useful for much the same reasons Jython is. IronRuby will be useful in a .NET environment, when it exists in a usable state.
Things like this make Ruby more acceptable on the Enterprise level, and hasten the spread of Good Programming Languages.
Of course, Blue Ruby is intended for SAP related people. I don't think is going to have much more of an impact on the Ruby community because most Ruby developers are not related to ABAP development.
The main purpose of Blue Ruby is to bring a powerful Scripting Language into the ABAP world, providing more tools for ABAP developers.
You can read my blog on Blue Ruby providing an SE16 (Data table explorer) emulator.
https://weblogs.sdn.sap.com/pub/wlg/14222
Greetings,
Alvaro "Blag" Tejada Galindo.
Senior ABAP Consultant - SAP Mentor.

Resources