Software Architecture : how to reach the next level in C# for Rh+Gh?

Hello,

As a structural engineer & phd, I’ve used Rhino & Grasshopper for more than 10+ years in my day to day business. I’ve coded hundreds of scripts and a few Rh/Gh plugins, mainly in C# + RhinoCommon. All this works at a certain complexity level.

Although I come from an “AEC background”, programming has always been a second skill to me. However, I feel I would benefit to take this skill to the next level in terms of software architecture.

1) Best practices / Resources

What resources (book, blog, youtube, …) would you recommend to gain practical knowledge in designing small scale C# softwares in terms of architecture : inheritance & interfaces, types, data modelling, patterns ? Something useful to make real life decisions, not too abstract/generic but yet conceptual.

2) (Generic) Use case

Frequently, I want to develop a standalone core library with some logic. Usually it’s a sort of computational engine (MyEngine.Core). In this single-file-library I want:

  • as few external dependencies as possible and easy to test independently
  • easy to embed in other softwares / ideally cross platform
  • provide a minimal usage of it through a basic console application with input/output files

In the other hand, because all I do ends in Rh+Gh for its power, I also want to provide a kind of GUI to this library (MyEngine.Gh for a Gh plugin) :

  • easy to build the inputs through rhino geometry
  • easy to visualise results of the engine
  • use existing plugins
  • easy to distribute to others

What I am describing here is a case where the MyEngine.Core is fully independent of Rhino. This would not be the case if my logic relies on complex nurbs operations or Rh types such as Curves or Surfaces.

In this use case, what kind of architecture would you recommend ?

  • Resort on interfaces in the MyEngine.Core and implement those interfaces on custom Types and Parameters in Gh. I can then pass those types directly to the MyEngine.Core logic to do the computations ?

  • Resort on concrete classes in the MyEngine.Core and extend (or simply embed ?) those types in custom Types and Parameters in Gh ?

Thank you in advance for your advices.
If “part 2” needs a more precise example, I can provide one.

1 Like

Hey @lionpeloux,

I feel like I am in the same boat. I am looking for open projects that demonstrate ways to make my algorithms accessible from within rhino, grasshopper, and potential outside of the rhino environment all together.

I think @dale put together a great example called Moose showing how to make a C++ code base that can be used by a C++ rhino plugin, a C# rhino plugin, and a C# grasshopper plugin.

I am thinking this architecture sounds a lot like what you are looking for. You would just need to make sure the code base (could be C++ or whatever you really want) doesn’t have any rhino dependency if you want to use that source code outside of the ecosystem.

Hey @lionpeloux,

Personally I found reading these coding books to be extremely helpful in moving to the “Next Level”. I work as a Software Architect with a team of 9, and now that everyone has read these books, the code and bug reporting has really improved.

Firstly,
Clean Code
And then,
Clean Architecture

– cs

1 Like

+1 for Clean Architecture and Clean Code (I’d recommend them in a reversed order, but whatever ;)) there is also “The Clean Coder” from the same author, which is also something I would recommend. This blog could be helpful as well: https://refactoring.guru/

There is a huge jump once you create something not for yourself, but for anybody to use. There is a huge jump once you write code not for yourself, but for anybody else to understand and modify. There is a huge jump once you write code that doesn’t depend on existing libraries or apps (such as Rhino). Books are helpful, but you need to try it yourself, see what’s working out for you, what’s not, have your own opinion on what’s worth spending time on, what’s not. These topics are really subjective, different developers value different things.

1 Like

I totally got my order wrong, thanks @w.radaczynski. I’ve re-ordered them

Thanks for these references.
I’ll have a look on them asap.