C++ vs C# for Rhino?


#1

Hi All

Firstly I realize this is a subjective topic, and I apologise ahead of time, but, I have been considering buckling down to learn C++ (just for fun) but everywhere else I go on the web it seems to be a dying language as most modern applications outside of IoT device programming, no longer have the requirement for the strict size and memory constraints of the past?

Is there any significant speed increase in writing rhino plugins in C++, or any other advantage?

Regards CB


(Nathan 'jesterKing' Letwory) #2

C++ is far from a dying language. Between C++ and C# the first is closer to the metal, as C# runs in a virtual runtime. Now that doesn’t necessarily mean C# is slower, it depends on the developer to achieve in-depth understanding about that extra layer in between, but it is possible to write high performance code in .NET.

My take on learning a new language: go for it. It’ll add to your toolkit for solving your problems. Not only well you learn a new language, you’ll learn its concepts, its strong points. It’ll teach you how to learn to think in new ways about the same problems, allowing you to come up with new solutions. Once you’ve done C++ start more languages: procedural languages, functional languages, and so on. It is not about the language per se, it is about learning new ways.


(Menno Deij - van Rijswijk) #3

First of all, learning a new language is always a good idea. Having experience in both languages and using them for rhino, I can advise you: use C#. Almost all functionality that is exposed in the C++ SDK is available in C# in RhinoCommon. And you don’t need to worry about memory management, which can be a huge time saver. For me, the difference in coding in C++ vs. C# is like riding a horse-drawn carriage or taking the train. The speed at which I can develop stuff for rhino in C# is about 5-10 times higher.


#4

Thank you for that. Pretty much confirms what Ive read everywhere else. The only compelling reason would be tighter memory management. For Rhino I dont think this is an issue but Ill still give it a punt even if just to be able to understand the librarys for ardiono which are almost eclusively in c.


(Nathan 'jesterKing' Letwory) #5

Note that C again is different from C++ … Maybe not much, but crucially not OOP built in.


(Menno Deij - van Rijswijk) #6

The only compelling reason would be tighter memory management.

The way RhinoCommon works is that it is a layer that sits on top of the C++ Rhino SDK. When you create a geometry object in RhinoCommon, it will ask the C++ library to create such an object, which gets wrapped by RhinoCommon. Whenever the object can be garbage collected by the .NET runtime, the C++ memory of the object will be freed.

If you want more control over when that happens, you can use the .Dispose() method of the object to immediately free the memory claimed by the C++ object. All geometry objects in RhinoCommon (that inherit from GeometryBase) have such a .Dispose() method. This can be useful, for instance if you create a lot of temporary geometry objects in a long loop. Calling .Dispose() when you no longer need the object will reclaim the memory.


#7

Sweet. Thank you that makes sense. Its the same way arduino ide works then. All the libraries are c based but all the core functions in the idea are translated from C# then compiled from c to binary (i guess).

Is it possible to compile C# to binary code? Im guessing as an interpreted language for .net probably not?

I want to release a free version of my plugin to the members of a forum Im on but C# .net compiles are ridiculously easy to decompile even after obsfucating.


(Nathan 'jesterKing' Letwory) #8

Nope. Your code gets compiled to .NET intermediate language, which gets JITted (just-in-time compiled) when run. If you really think you need to protect your code you can always write your core in C/C++, and write wrapping code in C#. But I doubt that many users would even consider decompiling your code. Besides, if someone really wanted to, they could reverse engineer the code from a binary compiled C/C++ code as well.

/Nathan


#9

Thanks. Pity. Ive written some really neat stuff for my CAD team but it belongs to the company. But in my industry code is torn apart on 0day release… take a wander past cgpersia.com. virtually every usefull jewellry plugin for rhino is ripped to shreds instantly.