« Google's Browser | Main | October 31 »

Oct 31, 2005

Comments

Susan Potter

I wanted to give CAD users a better understanding of Ruby from a programmer than just the above, "Rather than solve complex programming problems...Ruby seems more like AutoLISP -- designed to dash some lines of code to solve an immediate problem.".

As a note about who I am: I am a veteran software engineer with 10 years professional experience in C, C++, Java, Python and Ruby. In fact my blog url link below is about my Ruby and Python adventures.

While Ruby allows coders to get scripts working quickly, Ruby is still very capable of solving complex programming problems just like C, C++ or .NET languages such as C#. In fact, I would argue that if speed wasn't too important (although Ruby isn't as slow in my experience as, say, Java or C#), I would suggest CAD users utilize Ruby over C, C++ or even C# because of the following reasons:


  • Ruby provides an interactive shell where you can type in Ruby code to see what works before writing it into your Ruby source files.

  • Ruby is fully OO capable, if you are a programmer this would certainly matter and even if not, if you plan on writing a medium to large scale CAD library, you should look into how to organize your code better using OO. It could save you so much time in the future depending on what scale your codebase will be built to.

  • Ruby doesn't take forever to compile. For all intents and purposes when you run Ruby source files (98% of programmers do not need to know what really goes on when you run the ruby command to run a script) Ruby simply runs the source code. With C, C++, Java and even C# you must compile (or byte-compile) your source code before you can think about running your script. If you have a lot of C or C++ source files this can take a very long time. I was once on a medium sized C++ project where the build took 1.5 hours - no joke. Let me stress if you have a compilation error in your code you do not find out about it until the build ends (on average this will be half the usual time of the build), so you can waste so much time on C or C++ projects just getting it to compile before you test any code running.

  • The language is simple and elegant. While Ruby has some very powerful features, a quick hacker (the non-professional programmer) who writes small scripts does not need to worry about learning fairly involved concepts (which Ruby does still have). However, with C or C++ most vendor libraries expose nasty creatures such as pointers in one form or another. For a non-programmer this can be very daunting and extremely counter-productive. As with Python, the great thing about Ruby is that you only need to learn what you need from the Ruby language before you start coding.


All-in-all Ruby (as is Python for the most part) is an ideal choice for an API where the people using the libraries aren't necessarily programmers by day. I would even urge vendor developers to expose Ruby or Python for use full developer-oriented APIs as well.

Also for those that do not want to use C++ for AutoCAD work, there is a tool called Swig where you can roughly translate a C++ API into Ruby or Python bindings for your to use instead of the C++ library. You can find Swig at:
http://www.swig.org/

This could save you tons of time.

Susan Potter

For the programmers out there using Ruby to program against CAD or GIS applications:

I need to make a quick qualification to my posting above, which is that while Swig will provide you with the ability to write Ruby code, the API you can use will be in the style of a C++ API. This is simply because Swig unintelligently translates what is in C++ directly to a Ruby binding. So some of the benefits of using a Ruby designed API will obviously not be there for this reason.

prakash bajaj

Susan
your article was very informative.
thanks for such a good article

prakash

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.

Your Information

(Name is required. Email address will not be displayed with the comment.)

Advertisements


Search This Blog


  •  

Translate

Thank you for visiting!